diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/html/webappapis/scripting/event-loops | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/webappapis/scripting/event-loops')
8 files changed, 318 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/fully_active_document.window.js b/testing/web-platform/tests/html/webappapis/scripting/event-loops/fully_active_document.window.js new file mode 100644 index 0000000000..950a8a29ee --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/fully_active_document.window.js @@ -0,0 +1,29 @@ +async_test(t => { + const frame = document.body.appendChild(document.createElement("iframe")); + t.add_cleanup(() => frame.remove()); + + frame.onload = t.step_func(() => { + // Right now the doc of the iframe inside "frame" is still "fully-active". + // Navigate parent away, making the child iframe's doc "active", not "fully-active". + frame.contentWindow.location = "/common/blank.html"; + + frame.onload = t.step_func(() => { + // The child iframe's doc is "active", not "fully-active", and should not receive the storage notification. + sessionStorage.setItem('myCat', 'Tom'); + t.step_timeout(() => { + // The child iframe's hasn't received the storage notification. + assert_equals(sessionStorage.getItem("Received storage event"), null); + frame.contentWindow.history.go(-1); + t.step_timeout(() => { + // Now The child iframe's doc is "fully-active" again, + // the previously not run storage task should now have been run. + assert_equals(sessionStorage.getItem("Received storage event"), "true"); + t.done(); + }, 1000); + }, 1000); + }); + }); + + frame.src = "resources/page-with-frame.html"; +}, "Tasks for documents that are not fully active are stored, and run when the documents becomes fully-active"); + diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_raf.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_raf.html new file mode 100644 index 0000000000..824dbc4b92 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_raf.html @@ -0,0 +1,57 @@ +<!DOCTYPE html> +<head> +<link rel=author title="Aleks Totic" href="mailto:atotic@chromium.org"> +<link rel=help href="https://html.spec.whatwg.org/#clean-up-after-running-script"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/common.js"></script> +</head> +<body style="height:2000px;"> +<script> +/* +promise 1, promise 2 execute immediately after rAF +promise 1 child executes immediately after promise 2. + +Relevant specs: + +https://html.spec.whatwg.org/#clean-up-after-running-script +If the JavaScript execution context stack is now empty, perform a microtask checkpoint. + +https://html.spec.whatwg.org/#perform-a-microtask-checkpoint +"perform a microtask checkpoint" runs in a loop until all microtasks have been delivered. +*/ + +var test = async_test("Microtask execute immediately after script"); + +window.requestAnimationFrame( function() { + var events = []; + + Promise.resolve() + .then(function() { + events.push("promise 1"); + return Promise.resolve(); + }) + .then(function() { + test.step(function() { + events.push("promise 1 child"); + assert_array_equals(events, ["promise 1", "promise 2", "promise 1 child"]); + test.done(); + }); + }); + Promise.resolve() + .then(function() { + events.push("promise 2"); + }); + + // Set up events that must be executed after Promise. + window.setTimeout(function() { + events.push('timeout'); + }, 0); + window.addEventListener('scroll', function() { + events.push('scroll'); + }); + window.scrollBy(0,10); + +}); +</script> +</body> diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_script.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_script.html new file mode 100644 index 0000000000..799a0de605 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/microtask_after_script.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<head> +<link rel=author title="Aleks Totic" href="mailto:atotic@chromium.org"> +<link rel=help href="https://html.spec.whatwg.org/#clean-up-after-running-script"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/common.js"></script> +</head> +<body style="height:2000px;"> +<script> +/* +promise 1, promise 2 execute immediately after script tag +promise 1 child executes immediately after promise 2. + +Relevant specs: + +https://html.spec.whatwg.org/#clean-up-after-running-script +If the JavaScript execution context stack is now empty, perform a microtask checkpoint. + +https://html.spec.whatwg.org/#perform-a-microtask-checkpoint +"perform a microtask checkpoint" runs in a loop until all microtasks have been delivered. +*/ + +var test = async_test("Microtask immediately after script"); + +var events = []; + +Promise.resolve() +.then(function() { + events.push("promise 1"); + return Promise.resolve(); +}) +.then(function() { + test.step(function() { + events.push("promise 1 child"); + assert_array_equals(events, ["promise 1", "promise 2", "promise 1 child"]); + test.done(); + }); +}); +Promise.resolve() +.then(function() { + events.push("promise 2"); +}); + +// Set up events that must be executed after Promise. +window.setTimeout(function() { + events.push('timeout'); +}, 0); +window.addEventListener('scroll', function() { + events.push('scroll'); +}); +window.scrollBy(0,10); + +</script> +</body> diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/common.js b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/common.js new file mode 100644 index 0000000000..e2279f93dd --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/common.js @@ -0,0 +1,20 @@ +// Helper for tests that just want to verify the ordering of a series of events. +// Usage: +// log_test(function(t, log) { +// log('first'); +// log('second'); +// }, ['first', 'second'], 'Ordinal numbers are ordinal'); + +function log_test(func, expected, description) { + async_test(function(t) { + var actual = []; + function log(entry) { + actual.push(entry); + if (expected.length <= actual.length) { + assert_array_equals(actual, expected); + t.done(); + } + } + func(t, t.step_func(log)); + }, description); +} diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/iframe.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/iframe.html new file mode 100644 index 0000000000..32e4862360 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/iframe.html @@ -0,0 +1,7 @@ +<!doctype html> +<title>Childframe</title> +<script> + window.addEventListener('storage', () => { + sessionStorage.setItem("Received storage event", true); + }); +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/page-with-frame.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/page-with-frame.html new file mode 100644 index 0000000000..f13170576e --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/resources/page-with-frame.html @@ -0,0 +1 @@ +<iframe src="iframe.html"></iframe> diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering-manual.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering-manual.html new file mode 100644 index 0000000000..ed2f70e196 --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering-manual.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<title>Task and Microtask Ordering </title> +<link rel=author title="Joshua Bell" href="mailto:jsbell@google.com"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#event-loops"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/common.js"></script> +<style> +.inner { padding: 46px; width: 0; margin: 0 auto; background: #d4d4d4; } +.outer { padding: 25px; width: 92px; background: #f1f1f1; } +</style> + +<p>Click on the inner box:</p> +<div class="outer"> + <div class="inner"></div> +</div> + +<script> + +// Based on: https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ + +log_test(function(t, log) { + // Let's get hold of those elements + var outer = document.querySelector('.outer'); + var inner = document.querySelector('.inner'); + + // Let's listen for attribute changes on the + // outer element + new MutationObserver(function() { + log('mutate'); + }).observe(outer, { + attributes: true + }); + + // Here's a click listener... + function onClick() { + log('click'); + + setTimeout(function() { + log('timeout'); + }, 0); + + Promise.resolve().then(function() { + log('promise'); + }); + + outer.setAttribute('data-random', Math.random()); + } + + // ...which we'll attach to both elements + inner.addEventListener('click', onClick); + outer.addEventListener('click', onClick); +}, [ + 'click', + 'promise', + 'mutate', + 'click', + 'promise', + 'mutate', + 'timeout', + 'timeout' +], 'Level 1 bossfight (manual click)'); + +</script> diff --git a/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering.html b/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering.html new file mode 100644 index 0000000000..c14a043b6a --- /dev/null +++ b/testing/web-platform/tests/html/webappapis/scripting/event-loops/task_microtask_ordering.html @@ -0,0 +1,85 @@ +<!DOCTYPE html> +<title>Task and Microtask Ordering </title> +<link rel=author title="Joshua Bell" href="mailto:jsbell@google.com"> +<link rel=help href="https://html.spec.whatwg.org/multipage/#event-loops"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/common.js"></script> + +<div class="outer"> + <div class="inner"></div> +</div> + +<script> + +// Based on: https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/ + +log_test(function(t, log) { + log('script start'); + + setTimeout(function() { + log('setTimeout'); + }, 0); + + Promise.resolve().then(function() { + log('promise1'); + }).then(function() { + log('promise2'); + }); + + log('script end'); +}, [ + 'script start', + 'script end', + 'promise1', + 'promise2', + 'setTimeout' +], 'Basic task and microtask ordering'); + +log_test(function(t, log) { + // Let's get hold of those elements + var outer = document.querySelector('.outer'); + var inner = document.querySelector('.inner'); + + // Let's listen for attribute changes on the + // outer element + new MutationObserver(function() { + log('mutate'); + }).observe(outer, { + attributes: true + }); + + // Here's a click listener... + function onClick() { + log('click'); + + setTimeout(function() { + log('timeout'); + }, 0); + + Promise.resolve().then(function() { + log('promise'); + }); + + outer.setAttribute('data-random', Math.random()); + } + + // ...which we'll attach to both elements + inner.addEventListener('click', onClick); + outer.addEventListener('click', onClick); + + // Note that this will behave differently than a real click, + // since the dispatch is synchronous and microtasks will not + // run between event bubbling steps. + inner.click(); +}, [ + 'click', + 'click', + 'promise', + 'mutate', + 'promise', + 'timeout', + 'timeout' +], 'Level 1 bossfight (synthetic click)'); + +</script> |