1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Merge branch 'master' of github.com:thoughtbot/capybara-webkit

This commit is contained in:
Joe Ferris 2012-01-31 11:37:18 -08:00
commit 0e32d3c677
3 changed files with 69 additions and 6 deletions

View file

@ -1,5 +1,14 @@
We love pull requests. Here's a quick guide: We love pull requests. Here's a quick guide:
Dependencies
Some of the tests depend on the `identify` command that comes with Imagemagick.
Imagemagick can be installed via [homebrew](http://mxcl.github.com/homebrew/).
brew install imagemagick
Contributing
1. Fork the repo. 1. Fork the repo.
2. Run the tests. We only take pull requests with passing tests, and it's great 2. Run the tests. We only take pull requests with passing tests, and it's great

View file

@ -529,6 +529,44 @@ describe Capybara::Driver::Webkit do
end end
end end
context "dom events" do
before(:all) do
@app = lambda do |env|
body = <<-HTML
<html><body>
<a href='#' class='watch'>Link</a>
<ul id="events"></ul>
<script type="text/javascript">
var events = document.getElementById("events");
var recordEvent = function (event) {
var element = document.createElement("li");
element.innerHTML = event.type;
events.appendChild(element);
};
var elements = document.getElementsByClassName("watch");
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
element.addEventListener("mousedown", recordEvent);
element.addEventListener("mouseup", recordEvent);
element.addEventListener("click", recordEvent);
}
</script>
</body></html>
HTML
[200,
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end
end
it "triggers mouse events" do
subject.find("//a").first.click
subject.find("//li").map(&:text).should == %w(mousedown mouseup click)
end
end
context "form events app" do context "form events app" do
before(:all) do before(:all) do
@app = lambda do |env| @app = lambda do |env|
@ -564,6 +602,8 @@ describe Capybara::Driver::Webkit do
element.addEventListener("keyup", recordEvent); element.addEventListener("keyup", recordEvent);
element.addEventListener("change", recordEvent); element.addEventListener("change", recordEvent);
element.addEventListener("blur", recordEvent); element.addEventListener("blur", recordEvent);
element.addEventListener("mousedown", recordEvent);
element.addEventListener("mouseup", recordEvent);
element.addEventListener("click", recordEvent); element.addEventListener("click", recordEvent);
} }
</script> </script>
@ -597,12 +637,12 @@ describe Capybara::Driver::Webkit do
it "triggers radio input events" do it "triggers radio input events" do
subject.find("//input[@type='radio']").first.set(true) subject.find("//input[@type='radio']").first.set(true)
subject.find("//li").map(&:text).should == %w(click change) subject.find("//li").map(&:text).should == %w(mousedown mouseup change click)
end end
it "triggers checkbox events" do it "triggers checkbox events" do
subject.find("//input[@type='checkbox']").first.set(true) subject.find("//input[@type='checkbox']").first.set(true)
subject.find("//li").map(&:text).should == %w(click change) subject.find("//li").map(&:text).should == %w(mousedown mouseup change click)
end end
end end

View file

@ -96,7 +96,21 @@ Capybara = {
return this.nodes[index].submit(); return this.nodes[index].submit();
}, },
mousedown: function(index) {
var mousedownEvent = document.createEvent('MouseEvents');
mousedownEvent.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this.nodes[index].dispatchEvent(mousedownEvent);
},
mouseup: function(index) {
var mouseupEvent = document.createEvent('MouseEvents');
mouseupEvent.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this.nodes[index].dispatchEvent(mouseupEvent);
},
click: function (index) { click: function (index) {
this.mousedown(index);
this.mouseup(index);
var clickEvent = document.createEvent('MouseEvents'); var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this.nodes[index].dispatchEvent(clickEvent); this.nodes[index].dispatchEvent(clickEvent);
@ -167,13 +181,13 @@ Capybara = {
this.trigger(index, "blur"); this.trigger(index, "blur");
} else if (type === "checkbox" || type === "radio") { } else if (type === "checkbox" || type === "radio") {
node.checked = (value === "true"); if (node.checked != (value === "true")) {
this.trigger(index, "click"); this.click(index)
this.trigger(index, "change"); }
} else if (type === "file") { } else if (type === "file") {
this.lastAttachedFile = value; this.lastAttachedFile = value;
this.trigger(index, "click"); this.click(index)
} else { } else {
node.value = value; node.value = value;