lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.9.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.10.0
- old
+ new
@@ -1,6 +1,7 @@
-var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
+ slice = [].slice;
Poltergeist.Browser = (function() {
function Browser(width, height) {
this.width = width || 1024;
this.height = height || 768;
@@ -66,10 +67,13 @@
this.page.onPageCreated = (function(_this) {
return function(newPage) {
var page;
page = new Poltergeist.WebPage(newPage);
page.handle = "" + (_this._counter++);
+ page.urlBlacklist = _this.page.urlBlacklist;
+ page.urlWhitelist = _this.page.urlWhitelist;
+ page.setViewportSize(_this.page.viewportSize());
return _this.pages.push(page);
};
})(this);
};
@@ -107,11 +111,11 @@
throw new Poltergeist.ObsoleteNode;
}
};
Browser.prototype.visit = function(url, max_wait) {
- var command, prevUrl;
+ var command, loading_page, prevUrl;
if (max_wait == null) {
max_wait = 0;
}
this.currentPage.state = 'loading';
this.processed_modal_messages = [];
@@ -124,28 +128,25 @@
return this.current_command.sendResponse({
status: 'success'
});
} else {
command = this.current_command;
- this.currentPage.waitState('default', (function(_this) {
- return function() {
- if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
- return command.sendError(new Poltergeist.StatusFailError(url));
- } else {
- return command.sendResponse({
- status: _this.currentPage.status
- });
- }
- };
- })(this), max_wait, (function(_this) {
- return function() {
- var msg, resources;
- resources = _this.currentPage.openResourceRequests();
- msg = resources.length ? "Timed out with the following resources still waiting " + (_this.currentPage.openResourceRequests().join(',')) : void 0;
- return command.sendError(new Poltergeist.StatusFailError(url, msg));
- };
- })(this));
+ loading_page = this.currentPage;
+ this.currentPage.waitState('default', function() {
+ if (this.statusCode === null && this.status === 'fail') {
+ return command.sendError(new Poltergeist.StatusFailError(url));
+ } else {
+ return command.sendResponse({
+ status: this.status
+ });
+ }
+ }, max_wait, function() {
+ var msg, resources;
+ resources = this.openResourceRequests();
+ msg = resources.length ? "Timed out with the following resources still waiting " + (resources.join(',')) : void 0;
+ return command.sendError(new Poltergeist.StatusFailError(url, msg));
+ });
}
};
Browser.prototype.current_url = function() {
return this.current_command.sendResponse(this.currentPage.currentUrl());
@@ -260,29 +261,28 @@
Browser.prototype.frameUrl = function(frame_name) {
return this.currentPage.frameUrl(frame_name);
};
Browser.prototype.pushFrame = function(command, name, timeout) {
- var frame, ref;
+ var frame, frame_url;
if (Array.isArray(name)) {
frame = this.node.apply(this, name);
name = frame.getAttribute('name') || frame.getAttribute('id');
if (!name) {
frame.setAttribute('name', "_random_name_" + (new Date().getTime()));
name = frame.getAttribute('name');
}
}
- if (ref = this.frameUrl(name), indexOf.call(this.currentPage.blockedUrls(), ref) >= 0) {
+ frame_url = this.frameUrl(name);
+ if (indexOf.call(this.currentPage.blockedUrls(), frame_url) >= 0) {
return command.sendResponse(true);
} else if (this.currentPage.pushFrame(name)) {
- if (this.currentPage.currentUrl() === 'about:blank') {
+ if (frame_url && (frame_url !== 'about:blank') && (this.currentPage.currentUrl() === 'about:blank')) {
this.currentPage.state = 'awaiting_frame_load';
- return this.currentPage.waitState('default', (function(_this) {
- return function() {
- return command.sendResponse(true);
- };
- })(this));
+ return this.currentPage.waitState('default', function() {
+ return command.sendResponse(true);
+ });
} else {
return command.sendResponse(true);
}
} else {
if (new Date().getTime() < timeout) {
@@ -328,18 +328,18 @@
})[0], page ? page.handle : null) : this.currentPage.handle;
return this.current_command.sendResponse(handle);
};
Browser.prototype.switch_to_window = function(handle) {
- var command, page;
+ var command, new_page;
command = this.current_command;
- page = this.getPageByHandle(handle);
- if (page) {
- if (page !== this.currentPage) {
- return page.waitState('default', (function(_this) {
+ new_page = this.getPageByHandle(handle);
+ if (new_page) {
+ if (new_page !== this.currentPage) {
+ return new_page.waitState('default', (function(_this) {
return function() {
- _this.currentPage = page;
+ _this.currentPage = new_page;
return command.sendResponse(true);
};
})(this));
} else {
return command.sendResponse(true);
@@ -364,31 +364,30 @@
return this.current_command.sendResponse(false);
}
};
Browser.prototype.mouse_event = function(page_id, id, name) {
- var command, node;
+ var command, event_page, last_mouse_event, node;
node = this.node(page_id, id);
this.currentPage.state = 'mouse_event';
- this.last_mouse_event = node.mouseEvent(name);
+ last_mouse_event = node.mouseEvent(name);
+ event_page = this.currentPage;
command = this.current_command;
- return setTimeout((function(_this) {
- return function() {
- if (_this.currentPage.state === 'mouse_event') {
- _this.currentPage.state = 'default';
+ return setTimeout(function() {
+ if (event_page.state === 'mouse_event') {
+ event_page.state = 'default';
+ return command.sendResponse({
+ position: last_mouse_event
+ });
+ } else {
+ return event_page.waitState('default', function() {
return command.sendResponse({
- position: _this.last_mouse_event
+ position: last_mouse_event
});
- } else {
- return _this.currentPage.waitState('default', function() {
- return command.sendResponse({
- position: _this.last_mouse_event
- });
- });
- }
- };
- })(this), 5);
+ });
+ }
+ }, 5);
};
Browser.prototype.click = function(page_id, id) {
return this.mouse_event(page_id, id, 'click');
};
@@ -473,35 +472,46 @@
}
}
return this.current_command.sendResponse(true);
};
- Browser.prototype.render_base64 = function(format, full, selector) {
- var encoded_image;
- if (selector == null) {
- selector = null;
- }
- this.set_clip_rect(full, selector);
+ Browser.prototype.render_base64 = function(format, arg) {
+ var dimensions, encoded_image, full, ref, ref1, ref2, ref3, selector, window_scroll_position;
+ ref = arg != null ? arg : {}, full = (ref1 = ref.full) != null ? ref1 : false, selector = (ref2 = ref.selector) != null ? ref2 : null;
+ window_scroll_position = this.currentPage["native"]().evaluate("function(){ return [window.pageXOffset, window.pageYOffset] }");
+ dimensions = this.set_clip_rect(full, selector);
encoded_image = this.currentPage.renderBase64(format);
+ this.currentPage.setScrollPosition({
+ left: dimensions.left,
+ top: dimensions.top
+ });
+ (ref3 = this.currentPage["native"]()).evaluate.apply(ref3, ["window.scrollTo"].concat(slice.call(window_scroll_position)));
return this.current_command.sendResponse(encoded_image);
};
- Browser.prototype.render = function(path, full, selector) {
- var dimensions;
- if (selector == null) {
- selector = null;
- }
+ Browser.prototype.render = function(path, arg) {
+ var dimensions, format, full, options, quality, ref, ref1, ref2, ref3, ref4, ref5, selector, window_scroll_position;
+ ref = arg != null ? arg : {}, full = (ref1 = ref.full) != null ? ref1 : false, selector = (ref2 = ref.selector) != null ? ref2 : null, format = (ref3 = ref.format) != null ? ref3 : null, quality = (ref4 = ref.quality) != null ? ref4 : null;
+ window_scroll_position = this.currentPage["native"]().evaluate("function(){ return [window.pageXOffset, window.pageYOffset] }");
dimensions = this.set_clip_rect(full, selector);
+ options = {};
+ if (format != null) {
+ options["format"] = format;
+ }
+ if (quality != null) {
+ options["quality"] = quality;
+ }
this.currentPage.setScrollPosition({
left: 0,
top: 0
});
- this.currentPage.render(path);
+ this.currentPage.render(path, options);
this.currentPage.setScrollPosition({
left: dimensions.left,
top: dimensions.top
});
+ (ref5 = this.currentPage["native"]()).evaluate.apply(ref5, ["window.scrollTo"].concat(slice.call(window_scroll_position)));
return this.current_command.sendResponse(true);
};
Browser.prototype.set_clip_rect = function(full, selector) {
var dimensions, document, rect, ref, viewport;
@@ -547,10 +557,15 @@
Browser.prototype.clear_network_traffic = function() {
this.currentPage.clearNetworkTraffic();
return this.current_command.sendResponse(true);
};
+ Browser.prototype.set_proxy = function(ip, port, type, user, password) {
+ phantom.setProxy(ip, port, type, user, password);
+ return this.current_command.sendResponse(true);
+ };
+
Browser.prototype.get_headers = function() {
return this.current_command.sendResponse(this.currentPage.getCustomHeaders());
};
Browser.prototype.set_headers = function(headers) {
@@ -635,15 +650,13 @@
var command;
command = this.current_command;
if (this.currentPage.canGoBack) {
this.currentPage.state = 'loading';
this.currentPage.goBack();
- return this.currentPage.waitState('default', (function(_this) {
- return function() {
- return command.sendResponse(true);
- };
- })(this));
+ return this.currentPage.waitState('default', function() {
+ return command.sendResponse(true);
+ });
} else {
return command.sendResponse(false);
}
};
@@ -651,27 +664,45 @@
var command;
command = this.current_command;
if (this.currentPage.canGoForward) {
this.currentPage.state = 'loading';
this.currentPage.goForward();
- return this.currentPage.waitState('default', (function(_this) {
- return function() {
- return command.sendResponse(true);
- };
- })(this));
+ return this.currentPage.waitState('default', function() {
+ return command.sendResponse(true);
+ });
} else {
return command.sendResponse(false);
}
};
Browser.prototype.set_url_whitelist = function() {
- this.currentPage.urlWhitelist = Array.prototype.slice.call(arguments);
+ var wc, wildcards;
+ wildcards = 1 <= arguments.length ? slice.call(arguments, 0) : [];
+ this.currentPage.urlWhitelist = (function() {
+ var i, len, results;
+ results = [];
+ for (i = 0, len = wildcards.length; i < len; i++) {
+ wc = wildcards[i];
+ results.push(this._wildcardToRegexp(wc));
+ }
+ return results;
+ }).call(this);
return this.current_command.sendResponse(true);
};
Browser.prototype.set_url_blacklist = function() {
- this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
+ var wc, wildcards;
+ wildcards = 1 <= arguments.length ? slice.call(arguments, 0) : [];
+ this.currentPage.urlBlacklist = (function() {
+ var i, len, results;
+ results = [];
+ for (i = 0, len = wildcards.length; i < len; i++) {
+ wc = wildcards[i];
+ results.push(this._wildcardToRegexp(wc));
+ }
+ return results;
+ }).call(this);
return this.current_command.sendResponse(true);
};
Browser.prototype.set_confirm_process = function(process) {
this.confirm_processes.push(process);
@@ -683,9 +714,21 @@
return this.current_command.sendResponse(true);
};
Browser.prototype.modal_message = function() {
return this.current_command.sendResponse(this.processed_modal_messages.shift());
+ };
+
+ Browser.prototype.clear_memory_cache = function() {
+ this.currentPage.clearMemoryCache();
+ return this.current_command.sendResponse(true);
+ };
+
+ Browser.prototype._wildcardToRegexp = function(wildcard) {
+ wildcard = wildcard.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&");
+ wildcard = wildcard.replace(/\*/g, ".*");
+ wildcard = wildcard.replace(/\?/g, ".");
+ return new RegExp(wildcard, "i");
};
return Browser;
})();