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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/*
* User Override Mixed Content Block - Tests for Bug 822367
*/
const PREF_DISPLAY = "security.mixed_content.block_display_content";
const PREF_DISPLAY_UPGRADE = "security.mixed_content.upgrade_display_content";
const PREF_ACTIVE = "security.mixed_content.block_active_content";
// We alternate for even and odd test cases to simulate different hosts
const HTTPS_TEST_ROOT = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
);
const HTTPS_TEST_ROOT_2 = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://test1.example.com"
);
var gTestBrowser = null;
add_task(async function test() {
await SpecialPowers.pushPrefEnv({
set: [
[PREF_DISPLAY, true],
[PREF_DISPLAY_UPGRADE, false],
[PREF_ACTIVE, true],
],
});
var newTab = BrowserTestUtils.addTab(gBrowser);
gBrowser.selectedTab = newTab;
gTestBrowser = gBrowser.selectedBrowser;
newTab.linkedBrowser.stop();
// Mixed Script Test
var url = HTTPS_TEST_ROOT + "file_bug822367_1.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
});
// Mixed Script Test
add_task(async function MixedTest1A() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
gTestBrowser.ownerGlobal.gIdentityHandler.disableMixedContentProtection();
await BrowserTestUtils.browserLoaded(gTestBrowser);
});
add_task(async function MixedTest1B() {
await SpecialPowers.spawn(gTestBrowser, [], async function () {
await ContentTaskUtils.waitForCondition(
() => content.document.getElementById("p1").innerHTML == "hello",
"Waited too long for mixed script to run in Test 1"
);
});
gTestBrowser.ownerGlobal.gIdentityHandler.enableMixedContentProtectionNoReload();
});
// Mixed Display Test - Doorhanger should not appear
add_task(async function MixedTest2() {
var url = HTTPS_TEST_ROOT_2 + "file_bug822367_2.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: false,
passiveLoaded: false,
});
});
// Mixed Script and Display Test - User Override should cause both the script and the image to load.
add_task(async function MixedTest3() {
var url = HTTPS_TEST_ROOT + "file_bug822367_3.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
});
add_task(async function MixedTest3A() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
gTestBrowser.ownerGlobal.gIdentityHandler.disableMixedContentProtection();
await BrowserTestUtils.browserLoaded(gTestBrowser);
});
add_task(async function MixedTest3B() {
await SpecialPowers.spawn(gTestBrowser, [], async function () {
let p1 = ContentTaskUtils.waitForCondition(
() => content.document.getElementById("p1").innerHTML == "hello",
"Waited too long for mixed script to run in Test 3"
);
let p2 = ContentTaskUtils.waitForCondition(
() => content.document.getElementById("p2").innerHTML == "bye",
"Waited too long for mixed image to load in Test 3"
);
await Promise.all([p1, p2]);
});
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: true,
activeBlocked: false,
passiveLoaded: true,
});
gTestBrowser.ownerGlobal.gIdentityHandler.enableMixedContentProtectionNoReload();
});
// Location change - User override on one page doesn't propagate to another page after location change.
add_task(async function MixedTest4() {
var url = HTTPS_TEST_ROOT_2 + "file_bug822367_4.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
});
let preLocationChangePrincipal = null;
add_task(async function MixedTest4A() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
preLocationChangePrincipal = gTestBrowser.contentPrincipal;
gTestBrowser.ownerGlobal.gIdentityHandler.disableMixedContentProtection();
await BrowserTestUtils.browserLoaded(gTestBrowser);
});
add_task(async function MixedTest4B() {
let url = HTTPS_TEST_ROOT + "file_bug822367_4B.html";
await SpecialPowers.spawn(gTestBrowser, [url], async function (wantedUrl) {
await ContentTaskUtils.waitForCondition(
() => content.document.location == wantedUrl,
"Waited too long for mixed script to run in Test 4"
);
});
});
add_task(async function MixedTest4C() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
await SpecialPowers.spawn(gTestBrowser, [], async function () {
await ContentTaskUtils.waitForCondition(
() => content.document.getElementById("p1").innerHTML == "",
"Mixed script loaded in test 4 after location change!"
);
});
SitePermissions.removeFromPrincipal(
preLocationChangePrincipal,
"mixed-content"
);
});
// Mixed script attempts to load in a document.open()
add_task(async function MixedTest5() {
var url = HTTPS_TEST_ROOT + "file_bug822367_5.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
});
add_task(async function MixedTest5A() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
gTestBrowser.ownerGlobal.gIdentityHandler.disableMixedContentProtection();
await BrowserTestUtils.browserLoaded(gTestBrowser);
});
add_task(async function MixedTest5B() {
await SpecialPowers.spawn(gTestBrowser, [], async function () {
await ContentTaskUtils.waitForCondition(
() => content.document.getElementById("p1").innerHTML == "hello",
"Waited too long for mixed script to run in Test 5"
);
});
gTestBrowser.ownerGlobal.gIdentityHandler.enableMixedContentProtectionNoReload();
});
// Mixed script attempts to load in a document.open() that is within an iframe.
add_task(async function MixedTest6() {
var url = HTTPS_TEST_ROOT_2 + "file_bug822367_6.html";
BrowserTestUtils.loadURIString(gTestBrowser, url);
await BrowserTestUtils.browserLoaded(gTestBrowser, false, url);
});
add_task(async function MixedTest6A() {
gTestBrowser.removeEventListener("load", MixedTest6A, true);
let { gIdentityHandler } = gTestBrowser.ownerGlobal;
await BrowserTestUtils.waitForCondition(
() =>
gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"),
"Waited too long for control center to get mixed active blocked state"
);
});
add_task(async function MixedTest6B() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: false,
activeBlocked: true,
passiveLoaded: false,
});
gTestBrowser.ownerGlobal.gIdentityHandler.disableMixedContentProtection();
await BrowserTestUtils.browserLoaded(gTestBrowser);
});
add_task(async function MixedTest6C() {
await SpecialPowers.spawn(gTestBrowser, [], async function () {
function test() {
try {
return (
content.document
.getElementById("f1")
.contentDocument.getElementById("p1").innerHTML == "hello"
);
} catch (e) {
return false;
}
}
await ContentTaskUtils.waitForCondition(
test,
"Waited too long for mixed script to run in Test 6"
);
});
});
add_task(async function MixedTest6D() {
await assertMixedContentBlockingState(gTestBrowser, {
activeLoaded: true,
activeBlocked: false,
passiveLoaded: false,
});
gTestBrowser.ownerGlobal.gIdentityHandler.enableMixedContentProtectionNoReload();
});
add_task(async function cleanup() {
gBrowser.removeCurrentTab();
});
|