Skip to content

Commit

Permalink
Port the tests for mousedown, mouseup, and mousemove events.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Oct 10, 2014
1 parent 619225b commit eddb0db
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 107 deletions.
26 changes: 26 additions & 0 deletions test/module/webpage/mousedown-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var assert = require('../../assert');
var webpage = require('webpage');

var page = webpage.create();

page.evaluate(function() {
window.addEventListener('mousedown', function(event) {
window.loggedEvent = window.loggedEvent || [];
window.loggedEvent.push(event);
}, false);
});

page.sendEvent('mousedown', 42, 217);
var loggedEvent = page.evaluate(function() {
return window.loggedEvent;
});
assert.equal(loggedEvent.length, 1);
assert.equal(loggedEvent[0].clientX, 42);
assert.equal(loggedEvent[0].clientY, 217);

page.sendEvent('mousedown', 100, 100, 'left', page.event.modifier.shift);
loggedEvent = page.evaluate(function() {
return window.loggedEvent;
});
assert.equal(loggedEvent.length, 2);
assert.isTrue(loggedEvent[1].shiftKey);
19 changes: 19 additions & 0 deletions test/module/webpage/mousemove-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var assert = require('../../assert');
var webpage = require('webpage');

var page = webpage.create();

page.evaluate(function() {
window.addEventListener('mousemove', function(event) {
window.loggedEvent = window.loggedEvent || [];
window.loggedEvent.push(event);
}, false);
});

page.sendEvent('mousemove', 14, 3);
var loggedEvent = page.evaluate(function() {
return window.loggedEvent;
});
assert.equal(loggedEvent.length, 1);
assert.equal(loggedEvent[0].clientX, 14);
assert.equal(loggedEvent[0].clientY, 3);
26 changes: 26 additions & 0 deletions test/module/webpage/mouseup-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var assert = require('../../assert');
var webpage = require('webpage');

var page = webpage.create();

page.evaluate(function() {
window.addEventListener('mouseup', function(event) {
window.loggedEvent = window.loggedEvent || [];
window.loggedEvent.push(event);
}, false);
});

page.sendEvent('mouseup', 42, 217);
var loggedEvent = page.evaluate(function() {
return window.loggedEvent;
});
assert.equal(loggedEvent.length, 1);
assert.equal(loggedEvent[0].clientX, 42);
assert.equal(loggedEvent[0].clientY, 217);

page.sendEvent('mouseup', 100, 100, 'left', page.event.modifier.shift);
loggedEvent = page.evaluate(function() {
return window.loggedEvent;
});
assert.equal(loggedEvent.length, 2);
assert.isTrue(loggedEvent[1].shiftKey);
107 changes: 0 additions & 107 deletions test/webpage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,71 +173,6 @@ describe("WebPage object", function() {

checkViewportSize(page, {height:300,width:400});

it("should handle mousedown event", function() {
runs(function() {
page.evaluate(function() {
window.addEventListener('mousedown', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mousedown = event;
}, false);
});
page.sendEvent('mousedown', 42, 217);
});

runs(function() {
var event = page.evaluate(function() {
return window.loggedEvent.mousedown;
});
expect(event.clientX).toEqual(42);
expect(event.clientY).toEqual(217);
});
});

it("should handle mouseup event", function() {
runs(function() {
page.evaluate(function() {
window.addEventListener('mouseup', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mouseup = event;
}, false);
});
page.sendEvent('mouseup', 14, 3);
});

waits(50);

runs(function() {
var event = page.evaluate(function() {
return window.loggedEvent.mouseup;
});
expect(event.clientX).toEqual(14);
expect(event.clientY).toEqual(3);
});
});

it("should handle mousemove event", function() {
runs(function() {
page.evaluate(function() {
window.addEventListener('mousemove', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mousemove = event;
}, false);
});
page.sendEvent('mousemove', 14, 7);
});

waits(50);

runs(function() {
var event = page.evaluate(function() {
return window.loggedEvent.mousemove;
});
expect(event.clientX).toEqual(14);
expect(event.clientY).toEqual(7);
});
});


it("should handle click event", function() {
runs(function() {
page.evaluate(function() {
Expand Down Expand Up @@ -287,48 +222,6 @@ describe("WebPage object", function() {
});
});

it("should handle mousedown with modifier keys", function() {
runs(function() {
page.evaluate(function() {
window.addEventListener('mousedown', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mousedown = event;
}, false);
});
page.sendEvent('mousedown', 100, 100, 'left', page.event.modifier.shift);
});

waits(50);

runs(function() {
var event = page.evaluate(function() {
return window.loggedEvent.mousedown;
});
expect(event.shiftKey).toEqual(true);
});
});

it("should handle mouseup with modifier keys", function() {
runs(function() {
page.evaluate(function() {
window.addEventListener('mouseup', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mouseup = event;
}, false);
});
page.sendEvent('mouseup', 100, 100, 'left', page.event.modifier.shift);
});

waits(50);

runs(function() {
var event = page.evaluate(function() {
return window.loggedEvent.mouseup;
});
expect(event.shiftKey).toEqual(true);
});
});

it("should handle click with modifier keys", function() {
runs(function() {
page.evaluate(function() {
Expand Down

0 comments on commit eddb0db

Please sign in to comment.