lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.14.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.15.0

- old
+ new

@@ -143,11 +143,11 @@ }); } }, max_wait, function() { var msg, resources; resources = this.openResourceRequests(); - msg = resources.length ? "Timed out with the following resources still waiting " + (resources.join(',')) : void 0; + msg = resources.length ? "Timed out with the following resources still waiting " + (resources.join(',')) : "Timed out with no open resource requests"; return command.sendError(new Poltergeist.StatusFailError(url, msg)); }); } }; @@ -481,40 +481,43 @@ 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; + var i, j, k, key, len, len1, len2, modifier_code, modifier_key, modifier_keys, 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.key != null) { + if (!(key = this.currentPage.keyCode(sequence.key))) { + this.current_command.sendError(new Poltergeist.KeyError("Unknown key: " + sequence.key)); + return; + } + } else if (sequence.keys != null) { + key = sequence.keys; + } else { + key = sequence; + } if (sequence.modifier != null) { modifier_keys = this.currentPage.keyModifierKeys(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._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)); + for (k = 0, len2 = modifier_keys.length; k < len2; k++) { + modifier_key = modifier_keys[k]; + this.currentPage.sendEvent('keyup', modifier_key); + } } else { - results.push(this.currentPage.sendEvent('keypress', key, null, null, current_modifier_code)); + this.currentPage.sendEvent('keypress', key, null, null, current_modifier_code); } } - return results; + return true; }; Browser.prototype.render_base64 = function(format, arg1) { var dimensions, encoded_image, full, ref, ref1, ref2, ref3, selector, window_scroll_position; ref = arg1 != null ? arg1 : {}, full = (ref1 = ref.full) != null ? ref1 : false, selector = (ref2 = ref.selector) != null ? ref2 : null; @@ -691,34 +694,26 @@ Browser.prototype.browser_error = function() { throw new Error('zomg'); }; Browser.prototype.go_back = function() { - var command; - command = this.current_command; if (this.currentPage.canGoBack) { - this.currentPage.state = 'loading'; + this.currentPage.state = 'wait_for_loading'; this.currentPage.goBack(); - return this.currentPage.waitState('default', function() { - return command.sendResponse(true); - }); + return this._waitForHistoryChange(); } else { - return command.sendResponse(false); + return this.current_command.sendResponse(false); } }; Browser.prototype.go_forward = function() { - var command; - command = this.current_command; if (this.currentPage.canGoForward) { - this.currentPage.state = 'loading'; + this.currentPage.state = 'wait_for_loading'; this.currentPage.goForward(); - return this.currentPage.waitState('default', function() { - return command.sendResponse(true); - }); + return this._waitForHistoryChange(); } else { - return command.sendResponse(false); + return this.current_command.sendResponse(false); } }; Browser.prototype.set_url_whitelist = function() { var wc, wildcards; @@ -765,9 +760,26 @@ }; Browser.prototype.clear_memory_cache = function() { this.currentPage.clearMemoryCache(); return this.current_command.sendResponse(true); + }; + + Browser.prototype._waitForHistoryChange = function() { + var command; + command = this.current_command; + return this.currentPage.waitState(['loading', 'default'], function(cur_state) { + if (cur_state === 'loading') { + return this.waitState('default', function() { + return command.sendResponse(true); + }); + } else { + return command.sendResponse(true); + } + }, 0.5, function() { + this.state = 'default'; + return command.sendResponse(true); + }); }; Browser.prototype._wildcardToRegexp = function(wildcard) { wildcard = wildcard.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&"); wildcard = wildcard.replace(/\*/g, ".*");