Commit b1fdcde7 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Use promise in wpt tests to end the tests to avoid memory leak - Part 3

When we add default tick duration of two-frame time, we see some tests
memory leak which may end the tests when the page is still active, so
I add promise to each tests, once the actions are all finished, we will
call the test end in the promise callback.

Bug: 606367
Change-Id: Ie63b8fd168426b84bedc6c31d5b3bdbb1813ccd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790742Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699856}
parent c6c7b05f
......@@ -23,6 +23,7 @@
<div id="target"></div>
<script>
var test_auxclick = async_test("auxclick event sequence received.");
var actions_promise;
var target = document.querySelector('#target');
document.addEventListener('contextmenu', event => { event.preventDefault(); });
['click', 'dblclick'].forEach(eventName => {
......@@ -60,13 +61,16 @@
'There should be two auxclick events for a non-primary button double click each preceded by one mousemove and one mouseup');
assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
});
test_auxclick.done();
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_auxclick.done();
});
}
});
// Inject mouse double click events.
var actions = new test_driver.Actions();
actions.pointerMove(0, 0, {origin: target})
actions_promise = actions.pointerMove(0, 0, {origin: target})
.pointerDown({button: actions.ButtonType.MIDDLE})
.pointerUp({button: actions.ButtonType.MIDDLE})
.pointerDown({button: actions.ButtonType.MIDDLE})
......
......@@ -38,6 +38,7 @@
<button id="done">Done</button>
<script>
var test_click_target = async_test("Click targets the nearest common ancestor");
var actions_promise;
// Prevent drag to avoid interfering with the click.
document.addEventListener('dragstart', (e) => e.preventDefault());
......@@ -59,12 +60,15 @@
"mousedown@link1,mouseup@link_container1,click@link_container1,mousedown@link_container2,mouseup@link2,click@link_container2",
"Click should be sent to the nearest common ancestor");
});
test_click_target.done();
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_click_target.done();
});
});
// Inject mouse events.
var actions = new test_driver.Actions();
actions.pointerMove(0, 0, {origin: document.getElementById('link1')})
actions_promise = actions.pointerMove(0, 0, {origin: document.getElementById('link1')})
.pointerDown()
.pointerMove(0, 0, {origin: document.getElementById('link_container1')})
.pointerUp()
......
......@@ -51,6 +51,7 @@
<button id="done">Done</button>
<script>
var test_click_target = async_test("Click targets the nearest common ancestor");
var actions_promise;
// Prevent drag to avoid interfering with the click.
document.addEventListener('dragstart', (e) => e.preventDefault());
......@@ -72,12 +73,15 @@
"mousedown@red_div,mouseup@blue_div,click@div_container,mousedown@button1,mouseup@button2,click@button_container,mousedown@link1,mouseup@link2,click@link_container",
"Click should be sent to the nearest common ancestor");
});
test_click_target.done();
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_click_target.done();
});
});
// Inject mouse events.
var actions = new test_driver.Actions();
actions.pointerMove(0, 0, {origin: document.getElementById('red_div')})
actions_promise = actions.pointerMove(0, 0, {origin: document.getElementById('red_div')})
.pointerDown()
.pointerMove(0, 0, {origin: document.getElementById('blue_div')})
.pointerUp()
......
......@@ -25,15 +25,19 @@
function run() {
var testDoubleClick = async_test('Tests that the double click event is correctly generated by sending pointerDown, pointerUp, pointerDown and pointerUp for the mouse type.');
var elem = document.getElementById("click_area");
var actions_promise;
elem.addEventListener('dblclick', function(e) {
testDoubleClick.step(function () {
assert_equals(e.target.id, "click_area");
assert_equals(e.detail, 2);
});
testDoubleClick.done();
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
testDoubleClick.done();
});
});
new test_driver.Actions()
actions_promise = new test_driver.Actions()
.pointerMove(0, 0, {origin: elem})
.pointerDown()
.pointerUp()
......
......@@ -15,6 +15,7 @@
var received_forward = false;
const backButton = 3;
const forwardButton = 4;
var actions_promise;
window.addEventListener('mouseup', function(e) {
if (e.button == backButton) {
received_back = true;
......@@ -24,14 +25,17 @@
e.preventDefault();
}
if (received_back && received_forward) {
testMouseUp.done();
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
testMouseUp.done();
});
}
});
function inject_input() {
// First click on back button and then forward button.
var actions = new test_driver.Actions();
actions.pointerMove(0, 0, {origin: target})
actions_promise = actions.pointerMove(0, 0, {origin: target})
.pointerDown({button: actions.ButtonType.BACK})
.pointerUp({button: actions.ButtonType.BACK})
.pointerDown({button: actions.ButtonType.FORWARD})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment