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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const BLOCKED_PAGE =
"http://example.org:8000/browser/browser/base/content/test/about/xfo_iframe.sjs";
add_task(async function test_xfo_iframe() {
let { iframePageTab, blockedPageTab } = await setupPage(
"iframe_page_xfo.html",
BLOCKED_PAGE
);
let xfoBrowser = gBrowser.selectedTab.linkedBrowser;
// The blocked page opened in a new window/tab
await SpecialPowers.spawn(xfoBrowser, [BLOCKED_PAGE], async function(
xfoBlockedPage
) {
let cookieHeader = content.document.getElementById("strictCookie");
let location = content.document.location.href;
Assert.ok(
cookieHeader.textContent.includes("No same site strict cookie header"),
"Same site strict cookie has not been set"
);
Assert.equal(location, xfoBlockedPage, "Location of new page is correct!");
});
Services.cookies.removeAll();
BrowserTestUtils.removeTab(iframePageTab);
BrowserTestUtils.removeTab(blockedPageTab);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
async function setupPage(htmlPageName, blockedPage) {
let iFramePage =
getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
) + htmlPageName;
// Opening the blocked page once in a new tab
let blockedPageTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
blockedPage
);
let blockedPageBrowser = blockedPageTab.linkedBrowser;
let cookies = Services.cookies.getCookiesFromHost(
"example.org",
blockedPageBrowser.contentPrincipal.originAttributes
);
let strictCookie = cookies[0];
is(
strictCookie.value,
"creamy",
"Same site strict cookie has the expected value"
);
is(strictCookie.sameSite, 2, "The cookie is a same site strict cookie");
// Opening the page that contains the iframe
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
let browser = tab.linkedBrowser;
let browserLoaded = BrowserTestUtils.browserLoaded(
browser,
true,
blockedPage,
true
);
BrowserTestUtils.loadURI(browser, iFramePage);
await browserLoaded;
info("The error page has loaded!");
await SpecialPowers.spawn(browser, [], async function() {
let iframe = content.document.getElementById("theIframe");
await ContentTaskUtils.waitForCondition(() =>
iframe.contentDocument.body.classList.contains("neterror")
);
});
let frameContext = browser.browsingContext.children[0];
let newTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
// In the iframe, we see the correct error page and click on the button
// to open the blocked page in a new window/tab
await SpecialPowers.spawn(frameContext, [], async function() {
let doc = content.document;
let textLongDescription = doc.getElementById("errorLongDesc").textContent;
let learnMoreLinkLocation = doc.getElementById("learnMoreLink").href;
Assert.ok(
textLongDescription.includes(
"To see this page, you need to open it in a new window."
),
"Correct error message found"
);
let button = doc.getElementById("openInNewWindowButton");
Assert.ok(
button.textContent.includes("Open Site in New Window"),
"We see the correct button to open the site in a new window"
);
Assert.ok(
learnMoreLinkLocation.includes("xframe-neterror-page"),
"Correct Learn More URL for XFO error page"
);
// We click on the button
await EventUtils.synthesizeMouseAtCenter(button, {}, content);
});
info("Button was clicked!");
// We wait for the new tab to load
await newTabLoaded;
info("The new tab has loaded!");
let iframePageTab = tab;
return {
iframePageTab,
blockedPageTab,
};
}
|