From ce41218f4616fcca9963b967829fd4b26a987de5 Mon Sep 17 00:00:00 2001 From: Lan Wei Date: Fri, 9 Nov 2018 09:32:25 -0800 Subject: [PATCH] Add action_sequence in testdriver 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 Reviewed-by: Navid Zolghadr Reviewed-by: Dave Tapuska Cr-Commit-Position: refs/heads/master@{#606882} --- .../testdriver/actions/elementPosition.html | 2 +- .../testdriver/actions/eventOrder.html | 14 +++++------- ...ual.html => pointerevent_pointermove.html} | 6 +++++ resources/testdriver-actions.js | 22 +++++++++++++------ resources/testdriver.js | 4 ++-- 5 files changed, 30 insertions(+), 18 deletions(-) rename pointerevents/{pointerevent_pointermove-manual.html => pointerevent_pointermove.html} (86%) diff --git a/infrastructure/testdriver/actions/elementPosition.html b/infrastructure/testdriver/actions/elementPosition.html index 145852e7b51bd0..ab9fb31ad093b1 100644 --- a/infrastructure/testdriver/actions/elementPosition.html +++ b/infrastructure/testdriver/actions/elementPosition.html @@ -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]))) diff --git a/infrastructure/testdriver/actions/eventOrder.html b/infrastructure/testdriver/actions/eventOrder.html index c85b861c7fd9b1..bd7fef41e9af29 100644 --- a/infrastructure/testdriver/actions/eventOrder.html +++ b/infrastructure/testdriver/actions/eventOrder.html @@ -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))); diff --git a/pointerevents/pointerevent_pointermove-manual.html b/pointerevents/pointerevent_pointermove.html similarity index 86% rename from pointerevents/pointerevent_pointermove-manual.html rename to pointerevents/pointerevent_pointermove.html index cf1a1ee4ee852e..4b168439a4ee14 100644 --- a/pointerevents/pointerevent_pointermove-manual.html +++ b/pointerevents/pointerevent_pointermove.html @@ -7,6 +7,9 @@ + + + @@ -32,6 +35,9 @@

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(); }

Pointer Events pointermove Tests

diff --git a/resources/testdriver-actions.js b/resources/testdriver-actions.js index 46c68858e45746..82cac85347bfa6 100644 --- a/resources/testdriver-actions.js +++ b/resources/testdriver-actions.js @@ -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 @@ -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); } @@ -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); } @@ -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; }, @@ -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; @@ -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) { diff --git a/resources/testdriver.js b/resources/testdriver.js index e0741e8d61d4d6..8ffd765072c4e7 100644 --- a/resources/testdriver.js +++ b/resources/testdriver.js @@ -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); } }; @@ -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) {