lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.5.1 vs lib/capybara/poltergeist/client/compiled/agent.js in poltergeist-1.6.0

- old
+ new

@@ -42,11 +42,11 @@ } } }; PoltergeistAgent.prototype.currentUrl = function() { - return encodeURI(window.location.href); + return encodeURI(decodeURI(window.location.href)); }; PoltergeistAgent.prototype.find = function(method, selector, within) { var el, error, i, results, xpath, _i, _len, _results; if (within == null) { @@ -87,12 +87,12 @@ return this.elements.length - 1; }; PoltergeistAgent.prototype.documentSize = function() { return { - height: document.documentElement.scrollHeight, - width: document.documentElement.scrollWidth + height: document.documentElement.scrollHeight || document.documentElement.clientHeight, + width: document.documentElement.scrollWidth || document.documentElement.clientWidth }; }; PoltergeistAgent.prototype.get = function(id) { var _base; @@ -114,10 +114,14 @@ PoltergeistAgent.prototype.afterUpload = function(id) { return this.get(id).removeAttribute('_poltergeist_selected'); }; + PoltergeistAgent.prototype.clearLocalStorage = function() { + return localStorage.clear(); + }; + return PoltergeistAgent; })(); PoltergeistAgent.ObsoleteNode = (function() { @@ -143,11 +147,12 @@ })(); PoltergeistAgent.Node = (function() { Node.EVENTS = { FOCUS: ['blur', 'focus', 'focusin', 'focusout'], - MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup'] + MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'contextmenu'], + FORM: ['submit'] }; function Node(agent, element) { this.agent = agent; this.element = element; @@ -155,10 +160,21 @@ Node.prototype.parentId = function() { return this.agent.register(this.element.parentNode); }; + Node.prototype.parentIds = function() { + var ids, parent; + ids = []; + parent = this.element.parentNode; + while (parent !== document) { + ids.push(this.agent.register(parent)); + parent = parent.parentNode; + } + return ids; + }; + Node.prototype.find = function(method, selector) { return this.agent.find(method, selector, this.element); }; Node.prototype.isObsolete = function() { @@ -224,25 +240,39 @@ Node.prototype.allText = function() { return this.element.textContent; }; Node.prototype.visibleText = function() { - if (this.element.nodeName === "TEXTAREA") { - return this.element.textContent; - } else { - return this.element.innerText; + if (this.isVisible()) { + if (this.element.nodeName === "TEXTAREA") { + return this.element.textContent; + } else { + return this.element.innerText; + } } }; Node.prototype.deleteText = function() { var range; range = document.createRange(); range.selectNodeContents(this.element); + window.getSelection().removeAllRanges(); window.getSelection().addRange(range); return window.getSelection().deleteFromDocument(); }; + Node.prototype.getAttributes = function() { + var attr, attrs, i, _i, _len, _ref; + attrs = {}; + _ref = this.element.attributes; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + attr = _ref[i]; + attrs[attr.name] = attr.value.replace("\n", "\\n"); + } + return attrs; + }; + Node.prototype.getAttribute = function(name) { if (name === 'checked' || name === 'selected') { return this.element[name]; } else { return this.element.getAttribute(name); @@ -338,10 +368,22 @@ Node.prototype.isDisabled = function() { return this.element.disabled || this.element.tagName === 'OPTION' && this.element.parentNode.disabled; }; + Node.prototype.containsSelection = function() { + var selectedNode; + selectedNode = document.getSelection().focusNode; + if (!selectedNode) { + return false; + } + if (selectedNode.nodeType === 3) { + selectedNode = selectedNode.parentNode; + } + return this.element.contains(selectedNode); + }; + Node.prototype.frameOffset = function() { var offset, rect, style, win; win = window; offset = { top: 0, @@ -379,15 +421,23 @@ var event; if (Node.EVENTS.MOUSE.indexOf(name) !== -1) { event = document.createEvent('MouseEvent'); event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) { - event = document.createEvent('HTMLEvents'); - event.initEvent(name, true, true); + event = this.obtainEvent(name); + } else if (Node.EVENTS.FORM.indexOf(name) !== -1) { + event = this.obtainEvent(name); } else { throw "Unknown event"; } return this.element.dispatchEvent(event); + }; + + Node.prototype.obtainEvent = function(name) { + var event; + event = document.createEvent('HTMLEvents'); + event.initEvent(name, true, true); + return event; }; Node.prototype.mouseEventTest = function(x, y) { var el, frameOffset, origEl; frameOffset = this.frameOffset();