browser/base/content/test/general/browser_bug906190.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Description of the Tests for
michael@0 3 * - Bug 906190 - Persist "disable protection" option for Mixed Content Blocker in child tabs
michael@0 4 *
michael@0 5 * 1. Open a page from the same domain in a child tab
michael@0 6 * - Load a html page which has mixed content
michael@0 7 * - Doorhanger to disable protection appears - we disable it
michael@0 8 * - Load a subpage from the same origin in a new tab simulating a click
michael@0 9 * - Doorhanger should >> NOT << appear anymore!
michael@0 10 *
michael@0 11 * 2. Open a page from a different domain in a child tab
michael@0 12 * - Load a html page which has mixed content
michael@0 13 * - Doorhanger to disable protection appears - we disable it
michael@0 14 * - Load a new page from a different origin in a new tab simulating a click
michael@0 15 * - Doorhanger >> SHOULD << appear again!
michael@0 16 *
michael@0 17 * 3. [meta-refresh: same origin] Open a page from the same domain in a child tab
michael@0 18 * - Load a html page which has mixed content
michael@0 19 * - Doorhanger to disable protection appears - we disable it
michael@0 20 * - Load a new page from the same origin in a new tab simulating a click
michael@0 21 * - Redirect that page to another page from the same origin using meta-refresh
michael@0 22 * - Doorhanger should >> NOT << appear again!
michael@0 23 *
michael@0 24 * 4. [meta-refresh: different origin] Open a page from a different domain in a child tab
michael@0 25 * - Load a html page which has mixed content
michael@0 26 * - Doorhanger to disable protection appears - we disable it
michael@0 27 * - Load a new page from the same origin in a new tab simulating a click
michael@0 28 * - Redirect that page to another page from a different origin using meta-refresh
michael@0 29 * - Doorhanger >> SHOULD << appear again!
michael@0 30 *
michael@0 31 * 5. [302 redirect: same origin] Open a page from the same domain in a child tab
michael@0 32 * - Load a html page which has mixed content
michael@0 33 * - Doorhanger to disable protection appears - we disable it
michael@0 34 * - Load a new page from the same origin in a new tab simulating a click
michael@0 35 * - Redirect that page to another page from the same origin using 302 redirect
michael@0 36 * - Doorhanger >> APPEARS << , but should >> NOT << appear again!
michael@0 37 * - FOLLOW UP BUG 914860!
michael@0 38 *
michael@0 39 * 6. [302 redirect: different origin] Open a page from the same domain in a child tab
michael@0 40 * - Load a html page which has mixed content
michael@0 41 * - Doorhanger to disable protection appears - we disable it
michael@0 42 * - Load a new page from the same origin in a new tab simulating a click
michael@0 43 * - Redirect that page to another page from a different origin using 302 redirect
michael@0 44 * - Doorhanger >> SHOULD << appear again!
michael@0 45 *
michael@0 46 * Note, for all tests we set gHttpTestRoot to use 'https' and we test both,
michael@0 47 * - |CTRL-CLICK|, as well as
michael@0 48 * - |RIGHT-CLICK->OPEN LINK IN TAB|.
michael@0 49 */
michael@0 50
michael@0 51 const PREF_ACTIVE = "security.mixed_content.block_active_content";
michael@0 52
michael@0 53 // We use the different urls for testing same origin checks before allowing
michael@0 54 // mixed content on child tabs.
michael@0 55 const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/";
michael@0 56 const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/";
michael@0 57
michael@0 58 let origBlockActive;
michael@0 59 let gTestWin = null;
michael@0 60 let mainTab = null;
michael@0 61 let curClickHandler = null;
michael@0 62 let curContextMenu = null;
michael@0 63 let curTestFunc = null;
michael@0 64 let curTestName = null;
michael@0 65 let curChildTabLink = null;
michael@0 66
michael@0 67 //------------------------ Helper Functions ---------------------
michael@0 68
michael@0 69 registerCleanupFunction(function() {
michael@0 70 // Set preferences back to their original values
michael@0 71 Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
michael@0 72 });
michael@0 73
michael@0 74 /*
michael@0 75 * Whenever we disable the Mixed Content Blocker of the page
michael@0 76 * we have to make sure that our condition is properly loaded.
michael@0 77 */
michael@0 78 function waitForCondition(condition, nextTest, errorMsg) {
michael@0 79 var tries = 0;
michael@0 80 var interval = setInterval(function() {
michael@0 81 if (tries >= 30) {
michael@0 82 ok(false, errorMsg);
michael@0 83 moveOn();
michael@0 84 }
michael@0 85 if (condition()) {
michael@0 86 moveOn();
michael@0 87 }
michael@0 88 tries++;
michael@0 89 }, 100);
michael@0 90 var moveOn = function() {
michael@0 91 clearInterval(interval); nextTest();
michael@0 92 };
michael@0 93 }
michael@0 94
michael@0 95 // The purpose of this function is to simulate |CTRL+CLICK|.
michael@0 96 // The clickHandler intercepts simulated user clicks and performs
michael@0 97 // the |contentAreaClick| which dispatches to handleLinkClick.
michael@0 98 let clickHandler = function (aEvent, aFunc) {
michael@0 99 gTestWin.gBrowser.removeEventListener("click", curClickHandler, true);
michael@0 100 gTestWin.contentAreaClick(aEvent, true);
michael@0 101 gTestWin.gBrowser.addEventListener("load", aFunc, true);
michael@0 102 aEvent.preventDefault();
michael@0 103 aEvent.stopPropagation();
michael@0 104 }
michael@0 105
michael@0 106 // The purpose of this function is to simulate |RIGHT-CLICK|->|OPEN LINK IN TAB|
michael@0 107 // Once the contextmenu opens, this functions selects 'open link in tab'
michael@0 108 // from the contextmenu which dispatches to the function openLinkInTab.
michael@0 109 let contextMenuOpenHandler = function(aEvent, aFunc) {
michael@0 110 gTestWin.document.removeEventListener("popupshown", curContextMenu, false);
michael@0 111 gTestWin.gBrowser.addEventListener("load", aFunc, true);
michael@0 112 var openLinkInTabCommand = gTestWin.document.getElementById("context-openlinkintab");
michael@0 113 openLinkInTabCommand.doCommand();
michael@0 114 aEvent.target.hidePopup();
michael@0 115 };
michael@0 116
michael@0 117 function setUpTest(aTestName, aIDForNextTest, aFuncForNextTest, aChildTabLink) {
michael@0 118 curTestName = aTestName;
michael@0 119 curTestFunc = aFuncForNextTest;
michael@0 120 curChildTabLink = aChildTabLink;
michael@0 121
michael@0 122 mainTab = gTestWin.gBrowser.selectedTab;
michael@0 123 // get the link for the next test from the main page
michael@0 124 let target = gTestWin.content.document.getElementById(aIDForNextTest);
michael@0 125 gTestWin.gBrowser.addTab(target);
michael@0 126 gTestWin.gBrowser.selectTabAtIndex(1);
michael@0 127 gTestWin.gBrowser.addEventListener("load", checkPopUpNotification, true);
michael@0 128 }
michael@0 129
michael@0 130 function checkPopUpNotification() {
michael@0 131 gTestWin.gBrowser.removeEventListener("load", checkPopUpNotification, true);
michael@0 132 gTestWin.gBrowser.addEventListener("load", reloadedTabAfterDisablingMCB, true);
michael@0 133
michael@0 134 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 135 ok(notification, "OK: Mixed Content Doorhanger appeared in " + curTestName + "!");
michael@0 136
michael@0 137 // Disable Mixed Content Protection for the page
michael@0 138 notification.secondaryActions[0].callback();
michael@0 139 }
michael@0 140
michael@0 141 function reloadedTabAfterDisablingMCB() {
michael@0 142 gTestWin.gBrowser.removeEventListener("load", reloadedTabAfterDisablingMCB, true);
michael@0 143
michael@0 144 var expected = "Mixed Content Blocker disabled";
michael@0 145 waitForCondition(
michael@0 146 function() gTestWin.content.document.getElementById('mctestdiv').innerHTML == expected,
michael@0 147 makeSureMCBisDisabled, "Error: Waited too long for mixed script to run in " + curTestName + "!");
michael@0 148 }
michael@0 149
michael@0 150 function makeSureMCBisDisabled() {
michael@0 151 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 152 is(actual, "Mixed Content Blocker disabled", "OK: Made sure MCB is disabled in " + curTestName + "!");
michael@0 153
michael@0 154 // inject the provided link into the page, so we can test persistence of MCB
michael@0 155 let doc = gTestWin.content.document;
michael@0 156 let mainDiv = gTestWin.content.document.createElement("div");
michael@0 157 mainDiv.innerHTML =
michael@0 158 '<p><a id="' + curTestName + '" href="' + curChildTabLink + '">' +
michael@0 159 curTestName + '</a></p>';
michael@0 160 doc.body.appendChild(mainDiv);
michael@0 161
michael@0 162 curTestFunc();
michael@0 163 }
michael@0 164
michael@0 165 //------------------------ Test 1 ------------------------------
michael@0 166
michael@0 167 function test1() {
michael@0 168 curClickHandler = function (e) { clickHandler(e, test1A) };
michael@0 169 gTestWin.gBrowser.addEventListener("click", curClickHandler , true);
michael@0 170
michael@0 171 // simulating |CTRL-CLICK|
michael@0 172 let targetElt = gTestWin.content.document.getElementById("Test1");
michael@0 173 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 174 }
michael@0 175
michael@0 176 function test1A() {
michael@0 177 gTestWin.gBrowser.removeEventListener("load", test1A, true);
michael@0 178 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 179
michael@0 180 // The Doorhanger should >> NOT << appear, because our decision of disabling the
michael@0 181 // mixed content blocker is persistent across tabs.
michael@0 182 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 183 ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1A!");
michael@0 184
michael@0 185 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 186 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1A");
michael@0 187
michael@0 188 gTestWin.gBrowser.removeCurrentTab();
michael@0 189 test1B();
michael@0 190 }
michael@0 191
michael@0 192 function test1B() {
michael@0 193 curContextMenu = function (e) { contextMenuOpenHandler(e, test1C) };
michael@0 194 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 195
michael@0 196 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 197 let targetElt = gTestWin.content.document.getElementById("Test1");
michael@0 198 // button 2 is a right click, hence the context menu pops up
michael@0 199 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 200 }
michael@0 201
michael@0 202 function test1C() {
michael@0 203 gTestWin.gBrowser.removeEventListener("load", test1C, true);
michael@0 204 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 205
michael@0 206 // The Doorhanger should >> NOT << appear, because our decision of disabling the
michael@0 207 // mixed content blocker is persistent across tabs.
michael@0 208 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 209 ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1C!");
michael@0 210
michael@0 211 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 212 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C");
michael@0 213
michael@0 214 // remove tabs
michael@0 215 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
michael@0 216 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
michael@0 217 gTestWin.gBrowser.selectTabAtIndex(0);
michael@0 218
michael@0 219 var childTabLink = gHttpTestRoot2 + "file_bug906190_2.html";
michael@0 220 setUpTest("Test2", "linkForTest2", test2, childTabLink);
michael@0 221 }
michael@0 222
michael@0 223 //------------------------ Test 2 ------------------------------
michael@0 224
michael@0 225 function test2() {
michael@0 226 curClickHandler = function (e) { clickHandler(e, test2A) };
michael@0 227 gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
michael@0 228
michael@0 229 // simulating |CTRL-CLICK|
michael@0 230 let targetElt = gTestWin.content.document.getElementById("Test2");
michael@0 231 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 232 }
michael@0 233
michael@0 234 function test2A() {
michael@0 235 gTestWin.gBrowser.removeEventListener("load", test2A, true);
michael@0 236 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 237
michael@0 238 // The Doorhanger >> SHOULD << appear, because our decision of disabling the
michael@0 239 // mixed content blocker should only persist if pages are from the same domain.
michael@0 240 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 241 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2A!");
michael@0 242
michael@0 243 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 244 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2A");
michael@0 245
michael@0 246 gTestWin.gBrowser.removeCurrentTab();
michael@0 247 test2B();
michael@0 248 }
michael@0 249
michael@0 250 function test2B() {
michael@0 251 curContextMenu = function (e) { contextMenuOpenHandler(e, test2C) };
michael@0 252 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 253
michael@0 254 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 255 let targetElt = gTestWin.content.document.getElementById("Test2");
michael@0 256 // button 2 is a right click, hence the context menu pops up
michael@0 257 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 258 }
michael@0 259
michael@0 260 function test2C() {
michael@0 261 gTestWin.gBrowser.removeEventListener("load", test2C, true);
michael@0 262 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 263
michael@0 264 // The Doorhanger >> SHOULD << appear, because our decision of disabling the
michael@0 265 // mixed content blocker should only persist if pages are from the same domain.
michael@0 266 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 267 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2C!");
michael@0 268
michael@0 269 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 270 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2C");
michael@0 271
michael@0 272 // remove tabs
michael@0 273 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
michael@0 274 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
michael@0 275 gTestWin.gBrowser.selectTabAtIndex(0);
michael@0 276
michael@0 277 // file_bug906190_3_4.html redirects to page test1.example.com/* using meta-refresh
michael@0 278 var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html";
michael@0 279 setUpTest("Test3", "linkForTest3", test3, childTabLink);
michael@0 280 }
michael@0 281
michael@0 282 //------------------------ Test 3 ------------------------------
michael@0 283
michael@0 284 function test3() {
michael@0 285 curClickHandler = function (e) { clickHandler(e, test3A) };
michael@0 286 gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
michael@0 287 // simulating |CTRL-CLICK|
michael@0 288 let targetElt = gTestWin.content.document.getElementById("Test3");
michael@0 289 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 290 }
michael@0 291
michael@0 292 function test3A() {
michael@0 293 // we need this indirection because the page is reloaded caused by meta-refresh
michael@0 294 gTestWin.gBrowser.removeEventListener("load", test3A, true);
michael@0 295 gTestWin.gBrowser.addEventListener("load", test3B, true);
michael@0 296 }
michael@0 297
michael@0 298 function test3B() {
michael@0 299 gTestWin.gBrowser.removeEventListener("load", test3B, true);
michael@0 300 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 301
michael@0 302 // The Doorhanger should >> NOT << appear!
michael@0 303 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 304 ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3B!");
michael@0 305
michael@0 306 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 307 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3B");
michael@0 308
michael@0 309 // remove tabs
michael@0 310 gTestWin.gBrowser.removeCurrentTab();
michael@0 311 test3C();
michael@0 312 }
michael@0 313
michael@0 314 function test3C() {
michael@0 315 curContextMenu = function (e) { contextMenuOpenHandler(e, test3D) };
michael@0 316 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 317
michael@0 318 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 319 let targetElt = gTestWin.content.document.getElementById("Test3");
michael@0 320 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 321 }
michael@0 322
michael@0 323 function test3D() {
michael@0 324 // we need this indirection because the page is reloaded caused by meta-refresh
michael@0 325 gTestWin.gBrowser.removeEventListener("load", test3D, true);
michael@0 326 gTestWin.gBrowser.addEventListener("load", test3E, true);
michael@0 327 }
michael@0 328
michael@0 329 function test3E() {
michael@0 330 gTestWin.gBrowser.removeEventListener("load", test3E, true);
michael@0 331 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 332
michael@0 333 // The Doorhanger should >> NOT << appear!
michael@0 334 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 335 ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3E!");
michael@0 336
michael@0 337 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 338 is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3E");
michael@0 339
michael@0 340 // remove tabs
michael@0 341 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
michael@0 342 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
michael@0 343 gTestWin.gBrowser.selectTabAtIndex(0);
michael@0 344
michael@0 345 var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html";
michael@0 346 setUpTest("Test4", "linkForTest4", test4, childTabLink);
michael@0 347 }
michael@0 348
michael@0 349 //------------------------ Test 4 ------------------------------
michael@0 350
michael@0 351 function test4() {
michael@0 352 curClickHandler = function (e) { clickHandler(e, test4A) };
michael@0 353 gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
michael@0 354
michael@0 355 // simulating |CTRL-CLICK|
michael@0 356 let targetElt = gTestWin.content.document.getElementById("Test4");
michael@0 357 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 358 }
michael@0 359
michael@0 360 function test4A() {
michael@0 361 // we need this indirection because the page is reloaded caused by meta-refresh
michael@0 362 gTestWin.gBrowser.removeEventListener("load", test4A, true);
michael@0 363 gTestWin.gBrowser.addEventListener("load", test4B, true);
michael@0 364 }
michael@0 365
michael@0 366 function test4B() {
michael@0 367 gTestWin.gBrowser.removeEventListener("load", test4B, true);
michael@0 368 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 369
michael@0 370 // The Doorhanger >> SHOULD << appear!
michael@0 371 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 372 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4B!");
michael@0 373
michael@0 374 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 375 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4B");
michael@0 376
michael@0 377 // remove tabs
michael@0 378 gTestWin.gBrowser.removeCurrentTab();
michael@0 379 test4C();
michael@0 380 }
michael@0 381
michael@0 382 function test4C() {
michael@0 383 curContextMenu = function (e) { contextMenuOpenHandler(e, test4D) };
michael@0 384 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 385
michael@0 386 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 387 let targetElt = gTestWin.content.document.getElementById("Test4");
michael@0 388 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 389 }
michael@0 390
michael@0 391 function test4D() {
michael@0 392 // we need this indirection because the page is reloaded caused by meta-refresh
michael@0 393 gTestWin.gBrowser.removeEventListener("load", test4D, true);
michael@0 394 gTestWin.gBrowser.addEventListener("load", test4E, true);
michael@0 395 }
michael@0 396
michael@0 397 function test4E() {
michael@0 398 gTestWin.gBrowser.removeEventListener("load", test4E, true);
michael@0 399 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 400
michael@0 401 // The Doorhanger >> SHOULD << appear!
michael@0 402 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 403 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4E!");
michael@0 404
michael@0 405 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 406 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4E");
michael@0 407
michael@0 408 // remove tabs
michael@0 409 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
michael@0 410 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
michael@0 411 gTestWin.gBrowser.selectTabAtIndex(0);
michael@0 412
michael@0 413 // the sjs files returns a 302 redirect- note, same origins
michael@0 414 var childTabLink = gHttpTestRoot1 + "file_bug906190.sjs";
michael@0 415 setUpTest("Test5", "linkForTest5", test5, childTabLink);
michael@0 416 }
michael@0 417
michael@0 418 //------------------------ Test 5 ------------------------------
michael@0 419
michael@0 420 function test5() {
michael@0 421 curClickHandler = function (e) { clickHandler(e, test5A) };
michael@0 422 gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
michael@0 423
michael@0 424 // simulating |CTRL-CLICK|
michael@0 425 let targetElt = gTestWin.content.document.getElementById("Test5");
michael@0 426 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 427 }
michael@0 428
michael@0 429 function test5A() {
michael@0 430 gTestWin.gBrowser.removeEventListener("load", test5A, true);
michael@0 431 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 432
michael@0 433 // The Doorhanger should >> NOT << appear
michael@0 434 // Currently it >> APPEARS << - see follow up bug 914860
michael@0 435 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 436 todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5A!");
michael@0 437
michael@0 438 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 439 todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5A!");
michael@0 440
michael@0 441 // remove tabs
michael@0 442 gTestWin.gBrowser.removeCurrentTab();
michael@0 443 test5B();
michael@0 444 }
michael@0 445
michael@0 446 function test5B() {
michael@0 447 curContextMenu = function (e) { contextMenuOpenHandler(e, test5C) };
michael@0 448 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 449
michael@0 450 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 451 let targetElt = gTestWin.content.document.getElementById("Test5");
michael@0 452 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 453 }
michael@0 454
michael@0 455 function test5C() {
michael@0 456 gTestWin.gBrowser.removeEventListener("load", test5C, true);
michael@0 457 // move the tab again
michael@0 458 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 459
michael@0 460 // The Doorhanger should >> NOT << appear
michael@0 461 // Currently it >> APPEARS << - see follow up bug 914860
michael@0 462 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 463 todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5C!");
michael@0 464
michael@0 465 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 466 todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5C!");
michael@0 467
michael@0 468 // remove tabs
michael@0 469 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
michael@0 470 gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
michael@0 471 gTestWin.gBrowser.selectTabAtIndex(0);
michael@0 472
michael@0 473 // the sjs files returns a 302 redirect - note, different origins
michael@0 474 var childTabLink = gHttpTestRoot2 + "file_bug906190.sjs";
michael@0 475 setUpTest("Test6", "linkForTest6", test6, childTabLink);
michael@0 476 }
michael@0 477
michael@0 478 //------------------------ Test 6 ------------------------------
michael@0 479
michael@0 480 function test6() {
michael@0 481 curClickHandler = function (e) { clickHandler(e, test6A) };
michael@0 482 gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
michael@0 483
michael@0 484 // simulating |CTRL-CLICK|
michael@0 485 let targetElt = gTestWin.content.document.getElementById("Test6");
michael@0 486 EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
michael@0 487 }
michael@0 488
michael@0 489 function test6A() {
michael@0 490 gTestWin.gBrowser.removeEventListener("load", test6A, true);
michael@0 491 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 492
michael@0 493 // The Doorhanger >> SHOULD << appear!
michael@0 494 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 495 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6A!");
michael@0 496
michael@0 497 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 498 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6A");
michael@0 499
michael@0 500 // done
michael@0 501 gTestWin.gBrowser.removeCurrentTab();
michael@0 502 test6B();
michael@0 503 }
michael@0 504
michael@0 505 function test6B() {
michael@0 506 curContextMenu = function (e) { contextMenuOpenHandler(e, test6C) };
michael@0 507 gTestWin.document.addEventListener("popupshown", curContextMenu, false);
michael@0 508
michael@0 509 // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
michael@0 510 let targetElt = gTestWin.content.document.getElementById("Test6");
michael@0 511 EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
michael@0 512 }
michael@0 513
michael@0 514 function test6C() {
michael@0 515 gTestWin.gBrowser.removeEventListener("load", test6C, true);
michael@0 516 gTestWin.gBrowser.selectTabAtIndex(2);
michael@0 517
michael@0 518 // The Doorhanger >> SHOULD << appear!
michael@0 519 var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
michael@0 520 ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6C!");
michael@0 521
michael@0 522 var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
michael@0 523 is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6C");
michael@0 524
michael@0 525 gTestWin.close();
michael@0 526 finish();
michael@0 527 }
michael@0 528
michael@0 529 //------------------------ SETUP ------------------------------
michael@0 530
michael@0 531 function setupTestBrowserWindow() {
michael@0 532 // Inject links in content.
michael@0 533 let doc = gTestWin.content.document;
michael@0 534 let mainDiv = doc.createElement("div");
michael@0 535 mainDiv.innerHTML =
michael@0 536 '<p><a id="linkForTest1" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 1</a></p>' +
michael@0 537 '<p><a id="linkForTest2" href="'+ gHttpTestRoot1 + 'file_bug906190_2.html">Test 2</a></p>' +
michael@0 538 '<p><a id="linkForTest3" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 3</a></p>' +
michael@0 539 '<p><a id="linkForTest4" href="'+ gHttpTestRoot2 + 'file_bug906190_1.html">Test 4</a></p>' +
michael@0 540 '<p><a id="linkForTest5" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 5</a></p>' +
michael@0 541 '<p><a id="linkForTest6" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 6</a></p>';
michael@0 542 doc.body.appendChild(mainDiv);
michael@0 543 }
michael@0 544
michael@0 545 function startTests() {
michael@0 546 mainTab = gTestWin.gBrowser.selectedTab;
michael@0 547 var childTabLink = gHttpTestRoot1 + "file_bug906190_2.html";
michael@0 548 setUpTest("Test1", "linkForTest1", test1, childTabLink);
michael@0 549 }
michael@0 550
michael@0 551 function test() {
michael@0 552 // Performing async calls, e.g. 'onload', we have to wait till all of them finished
michael@0 553 waitForExplicitFinish();
michael@0 554
michael@0 555 // Store original preferences so we can restore settings after testing
michael@0 556 origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
michael@0 557 Services.prefs.setBoolPref(PREF_ACTIVE, true);
michael@0 558
michael@0 559 gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
michael@0 560 whenDelayedStartupFinished(gTestWin, function () {
michael@0 561 info("browser window opened");
michael@0 562 waitForFocus(function() {
michael@0 563 info("browser window focused");
michael@0 564 waitForFocus(function() {
michael@0 565 info("setting up browser...");
michael@0 566 setupTestBrowserWindow();
michael@0 567 info("running tests...");
michael@0 568 executeSoon(startTests);
michael@0 569 }, gTestWin.content, true);
michael@0 570 }, gTestWin);
michael@0 571 });
michael@0 572 }

mercurial