summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
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 /toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
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 'toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js')
-rw-r--r--toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js b/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
new file mode 100644
index 0000000000..4ae4ba74dd
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
@@ -0,0 +1,148 @@
+/** This tests that the service worker can be used if we have storage access
+ * permission. We manually write the storage access permission into the
+ * permission manager to simulate the storage access has been granted. We would
+ * test the service worker three times. The fist time is to check the service
+ * work is allowed. The second time is to load again and check it won't hit
+ * assertion, this assertion would only be hit if we have registered a service
+ * worker, see Bug 1631234.
+ *
+ * The third time is to load again but in a sandbox iframe to check it won't
+ * hit the assertion. See Bug 1637226 for details.
+ *
+ * The fourth time is to load again in a nested iframe to check it won't hit
+ * the assertion. See Bug 1641153 for details.
+ * */
+
+add_task(async _ => {
+ // Manually add the storage permission.
+ PermissionTestUtils.add(
+ TEST_DOMAIN,
+ "3rdPartyStorage^https://tracking.example.org",
+ Services.perms.ALLOW_ACTION
+ );
+
+ registerCleanupFunction(_ => {
+ Services.perms.removeAll();
+ });
+
+ AntiTracking._createTask({
+ name: "Test that we can use service worker if we have the storage access permission",
+ cookieBehavior: BEHAVIOR_REJECT_TRACKER,
+ allowList: false,
+ callback: async _ => {
+ await navigator.serviceWorker
+ .register("empty.js")
+ .then(
+ _ => {
+ ok(true, "ServiceWorker can be used!");
+ },
+ _ => {
+ ok(false, "ServiceWorker can be used!");
+ }
+ )
+ .catch(e => ok(false, "Promise rejected: " + e));
+ },
+ extraPrefs: [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ],
+ expectedBlockingNotifications: 0,
+ runInPrivateWindow: false,
+ iframeSandbox: null,
+ accessRemoval: null,
+ callbackAfterRemoval: null,
+ });
+
+ AntiTracking._createTask({
+ name: "Test again to check if we can still use service worker without hit the assertion.",
+ cookieBehavior: BEHAVIOR_REJECT_TRACKER,
+ allowList: false,
+ callback: async _ => {
+ await navigator.serviceWorker
+ .register("empty.js")
+ .then(
+ _ => {
+ ok(true, "ServiceWorker can be used!");
+ },
+ _ => {
+ ok(false, "ServiceWorker can be used!");
+ }
+ )
+ .catch(e => ok(false, "Promise rejected: " + e));
+ },
+ extraPrefs: [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ],
+ expectedBlockingNotifications: 0,
+ runInPrivateWindow: false,
+ iframeSandbox: null,
+ accessRemoval: null,
+ callbackAfterRemoval: null,
+ });
+
+ AntiTracking._createTask({
+ name: "Test again to check if we cannot use service worker in a sandbox iframe without hit the assertion.",
+ cookieBehavior: BEHAVIOR_REJECT_TRACKER,
+ allowList: false,
+ callback: async _ => {
+ await navigator.serviceWorker
+ .register("empty.js")
+ .then(
+ _ => {
+ ok(false, "ServiceWorker cannot be used in sandbox iframe!");
+ },
+ _ => {
+ ok(true, "ServiceWorker cannot be used in sandbox iframe!");
+ }
+ )
+ .catch(e => ok(false, "Promise rejected: " + e));
+ },
+ extraPrefs: [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ],
+ expectedBlockingNotifications:
+ Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER, // expect blocking notifications,
+ runInPrivateWindow: false,
+ iframeSandbox: "allow-scripts allow-same-origin",
+ accessRemoval: null,
+ callbackAfterRemoval: null,
+ });
+
+ const NESTED_THIRD_PARTY_PAGE =
+ TEST_DOMAIN + TEST_PATH + "3rdPartyRelay.html?" + TEST_3RD_PARTY_PAGE;
+
+ AntiTracking._createTask({
+ name: "Test again to check if we can use service worker in a nested iframe without hit the assertion.",
+ cookieBehavior: BEHAVIOR_REJECT_TRACKER,
+ allowList: false,
+ callback: async _ => {
+ await navigator.serviceWorker
+ .register("empty.js")
+ .then(
+ _ => {
+ ok(true, "ServiceWorker can be used in nested iframe!");
+ },
+ _ => {
+ ok(false, "ServiceWorker can be used in nested iframe!");
+ }
+ )
+ .catch(e => ok(false, "Promise rejected: " + e));
+ },
+ extraPrefs: [
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ],
+ expectedBlockingNotifications: 0,
+ runInPrivateWindow: false,
+ iframeSandbox: null,
+ accessRemoval: null,
+ callbackAfterRemoval: null,
+ thirdPartyPage: NESTED_THIRD_PARTY_PAGE,
+ });
+});