lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.3.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.4.0
- old
+ new
@@ -11,11 +11,10 @@
this.resetPage();
}
Browser.prototype.resetPage = function() {
var _this = this;
-
if (this.page != null) {
this.page.release();
phantom.clearCookies();
}
this.page = new Poltergeist.WebPage;
@@ -48,11 +47,10 @@
this.page.onInitialized = function() {
return _this.page_id += 1;
};
return this.page.onPageCreated = function(sub_page) {
var name;
-
if (_this.state === 'awaiting_sub_page') {
name = _this.page_name;
_this.page_name = null;
_this.setState('default');
return setTimeout((function() {
@@ -81,11 +79,10 @@
return this.state = state;
};
Browser.prototype.sendResponse = function(response) {
var errors;
-
errors = this.page.errors();
this.page.clearErrors();
if (errors.length > 0 && this.js_errors) {
return this.owner.sendError(new Poltergeist.JavascriptError(errors));
} else {
@@ -106,13 +103,12 @@
}
};
Browser.prototype.visit = function(url) {
var prev_url;
-
this.setState('loading');
- prev_url = this.page.currentUrl();
+ prev_url = this.page.source() === null ? 'about:blank' : this.page.currentUrl();
this.page.open(url);
if (/#/.test(url) && prev_url.split('#')[0] === url.split('#')[0]) {
this.setState('default');
return this.sendResponse('success');
}
@@ -170,11 +166,10 @@
return this.sendResponse(true);
};
Browser.prototype.select_file = function(page_id, id, value) {
var node;
-
node = this.node(page_id, id);
this.page.beforeUpload(node.id);
this.page.uploadFile('[_poltergeist_selected]', value);
this.page.afterUpload(node.id);
return this.sendResponse(true);
@@ -205,11 +200,10 @@
return this.sendResponse(true);
};
Browser.prototype.push_frame = function(name, timeout) {
var _this = this;
-
if (timeout == null) {
timeout = new Date().getTime() + 2000;
}
if (this.page.pushFrame(name)) {
if (this.page.currentUrl() === 'about:blank') {
@@ -226,18 +220,21 @@
return this.owner.sendError(new Poltergeist.FrameNotFound(name));
}
}
};
+ Browser.prototype.pages = function() {
+ return this.sendResponse(this.page.pages());
+ };
+
Browser.prototype.pop_frame = function() {
return this.sendResponse(this.page.popFrame());
};
Browser.prototype.push_window = function(name) {
var sub_page,
_this = this;
-
sub_page = this.page.getPage(name);
if (sub_page) {
if (sub_page.currentUrl() === 'about:blank') {
return sub_page.onLoadFinished = function() {
sub_page.onLoadFinished = null;
@@ -255,22 +252,20 @@
}
};
Browser.prototype.pop_window = function() {
var prev_page;
-
prev_page = this.page_stack.pop();
if (prev_page) {
this.page = prev_page;
}
return this.sendResponse(true);
};
Browser.prototype.mouse_event = function(page_id, id, name) {
var node,
_this = this;
-
node = this.node(page_id, id);
this.setState('mouse_event');
this.last_mouse_event = node.mouseEvent(name);
return setTimeout(function() {
if (_this.state !== 'loading') {
@@ -319,44 +314,65 @@
Browser.prototype.reset = function() {
this.resetPage();
return this.sendResponse(true);
};
- Browser.prototype.render = function(path, full) {
- var dimensions, document, viewport;
+ Browser.prototype.scroll_to = function(left, top) {
+ this.page.setScrollPosition({
+ left: left,
+ top: top
+ });
+ return this.sendResponse(true);
+ };
- dimensions = this.page.validatedDimensions();
- document = dimensions.document;
- viewport = dimensions.viewport;
- if (full) {
- this.page.setScrollPosition({
- left: 0,
- top: 0
- });
- this.page.setClipRect({
- left: 0,
- top: 0,
- width: document.width,
- height: document.height
- });
- this.page.render(path);
- this.page.setScrollPosition({
- left: dimensions.left,
- top: dimensions.top
- });
- } else {
- this.page.setClipRect({
- left: 0,
- top: 0,
- width: viewport.width,
- height: viewport.height
- });
- this.page.render(path);
+ Browser.prototype.render_base64 = function(format, full, selector) {
+ var encoded_image;
+ if (selector == null) {
+ selector = null;
}
+ this.set_clip_rect(full, selector);
+ encoded_image = this.page.renderBase64(format);
+ return this.sendResponse(encoded_image);
+ };
+
+ Browser.prototype.render = function(path, full, selector) {
+ var dimensions;
+ if (selector == null) {
+ selector = null;
+ }
+ dimensions = this.set_clip_rect(full, selector);
+ this.page.setScrollPosition({
+ left: 0,
+ top: 0
+ });
+ this.page.render(path);
+ this.page.setScrollPosition({
+ left: dimensions.left,
+ top: dimensions.top
+ });
return this.sendResponse(true);
};
+ Browser.prototype.set_clip_rect = function(full, selector) {
+ var dimensions, document, rect, viewport, _ref;
+ dimensions = this.page.validatedDimensions();
+ _ref = [dimensions.document, dimensions.viewport], document = _ref[0], viewport = _ref[1];
+ rect = full ? {
+ left: 0,
+ top: 0,
+ width: document.width,
+ height: document.height
+ } : selector != null ? this.page.elementBounds(selector) : {
+ left: 0,
+ top: 0,
+ width: viewport.width,
+ height: viewport.height
+ };
+ this.page.setClipRect(rect);
+ return dimensions;
+ };
+
Browser.prototype.resize = function(width, height) {
this.page.setViewportSize({
width: width,
height: height
});
@@ -365,15 +381,36 @@
Browser.prototype.network_traffic = function() {
return this.sendResponse(this.page.networkTraffic());
};
+ Browser.prototype.get_headers = function() {
+ return this.sendResponse(this.page.getCustomHeaders());
+ };
+
Browser.prototype.set_headers = function(headers) {
if (headers['User-Agent']) {
this.page.setUserAgent(headers['User-Agent']);
}
this.page.setCustomHeaders(headers);
return this.sendResponse(true);
+ };
+
+ Browser.prototype.add_headers = function(headers) {
+ var allHeaders, name, value;
+ allHeaders = this.page.getCustomHeaders();
+ for (name in headers) {
+ value = headers[name];
+ allHeaders[name] = value;
+ }
+ return this.set_headers(allHeaders);
+ };
+
+ Browser.prototype.add_header = function(header, permanent) {
+ if (!permanent) {
+ this.page.addTempHeader(header);
+ }
+ return this.add_headers(header);
};
Browser.prototype.response_headers = function() {
return this.sendResponse(this.page.responseHeaders());
};