diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/screen-wake-lock | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/screen-wake-lock')
22 files changed, 494 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-wake-lock/META.yml b/testing/web-platform/tests/screen-wake-lock/META.yml new file mode 100644 index 0000000000..b311993d82 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/META.yml @@ -0,0 +1,6 @@ +spec: https://w3c.github.io/screen-wake-lock/ +suggested_reviewers: + - Honry + - marcoscaceres + - rakuco + - reillyeon diff --git a/testing/web-platform/tests/screen-wake-lock/idlharness.https.window.js b/testing/web-platform/tests/screen-wake-lock/idlharness.https.window.js new file mode 100644 index 0000000000..6509d9c70e --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/idlharness.https.window.js @@ -0,0 +1,27 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js +// META: timeout=long + +// https://w3c.github.io/screen-wake-lock/ + +'use strict'; + +idl_test( + ['screen-wake-lock'], + ['dom', 'html'], + async idl_array => { + idl_array.add_objects({ Navigator: ['navigator'] }); + + idl_array.add_objects({ + WakeLock: ['navigator.wakeLock'], + WakeLockSentinel: ['sentinel'], + }); + + await test_driver.set_permission( + { name: 'screen-wake-lock' }, 'granted'); + self.sentinel = await navigator.wakeLock.request('screen'); + self.sentinel.release(); + } +); diff --git a/testing/web-platform/tests/screen-wake-lock/resources/page1.html b/testing/web-platform/tests/screen-wake-lock/resources/page1.html new file mode 100644 index 0000000000..7fc080d380 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/resources/page1.html @@ -0,0 +1 @@ +<meta charset="utf-8"> diff --git a/testing/web-platform/tests/screen-wake-lock/resources/page2.html b/testing/web-platform/tests/screen-wake-lock/resources/page2.html new file mode 100644 index 0000000000..7fc080d380 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/resources/page2.html @@ -0,0 +1 @@ +<meta charset="utf-8"> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-active-document.https.window.js b/testing/web-platform/tests/screen-wake-lock/wakelock-active-document.https.window.js new file mode 100644 index 0000000000..724ce09196 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-active-document.https.window.js @@ -0,0 +1,87 @@ +function getWakeLockObject(iframe, url) { + return new Promise(resolve => { + iframe.addEventListener( + "load", + () => { + const { wakeLock } = iframe.contentWindow.navigator; + resolve(wakeLock); + }, + { once: true } + ); + iframe.src = url; + }); +} + +promise_test(async t => { + const iframe = document.createElement("iframe"); + document.body.appendChild(iframe); + // We first got to page1.html, grab a WakeLock object. + const wakeLock1 = await getWakeLockObject( + iframe, + "/screen-wake-lock/resources/page1.html" + ); + // Save the DOMException of page1.html before navigating away. + const frameDOMException1 = iframe.contentWindow.DOMException; + // We navigate the iframe again, putting wakeLock1's document into an inactive state. + const wakeLock2 = await getWakeLockObject( + iframe, + "/screen-wake-lock/resources/page2.html" + ); + // Now, wakeLock1's relevant global object's document is no longer active. + // So, call .request(), and make sure it rejects appropriately. + await promise_rejects_dom( + t, + "NotAllowedError", + frameDOMException1, + wakeLock1.request('screen'), + "Inactive document, so must throw NotAllowedError" + ); + // We are done, so clean up. + iframe.remove(); +}, "navigator.wakeLock.request() aborts if the document is not active."); + +promise_test(async t => { + // We nest two iframes and wait for them to load. + const outerIframe = document.createElement("iframe"); + document.body.appendChild(outerIframe); + // Load the outer iframe (we don't care about the awaited request) + await getWakeLockObject( + outerIframe, + "/screen-wake-lock/resources/page1.html" + ); + + // Now we create the inner iframe + const innerIframe = outerIframe.contentDocument.createElement("iframe"); + + // nest them + outerIframe.contentDocument.body.appendChild(innerIframe); + + // load innerIframe, and get the WakeLock instance + const wakeLock = await getWakeLockObject( + innerIframe, + "/screen-wake-lock/resources/page2.html" + ); + // Save DOMException from innerIframe before navigating away. + const innerIframeDOMException = innerIframe.contentWindow.DOMException; + + // Navigate the outer iframe to a new location. + // Wait for the load event to fire. + await new Promise(resolve => { + outerIframe.addEventListener("load", resolve); + outerIframe.src = "/screen-wake-lock/resources/page2.html"; + }); + + // Now, request's relevant global object's document is still active + // (it is the active document of the inner iframe), but is not fully active + // (since the parent of the inner iframe is itself no longer active). + // So, call request.show() and make sure it rejects appropriately. + await promise_rejects_dom( + t, + "NotAllowedError", + innerIframeDOMException, + wakeLock.request('screen'), + "Active, but not fully active, so must throw NotAllowedError" + ); + // We are done, so clean up. + outerIframe.remove(); +}, "navigator.wakeLock.request() aborts if the document is active, but not fully active."); diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html new file mode 100644 index 0000000000..fe4147b46c --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/permissions-policy/resources/permissions-policy.js"></script> +<script src="/common/get-host-info.sub.js"></script> +<script> + "use strict"; + + const same_origin_src = + "/permissions-policy/resources/permissions-policy-screen-wakelock.html"; + const cross_origin_src = + get_host_info().HTTPS_REMOTE_ORIGIN + same_origin_src; + + const header = 'Permissions-Policy header "screen-wake-lock=()"'; + + promise_test(t => { + return promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request("screen")); + }, `${header} disallows the top-level document.`); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + same_origin_src, + expect_feature_unavailable_default + ); + }, `${header} disallows same-origin iframes.`); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + cross_origin_src, + expect_feature_unavailable_default + ); + }, `${header} disallows cross-origin iframes.`); +</script> +</body> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html.headers b/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html.headers new file mode 100644 index 0000000000..66f07f4c1c --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-disabled-by-permissions-policy.https.html.headers @@ -0,0 +1 @@ +Permissions-Policy: screen-wake-lock=() diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden-manual.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden-manual.https.html new file mode 100644 index 0000000000..05368bdfb8 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden-manual.https.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<meta name="timeout" content="long"> +<title>Screen wake locks respect page visibility changes</title> +<link rel="help" href="https://w3c.github.io/screen-wake-lock/#handling-document-loss-of-visibility"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +promise_test(async t => { + const screenWakeLock = await navigator.wakeLock.request('screen'); + assert_false(screenWakeLock.released, "The released attribute is initially false") + const screenWakeLockReleased = + new EventWatcher(t, screenWakeLock, "release").wait_for("release"); + + const eventWatcher = new EventWatcher(t, document, "visibilitychange"); + await eventWatcher.wait_for("visibilitychange"); + assert_true(document.hidden, "document is hidden after the visibilitychange event"); + await screenWakeLockReleased; + assert_true(screenWakeLock.released, "The released attribute is true after the lock is released"); + await promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen'), + "new screen locks are not allowed when the page is not visible"); + + await eventWatcher.wait_for("visibilitychange"); + assert_false(document.hidden, "document is no longer hidden after the visibilitychange event"); +}, "Test screen locks respect page visibility changes"); + +</script> + +<p>Switch the page to the background, then switch back to it.</p> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute-redirect-on-load.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute-redirect-on-load.https.html new file mode 100644 index 0000000000..acfce43f96 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute-redirect-on-load.https.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/permissions-policy/resources/permissions-policy.js"></script> +<script src="/common/get-host-info.sub.js"></script> +<script> + "use strict"; + + const relative_path = "/permissions-policy/resources/permissions-policy-screen-wakelock.html"; + const base_src = "/permissions-policy/resources/redirect-on-load.html#"; + const same_origin_src = base_src + relative_path; + const cross_origin_src = + base_src + get_host_info().HTTPS_REMOTE_ORIGIN + relative_path; + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + same_origin_src, + expect_feature_available_default, + "screen-wake-lock" + ); + }, 'Permissions-Policy allow="screen-wake-lock" allows same-origin relocation'); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + cross_origin_src, + expect_feature_unavailable_default, + "screen-wake-lock" + ); + }, 'Permissions-Policy allow="screen-wake-lock" disallows cross-origin relocation'); + +</script> +</body> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute.https.html new file mode 100644 index 0000000000..c2be3a4508 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy-attribute.https.html @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/permissions-policy/resources/permissions-policy.js"></script> +<script src="/common/get-host-info.sub.js"></script> +<script> + "use strict"; + + const same_origin_src = + "/permissions-policy/resources/permissions-policy-screen-wakelock.html"; + const cross_origin_src = + get_host_info().HTTPS_REMOTE_ORIGIN + same_origin_src; + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + same_origin_src, + expect_feature_available_default, + "screen-wake-lock" + ); + }, 'Permissions policy "screen-wake-lock" can be enabled in same-origin iframe using allow="screen-wake-lock" attribute'); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + cross_origin_src, + expect_feature_available_default, + "screen-wake-lock" + ); + }, 'Permissions policy "screen-wake-lock" can be enabled in cross-origin iframe using allow="screen-wake-lock" attribute'); +</script> +</body> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html new file mode 100644 index 0000000000..cc9106967e --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<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> + "use strict"; + + const same_origin_src = + "/permissions-policy/resources/permissions-policy-screen-wakelock.html"; + const cross_origin_src = + get_host_info().HTTPS_REMOTE_ORIGIN + same_origin_src; + + const header = 'Permissions-Policy header "screen-wake-lock=*"'; + + promise_test(async t => { + await test_driver.set_permission( + { name: 'screen-wake-lock' }, 'granted'); + await navigator.wakeLock.request('screen').then(lock => lock.release()); + }, `${header} allows the top-level document.`); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + same_origin_src, + expect_feature_available_default + ); + }, `${header} allows same-origin iframes.`); + + // Set allow="screen-wake-lock" on iframe element to delegate + // 'screen-wake-lock' to cross origin subframe. + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + cross_origin_src, + expect_feature_available_default, + 'screen-wake-lock' + ); + }, `${header} allows cross-origin iframes.`); + +</script> +</body> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html.headers b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html.headers new file mode 100644 index 0000000000..ea7d848e74 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-by-permissions-policy.https.html.headers @@ -0,0 +1 @@ +Permissions-Policy: screen-wake-lock=* diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html new file mode 100644 index 0000000000..5b90b4f4ce --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<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> + "use strict"; + + const same_origin_src = + "/permissions-policy/resources/permissions-policy-screen-wakelock.html"; + const cross_origin_src = + get_host_info().HTTPS_REMOTE_ORIGIN + same_origin_src; + + const header = 'Permissions-Policy header "screen-wake-lock=self"'; + + promise_test(async t => { + await test_driver.set_permission( + { name: 'screen-wake-lock' }, 'granted'); + await navigator.wakeLock.request('screen').then(lock => lock.release()); + }, `${header} allows the top-level document.`); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + same_origin_src, + expect_feature_available_default + ); + }, `${header} allows same-origin iframes.`); + + async_test(t => { + test_feature_availability( + 'navigator.wakeLock.request("screen")', + t, + cross_origin_src, + expect_feature_unavailable_default + ); + }, `${header} disallows cross-origin iframes.`); +</script> +</body> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html.headers b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html.headers new file mode 100644 index 0000000000..9849d6b89b --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-enabled-on-self-origin-by-permissions-policy.https.html.headers @@ -0,0 +1 @@ +Permissions-Policy: screen-wake-lock=self diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-insecure-context.any.js b/testing/web-platform/tests/screen-wake-lock/wakelock-insecure-context.any.js new file mode 100644 index 0000000000..f32cc3c354 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-insecure-context.any.js @@ -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"); diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-onrelease.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-onrelease.https.html new file mode 100644 index 0000000000..fb071b3763 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-onrelease.https.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<link rel="help" href="https://w3c.github.io/screen-wake-lock/#the-onrelease-attribute"> +<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> +promise_test(async t => { + await test_driver.set_permission({name: 'screen-wake-lock'}, 'granted'); + + const lock = await navigator.wakeLock.request("screen"); + return new Promise(resolve => { + lock.onrelease = resolve; + lock.release(); + }).then(ev => { + assert_class_string(ev, "Event", "release() must fire an Event object"); + assert_equals(ev.target, lock, "The event's target must be the lock that was acquired"); + assert_true(ev.isTrusted); + assert_false(ev.bubbles); + assert_false(ev.cancelable); + }); +}, "Test onreleased event's basic properties"); + +promise_test(async t => { + await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted'); + + const lock = await navigator.wakeLock.request("screen"); + + let releaseFired = false; + lock.onrelease = t.step_func(() => { + releaseFired = true; + }); + + const releasePromise = lock.release(); + assert_true(releaseFired, "The 'release' event fires immediately after release() is called"); + + return releasePromise; +}, "Ensure onreleased is called before WakeLockSentinel.release() resolves"); +</script> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-released.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-released.https.html new file mode 100644 index 0000000000..8d351e3e68 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-released.https.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<link rel="help" href="https://w3c.github.io/screen-wake-lock/#dom-wakelocksentinel-released"> +<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> +promise_test(async t => { + await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted'); + + const lock = await navigator.wakeLock.request("screen"); + assert_false(lock.released, "lock.released must be false on creation"); + + lock.onrelease = t.step_func(() => { + assert_true(lock.released, "WakeLockSentinel.released is true in an onrelease event handler"); + }); + await lock.release(); + assert_true(lock.released, "WakeLockSentinel.released remains true outside the event handler"); +}, "The released attribute inside an event handler"); +</script> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-request-denied.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-request-denied.https.html new file mode 100644 index 0000000000..f3fede6e10 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-request-denied.https.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> +<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> +'use strict'; + +promise_test(async t => { + await test_driver.set_permission({name: 'screen-wake-lock'}, 'denied'); + return promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen')); +}, 'Denied requests should abort with NotAllowedError'); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-screen-type-on-worker.https.worker.js b/testing/web-platform/tests/screen-wake-lock/wakelock-screen-type-on-worker.https.worker.js new file mode 100644 index 0000000000..0201294e23 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-screen-type-on-worker.https.worker.js @@ -0,0 +1,8 @@ +//META: title=Screen wake lock should not be allowed in dedicated worker +importScripts("/resources/testharness.js"); + +promise_test(t => { + return promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen')); +}, "Screen wake lock should not be allowed in dedicated worker"); + +done(); diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-supported-by-permissions-policy.html b/testing/web-platform/tests/screen-wake-lock/wakelock-supported-by-permissions-policy.html new file mode 100644 index 0000000000..cc0bb963b1 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-supported-by-permissions-policy.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<title>Test that screen-wake-lock 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://w3c.github.io/screen-wake-lock/#dfn-wake-lock-feature"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(() => { + assert_in_array('screen-wake-lock', document.featurePolicy.features()); +}, 'document.featurePolicy.features should advertise screen-wake-lock.'); +</script> diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-type.https.window.js b/testing/web-platform/tests/screen-wake-lock/wakelock-type.https.window.js new file mode 100644 index 0000000000..5008064684 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelock-type.https.window.js @@ -0,0 +1,21 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js + +promise_test(async t => { + await test_driver.set_permission( + {name: 'screen-wake-lock'}, 'granted'); + + const lock = await navigator.wakeLock.request(); + t.add_cleanup(() => { + lock.release(); + }); + assert_equals(lock.type, 'screen'); +}, '\'type\' parameter in WakeLock.request() defaults to \'screen\''); + +promise_test(t => { + const invalidTypes = ['invalid', null, 123, {}, '', true]; + return Promise.all(invalidTypes.map(invalidType => { + return promise_rejects_js( + t, TypeError, navigator.wakeLock.request(invalidType)); + })); +}, '\'TypeError\' is thrown when set an invalid wake lock type'); diff --git a/testing/web-platform/tests/screen-wake-lock/wakelockpermissiondescriptor.https.html b/testing/web-platform/tests/screen-wake-lock/wakelockpermissiondescriptor.https.html new file mode 100644 index 0000000000..252aa3ce28 --- /dev/null +++ b/testing/web-platform/tests/screen-wake-lock/wakelockpermissiondescriptor.https.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<link rel="help" href="https://w3c.github.io/screen-wake-lock/#the-screen-wake-lock-powerful-feature"> +<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> +promise_test(async t => { + await test_driver.set_permission({name: 'screen-wake-lock'}, 'denied'); + + return navigator.permissions.query({name:'screen-wake-lock'}).then(status => { + assert_class_string(status, "PermissionStatus"); + assert_equals(status.state, "denied"); + }); +}, "PermissionDescriptor with name='screen-wake-lock' works"); +</script> |