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

Use testdriver Action API in WPT pointerevent tests - Part 10

In order to run the web-platform-tests automatically, we will use
testdriver Action API in all the wpt to simulate inputs. Here we are
changing some pointerevent input test which taps on the elements inside
an inner frame.

This is the tenth CL that changes part of the pointerevent input
tests.

Bug: 606367
Change-Id: Ib90c92e8267f17fed74a86d70ca6d739b5ccedb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1638914
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675891}
parent 46a16ef8
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
<link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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 --> <!-- Additional helper script for common checks across event types -->
<script type="text/javascript" src="pointerevent_support.js"></script> <script type="text/javascript" src="pointerevent_support.js"></script>
<script> <script>
...@@ -95,6 +98,7 @@ ...@@ -95,6 +98,7 @@
var innerFrame = document.getElementById('innerFrame'); var innerFrame = document.getElementById('innerFrame');
var square2 = innerFrame.contentDocument.getElementById('square2'); var square2 = innerFrame.contentDocument.getElementById('square2');
var rectSquare2 = square2.getBoundingClientRect(); var rectSquare2 = square2.getBoundingClientRect();
var actions_promise;
eventList.forEach(function(eventName) { eventList.forEach(function(eventName) {
on_event(square1, eventName, function (event) { on_event(square1, eventName, function (event) {
...@@ -112,10 +116,32 @@ ...@@ -112,10 +116,32 @@
checkPointerEventAttributes(event, rectSquare2, "Inner frame "); checkPointerEventAttributes(event, rectSquare2, "Inner frame ");
if (Object.keys(detected_eventTypes).length == eventList.length) { if (Object.keys(detected_eventTypes).length == eventList.length) {
square2.style.visibility = 'hidden'; square2.style.visibility = 'hidden';
test_pointerEvent.done(); // Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_pointerEvent.done();
});
} }
}); });
}); });
// Inject mouse and pen inputs.
actions_promise = clickInTarget("mouse", square1).then(function() {
return moveToDocument("mouse");
}).then(function() {
return clickInTarget("mouse", square2);
}).then(function() {
return moveToDocument("mouse");
}).then(function() {
test_pointerEvent.done();
}).then(function() {
return clickInTarget("pen", square1);
}).then(function() {
return moveToDocument("pen");
}).then(function() {
return clickInTarget("pen", square2);
}).then(function() {
return moveToDocument("pen");
});
} }
</script> </script>
</head> </head>
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
<link rel="stylesheet" type="text/css" href="pointerevent_styles.css"> <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.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 --> <!-- Additional helper script for common checks across event types -->
<script type="text/javascript" src="pointerevent_support.js"></script> <script type="text/javascript" src="pointerevent_support.js"></script>
<script> <script>
...@@ -76,6 +79,7 @@ ...@@ -76,6 +79,7 @@
var innerFrame = document.getElementById('innerFrame'); var innerFrame = document.getElementById('innerFrame');
var square2 = innerFrame.contentDocument.getElementById('square2'); var square2 = innerFrame.contentDocument.getElementById('square2');
var rectSquare2 = square2.getBoundingClientRect(); var rectSquare2 = square2.getBoundingClientRect();
var actions_promise;
eventList.forEach(function(eventName) { eventList.forEach(function(eventName) {
on_event(square1, eventName, function (event) { on_event(square1, eventName, function (event) {
...@@ -93,10 +97,18 @@ ...@@ -93,10 +97,18 @@
checkPointerEventAttributes(event, rectSquare2, "Inner frame "); checkPointerEventAttributes(event, rectSquare2, "Inner frame ");
if (Object.keys(detected_eventTypes).length == eventList.length) { if (Object.keys(detected_eventTypes).length == eventList.length) {
square2.style.visibility = 'hidden'; square2.style.visibility = 'hidden';
test_pointerEvent.done(); // Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_pointerEvent.done();
});
} }
}); });
}); });
// Inject touch inputs.
actions_promise = clickInTarget("touch", square1).then(function() {
return clickInTarget("touch", square2);
});
} }
</script> </script>
</head> </head>
......
...@@ -353,3 +353,11 @@ function pointerHoverInTarget(pointerType, target, direction) { ...@@ -353,3 +353,11 @@ function pointerHoverInTarget(pointerType, target, direction) {
.pointerMove(3 * x_delta, 3 * y_delta, {origin: target}) .pointerMove(3 * x_delta, 3 * y_delta, {origin: target})
.send(); .send();
} }
function moveToDocument(pointerType) {
var pointerId = pointerType + "Pointer1";
return new test_driver.Actions()
.addPointer(pointerId, pointerType)
.pointerMove(0, 0)
.send();
}
importAutomationScript('/pointerevents/pointerevent_common_input.js');
function inject_input() {
return mouseClickInTarget('#square1').then(function() {
return mouseClickInTarget('#square2', document.querySelector('#innerFrame'));
}).then(function() {
return mouseMoveToDocument();
}).then(function() {
return penClickInTarget('#square1');
}).then(function() {
return penClickInTarget('#square2', document.querySelector('#innerFrame'));
}).then(function() {
return penMoveToDocument();
});
}
importAutomationScript('/pointerevents/pointerevent_common_input.js');
function inject_input() {
return touchTapInTarget('#square1').then(function() {
return touchTapInTarget('#square2', document.querySelector('#innerFrame'));
});
}
...@@ -17,31 +17,47 @@ ...@@ -17,31 +17,47 @@
return [x, y]; return [x, y];
} }
function getPointerInteractablePaintTree(element) { function getPointerInteractablePaintTree(element, frame) {
if (!window.document.contains(element)) { var frameDocument = frame == window ? window.document : frame.contentDocument;
if (!frameDocument.contains(element)) {
return []; return [];
} }
var rectangles = element.getClientRects(); var rectangles = element.getClientRects();
if (rectangles.length === 0) { if (rectangles.length === 0) {
return []; return [];
} }
var centerPoint = getInViewCenterPoint(rectangles[0]); var centerPoint = getInViewCenterPoint(rectangles[0]);
if ("elementsFromPoint" in document) { if ("elementsFromPoint" in document) {
return document.elementsFromPoint(centerPoint[0], centerPoint[1]); return frameDocument.elementsFromPoint(centerPoint[0], centerPoint[1]);
} else if ("msElementsFromPoint" in document) { } else if ("msElementsFromPoint" in document) {
var rv = document.msElementsFromPoint(centerPoint[0], centerPoint[1]); var rv = frameDocument.msElementsFromPoint(centerPoint[0], centerPoint[1]);
return Array.prototype.slice.call(rv ? rv : []); return Array.prototype.slice.call(rv ? rv : []);
} else { } else {
throw new Error("document.elementsFromPoint unsupported"); throw new Error("document.elementsFromPoint unsupported");
} }
} }
function inView(element) { function inView(element, frame) {
var pointerInteractablePaintTree = getPointerInteractablePaintTree(element); var pointerInteractablePaintTree = getPointerInteractablePaintTree(element, frame);
return pointerInteractablePaintTree.indexOf(element) !== -1 || element.contains(pointerInteractablePaintTree[0]); return pointerInteractablePaintTree.indexOf(element) !== -1 || element.contains(pointerInteractablePaintTree[0], frame);
}
function findElementInFrame(element, frame) {
var foundFrame = frame;
var frameDocument = frame == window ? window.document : frame.contentDocument;
if (!frameDocument.contains(element)) {
foundFrame = null;
var frames = document.getElementsByTagName("iframe");
for (let i = 0; i < frames.length; i++) {
if (findElementInFrame(element, frames[i])) {
foundFrame = frames[i];
break;
}
}
}
return foundFrame;
} }
window.test_driver_internal.click = function(element, coords) { window.test_driver_internal.click = function(element, coords) {
...@@ -122,12 +138,13 @@ ...@@ -122,12 +138,13 @@
return Promise.reject(new Error("pointer origin is not given correctly")); return Promise.reject(new Error("pointer origin is not given correctly"));
} }
} else { } else {
let element = actions[i].actions[j].origin; var element = actions[i].actions[j].origin;
if (!window.document.contains(element)) { var frame = findElementInFrame(element, window);
return Promise.reject(new Error("element in different document or shadow tree")); if (frame == null) {
return Promise.reject(new Error("element in different document or iframe"));
} }
if (!inView(element)) { if (!inView(element, frame)) {
if (didScrollIntoView) if (didScrollIntoView)
return Promise.reject(new Error("already scrolled into view, the element is not found")); return Promise.reject(new Error("already scrolled into view, the element is not found"));
...@@ -137,7 +154,7 @@ ...@@ -137,7 +154,7 @@
didScrollIntoView = true; didScrollIntoView = true;
} }
var pointerInteractablePaintTree = getPointerInteractablePaintTree(element); var pointerInteractablePaintTree = getPointerInteractablePaintTree(element, frame);
if (pointerInteractablePaintTree.length === 0 || if (pointerInteractablePaintTree.length === 0 ||
!element.contains(pointerInteractablePaintTree[0])) { !element.contains(pointerInteractablePaintTree[0])) {
return Promise.reject(new Error("element click intercepted error")); return Promise.reject(new Error("element click intercepted error"));
...@@ -147,6 +164,11 @@ ...@@ -147,6 +164,11 @@
var centerPoint = getInViewCenterPoint(rect); var centerPoint = getInViewCenterPoint(rect);
last_x_position = actions[i].actions[j].x + centerPoint[0]; last_x_position = actions[i].actions[j].x + centerPoint[0];
last_y_position = actions[i].actions[j].y + centerPoint[1]; last_y_position = actions[i].actions[j].y + centerPoint[1];
if (frame != window) {
var frameRect = frame.getClientRects();
last_x_position += frameRect[0].left;
last_y_position += frameRect[0].top;
}
} }
} }
......
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