Commit 2453e3e2 authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Test restricted gamepad access in WPT

This CL adds WPT for gamepad feature policy and secure context. It also
adds virtual tests suites and expected results as these restrictions are
currently behind a flag.

Bug: 1098921
Change-Id: Icde27ddfbb6f95220d0b7455ae7c8da3fea11d82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333537
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarJames Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794292}
parent d3904f71
...@@ -764,5 +764,10 @@ ...@@ -764,5 +764,10 @@
"http/tests/portals", "http/tests/portals",
"wpt_internal/portals" ], "wpt_internal/portals" ],
"args": [ "--enable-features=Portals,PortalsCrossOrigin" ] "args": [ "--enable-features=Portals,PortalsCrossOrigin" ]
},
{
"prefix": "restrict-gamepad",
"bases": [ "external/wpt/gamepad" ],
"args": [ "--enable-features=RestrictGamepadAccess" ]
} }
] ]
<script>
try {
let test = navigator.getGamepads();
if (test)
window.parent.postMessage({ enabled:true}, '*');
} catch (err) {
window.parent.postMessage({ enabled:false}, '*');
}
</script>
\ No newline at end of file
This is a testharness.js-based test.
PASS Feature-Policy allow="gamepad" allows same-origin by default.
PASS Feature-Policy allow="gamepad" allows cross-origin with feature allowed.
FAIL Feature-Policy allow="gamepad" disallows cross-origin by default. assert_false: getGamepads() expected false got true
Harness: the test ran to completion.
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/feature-policy/resources/featurepolicy.js></script>
<script src=util/utils.js></script>
<script>
'use strict';
const relative_path = '/gamepad/feature-policy-gamepad.html';
const base_src = '/feature-policy/resources/redirect-on-load.html#';
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = base_src + relative_path;
const cross_origin_src = sub + relative_path;
const header = 'Feature-Policy allow="gamepad"';
async_test(t => {
test_feature_availability(
'getGamepads()', t, same_origin_src,
expect_feature_available_default);
}, header + ' allows same-origin by default.');
async_test(t => {
test_feature_availability(
'getGamepads()', t, cross_origin_src,
expect_feature_available_default, 'gamepad');
}, header + ' allows cross-origin with feature allowed.');
async_test(t => {
test_feature_availability(
'getGamepads()', t, cross_origin_src,
expect_feature_unavailable_default);
}, header + ' disallows cross-origin by default.');
</script>
</body>
\ No newline at end of file
This is a testharness.js-based test.
FAIL When in a non-secure context, getGamepad() should throw an error. promise_test: Unhandled rejection with value: "getGamepads should throw an error when being called in non-secure contexts."
Harness: the test ran to completion.
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Gamepad Test: non-secure contexts</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(() => {
return new Promise((resolve, reject) => {
try {
navigator.getGamepads();
reject(
"getGamepads should throw an error when being called in non-secure contexts."
);
} catch (error) {
resolve();
}
});
}, "When in a non-secure context, getGamepad() should throw an error.");
</script>
<!DOCTYPE html>
<title>Test that gamepad is advertised in the feature list</title>
<link rel="help" href="https://w3c.github.io/webappsec-feature-policy/#dom-featurepolicy-features">
<link rel="help" href="https://github.com/w3c/encrypted-media/pull/432">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_in_array('gamepad', document.featurePolicy.features());
}, 'document.featurePolicy.features should advertise gamepad.');
</script>
\ No newline at end of file
This directory contains tests for the [Gamepad API](https://www.w3.org/TR/gamepad/).
Specifically this virtual test suite tests the new [Permission Policy requirement](https://github.com/w3c/gamepad/pull/112)
and the new [Secure Context requirement(https://github.com/w3c/gamepad/pull/120)
**This suite runs the tests with** `--enable-features=RestrictGamepadAccess`
\ No newline at end of file
These tests run the WPT for gamepad Permission Policy and Secure Context
requirements with the restrict-gamepad-access flag turned on.
\ No newline at end of file
This is a testharness.js-based test.
PASS Feature-Policy allow="gamepad" allows same-origin by default.
PASS Feature-Policy allow="gamepad" allows cross-origin with feature allowed.
PASS Feature-Policy allow="gamepad" disallows cross-origin by default.
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS When in a non-secure context, getGamepad() should throw an error.
Harness: the test ran to completion.
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