summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/long-animation-frame
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/long-animation-frame')
-rw-r--r--testing/web-platform/tests/long-animation-frame/META.yml2
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-basic.html57
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-blocking-duration.html64
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-buffered.html28
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-desired-exec-time.html121
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-event-listener.html44
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html101
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-idle.html36
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-iframe-popup.html65
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-pause-duration.html30
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-promise.html52
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-script-block.html50
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-script-window-attribution.html76
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-source-location.html43
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-supportedEntryTypes.html22
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-timeline.html27
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-toJSON.html46
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-user-callback.html56
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-visibility.html26
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/loaf-window-only.worker.js11
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/resources/busy.js4
-rw-r--r--testing/web-platform/tests/long-animation-frame/tentative/resources/utils.js131
22 files changed, 1092 insertions, 0 deletions
diff --git a/testing/web-platform/tests/long-animation-frame/META.yml b/testing/web-platform/tests/long-animation-frame/META.yml
new file mode 100644
index 0000000000..769c325aee
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/META.yml
@@ -0,0 +1,2 @@
+suggested_reviewers:
+ - noamr
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-basic.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-basic.html
new file mode 100644
index 0000000000..c6d3f8e32a
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-basic.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: basic</h1>
+<div id="log"></div>
+<script>
+
+promise_test(async t => {
+ await expect_long_frame(() => busy_wait(), t);
+}, 'A long busy wait is a long animation frame');
+
+promise_test(async t => {
+ await expect_long_frame(() => requestAnimationFrame(busy_wait), t);
+}, 'A long busy wait in a requestAnimationFrame is a long animation frame');
+
+promise_test(async t => {
+ const segment_duration = very_long_frame_duration / 2;
+ const entry = await expect_long_frame(async () => {
+ busy_wait(segment_duration);
+ await new Promise(resolve => requestAnimationFrame(() => {
+ busy_wait(segment_duration)
+ resolve();
+ }));
+ }, t);
+
+ assert_not_equals(entry, "timeout");
+ assert_greater_than_equal(entry.renderStart - entry.startTime, segment_duration);
+}, 'A long busy wait split between a task and a requestAnimationFrame is a long animation frame');
+
+promise_test(async t => {
+ const segment_duration = very_long_frame_duration / 3;
+ const entry = await expect_long_frame(async () => {
+ const element = document.createElement("div");
+ document.body.appendChild(element);
+ t.add_cleanup(() => element.remove());
+ busy_wait(segment_duration);
+ requestAnimationFrame(() => {
+ busy_wait(segment_duration);
+ });
+
+ new ResizeObserver(() => {
+ busy_wait(segment_duration);
+ }).observe(element);
+ }, t);
+
+ assert_not_equals(entry, "timeout");
+ assert_greater_than_equal(entry.renderStart - entry.startTime, segment_duration);
+ assert_greater_than_equal(entry.styleAndLayoutStart - entry.renderStart, segment_duration);
+}, 'ResizeObservers should create a long-frame and affect layoutStartTime');
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-blocking-duration.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-blocking-duration.html
new file mode 100644
index 0000000000..1671a386ac
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-blocking-duration.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: blocking duration</h1>
+<div id="log"></div>
+<script>
+
+function loaf_blocking_duration_test(run, label) {
+ const OVERHEAD_EPSILON = 5;
+ const BLOCKING_THRESHOLD = 50;
+ promise_test(async t => {
+ let found = false;
+ for (let i = 0; i < 10 && !found; ++i) {
+ const longtask_promise = new Promise(resolve => new PerformanceObserver(
+ (entries, observer) => {
+ resolve(entries.getEntries());
+ observer.disconnect();
+ }).observe({entryTypes: ["longtask"]}));
+ const [longtask_entries, loaf_entry] = await Promise.all(
+ [longtask_promise, expect_long_frame(run, t)]);
+ const overlapping = longtask_entries.filter(longtask =>
+ (longtask.startTime >= loaf_entry.startTime &&
+ longtask.startTime < (loaf_entry.startTime + loaf_entry.duration) &&
+ (!loaf_entry.renderStart ||
+ (longtask.startTime < loaf_entry.renderStart - OVERHEAD_EPSILON))));
+
+ const longest_index = overlapping.reduce(
+ (max, cur, i) => cur > overlapping[max] ? i : max, 0);
+ let expected_blocking_duration = 0;
+ overlapping.forEach(({duration}, i) => {
+ if (i === longest_index && loaf_entry.renderStart)
+ duration += loaf_entry.startTime + loaf_entry.duration -
+ loaf_entry.renderStart;
+ expected_blocking_duration += Math.max(0, duration - BLOCKING_THRESHOLD);
+ });
+
+ if (!overlapping.length && loaf_entry.renderStart) {
+ expected_blocking_duration =
+ Math.max(0,
+ loaf_entry.startTime + loaf_entry.duration - loaf_entry.renderStart -
+ BLOCKING_THRESHOLD);
+ }
+
+ if (Math.abs(loaf_entry.blockingDuration - expected_blocking_duration) <
+ OVERHEAD_EPSILON) {
+ found = true;
+ }
+ }
+ assert_true(found);
+ }, `LoAF blockingDuration should be equivalent to long tasks: ${label}`);
+}
+
+loaf_blocking_duration_test(t => t.step_timeout(busy_wait), "Non-rendering");
+loaf_blocking_duration_test(t => t.step_timeout(() => {
+ busy_wait();
+ requestAnimationFrame(busy_wait);
+}), "Rendering");
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-buffered.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-buffered.html
new file mode 100644
index 0000000000..1a07036b15
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-buffered.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: buffered</h1>
+<div id="log"></div>
+<script>
+promise_test(async t => {
+ busy_wait(very_long_frame_duration);
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ const result = await new Promise(resolve => {
+ new PerformanceObserver(t.step_func(entries => {
+ for (const e of entries.getEntries()) {
+ if (e.duration >= very_long_frame_duration)
+ resolve("entry-found");
+ }
+ })).observe({type: 'long-animation-frame', buffered: true});
+ t.step_timeout(() => resolve("timeout"), waiting_for_long_frame_timeout);
+ });
+ assert_equals(result, "entry-found");
+}, 'PerformanceObserver with buffered flag can see previous long-animation-frame entries.');
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-desired-exec-time.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-desired-exec-time.html
new file mode 100644
index 0000000000..dd350078b6
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-desired-exec-time.html
@@ -0,0 +1,121 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: queue time</title>
+<meta name="timeout" content="long">
+<script src=/resources/testdriver.js></script>
+<script src=/resources/testdriver-actions.js></script>
+<script src=/resources/testdriver-vendor.js></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: queue time</h1>
+<div id="log"></div>
+<script>
+
+const INTERNAL_OVERHEAD_DELAY_EPSILON = 5;
+
+promise_test(async t => {
+ const button = document.createElement("button");
+ button.innerText = "Click";
+ document.body.appendChild(button);
+ t.add_cleanup(() => button.remove());
+ const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
+ busy_wait();
+ resolve(event);
+ }));
+ const entryPromise = new Promise(resolve => new PerformanceObserver(
+ (entryList, observer) => {
+ const scriptPredicate = s => s.name === "BUTTON.onclick";
+ const entry = entryList.getEntries().find(
+ e => e.scripts.length && e.scripts.find(scriptPredicate));
+ if (entry) {
+ resolve([entry, entry.scripts.find(scriptPredicate)]);
+ observer.disconnect();
+ }
+ }).observe({entryTypes: ["long-animation-frame"]}));
+ test_driver.click(button);
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ const event = await eventPromise;
+ const [entry, script] = await entryPromise;
+ assert_equals(script.desiredExecutionStart, event.timeStamp);
+}, "event-listener entries desiredExecutionStart is the eventTimestamp");
+
+promise_test(async t => {
+ const entryPromise = loaf_promise(t);
+ let timeBeforeSetup, timeAfterSetup;
+ const delay = 100;
+ const timeoutPromise = new Promise(resolve => {
+ timeBeforeSetup = performance.now();
+ t.step_timeout(() => {
+ busy_wait();
+ resolve();
+ }, delay);
+ timeAfterSetup = performance.now();
+ });
+ const entry = await entryPromise;
+ const script = entry.scripts.find(s => s.name === "TimerHandler:setTimeout");
+ assert_greater_than_equal(script.desiredExecutionStart, timeBeforeSetup + delay - 5);
+ assert_less_than_equal(script.desiredExecutionStart, timeAfterSetup + delay);
+}, "desiredExecutionStart for setTimeout should be the setup time + delay");
+
+promise_test(async t => {
+ const entryPromise = loaf_promise(t);
+ let timeBeforeSetup, timeAfterSetup;
+ const timeoutPromise = new Promise(resolve => {
+ timeBeforeSetup = performance.now();
+ scheduler.postTask(t.step_func(() => {
+ busy_wait();
+ resolve();
+ }));
+ timeAfterSetup = performance.now();
+ });
+ const entry = await entryPromise;
+ const script = entry.scripts.find(s => s.name === "SchedulerPostTaskCallback");
+ assert_greater_than_equal(script.desiredExecutionStart, timeBeforeSetup);
+ assert_less_than_equal(script.desiredExecutionStart, timeAfterSetup);
+}, "desiredExecutionStart for Scheduler.postTask should be the time it was called");
+
+promise_test(async t => {
+ const entryPromise = loaf_promise(t);
+ const rafPromise = new Promise(resolve => {
+ // We fire two rAFs to ensure both of them receive the same
+ // desiredExecutionStart
+ requestAnimationFrame(rafTime => {
+ busy_wait();
+ })
+ requestAnimationFrame(rafTime => {
+ busy_wait();
+ resolve(rafTime);
+ })
+ });
+ const entry = await entryPromise;
+ const rafTime = await rafPromise;
+ const scripts = entry.scripts.filter(
+ s => s.name === "FrameRequestCallback");
+ for (const script of scripts) {
+ assert_approx_equals(script.desiredExecutionStart, rafTime, INTERNAL_OVERHEAD_DELAY_EPSILON);
+ }
+ assert_approx_equals(entry.desiredRenderStart, rafTime, INTERNAL_OVERHEAD_DELAY_EPSILON);
+}, "desiredExecutionStart & desiredRenderStart for requestAnimationFrame " +
+ "should be the same as the rAF argument");
+
+promise_test(async t => {
+ const entryPromise = loaf_promise(t);
+ const timeBeforeWait = performance.now();
+ let timeAfterWait;
+ const rafPromise = new Promise(resolve => t.step_timeout(() => {
+ requestAnimationFrame(rafTime => {
+ busy_wait(very_long_frame_duration / 2);
+ resolve(rafTime);
+ });
+
+ busy_wait(very_long_frame_duration / 2);
+ timeAfterWait = performance.now();
+ }), 0);
+ const [entry, rafTime] = await Promise.all([entryPromise, rafPromise]);
+ assert_approx_equals(entry.desiredRenderStart, rafTime, INTERNAL_OVERHEAD_DELAY_EPSILON);
+}, "desiredRenderStart and renderStart should reflect main thread delays");
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-event-listener.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-event-listener.html
new file mode 100644
index 0000000000..f866a1dfd8
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-event-listener.html
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: event handlers</h1>
+<div id="log"></div>
+<script>
+
+test_self_event_listener(t => {
+ const img = document.createElement("img");
+ img.src = "/images/green.png";
+ img.addEventListener("load", () => {
+ busy_wait();
+ });
+ img.id = "image";
+ document.body.appendChild(img);
+ t.add_cleanup(() => img.remove());
+}, "IMG#image.onload");
+
+test_self_event_listener(t => {
+ const img = document.createElement("img");
+ img.src = "/images/green.png";
+ img.addEventListener("load", () => {
+ busy_wait();
+ });
+ document.body.appendChild(img);
+ t.add_cleanup(() => img.remove());
+}, "IMG[src=/images/green.png].onload");
+
+test_self_event_listener(t => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("GET", "/common/dummy.xml");
+ xhr.addEventListener("load", () => {
+ busy_wait();
+ });
+ xhr.send();
+}, "XMLHttpRequest.onload");
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html
new file mode 100644
index 0000000000..47a3a51de2
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-first-ui-event.html
@@ -0,0 +1,101 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: first UI Event</title>
+<meta name="timeout" content="long">
+<script src=/resources/testdriver.js></script>
+<script src=/resources/testdriver-actions.js></script>
+<script src=/resources/testdriver-vendor.js></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: First UI Event</h1>
+<div id="log"></div>
+<script>
+
+promise_test(async t => {
+ const button = document.createElement("button");
+ button.innerText = "Click";
+ document.body.appendChild(button);
+ t.add_cleanup(() => button.remove());
+ const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
+ busy_wait();
+ resolve(event);
+ }));
+ const entryPromise = expect_long_frame_with_script(() => {
+ test_driver.click(button);
+ }, s => s.name === "BUTTON.onclick", t);
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ const event = await eventPromise;
+ const [entry] = await entryPromise;
+ assert_equals(entry.firstUIEventTimestamp, event.timeStamp);
+}, "LoAF should expose firstUIEventTimestamp for click events");
+
+promise_test(async t => {
+ const button = document.createElement("button");
+ button.innerText = "Hover";
+ document.body.appendChild(button);
+ t.add_cleanup(() => button.remove());
+ let expectedTimestamp = null;
+ const entryPromise = expect_long_frame_with_script(async () => {
+ const eventPromise = new Promise(resolve => button.addEventListener("pointermove", event => {
+ busy_wait();
+ expectedTimestamp = event.timeStamp;
+ resolve();
+ }));
+
+ const actions = new test_driver.Actions()
+ .pointerMove(0, 0, {origin: button})
+ .pointerDown()
+ .pointerUp();
+ await actions.send();
+ await eventPromise;
+ }, s => s.name === "BUTTON.onpointermove", t);
+ const [entry] = await entryPromise;
+ assert_equals(entry.firstUIEventTimestamp, expectedTimestamp);
+}, "LoAF should expose firstUIEventTimestamp for pointermove events");
+
+promise_test(async t => {
+ const button = document.createElement("button");
+ button.innerText = "Click";
+ document.body.appendChild(button);
+ t.add_cleanup(() => button.remove());
+ let firstUIEventTimestamp = null;
+ const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
+ if (firstUIEventTimestamp)
+ resolve(event);
+ else {
+ firstUIEventTimestamp = event.timeStamp;
+ busy_wait();
+ }
+ }));
+ const entryPromise = expect_long_frame_with_script(() => {
+ test_driver.click(button);
+ test_driver.click(button);
+ }, s => s.name === "BUTTON.onclick", t);
+ const [event, [entry]] = await Promise.all([eventPromise, entryPromise]);
+ assert_equals(entry.firstUIEventTimestamp, firstUIEventTimestamp);
+}, "firstUIEventTimestamp doesn't have to come from a long script");
+
+
+promise_test(async t => {
+ const entryPromise = expect_long_frame_with_script(() => {
+ const img = document.createElement("img");
+ img.src = "/images/green.png";
+ const promise = new Promise(resolve =>
+ img.addEventListener("load", event => {
+ busy_wait();
+ resolve();
+ }));
+ document.body.appendChild(img);
+ t.add_cleanup(() => img.remove());
+ return promise;
+ }, s => s.name === "IMG[src=/images/green.png].onload", t);
+
+ const [entry, script] = await entryPromise;
+ assert_not_equals(entry.firstUIEventTimestamp, script.desiredExecutionStart);
+}, "Non-UI events don't affect firstUIEventTimestamp");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-idle.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-idle.html
new file mode 100644
index 0000000000..bc9f910bb1
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-idle.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: requestIdleCallback</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: requestIdleCallback</h1>
+<div id="log"></div>
+<script>
+setup(() =>
+ assert_implements(window.requestIdleCallback,
+ 'requestIdleCallback is not supported.'));
+
+/*
+promise_test(async t => {
+ await expect_no_long_frame(() => requestIdleCallback(busy_wait), t);
+}, 'A long busy wait in an idle callback is not a long animation frame');
+*/
+
+promise_test(async t => {
+ const segment_duration = very_long_frame_duration / 2;
+ requestIdleCallback(() => {
+ busy_wait(segment_duration);
+ requestAnimationFrame(() => {
+ busy_wait(segment_duration);
+ });
+ });
+ await expect_long_frame(() => {}, t);
+}, 'A long busy wait split between an idle callback and a ' +
+ 'requestAnimationFrame is a long animation frame');
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-iframe-popup.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-iframe-popup.html
new file mode 100644
index 0000000000..565273b6c6
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-iframe-popup.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: iframes & popups</title>
+<meta name="timeout" content="long">
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/common/utils.js"></script>
+<script src="/common/dispatcher/dispatcher.js"></script>
+<script src="resources/utils.js"></script>
+<div id="log"></div>
+<script>
+const host_info = get_host_info();
+const {ORIGIN, REMOTE_ORIGIN, HTTP_NOTSAMESITE_ORIGIN} = host_info;
+
+promise_test(async t => {
+ const [executor] = await prepare_exec_iframe(t, ORIGIN);
+ await expect_no_long_frame(() => executor.execute_script((duration) => {
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), t);
+}, 'A long busy wait without render in a same-origin iframe is not a long animation frame');
+
+promise_test(async t => {
+ const [executor] = await prepare_exec_iframe(t, HTTP_NOTSAMESITE_ORIGIN);
+ await expect_no_long_frame(() => executor.execute_script((duration) => {
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), t);
+}, 'A long busy wait in a cross-origin iframe is not a long animation frame');
+
+promise_test(async t => {
+ const [executor] = await prepare_exec_iframe(t, ORIGIN);
+ await expect_long_frame(() => executor.execute_script(async (duration) => {
+ await new Promise(resolve => window.requestAnimationFrame(resolve));
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), t);
+}, 'A long busy wait in a same-origin requestAnimationFrame is a long animation frame');
+
+promise_test(async t => {
+ const [executor] = await prepare_exec_popup(t, ORIGIN);
+ await expect_no_long_frame(() => executor.execute_script((duration) => {
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), t);
+}, 'A long busy wait in a same-origin popup is a not long animation frame');
+
+for (const origin of ["ORIGIN", "REMOTE_ORIGIN", "HTTP_NOTSAMESITE_ORIGIN"]) {
+ promise_test(async t => {
+ const [executor] = await prepare_exec_iframe(t, host_info[origin]);
+ const entry = await executor.execute_script(async (duration) => {
+ const entryPromise = new Promise(resolve => new PerformanceObserver(list => {
+ resolve(list.getEntries(0));
+ }).observe({entryTypes: ["long-animation-frame"]}));
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ return entryPromise;
+ }, [very_long_frame_duration]);
+ }, `frames receive own long animation frames (${origin})`);
+}
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-pause-duration.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-pause-duration.html
new file mode 100644
index 0000000000..6894164fbf
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-pause-duration.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: pause</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: pause</h1>
+<div id="log"></div>
+<script>
+
+promise_test(async t => {
+ const pause_duration = very_long_frame_duration / 2;
+ [entry, script] = await expect_long_frame_with_script(() => t.step_timeout(() => {
+ busy_wait(pause_duration);
+ const sync_xhr = new XMLHttpRequest();
+ sync_xhr.open("GET", `/xhr/resources/delay.py?ms=${pause_duration}`, /*async=*/false);
+ sync_xhr.send();
+ }, 0), script => (
+ script.name === "TimerHandler:setTimeout" &&
+ script.duration >= very_long_frame_duration), t);
+ assert_true("pauseDuration" in script);
+ assert_greater_than(script.pauseDuration, pause_duration);
+}, "Synchronous XHR should be counted as pauseDuration");
+
+// TODO: Test for alert/confirm, requires WPT infra changes.
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-promise.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-promise.html
new file mode 100644
index 0000000000..5ead569c8a
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-promise.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: promise resolvers</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: promise resolvers</h1>
+<div id="log"></div>
+<script type="module">
+
+const {REMOTE_ORIGIN} = get_host_info();
+
+test_promise_script(async t => {
+ await fetch("/common/dummy.xml");
+ busy_wait(very_long_frame_duration);
+}, "resolve", "Window.fetch.then");
+
+test_promise_script(async t => {
+ const response = await fetch("/common/dummy.xml");
+ await response.text();
+ busy_wait(very_long_frame_duration);
+}, "resolve", "Response.text.then");
+
+test_promise_script(async t => {
+ const response = await fetch("/common/dummy.xml");
+ await response.arrayBuffer();
+ busy_wait(very_long_frame_duration);
+}, "resolve", "Response.arrayBuffer.then");
+
+test_promise_script(async t => {
+ const response = await fetch("/fetch/api/resources/data.json");
+ await response.json();
+ busy_wait(very_long_frame_duration);
+}, "resolve", "Response.json.then");
+
+test_promise_script(async t => {
+ const response = await import("/loading/resources/dummy.js");
+ busy_wait(very_long_frame_duration);
+}, "resolve", "import.then");
+
+test_promise_script(async t => {
+ fetch(new URL("/common/dummy.xml", REMOTE_ORIGIN).href, {mode: "cors"})
+ .catch(() => {
+ busy_wait(very_long_frame_duration);
+ })
+}, "reject", "Window.fetch.catch" );
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-block.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-block.html
new file mode 100644
index 0000000000..866eea09e0
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-block.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: script blocks</h1>
+<div id="log"></div>
+<script>
+test_self_script_block(t => {
+ const script = document.createElement("script");
+ script.innerHTML = `(${busy_wait.toString()})()`;
+ document.body.appendChild(script);
+}, location.href, "classic-script");
+
+test_self_script_block(t => {
+ const script = document.createElement("script");
+ script.type = "module";
+ script.innerHTML = `(${busy_wait.toString()})()`;
+ document.body.appendChild(script);
+}, location.href, "module-script");
+
+test_self_script_block(t => {
+ const script = document.createElement("script");
+ script.src = "resources/busy.js";
+ document.body.appendChild(script);
+}, new URL("resources/busy.js", location.href).href, "classic-script");
+
+test_self_script_block(t => {
+ const uid = token();
+ const script = document.createElement("script");
+ script.src = `resources/busy.js?token=${uid}`;
+ script.type = "module";
+ document.body.appendChild(script);
+}, new URL("resources/busy.js", location.href).href, "module-script");
+
+test_self_script_block(t => {
+ const uid = token();
+ const script = document.createElement("script");
+ script.type = "module";
+ script.innerHTML = `import("./resources/busy.js?import=${uid}");`;
+ document.body.appendChild(script);
+}, new URL("resources/busy.js?import", location.href).href, "execute-script");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-window-attribution.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-window-attribution.html
new file mode 100644
index 0000000000..f54a1f23cb
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-script-window-attribution.html
@@ -0,0 +1,76 @@
+
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: window attribution</title>
+<meta name="timeout" content="long">
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/common/utils.js"></script>
+<script src="/common/dispatcher/dispatcher.js"></script>
+<script src="resources/utils.js"></script>
+<div id="log"></div>
+<script>
+
+const host_info = get_host_info();
+const {ORIGIN, REMOTE_ORIGIN, HTTP_NOTSAMESITE_ORIGIN} = host_info;
+
+promise_test (async t => {
+ const [entry, script] = await expect_long_frame_with_script(() => {
+ requestAnimationFrame(() => busy_wait());
+ }, () => true, t);
+ assert_equals(script.windowAttribution, "self");
+ assert_equals(script.window, window);
+}, 'Scripts in this window should be self-attributed');
+
+promise_test (async t => {
+ let found = false;
+ for (let i = 0; i < 10 && !found; ++i) {
+ const [executor, iframe] = await prepare_exec_iframe(t, ORIGIN);
+ const [entry, script] = await expect_long_frame_with_script(() =>
+ executor.execute_script(async (duration) => {
+ await new Promise(resolve => window.requestAnimationFrame(resolve));
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), () => true, t);
+
+ if (script.windowAttribution === "descendant" && script.window === iframe.contentWindow) {
+ found = true;
+ }
+ }
+
+ assert_true(found);
+}, 'Scripts in subframes should be descendant-attributed');
+
+promise_test (async t => {
+ let found = false;
+ for (let i = 0; i < 10 && !found; ++i) {
+ const [executor1, iframe1] = await prepare_exec_iframe(t, ORIGIN);
+ const [executor2, iframe2] = await prepare_exec_iframe(t, ORIGIN);
+ const [entry, script] = await expect_long_frame_with_script(() =>
+ executor1.execute_script(async (duration) => {
+ await new Promise(resolve => window.requestAnimationFrame(resolve));
+ const deadline = performance.now() + duration;
+ while (performance.now() < deadline) {}
+ }, [very_long_frame_duration]), () => true, t);
+ const find_entry = win =>
+ win.performance.getEntriesByType("long-animation-frame").find(
+ e => e.duration >= very_long_frame_duration &&
+ e.scripts.length).scripts[0];
+
+ const iframe1_entry = find_entry(iframe1.contentWindow);
+ const iframe2_entry = find_entry(iframe2.contentWindow);
+ if (iframe1_entry.windowAttribution === "self" &&
+ iframe2_entry.windowAttribution === "same-page" &&
+ iframe1_entry.window === iframe1.contentWindow &&
+ iframe2_entry.window === iframe1.contentWindow) {
+ found = true;
+ }
+ }
+
+ assert_true(found);
+}, 'Scripts in subframes should be same-page-attributed to other subframes');
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-source-location.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-source-location.html
new file mode 100644
index 0000000000..ffda000207
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-source-location.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: source location extraction</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: source location extraction</h1>
+<div id="log"></div>
+<script>
+
+promise_test(async t => {
+ const [entry, script] = await expect_long_frame_with_script(() => {
+ requestAnimationFrame(function non_bound_function() {
+ busy_wait();
+ });
+ }, script => script.name === "FrameRequestCallback", t);
+ assert_true(script.sourceLocation?.startsWith("non_bound_function"));
+}, "Source location should be extracted from non-bound functions");
+
+promise_test(async t => {
+ const [entry, script] = await expect_long_frame_with_script(() => {
+ const object = {};
+ requestAnimationFrame((function my_bound_function() {
+ busy_wait();
+ }).bind(object));
+ }, script => script.name === "FrameRequestCallback", t);
+ assert_true(script.sourceLocation?.startsWith("my_bound_function"));
+}, "Source location should be extracted from bound functions");
+
+promise_test(async t => {
+ const [entry, script] = await expect_long_frame_with_script(() => {
+ t.step_timeout(function my_timeout() {
+ busy_wait();
+ });
+ }, script => script.name === "TimerHandler:setTimeout" && script.sourceLocation, t );
+ assert_true(script.sourceLocation.includes("testharness.js"));
+}, "Source location should be extracted for setTimeout");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-supportedEntryTypes.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-supportedEntryTypes.html
new file mode 100644
index 0000000000..efa01481fa
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-supportedEntryTypes.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: supportedEntryTypes</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<body>
+<h1>Long Animation Frame: supportedEntryTypes</h1>
+<div id="log"></div>
+<script>
+
+setup(() =>
+ assert_implements(window.PerformanceLongAnimationFrameTiming,
+ 'Long animation frames are not supported.'));
+
+test(() => {
+ assert_true(PerformanceObserver.supportedEntryTypes.includes("long-animation-frame"));
+}, 'supportedEntryTypes should include long-animation-frame');
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-timeline.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-timeline.html
new file mode 100644
index 0000000000..c434a26ef8
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-timeline.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: basic</h1>
+<div id="log"></div>
+<script>
+promise_test(async t => {
+ busy_wait(very_long_frame_duration);
+ const is_loaf = entry => entry.duration >= very_long_frame_duration &&
+ entry.entryType == "long-animation-frame";
+
+ await new Promise(resolve => t.step_timeout(resolve, 10));
+ const entry_from_all = [...performance.getEntries()].find(is_loaf);
+ const entry_by_type = [...performance.getEntriesByType("long-animation-frame")].find(is_loaf);
+ const entry_by_name = [...performance.getEntriesByName("long-animation-frame")].find(is_loaf);
+ assert_true(!!entry_from_all, "LoAF Entry found");
+ assert_equals(entry_from_all, entry_by_type);
+ assert_equals(entry_from_all, entry_by_name);
+}, 'LoAF entries are available in the performnace timeline');
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-toJSON.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-toJSON.html
new file mode 100644
index 0000000000..5b249e6972
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-toJSON.html
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+ promise_test(async t => {
+ window.onload = () => {
+ // Trigger a long task.
+ const begin = window.performance.now();
+ while (window.performance.now() < begin + 60);
+ };
+
+ assert_implements(window.PerformanceLongAnimationFrameTiming, 'Lon are not supported.');
+ const entry = await new Promise(resolve => new PerformanceObserver(
+ t.step_func(entryList => {
+ const entries = entryList.getEntries();
+ assert_greater_than_equal(entries.length, 1);
+ resolve(entries[0]);
+ })).observe({entryTypes: ["long-animation-frame"]}));
+
+ assert_equals(typeof(entry.toJSON), 'function');
+ const entryJSON = entry.toJSON();
+ assert_equals(typeof(entryJSON), 'object');
+ // Check attributes inheritted from PerformanceEntry.
+ const performanceEntryKeys = [
+ 'name',
+ 'entryType',
+ 'startTime',
+ 'duration',
+ 'renderStart',
+ 'styleAndLayoutStart',
+ 'blockingTime',
+ 'firstUIEventTimestamp'
+ ];
+ for (const key of performanceEntryKeys) {
+ assert_equals(entryJSON[key], entry[key],
+ `entry.toJSON().${key} should match entry.${key}`);
+ }
+
+ }, 'Test toJSON() in PerformanceLongAnimationFrameTiming');
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-user-callback.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-user-callback.html
new file mode 100644
index 0000000000..3d868af87f
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-user-callback.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<title>Long Animation Frame Timing: basic</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<h1>Long Animation Frame: user callbacks</h1>
+<div id="log"></div>
+<script>
+
+test_self_user_callback(t =>
+ t.step_timeout(() => busy_wait()), "TimerHandler:setTimeout");
+
+test_self_user_callback(() => {
+ const interval = setInterval(() => {
+ busy_wait();
+ clearInterval(interval);
+ }, 10);
+}, "TimerHandler:setInterval");
+test_self_user_callback(() =>
+ requestAnimationFrame(() => busy_wait()), "FrameRequestCallback");
+
+test_self_user_callback(t => {
+ const element = document.createElement("div");
+ document.body.appendChild(element);
+ t.add_cleanup(() => element.remove());
+ new ResizeObserver((entries, observer) => {
+ busy_wait(very_long_frame_duration);
+ observer.disconnect();
+ }).observe(element);
+}, "ResizeObserverCallback");
+
+test_self_user_callback(t => {
+ const element = document.createElement("div");
+ element.innerText = "123";
+ t.add_cleanup(() => element.remove());
+ new IntersectionObserver((entries, observer) => {
+ busy_wait(very_long_frame_duration);
+ observer.disconnect();
+ }).observe(element);
+ document.body.appendChild(element);
+}, "IntersectionObserverCallback");
+
+test_self_user_callback(t =>
+ scheduler.postTask(() => busy_wait()), "SchedulerPostTaskCallback");
+
+ test_self_user_callback(t => {
+ new PerformanceObserver(() => busy_wait()).observe(
+ {type: "navigation", buffered: true});
+}, "PerformanceObserverCallback");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-visibility.html b/testing/web-platform/tests/long-animation-frame/tentative/loaf-visibility.html
new file mode 100644
index 0000000000..97038e3073
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-visibility.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Long Animation Frame Timing: iframes</title>
+
+<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="/common/utils.js"></script>
+<script src="/page-visibility/resources/window_state_context.js"></script>
+<script src="resources/utils.js"></script>
+<body>
+ <div id="log"></div>
+<script>
+
+promise_test(async t => {
+ const {minimize, restore} = window_state_context(t);
+ await minimize();
+ expect_no_long_frame(busy_wait, t);
+ await restore();
+ expect_long_frame(busy_wait, t);
+}, 'Invisible windows do not report long animation frames');
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/loaf-window-only.worker.js b/testing/web-platform/tests/long-animation-frame/tentative/loaf-window-only.worker.js
new file mode 100644
index 0000000000..c1f0439c4b
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/loaf-window-only.worker.js
@@ -0,0 +1,11 @@
+importScripts("/resources/testharness.js");
+
+test(() => {
+ assert_false(PerformanceObserver.supportedEntryTypes.includes("long-animation-frame"));
+}, 'PerformanceObserver should not include "long-animation-frame" in workers');
+
+test(() => {
+ assert_false("PerformanceLongAnimationFrameTiming" in self);
+}, 'PerformanceLongAnimationFrameTiming should not be exposed in workers');
+
+done();
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/resources/busy.js b/testing/web-platform/tests/long-animation-frame/tentative/resources/busy.js
new file mode 100644
index 0000000000..9d761b6de5
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/resources/busy.js
@@ -0,0 +1,4 @@
+(() => {
+ const deadline = performance.now() + 360;
+ while (performance.now() < deadline) {}
+})();
diff --git a/testing/web-platform/tests/long-animation-frame/tentative/resources/utils.js b/testing/web-platform/tests/long-animation-frame/tentative/resources/utils.js
new file mode 100644
index 0000000000..8781252e94
--- /dev/null
+++ b/testing/web-platform/tests/long-animation-frame/tentative/resources/utils.js
@@ -0,0 +1,131 @@
+const windowLoaded = new Promise(resolve => window.addEventListener('load', resolve));
+setup(() =>
+ assert_implements(window.PerformanceLongAnimationFrameTiming,
+ 'Long animation frames are not supported.'));
+
+const very_long_frame_duration = 360;
+const no_long_frame_timeout = very_long_frame_duration * 3;
+const waiting_for_long_frame_timeout = very_long_frame_duration * 10;
+
+function loaf_promise(t) {
+ return new Promise(resolve => {
+ const observer = new PerformanceObserver(entries => {
+ const entry = entries.getEntries()[0];
+ // TODO: understand why we need this 5ms epsilon.
+ if (entry.duration > very_long_frame_duration - 5) {
+ observer.disconnect();
+ resolve(entry);
+ }
+ });
+
+ t.add_cleanup(() => observer.disconnect());
+
+ observer.observe({entryTypes: ['long-animation-frame']});
+ });
+}
+
+function busy_wait(ms_delay = very_long_frame_duration) {
+ const deadline = performance.now() + ms_delay;
+ while (performance.now() < deadline) {}
+}
+
+async function expect_long_frame(cb, t) {
+ await windowLoaded;
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+ const timeout = new Promise((resolve, reject) =>
+ t.step_timeout(() => resolve("timeout"), waiting_for_long_frame_timeout));
+ const receivedLongFrame = loaf_promise(t);
+ await cb(t);
+ const entry = await Promise.race([
+ receivedLongFrame,
+ timeout
+ ]);
+ return entry;
+}
+
+async function expect_long_frame_with_script(cb, predicate, t) {
+ for (let i = 0; i < 10; ++i) {
+ const entry = await expect_long_frame(cb, t);
+ if (entry === "timeout" || !entry.scripts.length)
+ continue;
+ for (const script of entry.scripts) {
+ if (predicate(script))
+ return [entry, script];
+ }
+ }
+
+ return [];
+}
+
+async function expect_no_long_frame(cb, t) {
+ await windowLoaded;
+ for (let i = 0; i < 5; ++i) {
+ const receivedLongFrame = loaf_promise(t);
+ await cb();
+ const result = await Promise.race([receivedLongFrame,
+ new Promise(resolve => t.step_timeout(() => resolve("timeout"),
+ no_long_frame_timeout))]);
+ if (result === "timeout")
+ return false;
+ }
+
+ throw new Error("Consistently creates long frame");
+}
+
+async function prepare_exec_iframe(t, origin) {
+ const iframe = document.createElement("iframe");
+ t.add_cleanup(() => iframe.remove());
+ const url = new URL("/common/dispatcher/remote-executor.html", origin);
+ const uuid = token();
+ url.searchParams.set("uuid", uuid);
+ iframe.src = url.href;
+ document.body.appendChild(iframe);
+ await new Promise(resolve => iframe.addEventListener("load", resolve));
+ return [new RemoteContext(uuid), iframe];
+}
+
+
+async function prepare_exec_popup(t, origin) {
+ const url = new URL("/common/dispatcher/remote-executor.html", origin);
+ const uuid = token();
+ url.searchParams.set("uuid", uuid);
+ const popup = window.open(url);
+ t.add_cleanup(() => popup.close());
+ return [new RemoteContext(uuid), popup];
+}
+function test_loaf_script(cb, name, type, label) {
+ promise_test(async t => {
+ let [entry, script] = [];
+ [entry, script] = await expect_long_frame_with_script(cb,
+ script => (
+ script.type === type &&
+ script.name.startsWith(name) &&
+ script.duration >= very_long_frame_duration), t);
+
+ assert_true(!!entry, "Entry detected");
+ assert_greater_than_equal(script.duration, very_long_frame_duration);
+ assert_greater_than_equal(entry.duration, script.duration);
+ assert_greater_than_equal(script.executionStart, script.startTime);
+ assert_greater_than_equal(script.startTime, entry.startTime)
+ assert_equals(script.window, window);
+ assert_equals(script.forcedStyleAndLayoutDuration, 0);
+ assert_equals(script.windowAttribution, "self");
+}, `LoAF script: ${name} ${type},${label ? ` ${label}` : ''}`);
+
+}
+
+function test_self_user_callback(cb, name, label) {
+ test_loaf_script(cb, name, "user-callback", label);
+}
+
+function test_self_event_listener(cb, name) {
+ test_loaf_script(cb, name, "event-listener");
+}
+
+function test_promise_script(cb, resolve_or_reject, name, label) {
+ test_loaf_script(cb, name, `${resolve_or_reject}-promise`, label);
+}
+
+function test_self_script_block(cb, name, type) {
+ test_loaf_script(cb, name, type);
+}