summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/dom/throttling
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/mozilla/tests/dom/throttling
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/mozilla/tests/dom/throttling')
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/resources/test.html5
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/resources/throttling.js136
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/resources/ws.sub.js3
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-1.window.js10
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-2.window.js11
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-3.window.js11
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-4.window.js11
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-indexeddb.window.js35
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-webaudio.window.js35
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-webrtc.window.js35
-rw-r--r--testing/web-platform/mozilla/tests/dom/throttling/throttling-ws.window.js37
11 files changed, 329 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/resources/test.html b/testing/web-platform/mozilla/tests/dom/throttling/resources/test.html
new file mode 100644
index 0000000000..7eb9dd1e40
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/resources/test.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="throttling.js"></script>
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/resources/throttling.js b/testing/web-platform/mozilla/tests/dom/throttling/resources/throttling.js
new file mode 100644
index 0000000000..280b0adc0d
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/resources/throttling.js
@@ -0,0 +1,136 @@
+function waitForLoad() {
+ return new Promise(resolve => addEventListener('load', resolve))
+ .then(() => delay(10));
+}
+
+function delay(timeout) {
+ return new Promise(resolve => step_timeout(() => resolve(), 10));
+}
+
+function busy(work) {
+ return delay(10).then(() => new Promise(resolve => {
+ step_timeout(() => {
+ let end = performance.now() + work;
+ while (performance.now() < end) {
+
+ }
+
+ resolve();
+ }, 1);
+ }));
+}
+
+function getThrottlingRate(delay) {
+ return new Promise(resolve => {
+ let start = performance.now();
+ setTimeout(() => {
+ let rate = Math.floor((performance.now() - start) / delay);
+ resolve(rate);
+ }, delay);
+ });
+}
+
+function addElement(t, element, src) {
+ return new Promise((resolve, reject) => {
+ let e = document.createElement(element);
+ e.addEventListener('load', () => resolve(e));
+ if (src) {
+ e.src = src;
+ }
+ document.body.appendChild(e);
+ t.add_cleanup(() => e.remove());
+ });
+}
+
+function inFrame(t) {
+ return addElement(t, "iframe", "resources/test.html")
+ .then(frame => delay(10).then(() => Promise.resolve(frame.contentWindow)));
+}
+
+function addWebSocket(t, url) {
+ return new Promise((resolve, reject) => {
+ let socket = new WebSocket(url);
+ socket.onopen = () => {
+ t.add_cleanup(() => socket.close());
+ resolve();
+ };
+ socket.onerror = reject;
+ });
+}
+
+function addRTCPeerConnection(t) {
+ return new Promise((resolve, reject) => {
+ let connection = new RTCPeerConnection();
+ t.add_cleanup(() => {
+ connection.close()
+ });
+
+ resolve();
+ });
+}
+
+function addIndexedDB(t) {
+ return new Promise((resolve, reject) => {
+ let iDBState = {
+ running: false,
+ db: null
+ };
+
+ let req = indexedDB.open("testDB", 1);
+
+ req.onupgradeneeded = e => {
+ let db = e.target.result;
+ let store = db.createObjectStore("testOS", {keyPath: "id"});
+ let index = store.createIndex("index", ["col"]);
+ };
+
+ req.onsuccess = e => {
+ let db = iDBState.db = e.target.result;
+ let store = db.transaction("testOS", "readwrite").objectStore("testOS");
+ let ctr = 0;
+
+ iDBState.running = true;
+
+ function putLoop() {
+ if (!iDBState.running) {
+ return;
+ }
+
+ let req = store.put({id: ctr++, col: "foo"});
+ req.onsuccess = putLoop;
+
+ if (!iDBState.request) {
+ iDBState.request = req;
+ }
+ }
+
+ putLoop();
+ resolve();
+ };
+
+ t.add_cleanup(() => {
+ iDBState.running = false;
+ iDBState.db && iDBState.db.close();
+ iDBState.db = null;
+ });
+ });
+}
+
+function addWebAudio(t) {
+ return new Promise(resolve => {
+ let context = new (window.AudioContext || window.webkitAudioContext)();
+ context.onstatechange = () => (context.state === "running") && resolve();
+
+ let gain = context.createGain();
+ gain.gain.value = 0.1;
+ gain.connect(context.destination);
+
+ let webaudionode = context.createOscillator();
+ webaudionode.type = 'square';
+ webaudionode.frequency.value = 440; // value in hertz
+ webaudionode.connect(gain);
+ webaudionode.start();
+
+ t.add_cleanup(() => webaudionode.stop());
+ });
+}
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/resources/ws.sub.js b/testing/web-platform/mozilla/tests/dom/throttling/resources/ws.sub.js
new file mode 100644
index 0000000000..a1ac273a54
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/resources/ws.sub.js
@@ -0,0 +1,3 @@
+var __SERVER__NAME = "{{host}}";
+var __PORT = "{{ports[ws][0]}}";
+var __PATH = "echo";
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-1.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-1.window.js
new file mode 100644
index 0000000000..86cefc8a81
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-1.window.js
@@ -0,0 +1,10 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => busy(100)
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_greater_than(rate, 10, "Timeout wasn't throttled");
+ }), "Throttle when all budget has been used.");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-2.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-2.window.js
new file mode 100644
index 0000000000..3ccb35dc08
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-2.window.js
@@ -0,0 +1,11 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => inFrame(t)
+ .then(win => win.busy(100)
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_greater_than(rate, 10, "Timeout wasn't throttled");
+ }), "Throttle iframe when all budget has been used");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-3.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-3.window.js
new file mode 100644
index 0000000000..d1c38bcc12
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-3.window.js
@@ -0,0 +1,11 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => inFrame(t)
+ .then(win => busy(100)
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when all budget in parent has been used");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-4.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-4.window.js
new file mode 100644
index 0000000000..b072b51809
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-4.window.js
@@ -0,0 +1,11 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => inFrame(t)
+ .then(win => win.busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle parent when all budget in iframe has been used");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-indexeddb.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-indexeddb.window.js
new file mode 100644
index 0000000000..73c734a584
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-indexeddb.window.js
@@ -0,0 +1,35 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => addIndexedDB(t)
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open IndexedDB transactions.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addIndexedDB(t))
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open IndexedDB transactions in iframe.");
+
+promise_test(t => inFrame(t)
+ .then(win => addIndexedDB(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open IndexedDB transactions in parent.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addIndexedDB(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open IndexedDB transactions in iframe.");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-webaudio.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-webaudio.window.js
new file mode 100644
index 0000000000..5cd7193788
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-webaudio.window.js
@@ -0,0 +1,35 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => addWebAudio(t)
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there is active WebAudio.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addWebAudio(t))
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there is active WebAudio in iframe.");
+
+promise_test(t => inFrame(t)
+ .then(win => addWebAudio(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there is active WebAudio in parent.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addWebAudio(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there is active WebAudio in iframe.");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-webrtc.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-webrtc.window.js
new file mode 100644
index 0000000000..2842f77e44
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-webrtc.window.js
@@ -0,0 +1,35 @@
+// META: script=resources/throttling.js
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => addRTCPeerConnection(t)
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open RTCPeerConnections.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addRTCPeerConnection(t))
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open RTCPeerConnections in iframe.");
+
+promise_test(t => inFrame(t)
+ .then(win => addRTCPeerConnection(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open RTCPeerConnections in parent.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addRTCPeerConnection(t)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open RTCPeerConnections in iframe.");
diff --git a/testing/web-platform/mozilla/tests/dom/throttling/throttling-ws.window.js b/testing/web-platform/mozilla/tests/dom/throttling/throttling-ws.window.js
new file mode 100644
index 0000000000..185654e04d
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/dom/throttling/throttling-ws.window.js
@@ -0,0 +1,37 @@
+// META: script=resources/ws.sub.js
+// META: script=resources/throttling.js
+let server = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
+
+setup(() => waitForLoad()
+ .then(() => "setup done"));
+
+promise_test(t => addWebSocket(t, server)
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open WebSockets.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addWebSocket(t, server))
+ .then(() => busy(100))
+ .then(() => getThrottlingRate(100))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle when there are open WebSockets in iframe.");
+
+promise_test(t => inFrame(t)
+ .then(win => addWebSocket(t, server)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open WebSockets in parent.");
+
+promise_test(t => inFrame(t)
+ .then(win => win.addWebSocket(t, server)
+ .then(() => win.busy(100))
+ .then(() => win.getThrottlingRate(100)))
+ .then(rate => {
+ assert_less_than(rate, 10, "Timeout was throttled");
+ }), "Don't throttle iframe when there are open WebSockets in iframe.");