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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
//
// Bug 1725996 - Test if the cookie set in a document which is created by
// document.open() in an about:blank iframe has a correct
// partitionKey
//
const TEST_PAGE = TEST_DOMAIN + TEST_PATH + "file_iframe_document_open.html";
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
[
"network.cookie.cookieBehavior",
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN,
],
[
"network.cookie.cookieBehavior.pbmode",
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN,
],
["privacy.dynamic_firstparty.use_site", true],
],
});
});
add_task(async function test_firstParty_iframe() {
// Clear all cookies before test.
Services.cookies.removeAll();
// Open the test page which creates an iframe and then calls document.write()
// to write a cookie in the iframe.
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
// Wait until the cookie appears.
await TestUtils.waitForCondition(_ => Services.cookies.cookies.length);
// Check the partitionKey in the cookie.
let cookie = Services.cookies.cookies[0];
is(
cookie.originAttributes.partitionKey,
"",
"The partitionKey should remain empty for first-party iframe."
);
// Clean up.
Services.cookies.removeAll();
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_thirdParty_iframe() {
// Clear all cookies before test.
Services.cookies.removeAll();
// Open a tab with a different domain with the test page.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_TOP_PAGE_2
);
// Open the test page within a third-party context.
await SpecialPowers.spawn(
tab.linkedBrowser,
[TEST_PAGE],
async function (page) {
let ifr = content.document.createElement("iframe");
let loading = ContentTaskUtils.waitForEvent(ifr, "load");
ifr.src = page;
content.document.body.appendChild(ifr);
await loading;
}
);
// Wait until the cookie appears.
await TestUtils.waitForCondition(_ => Services.cookies.cookies.length);
// Check the partitionKey in the cookie.
let cookie = Services.cookies.cookies[0];
is(
cookie.originAttributes.partitionKey,
"(http,xn--exmple-cua.test)",
"The partitionKey should exist for third-party iframe."
);
// Clean up.
Services.cookies.removeAll();
BrowserTestUtils.removeTab(tab);
});
|