Skip to content

Commit

Permalink
Add action_sequence in testdriver
Browse files Browse the repository at this point in the history
After we expose test_driver.Actions API to web users, we add their
implementation in our testdriver file, and fix the wpt tests of
Actions API.

Bug: 893480
Change-Id: Ib02c0223208eeb2cc30c2ca35b98d5fc938baa2c
Reviewed-on: https://chromium-review.googlesource.com/c/1289119
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: Navid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606882}
  • Loading branch information
LanWei22 authored and chromium-wpt-export-bot committed Nov 9, 2018
1 parent 7c568fd commit ce41218
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion infrastructure/testdriver/actions/elementPosition.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
let div = document.getElementById("test");
let actions = new test_driver.Actions()
.pointerMove(0, 0, {origin: test})
.pointerDown()
.pointerDown(0, 0, {origin: test})
.pointerUp()
.send()
.then(t.step_func_done(() => assert_array_equals(events, [50, 25])))
Expand Down
14 changes: 6 additions & 8 deletions infrastructure/testdriver/actions/eventOrder.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@

async_test(t => {
Array.prototype.forEach.call(document.getElementsByTagName("button"),
(x) => x.addEventListener("mousedown", () => {events.push(x.id)}));
(x) => x.addEventListener("pointerdown", () => {events.push(x.id)}));

let button_a = document.getElementById("a");
let button_b = document.getElementById("b");
let actions = new test_driver.Actions()
.addPointer("pointer1")
.addPointer("pointer2")
.pointerMove(0, 0, {origin: button_a, sourceName: "pointer1"})
.pointerMove(0, 0, {origin: button_b, sourceName: "pointer2"})
.pointerDown({sourceName: "pointer2"})
.pointerDown({sourceName: "pointer1"})
.pointerUp({sourceName: "pointer2"})
.addPointer("pointer1", "touch")
.addPointer("pointer2", "touch")
.pointerDown(0, 0, {origin: button_a, sourceName: "pointer1"})
.pointerDown(0, 0, {origin: button_b, sourceName: "pointer2"})
.pointerUp({sourceName: "pointer1"})
.pointerUp({sourceName: "pointer2"})
.send()
.then(t.step_func_done(() => assert_array_equals(events, ["a", "b"])))
.catch(e => t.step_func(() => assert_unreached("Actions sequence failed " + e)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<!-- Additional helper script for common checks across event types -->
<script type="text/javascript" src="pointerevent_support.js"></script>
</head>
Expand All @@ -32,6 +35,9 @@ <h4>Test Description: This test checks if pointermove event triggers. Move your
eventTested = true;
}
});

// Inject the inputs to run this test.
new test_driver.Actions().pointerMove(0, 0, {origin: target0}).send();
}
</script>
<h1>Pointer Events pointermove Tests</h1>
Expand Down
22 changes: 15 additions & 7 deletions resources/testdriver-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
}

Actions.prototype = {
ButtonType: {
LEFT: 0,
MIDDLE: 1,
RIGHT: 2,
BACK: 3,
FORWARD: 4,
},

/**
* Generate the action sequence suitable for passing to
* test_driver.action_sequence
Expand Down Expand Up @@ -98,7 +106,7 @@
* @returns {Actions}
*/
addKeyboard: function(name, set=true) {
this.createSource("key", name, true);
this.createSource("key", name);
if (set) {
this.setKeyboard(name);
}
Expand All @@ -125,7 +133,7 @@
* @returns {Actions}
*/
addPointer: function(name, pointerType="mouse", set=true) {
this.createSource("pointer", name, true, {pointerType: pointerType});
this.createSource("pointer", name, {pointerType: pointerType});
if (set) {
this.setPointer(name);
}
Expand Down Expand Up @@ -225,9 +233,9 @@
* pointer source
* @returns {Actions}
*/
pointerDown: function({button=0, sourceName=null}={}) {
pointerDown: function(x, y, {origin="viewport", button=this.ButtonType.LEFT, sourceName=null}={}) {
let source = this.getSource("pointer", sourceName);
source.pointerDown(this, button);
source.pointerDown(this, button, x, y, origin);
return this;
},

Expand All @@ -239,7 +247,7 @@
* source
* @returns {Actions}
*/
pointerUp: function({button=0, sourceName=null}={}) {
pointerUp: function({button=this.ButtonType.LEFT, sourceName=null}={}) {
let source = this.getSource("pointer", sourceName);
source.pointerUp(this, button);
return this;
Expand Down Expand Up @@ -359,12 +367,12 @@
return data;
},

pointerDown: function(actions, button) {
pointerDown: function(actions, button, x, y, origin) {
let tick = actions.tickIdx;
if (this.actions.has(tick)) {
tick = actions.addTick().tickIdx;
}
this.actions.set(tick, {type: "pointerDown", button});
this.actions.set(tick, {type: "pointerDown", button, x, y, origin});
},

pointerUp: function(actions, button) {
Expand Down
4 changes: 2 additions & 2 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
* @returns {Promise} fufiled after the actions are performed, or rejected in
* the cases the WebDriver command errors
*/
action_sequence(actions) {
action_sequence: function(actions) {
return window.test_driver_internal.action_sequence(actions);
}
};
Expand Down Expand Up @@ -233,7 +233,7 @@
/**
* Send a sequence of pointer actions
*
* @returns {Promise} fufilled after actions are sent, rejected if any actions
* @returns {Promise} fulfilled after actions are sent, rejected if any actions
* fail
*/
action_sequence: function(actions) {
Expand Down

0 comments on commit ce41218

Please sign in to comment.