Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #581 from jbaudanza/master
Browse files Browse the repository at this point in the history
Change events should fire from the SELECT element, not the OPTION element.
  • Loading branch information
route committed May 18, 2015
2 parents e3fc259 + fbe45eb commit 063fb3f
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 122 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,8 @@
* Support reading text from SVG elements (Oliver Searle-Barnes)
* Whitespace character in `current_url` remained unencoded [Issue #418]

* Fix event.target for change events on SELECT elements. (Jonathan Baudanza) [Issue #204]

### 1.6.0 ###

#### Features ####
Expand Down
10 changes: 9 additions & 1 deletion lib/capybara/poltergeist/client/agent.coffee
Expand Up @@ -115,7 +115,15 @@ class PoltergeistAgent.Node
changed: ->
event = document.createEvent('HTMLEvents')
event.initEvent('change', true, false)
@element.dispatchEvent(event)

# In the case of an OPTION tag, the change event should come
# from the parent SELECT
if @element.nodeName == 'OPTION'
element = @element.parentNode
else
element = @element

element.dispatchEvent(event)

input: ->
event = document.createEvent('HTMLEvents')
Expand Down
38 changes: 22 additions & 16 deletions lib/capybara/poltergeist/client/compiled/agent.js
Expand Up @@ -153,9 +153,9 @@ PoltergeistAgent.Node = (function() {
FORM: ['submit']
};

function Node(agent, element) {
this.agent = agent;
this.element = element;
function Node(_at_agent, _at_element) {
this.agent = _at_agent;
this.element = _at_element;
}

Node.prototype.parentId = function() {
Expand All @@ -178,27 +178,33 @@ PoltergeistAgent.Node = (function() {
};

Node.prototype.isObsolete = function() {
var obsolete,
_this = this;
obsolete = function(element) {
if (element.parentNode != null) {
if (element.parentNode === document) {
return false;
var obsolete;
obsolete = (function(_this) {
return function(element) {
if (element.parentNode != null) {
if (element.parentNode === document) {
return false;
} else {
return obsolete(element.parentNode);
}
} else {
return obsolete(element.parentNode);
return true;
}
} else {
return true;
}
};
};
})(this);
return obsolete(this.element);
};

Node.prototype.changed = function() {
var event;
var element, event;
event = document.createEvent('HTMLEvents');
event.initEvent('change', true, false);
return this.element.dispatchEvent(event);
if (this.element.nodeName === 'OPTION') {
element = this.element.parentNode;
} else {
element = this.element;
}
return element.dispatchEvent(event);
};

Node.prototype.input = function() {
Expand Down
121 changes: 65 additions & 56 deletions lib/capybara/poltergeist/client/compiled/browser.js
@@ -1,8 +1,8 @@
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; };

Poltergeist.Browser = (function() {
function Browser(owner, width, height) {
this.owner = owner;
function Browser(_at_owner, width, height) {
this.owner = _at_owner;
this.width = width || 1024;
this.height = height || 768;
this.pages = [];
Expand All @@ -13,8 +13,7 @@ Poltergeist.Browser = (function() {
}

Browser.prototype.resetPage = function() {
var _ref,
_this = this;
var _ref;
_ref = [0, []], this._counter = _ref[0], this.pages = _ref[1];
if (this.page != null) {
if (!this.page.closed) {
Expand All @@ -32,12 +31,14 @@ Poltergeist.Browser = (function() {
});
this.page.handle = "" + (this._counter++);
this.pages.push(this.page);
return this.page.onPageCreated = function(newPage) {
var page;
page = new Poltergeist.WebPage(newPage);
page.handle = "" + (_this._counter++);
return _this.pages.push(page);
};
return this.page.onPageCreated = (function(_this) {
return function(newPage) {
var page;
page = new Poltergeist.WebPage(newPage);
page.handle = "" + (_this._counter++);
return _this.pages.push(page);
};
})(this);
};

Browser.prototype.getPageByHandle = function(handle) {
Expand Down Expand Up @@ -82,8 +83,7 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.visit = function(url) {
var prevUrl,
_this = this;
var prevUrl;
this.currentPage.state = 'loading';
prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
this.currentPage.open(url);
Expand All @@ -93,15 +93,17 @@ Poltergeist.Browser = (function() {
status: 'success'
});
} else {
return this.currentPage.waitState('default', function() {
if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
return _this.owner.sendError(new Poltergeist.StatusFailError);
} else {
return _this.sendResponse({
status: _this.currentPage.status
});
}
});
return this.currentPage.waitState('default', (function(_this) {
return function() {
if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
return _this.owner.sendError(new Poltergeist.StatusFailError);
} else {
return _this.sendResponse({
status: _this.currentPage.status
});
}
};
})(this));
}
};

Expand Down Expand Up @@ -208,8 +210,7 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.push_frame = function(name, timeout) {
var _ref,
_this = this;
var _ref;
if (timeout == null) {
timeout = new Date().getTime() + 2000;
}
Expand All @@ -218,17 +219,21 @@ Poltergeist.Browser = (function() {
} else if (this.currentPage.pushFrame(name)) {
if (this.currentPage.currentUrl() === 'about:blank') {
this.currentPage.state = 'awaiting_frame_load';
return this.currentPage.waitState('default', function() {
return _this.sendResponse(true);
});
return this.currentPage.waitState('default', (function(_this) {
return function() {
return _this.sendResponse(true);
};
})(this));
} else {
return this.sendResponse(true);
}
} else {
if (new Date().getTime() < timeout) {
return setTimeout((function() {
return _this.push_frame(name, timeout);
}), 50);
return setTimeout(((function(_this) {
return function() {
return _this.push_frame(name, timeout);
};
})(this)), 50);
} else {
return this.owner.sendError(new Poltergeist.FrameNotFound(name));
}
Expand Down Expand Up @@ -261,15 +266,16 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.switch_to_window = function(handle) {
var page,
_this = this;
var page;
page = this.getPageByHandle(handle);
if (page) {
if (page !== this.currentPage) {
return page.waitState('default', function() {
_this.currentPage = page;
return _this.sendResponse(true);
});
return page.waitState('default', (function(_this) {
return function() {
_this.currentPage = page;
return _this.sendResponse(true);
};
})(this));
} else {
return this.sendResponse(true);
}
Expand All @@ -295,25 +301,26 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.mouse_event = function(page_id, id, name) {
var node,
_this = this;
var node;
node = this.node(page_id, id);
this.currentPage.state = 'mouse_event';
this.last_mouse_event = node.mouseEvent(name);
return setTimeout(function() {
if (_this.currentPage.state === 'mouse_event') {
_this.currentPage.state = 'default';
return _this.sendResponse({
position: _this.last_mouse_event
});
} else {
return _this.currentPage.waitState('default', function() {
return setTimeout((function(_this) {
return function() {
if (_this.currentPage.state === 'mouse_event') {
_this.currentPage.state = 'default';
return _this.sendResponse({
position: _this.last_mouse_event
});
});
}
}, 5);
} else {
return _this.currentPage.waitState('default', function() {
return _this.sendResponse({
position: _this.last_mouse_event
});
});
}
};
})(this), 5);
};

Browser.prototype.click = function(page_id, id) {
Expand Down Expand Up @@ -550,26 +557,28 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.go_back = function() {
var _this = this;
if (this.currentPage.canGoBack) {
this.currentPage.state = 'loading';
this.currentPage.goBack();
return this.currentPage.waitState('default', function() {
return _this.sendResponse(true);
});
return this.currentPage.waitState('default', (function(_this) {
return function() {
return _this.sendResponse(true);
};
})(this));
} else {
return this.sendResponse(false);
}
};

Browser.prototype.go_forward = function() {
var _this = this;
if (this.currentPage.canGoForward) {
this.currentPage.state = 'loading';
this.currentPage.goForward();
return this.currentPage.waitState('default', function() {
return _this.sendResponse(true);
});
return this.currentPage.waitState('default', (function(_this) {
return function() {
return _this.sendResponse(true);
};
})(this));
} else {
return this.sendResponse(false);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/poltergeist/client/compiled/connection.js
@@ -1,9 +1,9 @@
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

Poltergeist.Connection = (function() {
function Connection(owner, port) {
this.owner = owner;
this.port = port;
function Connection(_at_owner, _at_port) {
this.owner = _at_owner;
this.port = _at_port;
this.commandReceived = __bind(this.commandReceived, this);
this.socket = new WebSocket("ws://127.0.0.1:" + this.port + "/");
this.socket.onmessage = this.commandReceived;
Expand Down

0 comments on commit 063fb3f

Please sign in to comment.