Commit 0f9ac276 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Use promise in wpt pointer event tests to end the tests

Instead of adding a variable to check if the test should be finished,
we can create a promise object and end the test at its last callback.

Bug: 606367
Change-Id: I6be3a61db1f54fa88b56e919b8be6dfa318b21c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704865Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684399}
parent b3395733
......@@ -27,13 +27,16 @@
var test_pointer_event = setup_pointerevent_test("Event sequence at implicit release on drag", ["touch"]);
var button = document.getElementById("done");
var clickIsReceived = false;
var actions_promise;
on_event(document.getElementById("done"), "click", function() {
test_pointer_event.step(function () {
var expected_events = "pointercancel, lostpointercapture, pointerout, pointerleave";
assert_equals(event_log.join(", "), expected_events);
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_pointer_event.done();
});
});
var target = document.getElementById("target");
......@@ -55,13 +58,8 @@
});
// Inject touch inputs.
pointerDragInTarget("touch", target, 'right').then(function() {
actions_promise = pointerDragInTarget("touch", target, 'right').then(function() {
return clickInTarget("touch", button);
}).then(function() {
test_pointer_event.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_pointer_event.done();
});
}
</script>
......
......@@ -89,6 +89,7 @@
var target0 = document.getElementById("target0");
var test_touchaction = async_test("touch-action attribute test");
var actions_promise;
xScr0 = target0.scrollLeft;
yScr0 = target0.scrollTop;
......@@ -117,18 +118,17 @@
}
if(xScrollIsReceived && yScrollIsReceived) {
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
}
});
// Inject touch inputs and wait for all the actions finish to end the test.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
test_touchaction.step(function () {
assert_true(xScrollIsReceived && yScrollIsReceived, "x-scroll and y-scroll should be received before the test finishes");
}, "x-scroll and y-scroll should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -87,7 +87,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if touch-action attribute works properly for embedded divs
//
......@@ -98,7 +98,11 @@
assert_equals(target0.scrollLeft, 0, "scroll x offset should be 0 in the end of the test");
assert_equals(target0.scrollTop, 0, "scroll y offset should be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
......@@ -107,15 +111,10 @@
});
// Inject touch inputs.
touchScrollInTarget(scrollTarget, 'down').then(function() {
actions_promise = touchScrollInTarget(scrollTarget, 'down').then(function() {
return touchScrollInTarget(scrollTarget, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -91,7 +91,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if touch-action attribute works properly for embedded divs
//
......@@ -102,20 +102,19 @@
assert_not_equals(target0.scrollLeft, 0, "scroll x offset should not be 0 in the end of the test");
assert_equals(target0.scrollTop, 0, "scroll y offset should be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
// Inject touch inputs.
touchScrollInTarget(scrollTarget, 'down').then(function() {
actions_promise = touchScrollInTarget(scrollTarget, 'down').then(function() {
return touchScrollInTarget(scrollTarget, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -92,6 +92,7 @@
var target0 = document.getElementById("target0");
var test_touchaction = async_test("touch-action attribute test");
var actions_promise;
xScr0 = target0.scrollLeft;
yScr0 = target0.scrollTop;
......@@ -117,18 +118,17 @@
}
if(xScrollIsReceived && yScrollIsReceived) {
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
}
});
// Inject touch inputs and wait for all the actions finish to end the test.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
test_touchaction.step(function () {
assert_true(xScrollIsReceived && yScrollIsReceived, "x-scroll and y-scroll should be received before the test finishes");
}, "x-scroll and y-scroll should be received before the test finishes");
test_touchaction.done();
});
}
......
......@@ -87,7 +87,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if touch-action attribute works properly for embedded divs
//
......@@ -98,7 +98,11 @@
assert_equals(target0.scrollLeft, 0, "scroll x offset should be 0 in the end of the test");
assert_equals(target0.scrollTop, 0, "scroll y offset should be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
......@@ -107,15 +111,10 @@
});
// Inject touch inputs.
touchScrollInTarget(scrollTarget, 'down').then(function() {
actions_promise = touchScrollInTarget(scrollTarget, 'down').then(function() {
return touchScrollInTarget(scrollTarget, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -87,7 +87,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if "touch-action: none" attribute works properly
//TA: 15.2
......@@ -97,7 +97,11 @@
assert_equals(target0.scrollLeft, 0, "scroll x offset should be 0 in the end of the test");
assert_equals(target0.scrollTop, 0, "scroll y offset should be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
......@@ -106,15 +110,10 @@
});
// Inject touch inputs.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -86,7 +86,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if "touch-action: pan-x" attribute works properly
//TA: 15.3
......@@ -96,20 +96,19 @@
assert_not_equals(target0.scrollLeft, 0, "scroll x offset should not be 0 in the end of the test");
assert_equals(target0.scrollTop, 0, "scroll y offset should be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
// Inject touch inputs.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -90,7 +90,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if touch-action attribute works properly for embedded divs
//
......@@ -101,20 +101,19 @@
assert_equals(target0.scrollLeft, 0, "scroll x offset should be 0 in the end of the test");
assert_not_equals(target0.scrollTop, 0, "scroll y offset should not be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
// Inject touch inputs.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -89,6 +89,7 @@
var target0 = document.getElementById("target0");
var test_touchaction = async_test("touch-action attribute test");
var actions_promise;
xScr0 = target0.scrollLeft;
yScr0 = target0.scrollTop;
......@@ -114,18 +115,17 @@
}
if(xScrollIsReceived && yScrollIsReceived) {
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
}
});
// Inject touch inputs and wait for all the actions finish to end the test.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
test_touchaction.step(function () {
assert_true(xScrollIsReceived && yScrollIsReceived, "x-scroll and y-scroll should be received before the test finishes");
}, "x-scroll and y-scroll should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
......@@ -87,7 +87,7 @@
function run() {
var target0 = document.getElementById("target0");
var btnComplete = document.getElementById("btnComplete");
var clickIsReceived = false;
var actions_promise;
// Check if "touch-action: pan-y" attribute works properly
//TA: 15.4
......@@ -97,20 +97,19 @@
assert_equals(target0.scrollLeft, 0, "scroll x offset should be 0 in the end of the test");
assert_not_equals(target0.scrollTop, 0, "scroll y offset should not be 0 in the end of the test");
});
clickIsReceived = true;
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_touchaction.done();
});
updateDescriptionComplete();
});
// Inject touch inputs.
touchScrollInTarget(target0, 'down').then(function() {
actions_promise = touchScrollInTarget(target0, 'down').then(function() {
return touchScrollInTarget(target0, 'right');
}).then(function() {
return clickInTarget("touch", btnComplete);
}).then(function() {
test_touchaction.step(function () {
assert_true(clickIsReceived, "click should be received before the test finishes");
}, "click should be received before the test finishes");
test_touchaction.done();
});
}
</script>
......
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