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
  • Loading branch information
LanWei22 authored and chromium-wpt-export-bot committed Nov 6, 2018
1 parent c8dce72 commit f2c4c0f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 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 @@ -33,6 +36,9 @@ <h4>Test Description: This test checks if pointermove event triggers. Move your
}
});
}

// Inject the inputs to run this test.
new test_driver.Actions().pointerMove(0, 0, {origin: target0}).send();
</script>
<h1>Pointer Events pointermove Tests</h1>
<div id="complete-notice">
Expand Down
12 changes: 6 additions & 6 deletions resources/testdriver-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 +125,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 +225,9 @@
* pointer source
* @returns {Actions}
*/
pointerDown: function({button=0, sourceName=null}={}) {
pointerDown: function(x, y, {origin="viewport", button=0, sourceName=null}={}) {
let source = this.getSource("pointer", sourceName);
source.pointerDown(this, button);
source.pointerDown(this, button, x, y, origin);
return this;
},

Expand Down Expand Up @@ -359,12 +359,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 f2c4c0f

Please sign in to comment.