summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js')
-rw-r--r--testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js b/testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js
new file mode 100644
index 0000000000..55704388b7
--- /dev/null
+++ b/testing/web-platform/tests/pending-beacon/pending_beacon-sendondiscard.tentative.https.window.js
@@ -0,0 +1,97 @@
+// META: script=/resources/testharness.js
+// META: script=/resources/testharnessreport.js
+// META: script=/common/utils.js
+// META: script=./resources/pending_beacon-helper.js
+
+'use strict';
+
+parallelPromiseTest(async t => {
+ const uuid = token();
+ const url = generateSetBeaconURL(uuid);
+ const numPerMethod = 20;
+ const total = numPerMethod * 2;
+
+ // Loads an iframe that creates `numPerMethod` GET & POST beacons.
+ const iframe = await loadScriptAsIframe(`
+ const url = "${url}";
+ for (let i = 0; i < ${numPerMethod}; i++) {
+ let get = new PendingGetBeacon(url);
+ let post = new PendingPostBeacon(url);
+ }
+ `);
+
+ // Delete the iframe to trigger beacon sending.
+ document.body.removeChild(iframe);
+
+ // The iframe should have sent all beacons.
+ await expectBeacon(uuid, {count: total});
+}, 'A discarded document sends all its beacons with default config.');
+
+parallelPromiseTest(async t => {
+ const uuid = token();
+ const url = generateSetBeaconURL(uuid);
+
+ // Loads an iframe that creates a GET beacon,
+ // then sends it out with `sendNow()`.
+ const iframe = await loadScriptAsIframe(`
+ const url = "${url}";
+ let beacon = new PendingGetBeacon(url);
+ beacon.sendNow();
+ `);
+
+ // Delete the document and verify no more beacons are sent.
+ document.body.removeChild(iframe);
+
+ // The iframe should have sent only 1 beacon.
+ await expectBeacon(uuid, {count: 1});
+}, 'A discarded document does not send an already sent beacon.');
+
+parallelPromiseTest(async t => {
+ const uuid = token();
+ const url = generateSetBeaconURL(uuid);
+ const numPerMethod = 20;
+ const total = numPerMethod * 2;
+
+ // Loads an iframe that creates `numPerMethod` GET & POST beacons with
+ // different timeouts.
+ const iframe = await loadScriptAsIframe(`
+ const url = "${url}";
+ for (let i = 0; i < ${numPerMethod}; i++) {
+ let get = new PendingGetBeacon(url, {timeout: 100*i});
+ let post = new PendingPostBeacon(url, {timeout: 100*i});
+ }
+ `);
+
+ // Delete the iframe to trigger beacon sending.
+ document.body.removeChild(iframe);
+
+ // Even beacons are configured with different timeouts,
+ // the iframe should have sent all beacons when it is discarded.
+ await expectBeacon(uuid, {count: total});
+}, `A discarded document sends all its beacons of which timeouts are not
+ default.`);
+
+parallelPromiseTest(async t => {
+ const uuid = token();
+ const url = generateSetBeaconURL(uuid);
+ const numPerMethod = 20;
+ const total = numPerMethod * 2;
+
+ // Loads an iframe that creates `numPerMethod` GET & POST beacons with
+ // different backgroundTimeouts.
+ const iframe = await loadScriptAsIframe(`
+ const url = "${url}";
+ for (let i = 0; i < ${numPerMethod}; i++) {
+ let get = new PendingGetBeacon(url, {backgroundTimeout: 100*i});
+ let post = new PendingPostBeacon(url, {backgroundTimeout: 100*i});
+ }
+ `);
+
+ // Delete the iframe to trigger beacon sending.
+ document.body.removeChild(iframe);
+
+ // Even beacons are configured with different backgroundTimeouts,
+ // the iframe should have sent all beacons when it is discarded.
+ await expectBeacon(uuid, {count: total});
+}, `A discarded document sends all its beacons of which backgroundTimeouts are
+ not default.`);