summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/lifecycle
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/lifecycle
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/lifecycle')
-rw-r--r--testing/web-platform/tests/lifecycle/META.yml3
-rw-r--r--testing/web-platform/tests/lifecycle/child-display-none.tentative.html36
-rw-r--r--testing/web-platform/tests/lifecycle/child-out-of-viewport.tentative.html36
-rw-r--r--testing/web-platform/tests/lifecycle/freeze.html75
-rw-r--r--testing/web-platform/tests/lifecycle/resources/beacon.py25
-rw-r--r--testing/web-platform/tests/lifecycle/resources/child.html15
-rw-r--r--testing/web-platform/tests/lifecycle/resources/subframe.html16
-rw-r--r--testing/web-platform/tests/lifecycle/resources/subframe_worker.html17
-rw-r--r--testing/web-platform/tests/lifecycle/resources/subframe_worker1.js7
-rw-r--r--testing/web-platform/tests/lifecycle/resources/subframe_worker2.js5
-rw-r--r--testing/web-platform/tests/lifecycle/resources/window.html84
-rw-r--r--testing/web-platform/tests/lifecycle/set-composited-layer-position-ref.html18
-rw-r--r--testing/web-platform/tests/lifecycle/set-composited-layer-position.html45
-rw-r--r--testing/web-platform/tests/lifecycle/worker-dispay-none.tentative.html66
14 files changed, 448 insertions, 0 deletions
diff --git a/testing/web-platform/tests/lifecycle/META.yml b/testing/web-platform/tests/lifecycle/META.yml
new file mode 100644
index 0000000000..abd5e0f6ed
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/META.yml
@@ -0,0 +1,3 @@
+spec: https://wicg.github.io/page-lifecycle/
+suggested_reviewers:
+ - fmeawad
diff --git a/testing/web-platform/tests/lifecycle/child-display-none.tentative.html b/testing/web-platform/tests/lifecycle/child-display-none.tentative.html
new file mode 100644
index 0000000000..d4ca6dab1e
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/child-display-none.tentative.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Child frame marked as frozen</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+async_test((t) => {
+
+ var child = document.createElement('iframe');
+
+ var loaded = false;
+ var frozen = false;
+
+ window.addEventListener('message', t.step_func((e) => {
+ if (e.data == "load") {
+ loaded = true;
+ } else if (e.data == "freeze") {
+ assert_true(loaded);
+ frozen = true;
+ child.style = "display: block";
+ } else if (e.data == "resume") {
+ assert_true(loaded);
+ assert_true(frozen);
+ t.done();
+ }
+ }));
+
+ child.allow = "execution-while-not-rendered 'none'";
+ child.src = "resources/subframe.html";
+ document.body.appendChild(child);
+ child.style = "display: none";
+}, "Child frame frozen");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/lifecycle/child-out-of-viewport.tentative.html b/testing/web-platform/tests/lifecycle/child-out-of-viewport.tentative.html
new file mode 100644
index 0000000000..4d8f868bfb
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/child-out-of-viewport.tentative.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Child frame marked as frozen</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<div style="width: 200px; height: 4000px"></div>
+<script>
+async_test((t) => {
+
+ var child = document.createElement('iframe');
+
+ var loaded = false;
+ var frozen = false;
+
+ window.addEventListener('message', t.step_func((e) => {
+ if (e.data == "load") {
+ loaded = true;
+ } else if (e.data == "freeze") {
+ assert_true(loaded);
+ frozen = true;
+ child.scrollIntoView();
+ } else if (e.data == "resume") {
+ assert_true(loaded);
+ assert_true(frozen);
+ t.done();
+ }
+ }));
+
+ child.allow = "execution-while-out-of-viewport 'none'";
+ child.src = "resources/subframe.html";
+ document.body.appendChild(child);
+}, "Child frame frozen");
+
+</script>
+</body>
diff --git a/testing/web-platform/tests/lifecycle/freeze.html b/testing/web-platform/tests/lifecycle/freeze.html
new file mode 100644
index 0000000000..a2a9a7d3f1
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/freeze.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>TestDriver freeze method</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+var test = async_test('Test freeze callback.');
+window.open('resources/window.html', 'Child Window');
+
+var total_steps = 0;
+
+const StepStatus = {
+ ADDED: 0,
+ SUCCESS: 1,
+ FAIL: 2,
+};
+
+var steps_map = new Map();
+
+function poll_for_result(request_token, step_name, expect_success) {
+ test.step(() => {
+ var iteration = 5;
+ var checkResult = () => {
+ fetch("resources/beacon.py?query&token=" + request_token).then(test.step_func((response) => {
+ var count = response.headers.get("Count");
+ if (count != '0') {
+ // If the server received something we can terminate polling.
+ if (expect_success) {
+ step_success(step_name);
+ } else {
+ step_fail(step_name);
+ }
+ } else if (!expect_success && count == '0' && iteration == 0) {
+ // When we are out of iterations and we aren't expecting success, declare this step complete.
+ // Should be 125 ms looking to make sure server didn't see the request.
+ step_success(step_name);
+ } else {
+ iteration--;
+ test.step_timeout(checkResult, 25);
+ }
+ }));
+ };
+ test.step_timeout(checkResult, 25);
+ });
+}
+
+function add_step(name) {
+ steps_map[name] = StepStatus.ADDED;
+ total_steps++;
+}
+
+function step_success(name) {
+ total_steps--;
+ steps_map[name] = StepStatus.SUCCESS;
+ if (total_steps == 0)
+ test.done();
+}
+
+function step_fail(name) {
+ total_steps--;
+ steps_map[name] = StepStatus.FAIL;
+ test.step(() => assert_unreached('During onfreeze: ' + name + ' failed to behave as expected.'));
+ if (total_steps == 0)
+ test.done();
+}
+
+test.step_timeout(() => {
+ for (var step in steps_map) {
+ if(steps_map[step] == StepStatus.ADDED)
+ test.step(() => assert_unreached('During onfreeze: ' + step + ' never finshed.'));
+ }
+}, 1000);
+
+</script>
diff --git a/testing/web-platform/tests/lifecycle/resources/beacon.py b/testing/web-platform/tests/lifecycle/resources/beacon.py
new file mode 100644
index 0000000000..09915ffbcf
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/beacon.py
@@ -0,0 +1,25 @@
+def main(request, response):
+
+ # |token| should be a unique UUID request parameter for the duration of this
+ # request. It will get stored in the server stash and will be used later in
+ # a query request.
+ # |query| should be a request parameter indicating the request would like
+ # to know how many times the server has seen the request (with the
+ # same token).
+ token = request.GET.first(b"token", None)
+ is_query = request.GET.first(b"query", None) is not None
+ with request.server.stash.lock:
+ value = request.server.stash.take(token)
+ count = 0
+ if value is not None:
+ count = int(value)
+ if is_query:
+ request.server.stash.put(token, count)
+ else:
+ count += 1
+ request.server.stash.put(token, count)
+
+ headers = []
+ if is_query:
+ headers = [(b"Count", count)]
+ return (200, headers, b"")
diff --git a/testing/web-platform/tests/lifecycle/resources/child.html b/testing/web-platform/tests/lifecycle/resources/child.html
new file mode 100644
index 0000000000..708bbfe02d
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/child.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<html>
+<head><title>Frozen Child iframe</title></head>
+<body>
+<script>
+
+// This child removes itself from the parent on dispatch of the freeze event.
+// Regression test of https://crbug.com/994442
+window.document.addEventListener("freeze", () => {
+ window.frameElement.remove();
+});
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/lifecycle/resources/subframe.html b/testing/web-platform/tests/lifecycle/resources/subframe.html
new file mode 100644
index 0000000000..2f1d70a80a
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/subframe.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script>
+window.addEventListener('load', () => {
+ window.parent.postMessage('load');
+});
+
+document.addEventListener('freeze', () => {
+ window.parent.postMessage('freeze');
+});
+
+document.addEventListener('resume', () => {
+ window.parent.postMessage('resume');
+});
+
+</script>
diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker.html b/testing/web-platform/tests/lifecycle/resources/subframe_worker.html
new file mode 100644
index 0000000000..350d27437a
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script>
+window.addEventListener('load', () => {
+ window.parent.postMessage('load');
+});
+
+document.addEventListener('freeze', () => {
+ window.parent.postMessage('freeze');
+});
+
+document.addEventListener('resume', () => {
+ window.parent.postMessage('resume');
+});
+
+worker = new Worker("subframe_worker1.js");
+</script>
diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js b/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js
new file mode 100644
index 0000000000..2d13e89065
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js
@@ -0,0 +1,7 @@
+var bc = new BroadcastChannel('subworker_channel');
+
+setInterval(() => {
+ bc.postMessage('subworker');
+}, 10);
+
+w2 = new Worker("subframe_worker2.js");
diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js b/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js
new file mode 100644
index 0000000000..32d2741331
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js
@@ -0,0 +1,5 @@
+var bc = new BroadcastChannel('subworker_channel');
+
+setInterval(() => {
+ bc.postMessage('subworker2');
+}, 10);
diff --git a/testing/web-platform/tests/lifecycle/resources/window.html b/testing/web-platform/tests/lifecycle/resources/window.html
new file mode 100644
index 0000000000..58181f32da
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/window.html
@@ -0,0 +1,84 @@
+<!doctype html>
+<html>
+<head><title>Frozen Window</title></head>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/common/utils.js"></script>
+<body>
+<h1>This window will be frozen</h1>
+<iframe id="child_frame" src="child.html"></iframe>
+<script>
+
+const freezingStepName = 'testOnFreeze';
+
+function testFetch(keepalive) {
+ var request_token = token();
+ var name = 'testfetch' + (keepalive ? 'with' : 'without') + 'keepalive';
+ window.opener.add_step(name);
+
+ function handler() {
+ window.opener.step_fail(name);
+ }
+
+ fetch('beacon.py?token=' + request_token, {
+ keepalive: keepalive
+ }).then(() => handler()).catch(() => handler());
+
+ window.opener.poll_for_result(request_token, name, keepalive);
+}
+
+function testXHR(async) {
+ var request_token = token();
+ var name = 'test' + (async ? 'Async' : 'Sync') + 'XHR';
+ window.opener.add_step(name);
+ var xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = () => {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 0)
+ window.opener.step_success(name);
+ else
+ window.opener.step_fail(name);
+ }
+ }
+ xhr.open('GET', 'beacon.py?token=' + request_token, async);
+ try {
+ xhr.send(null);
+ if (async) {
+ window.opener.poll_for_result(request_token, name, false);
+ }
+ } catch {
+ window.opener.step_success(name);
+ };
+}
+
+function testSendBeacon() {
+ var request_token = token();
+ var name = 'testSendBeacon';
+ window.opener.add_step(name);
+ if (navigator.sendBeacon("beacon.py?token=" + request_token, "")) {
+ window.opener.poll_for_result(request_token, name, true);
+ } else {
+ window.opener.step_fail(name);
+ }
+}
+
+window.document.addEventListener("freeze", () => {
+ // Testing fetch, only fetch keepalive should succeed.
+ testFetch(true /* keepalive */);
+ testFetch(false /* keepalive */);
+ // Testing XHR, both sync and async should fail.
+ testXHR(true /* async */);
+ testXHR(false /* sync */);
+ // Testing navigator.sendBeacon, which should be allowed.
+ testSendBeacon();
+ window.opener.step_success(freezingStepName);
+});
+
+onload = function() {
+ window.opener.add_step(freezingStepName);
+ test_driver.freeze();
+};
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/lifecycle/set-composited-layer-position-ref.html b/testing/web-platform/tests/lifecycle/set-composited-layer-position-ref.html
new file mode 100644
index 0000000000..600de56d60
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/set-composited-layer-position-ref.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+
+<meta charset="utf-8">
+<title>Setting composited layer position paints properly</title>
+<link rel="author" href="masonf@chromium.org">
+
+
+
+<div id="box"></div>
+<style>
+div {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 200px;
+ height: 200px;
+ background: green;
+}
diff --git a/testing/web-platform/tests/lifecycle/set-composited-layer-position.html b/testing/web-platform/tests/lifecycle/set-composited-layer-position.html
new file mode 100644
index 0000000000..f1a3807d81
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/set-composited-layer-position.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<meta charset="utf-8">
+<title>Setting composited layer position paints properly</title>
+<link rel="author" href="masonf@chromium.org">
+<link rel="help" href="https://drafts.csswg.org/cssom-view-1/">
+<link rel="match" href="set-composited-layer-position-ref.html">
+
+<div id="box"></div>
+<div id="tomove"></div>
+<style>
+div {
+ position: absolute;
+ top: 0;
+ left: 0;
+ will-change: transform;
+ width: 200px;
+ height: 200px;
+}
+#box {
+ background: red;
+}
+#tomove {
+ background: green;
+ top: 200px;
+ left: 200px;
+ filter: invert(0);
+}
+</style>
+<script>
+ window.onload = function() {
+ requestAnimationFrame(function() {
+ requestAnimationFrame(function() {
+ tomove = document.getElementById("tomove");
+ tomove.style.top = 0;
+ tomove.style.left = 0;
+ document.documentElement.classList.remove("reftest-wait");
+ });
+ });
+ }
+</script>
+</html>
+
+
+
diff --git a/testing/web-platform/tests/lifecycle/worker-dispay-none.tentative.html b/testing/web-platform/tests/lifecycle/worker-dispay-none.tentative.html
new file mode 100644
index 0000000000..0bcfde6d17
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/worker-dispay-none.tentative.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Child frame with worker marked as frozen</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<script>
+async_test((t) => {
+
+ var child = document.createElement('iframe');
+
+ var loaded = false;
+ var frozen = false;
+ var resumed = false;
+
+ var subworker_freeze_count = 0;
+ var subworker2_freeze_count = 0;
+ var subworker_count = 0;
+ var subworker2_count = 0;
+ var bc = new BroadcastChannel('subworker_channel');
+ bc.onmessage = t.step_func((e) => {
+ if (e.data == 'subworker') {
+ subworker_count++;
+ } else if (e.data == 'subworker2') {
+ subworker2_count++;
+ } else {
+ assert_unreached('bad message');
+ }
+
+ // Ensure that if we have resumed that we get at least
+ // one message from each worker.
+ if (loaded && frozen && resumed &&
+ subworker2_count > subworker2_freeze_count &&
+ subworker_count > subworker_freeze_count) {
+ t.done();
+ } else if (loaded && frozen && !resumed) {
+ // Ensure that at most one message is sent after the frozen state.
+ assert_true(subworker_count - subworker_freeze_count <= 1);
+ assert_true(subworker2_count - subworker2_freeze_count <= 1);
+ }
+ });
+
+ window.addEventListener('message', t.step_func((e) => {
+ if (e.data == "load") {
+ loaded = true;
+ } else if (e.data == "freeze") {
+ assert_true(loaded);
+ frozen = true;
+ subworker_freeze_count = subworker_count;
+ subworker2_freeze_count = subworker2_count;
+ child.style = "display: block";
+ } else if (e.data == "resume") {
+ assert_true(loaded);
+ assert_true(frozen);
+ resumed = true;
+ }
+ }));
+
+ child.allow = "execution-while-not-rendered 'none'";
+ child.src = "resources/subframe_worker.html";
+ document.body.appendChild(child);
+ child.style = "display: none";
+}, "Child frame frozen");
+
+</script>
+</body>