summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html49
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html b/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html
new file mode 100644
index 0000000000..c8c9712bdd
--- /dev/null
+++ b/testing/web-platform/tests/screen-wake-lock/wakelock-document-hidden.https.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<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">
+<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="/page-visibility/resources/window_state_context.js"></script>
+<script>
+'use strict';
+
+promise_test(async t => {
+ await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
+
+ const {minimize, restore} = window_state_context(t);
+ await minimize();
+
+ assert_true(document.hidden);
+ await promise_rejects_dom(t, "NotAllowedError", navigator.wakeLock.request('screen'),
+ "new screen locks are not allowed when the page is not visible");
+}, "navigator.wakeLock.request('screen') fails when the document is hidden");
+
+promise_test(async t => {
+ await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');
+
+ const { minimize, restore } = window_state_context(t);
+
+ const screenLock1 = await navigator.wakeLock.request('screen');
+ const screenLock2 = await navigator.wakeLock.request('screen');
+
+ assert_false(screenLock1.released, "The released attribute is initially false");
+ assert_false(screenLock2.released, "The released attribute is initially false");
+
+ const wait1 = new EventWatcher(t, screenLock1, 'release').wait_for('release');
+ const wait2 = new EventWatcher(t, screenLock2, 'release').wait_for('release');
+
+ await minimize();
+ assert_true(document.hidden);
+
+ await Promise.all([wait1, wait2]);
+
+ assert_true(screenLock1.released, "The released attribute is true after the lock is released");
+ assert_true(screenLock2.released, "The released attribute is true after the lock is released");
+}, "Screen wake locks are released when the document the page is hidden");
+</script>
+</body>
+</html>