mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
Bug 1554569 [wpt PR 17019] - Adapt the rest wake lock tests to latest spec, a=testonly
Automatic update from web-platform-tests Adapt the rest wake lock tests to latest spec (#17019) - Remove some tests since `state`, `type` and `onactivechange` had been removed from latest spec - Enable insecure context and invalid type tests on Worker -- wp5At-commits: 7cb8a811bbba84c4da802dbd9cce3247104dca77 wpt-pr: 17019
This commit is contained in:
parent
ff9e53f2f1
commit
85c9f7f56a
@ -0,0 +1,5 @@
|
|||||||
|
//META: title=Wake Lock API is not exposed in an insecure context
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
assert_false("WakeLock" in self, "'WakeLock' must not be exposed");
|
||||||
|
}, "Wake Lock API is not exposed in an insecure context");
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Wake Lock API is not exposed in an insecure context</title>
|
|
||||||
<link rel="help" href="https://w3c.github.io/wake-lock/#wake-locks">
|
|
||||||
<script src="/resources/testharness.js"></script>
|
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
|
||||||
<script>
|
|
||||||
|
|
||||||
test(t => {
|
|
||||||
assert_false("WakeLock" in self, "'WakeLock' must not be exposed");
|
|
||||||
}, "Wake Lock API is not exposed in an insecure context");
|
|
||||||
|
|
||||||
</script>
|
|
@ -1,75 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>wake lock state should be global</title>
|
|
||||||
<link rel="help" href="https://w3c.github.io/wake-lock/">
|
|
||||||
<script src="/resources/testharness.js"></script>
|
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<script id="iframe" type="text/plain">
|
|
||||||
let iframeWakeLock;
|
|
||||||
const controller = new AbortController();
|
|
||||||
const signal = controller.signal;
|
|
||||||
window.onmessage = async message => {
|
|
||||||
switch(message.data) {
|
|
||||||
case "ACQUIRED":
|
|
||||||
iframeWakeLock = new WakeLock("screen");
|
|
||||||
await iframeWakeLock.request({ signal });
|
|
||||||
parent.postMessage(iframeWakeLock.active, "*");
|
|
||||||
break;
|
|
||||||
case "RELEASED":
|
|
||||||
controller.abort();
|
|
||||||
parent.postMessage(iframeWakeLock.active, "*");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
parent.postMessage("unknown operation", "*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function load_iframe() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const iframe = document.createElement("iframe");
|
|
||||||
iframe.onload = () => { resolve(iframe); };
|
|
||||||
iframe.srcdoc = "<script>" +
|
|
||||||
document.getElementById('iframe').textContent +
|
|
||||||
"<\/script>";
|
|
||||||
document.body.appendChild(iframe);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function wait_for_message(iframe) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
self.addEventListener("message", function listener(e) {
|
|
||||||
if (e.source === iframe.contentWindow) {
|
|
||||||
resolve(e.data);
|
|
||||||
self.removeEventListener("message", listener);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
promise_test(async t => {
|
|
||||||
const wakeLock = await new WakeLock("screen");
|
|
||||||
const iframe = await load_iframe();
|
|
||||||
const eventWatcher = new EventWatcher(t, wakeLock, "activechange");
|
|
||||||
|
|
||||||
assert_false(wakeLock.active, "wakeLock is initially false");
|
|
||||||
|
|
||||||
//when iframe wake lock is acquired, parent wake lock should be actived
|
|
||||||
iframe.contentWindow.postMessage("ACQUIRED", "*");
|
|
||||||
const isActive1 = await wait_for_message(iframe);
|
|
||||||
await eventWatcher.wait_for("activechange");
|
|
||||||
assert_true(isActive1, "the iframe wake lock state is actived when iframe wake lock is acquired");
|
|
||||||
assert_true(wakeLock.active, "the wake lock state is actived when iframe wake lock is acquired");
|
|
||||||
|
|
||||||
//when iframe wake lock is released, parent wake lock should be inactived
|
|
||||||
iframe.contentWindow.postMessage("RELEASED", "*");
|
|
||||||
const isActive2 = await wait_for_message(iframe);
|
|
||||||
eventWatcher.wait_for("activechange");
|
|
||||||
assert_false(isActive2, "the iframe wake lock state is inactived when iframe wake lock is released");
|
|
||||||
assert_false(wakeLock.active, "the wake lock state is inactived when iframe wake lock is released");
|
|
||||||
}, "Test that wake lock state should be global");
|
|
||||||
</script>
|
|
||||||
</body>
|
|
@ -0,0 +1,19 @@
|
|||||||
|
//META: title=WakeLock.request() with invaild type
|
||||||
|
|
||||||
|
promise_test(async t => {
|
||||||
|
await promise_rejects(t, new TypeError(), WakeLock.request());
|
||||||
|
}, "'TypeError' is thrown when set an empty wake lock type");
|
||||||
|
|
||||||
|
promise_test(t => {
|
||||||
|
const invalidTypes = [
|
||||||
|
"invalid",
|
||||||
|
null,
|
||||||
|
123,
|
||||||
|
{},
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
];
|
||||||
|
invalidTypes.map(async invalidType => {
|
||||||
|
await promise_rejects(t, new TypeError(), WakeLock.request(invalidType));
|
||||||
|
});
|
||||||
|
}, "'TypeError' is thrown when set an invalid wake lock type");
|
@ -1,38 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>WakeLockType Test</title>
|
|
||||||
<link rel="help" href="https://w3c.github.io/wake-lock/">
|
|
||||||
<script src="/resources/testharness.js"></script>
|
|
||||||
<script src="/resources/testharnessreport.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
test(() => {
|
|
||||||
const wakeLock = new WakeLock("screen");
|
|
||||||
assert_equals(wakeLock.type, "screen");
|
|
||||||
}, "Test that wakeLock.type is 'screen' when screen wake lock is invoked");
|
|
||||||
|
|
||||||
test(() => {
|
|
||||||
const wakeLock = new WakeLock("system");
|
|
||||||
assert_equals(wakeLock.type, "system");
|
|
||||||
}, "Test that wakeLock.type is 'system' when system wake lock is invoked");
|
|
||||||
|
|
||||||
test(() => {
|
|
||||||
assert_throws(new TypeError(), () => new WakeLock());
|
|
||||||
}, "'TypeError' is thrown when set an empty wake lock type");
|
|
||||||
|
|
||||||
test(() => {
|
|
||||||
const invalidTypes = [
|
|
||||||
"invalid",
|
|
||||||
null,
|
|
||||||
123,
|
|
||||||
{},
|
|
||||||
"",
|
|
||||||
true
|
|
||||||
];
|
|
||||||
invalidTypes.map(invalidType => {
|
|
||||||
assert_throws(new TypeError(), () => new WakeLock(invalidType));
|
|
||||||
})
|
|
||||||
}, "'TypeError' is thrown when set an invalid wake lock type");
|
|
||||||
|
|
||||||
</script>
|
|
Loading…
Reference in New Issue
Block a user