lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.12.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.13.0
- old
+ new
@@ -1,7 +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; },
- slice = [].slice;
+var slice = [].slice,
+ 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; };
Poltergeist.Browser = (function() {
function Browser(width, height) {
this.width = width || 1024;
this.height = height || 768;
@@ -247,16 +247,36 @@
Browser.prototype.path = function(page_id, id) {
return this.current_command.sendResponse(this.node(page_id, id).path());
};
- Browser.prototype.evaluate = function(script) {
- return this.current_command.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
+ Browser.prototype.evaluate = function() {
+ var arg, args, i, len, ref, script;
+ script = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
+ for (i = 0, len = args.length; i < len; i++) {
+ arg = args[i];
+ if (this._isElementArgument(arg)) {
+ if (arg["ELEMENT"]["page_id"] !== this.currentPage.id) {
+ throw new Poltergeist.ObsoleteNode;
+ }
+ }
+ }
+ return this.current_command.sendResponse((ref = this.currentPage).evaluate.apply(ref, ["function() { return " + script + " }"].concat(slice.call(args))));
};
- Browser.prototype.execute = function(script) {
- this.currentPage.execute("function() { " + script + " }");
+ Browser.prototype.execute = function() {
+ var arg, args, i, len, ref, script;
+ script = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
+ for (i = 0, len = args.length; i < len; i++) {
+ arg = args[i];
+ if (this._isElementArgument(arg)) {
+ if (arg["ELEMENT"]["page_id"] !== this.currentPage.id) {
+ throw new Poltergeist.ObsoleteNode;
+ }
+ }
+ }
+ (ref = this.currentPage).execute.apply(ref, ["function() { " + script + " }"].concat(slice.call(args)));
return this.current_command.sendResponse(true);
};
Browser.prototype.frameUrl = function(frame_name) {
return this.currentPage.frameUrl(frame_name);
@@ -448,40 +468,55 @@
});
return this.current_command.sendResponse(true);
};
Browser.prototype.send_keys = function(page_id, id, keys) {
- var i, j, k, key, len, len1, len2, modifier_code, modifier_key, modifier_keys, sequence, target;
+ var target;
target = this.node(page_id, id);
if (!target.containsSelection()) {
target.mouseEvent('click');
}
+ this._send_keys_with_modifiers(keys);
+ return this.current_command.sendResponse(true);
+ };
+
+ Browser.prototype._send_keys_with_modifiers = function(keys, current_modifier_code) {
+ var i, j, key, len, len1, modifier_code, modifier_key, modifier_keys, results, sequence;
+ if (current_modifier_code == null) {
+ current_modifier_code = 0;
+ }
+ results = [];
for (i = 0, len = keys.length; i < len; i++) {
sequence = keys[i];
key = sequence.key != null ? this.currentPage.keyCode(sequence.key) || sequence.key : sequence;
if (sequence.modifier != null) {
modifier_keys = this.currentPage.keyModifierKeys(sequence.modifier);
- modifier_code = this.currentPage.keyModifierCode(sequence.modifier);
+ modifier_code = this.currentPage.keyModifierCode(sequence.modifier) | current_modifier_code;
for (j = 0, len1 = modifier_keys.length; j < len1; j++) {
modifier_key = modifier_keys[j];
this.currentPage.sendEvent('keydown', modifier_key);
}
- this.currentPage.sendEvent('keypress', key, null, null, modifier_code);
- for (k = 0, len2 = modifier_keys.length; k < len2; k++) {
- modifier_key = modifier_keys[k];
- this.currentPage.sendEvent('keyup', modifier_key);
- }
+ this._send_keys_with_modifiers([].concat(key), modifier_code);
+ results.push((function() {
+ var k, len2, results1;
+ results1 = [];
+ for (k = 0, len2 = modifier_keys.length; k < len2; k++) {
+ modifier_key = modifier_keys[k];
+ results1.push(this.currentPage.sendEvent('keyup', modifier_key));
+ }
+ return results1;
+ }).call(this));
} else {
- this.currentPage.sendEvent('keypress', key);
+ results.push(this.currentPage.sendEvent('keypress', key, null, null, current_modifier_code));
}
}
- return this.current_command.sendResponse(true);
+ return results;
};
- Browser.prototype.render_base64 = function(format, arg) {
+ Browser.prototype.render_base64 = function(format, arg1) {
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;
+ ref = arg1 != null ? arg1 : {}, 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,
@@ -489,13 +524,13 @@
});
(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, arg) {
+ Browser.prototype.render = function(path, arg1) {
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;
+ ref = arg1 != null ? arg1 : {}, 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;
@@ -729,9 +764,13 @@
Browser.prototype._wildcardToRegexp = function(wildcard) {
wildcard = wildcard.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&");
wildcard = wildcard.replace(/\*/g, ".*");
wildcard = wildcard.replace(/\?/g, ".");
return new RegExp(wildcard, "i");
+ };
+
+ Browser.prototype._isElementArgument = function(arg) {
+ return typeof arg === "object" && typeof arg['ELEMENT'] === "object";
};
return Browser;
})();