1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
"use strict";
const server = createHttpServer({ hosts: ["example.com"] });
server.registerPathHandler("/dummy", (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/html", false);
response.write("<!DOCTYPE html><html></html>");
});
add_task(async function test_userContextId_webRequest() {
Services.prefs.setBoolPref("extensions.userContextIsolation.enabled", true);
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["webRequest", "<all_urls>"],
},
background() {
browser.webRequest.onBeforeRequest.addListener(
async details => {
browser.test.assertEq(
"firefox-container-2",
details.cookieStoreId,
"cookieStoreId is set"
);
browser.test.notifyPass("allowed");
},
{ urls: ["http://example.com/dummy"] }
);
},
});
Services.prefs.setCharPref(
"extensions.userContextIsolation.defaults.restricted",
"[1]"
);
await extension.startup();
let restrictedPage = await ExtensionTestUtils.loadContentPage(
"http://example.com/dummy",
{ userContextId: 1 }
);
let allowedPage = await ExtensionTestUtils.loadContentPage(
"http://example.com/dummy",
{
userContextId: 2,
}
);
await extension.awaitFinish("allowed");
await extension.unload();
await restrictedPage.close();
await allowedPage.close();
Services.prefs.clearUserPref("extensions.userContextIsolation.enabled");
Services.prefs.clearUserPref(
"extensions.userContextIsolation.defaults.restricted"
);
});
|