|
1 /* |
|
2 * Description of the Tests for |
|
3 * - Bug 902156: Persist "disable protection" option for Mixed Content Blocker |
|
4 * |
|
5 * 1. Navigate to the same domain via document.location |
|
6 * - Load a html page which has mixed content |
|
7 * - Doorhanger to disable protection appears - we disable it |
|
8 * - Load a new page from the same origin using document.location |
|
9 * - Doorhanger should not appear anymore! |
|
10 * |
|
11 * 2. Navigate to the same domain via simulateclick for a link on the page |
|
12 * - Load a html page which has mixed content |
|
13 * - Doorhanger to disable protection appears - we disable it |
|
14 * - Load a new page from the same origin simulating a click |
|
15 * - Doorhanger should not appear anymore! |
|
16 * |
|
17 * 3. Navigate to a differnet domain and show the content is still blocked |
|
18 * - Load a different html page which has mixed content |
|
19 * - Doorhanger to disable protection should appear again because |
|
20 * we navigated away from html page where we disabled the protection. |
|
21 * |
|
22 * Note, for all tests we set gHttpTestRoot to use 'https'. |
|
23 */ |
|
24 |
|
25 const PREF_ACTIVE = "security.mixed_content.block_active_content"; |
|
26 |
|
27 // We alternate for even and odd test cases to simulate different hosts |
|
28 const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/"; |
|
29 const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/"; |
|
30 |
|
31 var origBlockActive; |
|
32 var gTestBrowser = null; |
|
33 |
|
34 registerCleanupFunction(function() { |
|
35 // Set preferences back to their original values |
|
36 Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive); |
|
37 }); |
|
38 |
|
39 function cleanUpAfterTests() { |
|
40 gBrowser.removeCurrentTab(); |
|
41 window.focus(); |
|
42 finish(); |
|
43 } |
|
44 |
|
45 //------------------------ Test 1 ------------------------------ |
|
46 |
|
47 function test1A() { |
|
48 // Removing EventListener because we have to register a new |
|
49 // one once the page is loaded with mixed content blocker disabled |
|
50 gTestBrowser.removeEventListener("load", test1A, true); |
|
51 gTestBrowser.addEventListener("load", test1B, true); |
|
52 |
|
53 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); |
|
54 ok(notification, "OK: Mixed Content Doorhanger appeared in Test1A!"); |
|
55 |
|
56 // Disable Mixed Content Protection for the page |
|
57 notification.secondaryActions[0].callback(); |
|
58 } |
|
59 |
|
60 function test1B() { |
|
61 var expected = "Mixed Content Blocker disabled"; |
|
62 waitForCondition( |
|
63 function() content.document.getElementById('mctestdiv').innerHTML == expected, |
|
64 test1C, "Error: Waited too long for mixed script to run in Test 1B"); |
|
65 } |
|
66 |
|
67 function test1C() { |
|
68 gTestBrowser.removeEventListener("load", test1B, true); |
|
69 var actual = content.document.getElementById('mctestdiv').innerHTML; |
|
70 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C"); |
|
71 |
|
72 // The Script loaded after we disabled the page, now we are going to reload the |
|
73 // page and see if our decision is persistent |
|
74 gTestBrowser.addEventListener("load", test1D, true); |
|
75 |
|
76 var url = gHttpTestRoot1 + "file_bug902156_2.html"; |
|
77 gTestBrowser.contentWindow.location = url; |
|
78 } |
|
79 |
|
80 function test1D() { |
|
81 gTestBrowser.removeEventListener("load", test1D, true); |
|
82 |
|
83 // The Doorhanger should not appear, because our decision of disabling the |
|
84 // mixed content blocker is persistent. |
|
85 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); |
|
86 ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test1D!"); |
|
87 |
|
88 var actual = content.document.getElementById('mctestdiv').innerHTML; |
|
89 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1D"); |
|
90 |
|
91 // move on to Test 2 |
|
92 test2(); |
|
93 } |
|
94 |
|
95 //------------------------ Test 2 ------------------------------ |
|
96 |
|
97 function test2() { |
|
98 gTestBrowser.addEventListener("load", test2A, true); |
|
99 var url = gHttpTestRoot2 + "file_bug902156_2.html"; |
|
100 gTestBrowser.contentWindow.location = url; |
|
101 } |
|
102 |
|
103 function test2A() { |
|
104 // Removing EventListener because we have to register a new |
|
105 // one once the page is loaded with mixed content blocker disabled |
|
106 gTestBrowser.removeEventListener("load", test2A, true); |
|
107 gTestBrowser.addEventListener("load", test2B, true); |
|
108 |
|
109 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); |
|
110 ok(notification, "OK: Mixed Content Doorhanger appeared in Test 2A!"); |
|
111 |
|
112 // Disable Mixed Content Protection for the page |
|
113 notification.secondaryActions[0].callback(); |
|
114 } |
|
115 |
|
116 function test2B() { |
|
117 var expected = "Mixed Content Blocker disabled"; |
|
118 waitForCondition( |
|
119 function() content.document.getElementById('mctestdiv').innerHTML == expected, |
|
120 test2C, "Error: Waited too long for mixed script to run in Test 2B"); |
|
121 } |
|
122 |
|
123 function test2C() { |
|
124 gTestBrowser.removeEventListener("load", test2B, true); |
|
125 var actual = content.document.getElementById('mctestdiv').innerHTML; |
|
126 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2C"); |
|
127 |
|
128 // The Script loaded after we disabled the page, now we are going to reload the |
|
129 // page and see if our decision is persistent |
|
130 gTestBrowser.addEventListener("load", test2D, true); |
|
131 |
|
132 // reload the page using the provided link in the html file |
|
133 var mctestlink = content.document.getElementById("mctestlink"); |
|
134 mctestlink.click(); |
|
135 } |
|
136 |
|
137 function test2D() { |
|
138 gTestBrowser.removeEventListener("load", test2D, true); |
|
139 |
|
140 // The Doorhanger should not appear, because our decision of disabling the |
|
141 // mixed content blocker is persistent. |
|
142 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); |
|
143 ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test2D!"); |
|
144 |
|
145 var actual = content.document.getElementById('mctestdiv').innerHTML; |
|
146 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2D"); |
|
147 |
|
148 // move on to Test 3 |
|
149 test3(); |
|
150 } |
|
151 |
|
152 //------------------------ Test 3 ------------------------------ |
|
153 |
|
154 function test3() { |
|
155 gTestBrowser.addEventListener("load", test3A, true); |
|
156 var url = gHttpTestRoot1 + "file_bug902156_3.html"; |
|
157 gTestBrowser.contentWindow.location = url; |
|
158 } |
|
159 |
|
160 function test3A() { |
|
161 // Removing EventListener because we have to register a new |
|
162 // one once the page is loaded with mixed content blocker disabled |
|
163 gTestBrowser.removeEventListener("load", test3A, true); |
|
164 |
|
165 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); |
|
166 ok(notification, "OK: Mixed Content Doorhanger appeared in Test 3A!"); |
|
167 |
|
168 // We are done with tests, clean up |
|
169 cleanUpAfterTests(); |
|
170 } |
|
171 |
|
172 //------------------------------------------------------ |
|
173 |
|
174 function test() { |
|
175 // Performing async calls, e.g. 'onload', we have to wait till all of them finished |
|
176 waitForExplicitFinish(); |
|
177 |
|
178 // Store original preferences so we can restore settings after testing |
|
179 origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE); |
|
180 |
|
181 Services.prefs.setBoolPref(PREF_ACTIVE, true); |
|
182 |
|
183 // Not really sure what this is doing |
|
184 var newTab = gBrowser.addTab(); |
|
185 gBrowser.selectedTab = newTab; |
|
186 gTestBrowser = gBrowser.selectedBrowser; |
|
187 newTab.linkedBrowser.stop() |
|
188 |
|
189 // Starting Test Number 1: |
|
190 gTestBrowser.addEventListener("load", test1A, true); |
|
191 var url = gHttpTestRoot1 + "file_bug902156_1.html"; |
|
192 gTestBrowser.contentWindow.location = url; |
|
193 } |