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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const baseURL = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.com"
);
async function test_opening_blocked_popups(testURL) {
// Enable the popup blocker.
await SpecialPowers.pushPrefEnv({
set: [["dom.disable_open_during_load", true]],
});
// Open the test page.
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, testURL);
let popupframeBC = await SpecialPowers.spawn(
tab.linkedBrowser,
[baseURL + "popup_blocker.html"],
uri => {
let iframe = content.document.createElement("iframe");
iframe.id = "popupframe";
iframe.src = uri;
content.document.body.appendChild(iframe);
return iframe.browsingContext;
}
);
// Wait for the popup-blocked notification.
let notification;
await TestUtils.waitForCondition(
() =>
(notification = gBrowser
.getNotificationBox()
.getNotificationWithValue("popup-blocked")),
"Waiting for the popup-blocked notification."
);
ok(notification, "Should have notification.");
let pageHideHappened = BrowserTestUtils.waitForContentEvent(
tab.linkedBrowser,
"pagehide",
true
);
await SpecialPowers.spawn(tab.linkedBrowser, [baseURL], async function (uri) {
let iframe = content.document.createElement("iframe");
content.document.body.appendChild(iframe);
iframe.src = uri;
});
await pageHideHappened;
notification = gBrowser
.getNotificationBox()
.getNotificationWithValue("popup-blocked");
ok(notification, "Should still have notification");
pageHideHappened = BrowserTestUtils.waitForContentEvent(
tab.linkedBrowser,
"pagehide",
true
);
// Now navigate the subframe.
await SpecialPowers.spawn(popupframeBC, [], async function () {
content.document.location.href = "about:blank";
});
await pageHideHappened;
await TestUtils.waitForCondition(
() =>
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"),
"Notification should go away"
);
ok(
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"),
"Should no longer have notification"
);
// Remove the frame and add another one:
await SpecialPowers.spawn(
tab.linkedBrowser,
[baseURL + "popup_blocker.html"],
uri => {
content.document.getElementById("popupframe").remove();
let iframe = content.document.createElement("iframe");
iframe.id = "popupframe";
iframe.src = uri;
content.document.body.appendChild(iframe);
}
);
// Wait for the popup-blocked notification.
await TestUtils.waitForCondition(
() =>
(notification = gBrowser
.getNotificationBox()
.getNotificationWithValue("popup-blocked"))
);
ok(notification, "Should have notification.");
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
content.document.getElementById("popupframe").remove();
});
await TestUtils.waitForCondition(
() =>
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked")
);
ok(
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"),
"Should no longer have notification"
);
BrowserTestUtils.removeTab(tab);
}
add_task(async function () {
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
await test_opening_blocked_popups("http://example.com/");
});
add_task(async function () {
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
await test_opening_blocked_popups("http://w3c-test.org/");
});
|