michael@0: /* michael@0: * Description of the Tests for michael@0: * - Bug 906190 - Persist "disable protection" option for Mixed Content Blocker in child tabs michael@0: * michael@0: * 1. Open a page from the same domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a subpage from the same origin in a new tab simulating a click michael@0: * - Doorhanger should >> NOT << appear anymore! michael@0: * michael@0: * 2. Open a page from a different domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from a different origin in a new tab simulating a click michael@0: * - Doorhanger >> SHOULD << appear again! michael@0: * michael@0: * 3. [meta-refresh: same origin] Open a page from the same domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin in a new tab simulating a click michael@0: * - Redirect that page to another page from the same origin using meta-refresh michael@0: * - Doorhanger should >> NOT << appear again! michael@0: * michael@0: * 4. [meta-refresh: different origin] Open a page from a different domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin in a new tab simulating a click michael@0: * - Redirect that page to another page from a different origin using meta-refresh michael@0: * - Doorhanger >> SHOULD << appear again! michael@0: * michael@0: * 5. [302 redirect: same origin] Open a page from the same domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin in a new tab simulating a click michael@0: * - Redirect that page to another page from the same origin using 302 redirect michael@0: * - Doorhanger >> APPEARS << , but should >> NOT << appear again! michael@0: * - FOLLOW UP BUG 914860! michael@0: * michael@0: * 6. [302 redirect: different origin] Open a page from the same domain in a child tab michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin in a new tab simulating a click michael@0: * - Redirect that page to another page from a different origin using 302 redirect michael@0: * - Doorhanger >> SHOULD << appear again! michael@0: * michael@0: * Note, for all tests we set gHttpTestRoot to use 'https' and we test both, michael@0: * - |CTRL-CLICK|, as well as michael@0: * - |RIGHT-CLICK->OPEN LINK IN TAB|. michael@0: */ michael@0: michael@0: const PREF_ACTIVE = "security.mixed_content.block_active_content"; michael@0: michael@0: // We use the different urls for testing same origin checks before allowing michael@0: // mixed content on child tabs. michael@0: const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/"; michael@0: const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/"; michael@0: michael@0: let origBlockActive; michael@0: let gTestWin = null; michael@0: let mainTab = null; michael@0: let curClickHandler = null; michael@0: let curContextMenu = null; michael@0: let curTestFunc = null; michael@0: let curTestName = null; michael@0: let curChildTabLink = null; michael@0: michael@0: //------------------------ Helper Functions --------------------- michael@0: michael@0: registerCleanupFunction(function() { michael@0: // Set preferences back to their original values michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive); michael@0: }); michael@0: michael@0: /* michael@0: * Whenever we disable the Mixed Content Blocker of the page michael@0: * we have to make sure that our condition is properly loaded. michael@0: */ michael@0: function waitForCondition(condition, nextTest, errorMsg) { michael@0: var tries = 0; michael@0: var interval = setInterval(function() { michael@0: if (tries >= 30) { michael@0: ok(false, errorMsg); michael@0: moveOn(); michael@0: } michael@0: if (condition()) { michael@0: moveOn(); michael@0: } michael@0: tries++; michael@0: }, 100); michael@0: var moveOn = function() { michael@0: clearInterval(interval); nextTest(); michael@0: }; michael@0: } michael@0: michael@0: // The purpose of this function is to simulate |CTRL+CLICK|. michael@0: // The clickHandler intercepts simulated user clicks and performs michael@0: // the |contentAreaClick| which dispatches to handleLinkClick. michael@0: let clickHandler = function (aEvent, aFunc) { michael@0: gTestWin.gBrowser.removeEventListener("click", curClickHandler, true); michael@0: gTestWin.contentAreaClick(aEvent, true); michael@0: gTestWin.gBrowser.addEventListener("load", aFunc, true); michael@0: aEvent.preventDefault(); michael@0: aEvent.stopPropagation(); michael@0: } michael@0: michael@0: // The purpose of this function is to simulate |RIGHT-CLICK|->|OPEN LINK IN TAB| michael@0: // Once the contextmenu opens, this functions selects 'open link in tab' michael@0: // from the contextmenu which dispatches to the function openLinkInTab. michael@0: let contextMenuOpenHandler = function(aEvent, aFunc) { michael@0: gTestWin.document.removeEventListener("popupshown", curContextMenu, false); michael@0: gTestWin.gBrowser.addEventListener("load", aFunc, true); michael@0: var openLinkInTabCommand = gTestWin.document.getElementById("context-openlinkintab"); michael@0: openLinkInTabCommand.doCommand(); michael@0: aEvent.target.hidePopup(); michael@0: }; michael@0: michael@0: function setUpTest(aTestName, aIDForNextTest, aFuncForNextTest, aChildTabLink) { michael@0: curTestName = aTestName; michael@0: curTestFunc = aFuncForNextTest; michael@0: curChildTabLink = aChildTabLink; michael@0: michael@0: mainTab = gTestWin.gBrowser.selectedTab; michael@0: // get the link for the next test from the main page michael@0: let target = gTestWin.content.document.getElementById(aIDForNextTest); michael@0: gTestWin.gBrowser.addTab(target); michael@0: gTestWin.gBrowser.selectTabAtIndex(1); michael@0: gTestWin.gBrowser.addEventListener("load", checkPopUpNotification, true); michael@0: } michael@0: michael@0: function checkPopUpNotification() { michael@0: gTestWin.gBrowser.removeEventListener("load", checkPopUpNotification, true); michael@0: gTestWin.gBrowser.addEventListener("load", reloadedTabAfterDisablingMCB, true); michael@0: michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger appeared in " + curTestName + "!"); michael@0: michael@0: // Disable Mixed Content Protection for the page michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: michael@0: function reloadedTabAfterDisablingMCB() { michael@0: gTestWin.gBrowser.removeEventListener("load", reloadedTabAfterDisablingMCB, true); michael@0: michael@0: var expected = "Mixed Content Blocker disabled"; michael@0: waitForCondition( michael@0: function() gTestWin.content.document.getElementById('mctestdiv').innerHTML == expected, michael@0: makeSureMCBisDisabled, "Error: Waited too long for mixed script to run in " + curTestName + "!"); michael@0: } michael@0: michael@0: function makeSureMCBisDisabled() { michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Made sure MCB is disabled in " + curTestName + "!"); michael@0: michael@0: // inject the provided link into the page, so we can test persistence of MCB michael@0: let doc = gTestWin.content.document; michael@0: let mainDiv = gTestWin.content.document.createElement("div"); michael@0: mainDiv.innerHTML = michael@0: '

' + michael@0: curTestName + '

'; michael@0: doc.body.appendChild(mainDiv); michael@0: michael@0: curTestFunc(); michael@0: } michael@0: michael@0: //------------------------ Test 1 ------------------------------ michael@0: michael@0: function test1() { michael@0: curClickHandler = function (e) { clickHandler(e, test1A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler , true); michael@0: michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test1"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test1A() { michael@0: gTestWin.gBrowser.removeEventListener("load", test1A, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear, because our decision of disabling the michael@0: // mixed content blocker is persistent across tabs. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1A!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1A"); michael@0: michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test1B(); michael@0: } michael@0: michael@0: function test1B() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test1C) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test1"); michael@0: // button 2 is a right click, hence the context menu pops up michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test1C() { michael@0: gTestWin.gBrowser.removeEventListener("load", test1C, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear, because our decision of disabling the michael@0: // mixed content blocker is persistent across tabs. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1C!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false}); michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false}); michael@0: gTestWin.gBrowser.selectTabAtIndex(0); michael@0: michael@0: var childTabLink = gHttpTestRoot2 + "file_bug906190_2.html"; michael@0: setUpTest("Test2", "linkForTest2", test2, childTabLink); michael@0: } michael@0: michael@0: //------------------------ Test 2 ------------------------------ michael@0: michael@0: function test2() { michael@0: curClickHandler = function (e) { clickHandler(e, test2A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler, true); michael@0: michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test2"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test2A() { michael@0: gTestWin.gBrowser.removeEventListener("load", test2A, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear, because our decision of disabling the michael@0: // mixed content blocker should only persist if pages are from the same domain. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2A!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2A"); michael@0: michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test2B(); michael@0: } michael@0: michael@0: function test2B() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test2C) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test2"); michael@0: // button 2 is a right click, hence the context menu pops up michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test2C() { michael@0: gTestWin.gBrowser.removeEventListener("load", test2C, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear, because our decision of disabling the michael@0: // mixed content blocker should only persist if pages are from the same domain. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2C!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2C"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false}); michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false}); michael@0: gTestWin.gBrowser.selectTabAtIndex(0); michael@0: michael@0: // file_bug906190_3_4.html redirects to page test1.example.com/* using meta-refresh michael@0: var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html"; michael@0: setUpTest("Test3", "linkForTest3", test3, childTabLink); michael@0: } michael@0: michael@0: //------------------------ Test 3 ------------------------------ michael@0: michael@0: function test3() { michael@0: curClickHandler = function (e) { clickHandler(e, test3A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler, true); michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test3"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test3A() { michael@0: // we need this indirection because the page is reloaded caused by meta-refresh michael@0: gTestWin.gBrowser.removeEventListener("load", test3A, true); michael@0: gTestWin.gBrowser.addEventListener("load", test3B, true); michael@0: } michael@0: michael@0: function test3B() { michael@0: gTestWin.gBrowser.removeEventListener("load", test3B, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3B!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3B"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test3C(); michael@0: } michael@0: michael@0: function test3C() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test3D) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test3"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test3D() { michael@0: // we need this indirection because the page is reloaded caused by meta-refresh michael@0: gTestWin.gBrowser.removeEventListener("load", test3D, true); michael@0: gTestWin.gBrowser.addEventListener("load", test3E, true); michael@0: } michael@0: michael@0: function test3E() { michael@0: gTestWin.gBrowser.removeEventListener("load", test3E, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3E!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3E"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false}); michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false}); michael@0: gTestWin.gBrowser.selectTabAtIndex(0); michael@0: michael@0: var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html"; michael@0: setUpTest("Test4", "linkForTest4", test4, childTabLink); michael@0: } michael@0: michael@0: //------------------------ Test 4 ------------------------------ michael@0: michael@0: function test4() { michael@0: curClickHandler = function (e) { clickHandler(e, test4A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler, true); michael@0: michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test4"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test4A() { michael@0: // we need this indirection because the page is reloaded caused by meta-refresh michael@0: gTestWin.gBrowser.removeEventListener("load", test4A, true); michael@0: gTestWin.gBrowser.addEventListener("load", test4B, true); michael@0: } michael@0: michael@0: function test4B() { michael@0: gTestWin.gBrowser.removeEventListener("load", test4B, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4B!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4B"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test4C(); michael@0: } michael@0: michael@0: function test4C() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test4D) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test4"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test4D() { michael@0: // we need this indirection because the page is reloaded caused by meta-refresh michael@0: gTestWin.gBrowser.removeEventListener("load", test4D, true); michael@0: gTestWin.gBrowser.addEventListener("load", test4E, true); michael@0: } michael@0: michael@0: function test4E() { michael@0: gTestWin.gBrowser.removeEventListener("load", test4E, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4E!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4E"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false}); michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false}); michael@0: gTestWin.gBrowser.selectTabAtIndex(0); michael@0: michael@0: // the sjs files returns a 302 redirect- note, same origins michael@0: var childTabLink = gHttpTestRoot1 + "file_bug906190.sjs"; michael@0: setUpTest("Test5", "linkForTest5", test5, childTabLink); michael@0: } michael@0: michael@0: //------------------------ Test 5 ------------------------------ michael@0: michael@0: function test5() { michael@0: curClickHandler = function (e) { clickHandler(e, test5A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler, true); michael@0: michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test5"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test5A() { michael@0: gTestWin.gBrowser.removeEventListener("load", test5A, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear michael@0: // Currently it >> APPEARS << - see follow up bug 914860 michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5A!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5A!"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test5B(); michael@0: } michael@0: michael@0: function test5B() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test5C) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test5"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test5C() { michael@0: gTestWin.gBrowser.removeEventListener("load", test5C, true); michael@0: // move the tab again michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger should >> NOT << appear michael@0: // Currently it >> APPEARS << - see follow up bug 914860 michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5C!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5C!"); michael@0: michael@0: // remove tabs michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false}); michael@0: gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false}); michael@0: gTestWin.gBrowser.selectTabAtIndex(0); michael@0: michael@0: // the sjs files returns a 302 redirect - note, different origins michael@0: var childTabLink = gHttpTestRoot2 + "file_bug906190.sjs"; michael@0: setUpTest("Test6", "linkForTest6", test6, childTabLink); michael@0: } michael@0: michael@0: //------------------------ Test 6 ------------------------------ michael@0: michael@0: function test6() { michael@0: curClickHandler = function (e) { clickHandler(e, test6A) }; michael@0: gTestWin.gBrowser.addEventListener("click", curClickHandler, true); michael@0: michael@0: // simulating |CTRL-CLICK| michael@0: let targetElt = gTestWin.content.document.getElementById("Test6"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content); michael@0: } michael@0: michael@0: function test6A() { michael@0: gTestWin.gBrowser.removeEventListener("load", test6A, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6A!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6A"); michael@0: michael@0: // done michael@0: gTestWin.gBrowser.removeCurrentTab(); michael@0: test6B(); michael@0: } michael@0: michael@0: function test6B() { michael@0: curContextMenu = function (e) { contextMenuOpenHandler(e, test6C) }; michael@0: gTestWin.document.addEventListener("popupshown", curContextMenu, false); michael@0: michael@0: // simulating |RIGHT-CLICK -> OPEN LINK IN TAB| michael@0: let targetElt = gTestWin.content.document.getElementById("Test6"); michael@0: EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content); michael@0: } michael@0: michael@0: function test6C() { michael@0: gTestWin.gBrowser.removeEventListener("load", test6C, true); michael@0: gTestWin.gBrowser.selectTabAtIndex(2); michael@0: michael@0: // The Doorhanger >> SHOULD << appear! michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6C!"); michael@0: michael@0: var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6C"); michael@0: michael@0: gTestWin.close(); michael@0: finish(); michael@0: } michael@0: michael@0: //------------------------ SETUP ------------------------------ michael@0: michael@0: function setupTestBrowserWindow() { michael@0: // Inject links in content. michael@0: let doc = gTestWin.content.document; michael@0: let mainDiv = doc.createElement("div"); michael@0: mainDiv.innerHTML = michael@0: '

Test 1

' + michael@0: '

Test 2

' + michael@0: '

Test 3

' + michael@0: '

Test 4

' + michael@0: '

Test 5

' + michael@0: '

Test 6

'; michael@0: doc.body.appendChild(mainDiv); michael@0: } michael@0: michael@0: function startTests() { michael@0: mainTab = gTestWin.gBrowser.selectedTab; michael@0: var childTabLink = gHttpTestRoot1 + "file_bug906190_2.html"; michael@0: setUpTest("Test1", "linkForTest1", test1, childTabLink); michael@0: } michael@0: michael@0: function test() { michael@0: // Performing async calls, e.g. 'onload', we have to wait till all of them finished michael@0: waitForExplicitFinish(); michael@0: michael@0: // Store original preferences so we can restore settings after testing michael@0: origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE); michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, true); michael@0: michael@0: gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank"); michael@0: whenDelayedStartupFinished(gTestWin, function () { michael@0: info("browser window opened"); michael@0: waitForFocus(function() { michael@0: info("browser window focused"); michael@0: waitForFocus(function() { michael@0: info("setting up browser..."); michael@0: setupTestBrowserWindow(); michael@0: info("running tests..."); michael@0: executeSoon(startTests); michael@0: }, gTestWin.content, true); michael@0: }, gTestWin); michael@0: }); michael@0: }