mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1589554 - Part 6: Screen Wake Lock testing. r=webdriver-reviewers,webidl,dom-core,saschanaz,whimboo,edgar
Depends on D189512 Differential Revision: https://phabricator.services.mozilla.com/D189513
This commit is contained in:
parent
6f5f80d733
commit
438533784b
@ -32,6 +32,8 @@ UNIFIED_SOURCES += [
|
||||
"WakeLockSentinel.cpp",
|
||||
]
|
||||
|
||||
MOCHITEST_MANIFESTS += ["tests/mochitest.toml"]
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
|
9
dom/power/tests/mochitest.toml
Normal file
9
dom/power/tests/mochitest.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[DEFAULT]
|
||||
prefs = ["dom.screenwakelock.enabled=true"]
|
||||
scheme = "https"
|
||||
|
||||
["test_wakelock_default_permission.html"]
|
||||
fail-if = ["xorigin"] # cross-origin use requires permissions policy
|
||||
|
||||
["test_dynamic_pref_change.html"]
|
||||
fail-if = ["xorigin"] # cross-origin use requires permissions policy
|
34
dom/power/tests/test_dynamic_pref_change.html
Normal file
34
dom/power/tests/test_dynamic_pref_change.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Screen Wake Lock responds to dynamic pref changes</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
/* globals SpecialPowers */
|
||||
'use strict';
|
||||
|
||||
function spinEventLoop() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function my_test() {
|
||||
const lock = await navigator.wakeLock.request("screen");
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.screenwakelock.enabled", false]],
|
||||
});
|
||||
await spinEventLoop();
|
||||
ok(lock.released, "Lock was released once pref was deactivated");
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
</body>
|
||||
</html>
|
20
dom/power/tests/test_wakelock_default_permission.html
Normal file
20
dom/power/tests/test_wakelock_default_permission.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Screen Wake Lock Permission Granted by Default</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||
<script>
|
||||
add_task(async function my_test() {
|
||||
const status = await navigator.permissions.query({name:'screen-wake-lock'});
|
||||
is(status.state, "granted", "Permission is granted by default");
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
</body>
|
||||
</html>
|
@ -26,6 +26,7 @@ let supportedFeatures = [
|
||||
"speaker-selection",
|
||||
"vr",
|
||||
"web-share",
|
||||
"screen-wake-lock",
|
||||
];
|
||||
|
||||
function checkFeatures(features) {
|
||||
|
@ -1967,6 +1967,10 @@ let interfaceNamesInGlobalScope = [
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "visualViewport", insecureContext: true },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "WakeLock", nightly: true },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "WakeLockSentinel", nightly: true },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "webkitURL", insecureContext: true },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "window", insecureContext: true },
|
||||
|
@ -3467,6 +3467,12 @@
|
||||
value: @IS_NIGHTLY_BUILD@
|
||||
mirror: always
|
||||
|
||||
# Prevent errors when using set_permission from permissions.sys.mjs
|
||||
- name: dom.screenwakelock.testing
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether to enable the JavaScript start-up cache. This causes one of the first
|
||||
# execution to record the bytecode of the JavaScript function used, and save it
|
||||
# in the existing cache entry. On the following loads of the same script, the
|
||||
|
@ -114,6 +114,13 @@ permissions.set = function (
|
||||
`'Set Permission' did not work for storage-access'`
|
||||
);
|
||||
}
|
||||
} else if (name === "screen-wake-lock") {
|
||||
if (Services.prefs.getBoolPref("dom.screenwakelock.testing", false)) {
|
||||
return;
|
||||
}
|
||||
throw new lazy.error.UnsupportedOperationError(
|
||||
"'Set Permission' expected dom.screenwakelock.testing to be set"
|
||||
);
|
||||
}
|
||||
|
||||
throw new lazy.error.UnsupportedOperationError(
|
||||
|
@ -23,9 +23,6 @@
|
||||
[Query "nfc" permission]
|
||||
expected: FAIL
|
||||
|
||||
[Query "screen-wake-lock" permission]
|
||||
expected: FAIL
|
||||
|
||||
[Query "camera" permission]
|
||||
expected: FAIL
|
||||
|
||||
|
1
testing/web-platform/meta/screen-wake-lock/__dir__.ini
Normal file
1
testing/web-platform/meta/screen-wake-lock/__dir__.ini
Normal file
@ -0,0 +1 @@
|
||||
prefs: [marionette.setpermission.enabled:true, dom.screenwakelock.enabled:true, dom.screenwakelock.testing:true]
|
@ -1,3 +1,3 @@
|
||||
[chrome-bug-1348019.https.html]
|
||||
[Appending iframe in release event listener does not cause a crash when page visibility changes]
|
||||
expected: FAIL
|
||||
expected:
|
||||
if (os == "android"): ERROR # cannot minimize window
|
||||
|
@ -1,91 +0,0 @@
|
||||
[idlharness.https.window.html]
|
||||
[WakeLockSentinel interface: operation release()]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[idl_test setup]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: existence and properties of interface object]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: existence and properties of interface prototype object's @@unscopables property]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel must be primary interface of sentinel]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: sentinel must inherit property "onrelease" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: sentinel must inherit property "release()" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[Stringification of sentinel]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface object name]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: attribute type]
|
||||
expected: FAIL
|
||||
|
||||
[Navigator interface: attribute wakeLock]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: existence and properties of interface object]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface object name]
|
||||
expected: FAIL
|
||||
|
||||
[Stringification of navigator.wakeLock]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: existence and properties of interface prototype object's "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: sentinel must inherit property "type" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: attribute onrelease]
|
||||
expected: FAIL
|
||||
|
||||
[Navigator interface: navigator must inherit property "wakeLock" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: existence and properties of interface prototype object's @@unscopables property]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: existence and properties of interface prototype object's "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock must be primary interface of navigator.wakeLock]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: sentinel must inherit property "released" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLockSentinel interface: attribute released]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: calling request(optional WakeLockType) on navigator.wakeLock with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: navigator.wakeLock must inherit property "request(optional WakeLockType)" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[WakeLock interface: operation request(optional WakeLockType)]
|
||||
expected: FAIL
|
||||
|
@ -1,7 +0,0 @@
|
||||
[wakelock-active-document.https.window.html]
|
||||
[navigator.wakeLock.request() aborts if the document is not active.]
|
||||
expected: FAIL
|
||||
|
||||
[navigator.wakeLock.request() aborts if the document is active, but not fully active.]
|
||||
expected: FAIL
|
||||
|
@ -3,3 +3,6 @@
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[Permissions-Policy header "screen-wake-lock=()" disallows the top-level document.]
|
||||
expected: FAIL
|
||||
|
||||
[Permissions-Policy header "screen-wake-lock=()" disallows same-origin iframes.]
|
||||
expected: FAIL
|
||||
|
@ -1,6 +1,3 @@
|
||||
[wakelock-document-hidden.https.html]
|
||||
[navigator.wakeLock.request('screen') fails when the document is hidden]
|
||||
expected: FAIL
|
||||
|
||||
[Screen wake locks are released when the document the page is hidden]
|
||||
expected: FAIL
|
||||
expected:
|
||||
if (os == "android"): ERROR # cannot minimize window
|
||||
|
@ -1,5 +0,0 @@
|
||||
[wakelock-enabled-by-permissions-policy-attribute-redirect-on-load.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[Permissions-Policy allow="screen-wake-lock" allows same-origin relocation]
|
||||
expected: FAIL
|
@ -1,6 +0,0 @@
|
||||
[wakelock-enabled-by-permissions-policy-attribute.https.html]
|
||||
[Permissions policy "screen-wake-lock" can be enabled in same-origin iframe using allow="screen-wake-lock" attribute]
|
||||
expected: FAIL
|
||||
|
||||
[Permissions policy "screen-wake-lock" can be enabled in cross-origin iframe using allow="screen-wake-lock" attribute]
|
||||
expected: FAIL
|
@ -1,11 +0,0 @@
|
||||
[wakelock-enabled-by-permissions-policy.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[Permissions-Policy header "screen-wake-lock=*" allows the top-level document.]
|
||||
expected: FAIL
|
||||
|
||||
[Permissions-Policy header "screen-wake-lock=*" allows same-origin iframes.]
|
||||
expected: FAIL
|
||||
|
||||
[Permissions-Policy header "screen-wake-lock=*" allows cross-origin iframes.]
|
||||
expected: FAIL
|
@ -1,8 +0,0 @@
|
||||
[wakelock-enabled-on-self-origin-by-permissions-policy.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[Permissions-Policy header "screen-wake-lock=self" allows the top-level document.]
|
||||
expected: FAIL
|
||||
|
||||
[Permissions-Policy header "screen-wake-lock=self" allows same-origin iframes.]
|
||||
expected: FAIL
|
@ -1,7 +0,0 @@
|
||||
[wakelock-insecure-context.any.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
|
||||
[wakelock-insecure-context.any.worker.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
@ -1,8 +0,0 @@
|
||||
[wakelock-onrelease.https.html]
|
||||
expected:
|
||||
if swgl and (os == "win"): [OK, ERROR]
|
||||
[Test onreleased event's basic properties]
|
||||
expected: FAIL
|
||||
|
||||
[Ensure onreleased is called before WakeLockSentinel.release() resolves]
|
||||
expected: FAIL
|
@ -1,5 +0,0 @@
|
||||
[wakelock-released.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[The released attribute inside an event handler]
|
||||
expected: FAIL
|
@ -1,5 +1,3 @@
|
||||
[wakelock-request-denied.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[Denied requests should abort with NotAllowedError]
|
||||
expected: FAIL
|
||||
|
@ -1,5 +1,2 @@
|
||||
[wakelock-supported-by-permissions-policy.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[document.featurePolicy.features should advertise screen-wake-lock.]
|
||||
expected: FAIL
|
||||
prefs: [dom.security.featurePolicy.webidl.enabled:true]
|
||||
|
@ -1,8 +0,0 @@
|
||||
[wakelock-type.https.window.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
['type' parameter in WakeLock.request() defaults to 'screen']
|
||||
expected: FAIL
|
||||
|
||||
['TypeError' is thrown when set an invalid wake lock type]
|
||||
expected: FAIL
|
@ -1,5 +1,2 @@
|
||||
[wakelockpermissiondescriptor.https.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[PermissionDescriptor with name='screen-wake-lock' works]
|
||||
expected: FAIL
|
||||
prefs: [permissions.default.screen-wake-lock:2]
|
||||
|
@ -4,15 +4,19 @@
|
||||
"use strict";
|
||||
|
||||
Promise.resolve().then(async () => {
|
||||
try {
|
||||
await test_driver.set_permission(
|
||||
{ name: 'screen-wake-lock' }, 'granted');
|
||||
test_driver.set_test_context(window.parent);
|
||||
await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
|
||||
|
||||
try {
|
||||
const wakeLock = await navigator.wakeLock.request("screen");
|
||||
await wakeLock.release();
|
||||
window.parent.postMessage({ type: 'availability-result', enabled: true }, "*");
|
||||
await wakeLock.release();
|
||||
} catch (e) {
|
||||
window.parent.postMessage({ type: 'availability-result', enabled: false }, "*");
|
||||
if (e instanceof DOMException && e.name === "NotAllowedError") {
|
||||
window.parent.postMessage({ type: 'availability-result', enabled: false }, "*");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -2,6 +2,8 @@
|
||||
<body>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<script src="/permissions-policy/resources/permissions-policy.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
|
@ -2,6 +2,8 @@
|
||||
<body>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<script src="/permissions-policy/resources/permissions-policy.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
|
@ -2,6 +2,8 @@
|
||||
<body>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<script src="/permissions-policy/resources/permissions-policy.js"></script>
|
||||
<script src="/common/get-host-info.sub.js"></script>
|
||||
<script>
|
||||
|
@ -35,5 +35,20 @@ promise_test(async t => {
|
||||
assert_true(releaseFired, "The 'release' event fires immediately after release() is called");
|
||||
|
||||
return releasePromise;
|
||||
}, "Ensure onreleased is called before WakeLockSentinel.release() resolves");
|
||||
}, "Ensure onrelease is called before WakeLockSentinel.release() resolves");
|
||||
|
||||
promise_test(async t => {
|
||||
await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
|
||||
|
||||
const lock = await navigator.wakeLock.request("screen");
|
||||
|
||||
let eventCount = 0;
|
||||
lock.onrelease = t.step_func(() => {
|
||||
eventCount++;
|
||||
});
|
||||
|
||||
await lock.release();
|
||||
await lock.release();
|
||||
assert_equals(eventCount, 1, "The 'release' event was fired once");
|
||||
}, "Ensure onrelease is fired exactly once");
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user