summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/page-visibility/iframe-session-history.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/page-visibility/iframe-session-history.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 'testing/web-platform/tests/page-visibility/iframe-session-history.html')
-rw-r--r--testing/web-platform/tests/page-visibility/iframe-session-history.html65
1 files changed, 65 insertions, 0 deletions
diff --git a/testing/web-platform/tests/page-visibility/iframe-session-history.html b/testing/web-platform/tests/page-visibility/iframe-session-history.html
new file mode 100644
index 0000000000..e023215316
--- /dev/null
+++ b/testing/web-platform/tests/page-visibility/iframe-session-history.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<title>Test the correct sequence of pagevisibility-related events in conjunction with history navigation</title>
+<link rel="author" title="Noam Rosenthal" href="mailto:noam@webkit.org">
+<link rel="help" href="https://www.w3.org/TR/page-visibility-2/">
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+
+const iframePath1 = 'resources/iframe-post-load.html?v=1'
+const iframePath2 = 'resources/iframe-post-load.html?v=2'
+
+function waitForLoad(iframe) {
+ return new Promise(resolve => {
+ const callback = e => {
+ if (e.data === 'load') {
+ window.removeEventListener('message', callback)
+ resolve()
+ }
+ }
+
+ window.addEventListener('message', callback)
+ })
+}
+
+function assert_sequence(sequence) {
+ assert_equals(sequence.length, 2)
+ assert_equals(sequence[0].type, 'pagehide')
+ assert_equals(sequence[0].target, '#document')
+ assert_equals(sequence[0].visibilityState, 'visible')
+ assert_equals(sequence[0].cancelable, true)
+ assert_equals(sequence[1].type, 'visibilitychange')
+ assert_equals(sequence[1].target, '#document')
+ assert_equals(sequence[1].visibilityState, 'hidden')
+ assert_equals(sequence[1].cancelable, false)
+}
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ iframe.src = iframePath1;
+ document.body.appendChild(iframe);
+ let sequence = [];
+ t.add_cleanup(() => iframe.remove());
+ iframe.src = iframePath1;
+ await waitForLoad(iframe);
+ const handler = t.step_func(event => sequence.push({
+ type: event.type,
+ target: event.target.nodeName,
+ cancelable: event.cancelable,
+ visibilityState: iframe.contentWindow.document.visibilityState
+ }));
+ iframe.contentWindow.document.addEventListener('visibilitychange', handler);
+ iframe.contentWindow.addEventListener('pagehide', handler);
+ iframe.contentWindow.location.href = iframePath2;
+ await waitForLoad(iframe);
+ assert_sequence(sequence);
+ sequence = [];
+ iframe.contentWindow.addEventListener('pagehide', handler);
+ iframe.contentWindow.document.addEventListener('visibilitychange', handler);
+ iframe.contentWindow.history.back();
+ await waitForLoad(iframe);
+ assert_sequence(sequence);
+}, "pagehide should be called before visibilitychange, and visibilityState should be set to hidden at the right time");
+</script>
+</body> \ No newline at end of file