Commit c917c5b4 authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Run blink tests with Pointer Lock Options enabled

Pointer Lock Options was not set up to run tests while enabled.  This CL
fixes that and then fixes the necessary tests so that all runs smoothly
when the flag is enabled by default.

Bug: 1124396
Change-Id: Ie1d9b431b89a4cce77023d9c3aadad4e2d824be2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431459Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823566}
parent e43fda67
......@@ -293,7 +293,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
net::features::kSameSiteByDefaultCookies},
{wf::EnableCookiesWithoutSameSiteMustBeSecure,
net::features::kCookiesWithoutSameSiteMustBeSecure},
{wf::EnablePointerLockOptions, features::kPointerLockOptions},
{wf::EnablePointerLockOptions, features::kPointerLockOptions,
kSetOnlyIfOverridden},
{wf::EnableDocumentPolicy, features::kDocumentPolicy},
{wf::EnableDocumentPolicyNegotiation, features::kDocumentPolicyNegotiation},
{wf::EnableScrollUnification, features::kScrollUnification},
......
......@@ -1531,6 +1531,7 @@
{
name: "PointerLockOptions",
origin_trial_feature_name: "PointerLockOptions",
status: 'experimental',
},
{
name: "PointerRawUpdate",
......
CONSOLE ERROR: Blocked pointer lock on an element because the element's frame is sandboxed and the 'allow-pointer-lock' permission is not set.
Test sandboxed iframe blocks pointer lock.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS message is "inner-iframe.html onpointerlockerror"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<script src="../resources/pointer-lock/pointer-lock-test-harness.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div>
<div id="target1"></div>
<iframe src="../resources/pointer-lock/inner-iframe.html" sandbox="allow-scripts" onload="doNextStepWithUserGesture()"></iframe>
</div>
<script>
description("Test sandboxed iframe blocks pointer lock.")
window.jsTestIsAsync = true;
targetDiv1 = document.getElementById("target1");
iframe = document.getElementsByTagName("iframe")[0];
todo = [
function () {
iframe.contentWindow.postMessage(["eval", 'document.body.requestPointerLock()'], "*");
window.onmessage = function (messageEvent) {
message = messageEvent.data;
shouldBeEqualToString("message", "inner-iframe.html onpointerlockerror");
window.onmessage = null;
doNextStep();
}
},
];
// doNextStep() called by iframe onload handler.
promise_test(() => {
return new Promise((resolve, reject) => {
window.addEventListener('message', (event) => {
if (event.data == "inner-iframe.html onpointerlockerror") {
resolve();
} else {
reject(event.data);
}
});
function onIframeLoaded() {
clickOnElement(iframe);
}
var iframe = document.createElement('iframe');
iframe.sandbox = 'allow-scripts';
iframe.onload = onIframeLoaded;
iframe.src = '../resources/pointer-lock/inner-iframe.html';
document.body.appendChild(iframe);
});
}, 'Test sandboxed iframe with allow-pointer-lock allows pointer lock.');
</script>
</body>
</html>
......@@ -27,7 +27,7 @@
doNextStep();
},
function () {
iframe.contentWindow.postMessage(["eval", 'document.body.requestPointerLock()'], "*");
iframe.contentWindow.postMessage(["eval", 'document.body.requestPointerLock().catch(()=>{})'], "*");
window.onmessage = function (messageEvent) {
message = messageEvent.data;
shouldBeEqualToString("message", "inner-iframe.html onpointerlockerror");
......
......@@ -4,7 +4,11 @@
<script src="iframe-common.js"></script>
<script>
document.addEventListener('click', () => {
document.body.requestPointerLock();
document.body.requestPointerLock().catch(error => {
// Do nothing here. The errors returned in the promise are
// tested in Web Platform Tests. These test are testing that
// the proper events are fires.
});
})
</script>
</head>
......
......@@ -13,6 +13,7 @@
window.jsTestIsAsync = true;
targetDiv1 = document.getElementById("target1");
let error_code;
todo = [
function () {
......@@ -20,7 +21,11 @@
expectOnlyErrorEvent("Remove targetDiv1 from document, and try to lock it.");
targetDiv1.parentElement.removeChild(targetDiv1);
shouldBe("targetDiv1.parentElement", "null");
targetDiv1.requestPointerLock();
let request_promise = targetDiv1.requestPointerLock();
request_promise.catch(error => {
error_code = error.code;
shouldBe("error_code", "4", "Should reject with a WrongDocumentError");
});
// doNextStep called by event handler.
},
];
......
......@@ -19,6 +19,7 @@
targetDiv2 = document.getElementById("target2");
targetIframe1 = document.getElementById("iframe1");
targetIframe2 = document.getElementById("iframe2");
let error_code;
// Events must not bubble from document.
function errorIfEventsBubble() {
......@@ -75,7 +76,10 @@
expectNoEvents("Lock targetIframe2.");
expectNoEvents("Lock targetIframe2 (handler for iframe1).", targetIframe1.contentDocument);
expectOnlyErrorEvent("Lock targetIframe2 (handler for iframe2).", targetIframe2.contentDocument);
targetIframe2.contentDocument.body.requestPointerLock();
targetIframe2.contentDocument.body.requestPointerLock().catch(error => {
error_code = error.code;
shouldBe("error_code", "4", "Should reject with a WrongDocumentError");
});
},
function () {
expectNoEvents("Unlock targetIframe2.");
......@@ -87,7 +91,9 @@
shouldBeDefined("testRunner.setPointerLockWillFail");
testRunner.setPointerLockWillFail();
expectOnlyErrorEvent("Lock with synchronous failure.");
targetDiv1.requestPointerLock();
targetDiv1.requestPointerLock().catch(error => {
// This is a forced error the type of error returned here is not important.
});
},
function () {
shouldBeDefined("testRunner.setPointerLockWillRespondAsynchronously");
......@@ -95,7 +101,10 @@
shouldBeDefined("testRunner.allowPointerLock");
testRunner.setPointerLockWillRespondAsynchronously();
expectOnlyErrorEvent("Lock with asynchronous failure.");
targetDiv1.requestPointerLock();
targetDiv1.requestPointerLock().catch(error => {
error_code = error.code;
shouldBe("error_code", "0", "Should reject with a forced error");
});
doNextStep();
},
function () {
......
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