Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 4b821be

Browse files
committed
Bug 1631234 - Part 1: Add a test case to check we won't hit the assertion when we have service workers registered in the tracker who has storage access permission. r=baku
We add a test to ensure we won't hit the assertion here. https://searchfox.org/mozilla-central/rev/a4d62e09a4c46aef918667fa759bf9ae898dc258/dom/clients/manager/ClientSource.cpp#265-268 Differential Revision: https://phabricator.services.mozilla.com/D71564
1 parent f9d7f39 commit 4b821be

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

toolkit/components/antitracking/test/browser/browser.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ support-files = subResources.sjs
102102
skip-if = fission
103103
support-files = tracker.js
104104
[browser_userInteraction.js]
105+
[browser_serviceWorkersWithStorageAccessGranted.js]
106+
skip-if = fission
105107
[browser_storageAccessDoorHanger.js]
106108
skip-if = fission
107109
[browser_storageAccessPromiseRejectHandlerUserInteraction.js]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/** This tests that the service worker can be used if we have storage access
2+
* permission. We manually write the storage access permission into the
3+
* permission manager to simulate the storage access has been granted. We would
4+
* test the service worker twice. The fist time is to check the service
5+
* work is allowed. The second time is to load again and check it won't hit
6+
* assertion, this assertion would only be hit if we have registered a service
7+
* worker, see Bug 1631234. */
8+
9+
/* import-globals-from antitracking_head.js */
10+
11+
add_task(async _ => {
12+
// Manually add the storage permission.
13+
PermissionTestUtils.add(
14+
TEST_DOMAIN,
15+
"3rdPartyStorage^https://tracking.example.org",
16+
Services.perms.ALLOW_ACTION
17+
);
18+
19+
registerCleanupFunction(_ => {
20+
Services.perms.removeAll();
21+
});
22+
23+
AntiTracking._createTask({
24+
name:
25+
"Test that we can use service worker if we have the storage access permission",
26+
cookieBehavior: BEHAVIOR_REJECT_TRACKER,
27+
allowList: false,
28+
callback: async _ => {
29+
await navigator.serviceWorker
30+
.register("empty.js")
31+
.then(
32+
_ => {
33+
ok(true, "ServiceWorker can be used!");
34+
},
35+
_ => {
36+
ok(false, "ServiceWorker can be used!");
37+
}
38+
)
39+
.catch(e => ok(false, "Promise rejected: " + e));
40+
},
41+
extraPrefs: [
42+
["dom.serviceWorkers.exemptFromPerDomainMax", true],
43+
["dom.serviceWorkers.enabled", true],
44+
["dom.serviceWorkers.testing.enabled", true],
45+
],
46+
expectedBlockingNotifications: 0,
47+
runInPrivateWindow: false,
48+
iframeSandbox: null,
49+
accessRemoval: null,
50+
callbackAfterRemoval: null,
51+
});
52+
53+
AntiTracking._createTask({
54+
name:
55+
"Test again to check if we can still use service worker without hit the assertion.",
56+
cookieBehavior: BEHAVIOR_REJECT_TRACKER,
57+
allowList: false,
58+
callback: async _ => {
59+
await navigator.serviceWorker
60+
.register("empty.js")
61+
.then(
62+
_ => {
63+
ok(true, "ServiceWorker can be used!");
64+
},
65+
_ => {
66+
ok(false, "ServiceWorker can be used!");
67+
}
68+
)
69+
.catch(e => ok(false, "Promise rejected: " + e));
70+
},
71+
extraPrefs: [
72+
["dom.serviceWorkers.exemptFromPerDomainMax", true],
73+
["dom.serviceWorkers.enabled", true],
74+
["dom.serviceWorkers.testing.enabled", true],
75+
],
76+
expectedBlockingNotifications: 0,
77+
runInPrivateWindow: false,
78+
iframeSandbox: null,
79+
accessRemoval: null,
80+
callbackAfterRemoval: null,
81+
});
82+
});

0 commit comments

Comments
 (0)