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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug906190.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,572 @@
     1.4 +/*
     1.5 + * Description of the Tests for
     1.6 + *  - Bug 906190 - Persist "disable protection" option for Mixed Content Blocker in child tabs
     1.7 + *
     1.8 + * 1. Open a page from the same domain in a child tab
     1.9 + *    - Load a html page which has mixed content
    1.10 + *    - Doorhanger to disable protection appears - we disable it
    1.11 + *    - Load a subpage from the same origin in a new tab simulating a click
    1.12 + *    - Doorhanger should >> NOT << appear anymore!
    1.13 + *
    1.14 + * 2. Open a page from a different domain in a child tab
    1.15 + *    - Load a html page which has mixed content
    1.16 + *    - Doorhanger to disable protection appears - we disable it
    1.17 + *    - Load a new page from a different origin in a new tab simulating a click
    1.18 + *    - Doorhanger >> SHOULD << appear again!
    1.19 + *
    1.20 + * 3. [meta-refresh: same origin] Open a page from the same domain in a child tab
    1.21 + *    - Load a html page which has mixed content
    1.22 + *    - Doorhanger to disable protection appears - we disable it
    1.23 + *    - Load a new page from the same origin in a new tab simulating a click
    1.24 + *    - Redirect that page to another page from the same origin using meta-refresh
    1.25 + *    - Doorhanger should >> NOT << appear again!
    1.26 + *
    1.27 + * 4. [meta-refresh: different origin] Open a page from a different domain in a child tab
    1.28 + *    - Load a html page which has mixed content
    1.29 + *    - Doorhanger to disable protection appears - we disable it
    1.30 + *    - Load a new page from the same origin in a new tab simulating a click
    1.31 + *    - Redirect that page to another page from a different origin using meta-refresh
    1.32 + *    - Doorhanger >> SHOULD << appear again!
    1.33 + *
    1.34 + * 5. [302 redirect: same origin] Open a page from the same domain in a child tab
    1.35 + *    - Load a html page which has mixed content
    1.36 + *    - Doorhanger to disable protection appears - we disable it
    1.37 + *    - Load a new page from the same origin in a new tab simulating a click
    1.38 + *    - Redirect that page to another page from the same origin using 302 redirect
    1.39 + *    - Doorhanger >> APPEARS << , but should >> NOT << appear again!
    1.40 + *    - FOLLOW UP BUG 914860!
    1.41 + *
    1.42 + * 6. [302 redirect: different origin] Open a page from the same domain in a child tab
    1.43 + *    - Load a html page which has mixed content
    1.44 + *    - Doorhanger to disable protection appears - we disable it
    1.45 + *    - Load a new page from the same origin in a new tab simulating a click
    1.46 + *    - Redirect that page to another page from a different origin using 302 redirect
    1.47 + *    - Doorhanger >> SHOULD << appear again!
    1.48 + *
    1.49 + * Note, for all tests we set gHttpTestRoot to use 'https' and we test both,
    1.50 + *   - |CTRL-CLICK|, as well as
    1.51 + *   - |RIGHT-CLICK->OPEN LINK IN TAB|.
    1.52 + */
    1.53 +
    1.54 +const PREF_ACTIVE = "security.mixed_content.block_active_content";
    1.55 +
    1.56 +// We use the different urls for testing same origin checks before allowing
    1.57 +// mixed content on child tabs.
    1.58 +const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/";
    1.59 +const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/";
    1.60 +
    1.61 +let origBlockActive;
    1.62 +let gTestWin = null;
    1.63 +let mainTab = null;
    1.64 +let curClickHandler = null;
    1.65 +let curContextMenu = null;
    1.66 +let curTestFunc = null;
    1.67 +let curTestName = null;
    1.68 +let curChildTabLink = null;
    1.69 +
    1.70 +//------------------------ Helper Functions ---------------------
    1.71 +
    1.72 +registerCleanupFunction(function() {
    1.73 +  // Set preferences back to their original values
    1.74 +  Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
    1.75 +});
    1.76 +
    1.77 +/*
    1.78 + * Whenever we disable the Mixed Content Blocker of the page
    1.79 + * we have to make sure that our condition is properly loaded.
    1.80 + */
    1.81 +function waitForCondition(condition, nextTest, errorMsg) {
    1.82 +  var tries = 0;
    1.83 +  var interval = setInterval(function() {
    1.84 +    if (tries >= 30) {
    1.85 +      ok(false, errorMsg);
    1.86 +      moveOn();
    1.87 +    }
    1.88 +    if (condition()) {
    1.89 +      moveOn();
    1.90 +    }
    1.91 +    tries++;
    1.92 +  }, 100);
    1.93 +  var moveOn = function() {
    1.94 +    clearInterval(interval); nextTest();
    1.95 +  };
    1.96 +}
    1.97 +
    1.98 +// The purpose of this function is to simulate |CTRL+CLICK|.
    1.99 +// The clickHandler intercepts simulated user clicks and performs
   1.100 +// the |contentAreaClick| which dispatches to handleLinkClick.
   1.101 +let clickHandler = function (aEvent, aFunc) {
   1.102 +  gTestWin.gBrowser.removeEventListener("click", curClickHandler, true);
   1.103 +  gTestWin.contentAreaClick(aEvent, true);
   1.104 +  gTestWin.gBrowser.addEventListener("load", aFunc, true);
   1.105 +  aEvent.preventDefault();
   1.106 +  aEvent.stopPropagation();
   1.107 +}
   1.108 +
   1.109 +// The purpose of this function is to simulate |RIGHT-CLICK|->|OPEN LINK IN TAB|
   1.110 +// Once the contextmenu opens, this functions selects 'open link in tab'
   1.111 +// from the contextmenu which dispatches to the function openLinkInTab.
   1.112 +let contextMenuOpenHandler = function(aEvent, aFunc) {
   1.113 +  gTestWin.document.removeEventListener("popupshown", curContextMenu, false);
   1.114 +  gTestWin.gBrowser.addEventListener("load", aFunc, true);
   1.115 +  var openLinkInTabCommand = gTestWin.document.getElementById("context-openlinkintab");
   1.116 +  openLinkInTabCommand.doCommand();
   1.117 +  aEvent.target.hidePopup();
   1.118 +};
   1.119 +
   1.120 +function setUpTest(aTestName, aIDForNextTest, aFuncForNextTest, aChildTabLink) {
   1.121 +  curTestName = aTestName;
   1.122 +  curTestFunc = aFuncForNextTest;
   1.123 +  curChildTabLink = aChildTabLink;
   1.124 +
   1.125 +  mainTab = gTestWin.gBrowser.selectedTab;
   1.126 +  // get the link for the next test from the main page
   1.127 +  let target = gTestWin.content.document.getElementById(aIDForNextTest);
   1.128 +  gTestWin.gBrowser.addTab(target);
   1.129 +  gTestWin.gBrowser.selectTabAtIndex(1);
   1.130 +  gTestWin.gBrowser.addEventListener("load", checkPopUpNotification, true);
   1.131 +}
   1.132 +
   1.133 +function checkPopUpNotification() {
   1.134 +  gTestWin.gBrowser.removeEventListener("load", checkPopUpNotification, true);
   1.135 +  gTestWin.gBrowser.addEventListener("load", reloadedTabAfterDisablingMCB, true);
   1.136 +
   1.137 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.138 +  ok(notification, "OK: Mixed Content Doorhanger appeared in " + curTestName + "!");
   1.139 +
   1.140 +  // Disable Mixed Content Protection for the page
   1.141 +  notification.secondaryActions[0].callback();
   1.142 +}
   1.143 +
   1.144 +function reloadedTabAfterDisablingMCB() {
   1.145 +  gTestWin.gBrowser.removeEventListener("load", reloadedTabAfterDisablingMCB, true);
   1.146 +
   1.147 +  var expected = "Mixed Content Blocker disabled";
   1.148 +  waitForCondition(
   1.149 +    function() gTestWin.content.document.getElementById('mctestdiv').innerHTML == expected,
   1.150 +    makeSureMCBisDisabled, "Error: Waited too long for mixed script to run in " + curTestName + "!");
   1.151 +}
   1.152 +
   1.153 +function makeSureMCBisDisabled() {
   1.154 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.155 +  is(actual, "Mixed Content Blocker disabled", "OK: Made sure MCB is disabled in " + curTestName + "!");
   1.156 +
   1.157 +  // inject the provided link into the page, so we can test persistence of MCB
   1.158 +  let doc = gTestWin.content.document;
   1.159 +  let mainDiv = gTestWin.content.document.createElement("div");
   1.160 +  mainDiv.innerHTML =
   1.161 +    '<p><a id="' + curTestName + '" href="' + curChildTabLink + '">' +
   1.162 +    curTestName + '</a></p>';
   1.163 +  doc.body.appendChild(mainDiv);
   1.164 +
   1.165 +  curTestFunc();
   1.166 +}
   1.167 +
   1.168 +//------------------------ Test 1 ------------------------------
   1.169 +
   1.170 +function test1() {
   1.171 +  curClickHandler = function (e) { clickHandler(e, test1A) };
   1.172 +  gTestWin.gBrowser.addEventListener("click", curClickHandler , true);
   1.173 +
   1.174 +  // simulating |CTRL-CLICK|
   1.175 +  let targetElt = gTestWin.content.document.getElementById("Test1");
   1.176 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.177 +}
   1.178 +
   1.179 +function test1A() {
   1.180 +  gTestWin.gBrowser.removeEventListener("load", test1A, true);
   1.181 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.182 +
   1.183 +  // The Doorhanger should >> NOT << appear, because our decision of disabling the
   1.184 +  // mixed content blocker is persistent across tabs.
   1.185 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.186 +  ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1A!");
   1.187 +
   1.188 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.189 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1A");
   1.190 +
   1.191 +  gTestWin.gBrowser.removeCurrentTab();
   1.192 +  test1B();
   1.193 +}
   1.194 +
   1.195 +function test1B() {
   1.196 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test1C) };
   1.197 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.198 +
   1.199 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.200 +  let targetElt = gTestWin.content.document.getElementById("Test1");
   1.201 +  // button 2 is a right click, hence the context menu pops up
   1.202 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.203 +}
   1.204 +
   1.205 +function test1C() {
   1.206 +  gTestWin.gBrowser.removeEventListener("load", test1C, true);
   1.207 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.208 +
   1.209 +  // The Doorhanger should >> NOT << appear, because our decision of disabling the
   1.210 +  // mixed content blocker is persistent across tabs.
   1.211 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.212 +  ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 1C!");
   1.213 +
   1.214 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.215 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C");
   1.216 +
   1.217 +  // remove tabs
   1.218 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
   1.219 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
   1.220 +  gTestWin.gBrowser.selectTabAtIndex(0);
   1.221 +
   1.222 +  var childTabLink = gHttpTestRoot2 + "file_bug906190_2.html";
   1.223 +  setUpTest("Test2", "linkForTest2", test2, childTabLink);
   1.224 +}
   1.225 +
   1.226 +//------------------------ Test 2 ------------------------------
   1.227 +
   1.228 +function test2() {
   1.229 +  curClickHandler = function (e) { clickHandler(e, test2A) };
   1.230 +  gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
   1.231 +
   1.232 +  // simulating |CTRL-CLICK|
   1.233 +  let targetElt = gTestWin.content.document.getElementById("Test2");
   1.234 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.235 +}
   1.236 +
   1.237 +function test2A() {
   1.238 +  gTestWin.gBrowser.removeEventListener("load", test2A, true);
   1.239 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.240 +
   1.241 +  // The Doorhanger >> SHOULD << appear, because our decision of disabling the
   1.242 +  // mixed content blocker should only persist if pages are from the same domain.
   1.243 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.244 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2A!");
   1.245 +
   1.246 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.247 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2A");
   1.248 +
   1.249 +  gTestWin.gBrowser.removeCurrentTab();
   1.250 +  test2B();
   1.251 +}
   1.252 +
   1.253 +function test2B() {
   1.254 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test2C) };
   1.255 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.256 +
   1.257 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.258 +  let targetElt = gTestWin.content.document.getElementById("Test2");
   1.259 +  // button 2 is a right click, hence the context menu pops up
   1.260 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.261 +}
   1.262 +
   1.263 +function test2C() {
   1.264 +  gTestWin.gBrowser.removeEventListener("load", test2C, true);
   1.265 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.266 +
   1.267 +  // The Doorhanger >> SHOULD << appear, because our decision of disabling the
   1.268 +  // mixed content blocker should only persist if pages are from the same domain.
   1.269 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.270 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 2C!");
   1.271 +
   1.272 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.273 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 2C");
   1.274 +
   1.275 +  // remove tabs
   1.276 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
   1.277 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
   1.278 +  gTestWin.gBrowser.selectTabAtIndex(0);
   1.279 +
   1.280 +  // file_bug906190_3_4.html redirects to page test1.example.com/* using meta-refresh
   1.281 +  var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html";
   1.282 +  setUpTest("Test3", "linkForTest3", test3, childTabLink);
   1.283 +}
   1.284 +
   1.285 +//------------------------ Test 3 ------------------------------
   1.286 +
   1.287 +function test3() {
   1.288 +  curClickHandler = function (e) { clickHandler(e, test3A) };
   1.289 +  gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
   1.290 +  // simulating |CTRL-CLICK|
   1.291 +  let targetElt = gTestWin.content.document.getElementById("Test3");
   1.292 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.293 +}
   1.294 +
   1.295 +function test3A() {
   1.296 +  // we need this indirection because the page is reloaded caused by meta-refresh
   1.297 +  gTestWin.gBrowser.removeEventListener("load", test3A, true);
   1.298 +  gTestWin.gBrowser.addEventListener("load", test3B, true);
   1.299 +}
   1.300 +
   1.301 +function test3B() {
   1.302 +  gTestWin.gBrowser.removeEventListener("load", test3B, true);
   1.303 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.304 +
   1.305 +  // The Doorhanger should >> NOT << appear!
   1.306 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.307 +  ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3B!");
   1.308 +
   1.309 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.310 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3B");
   1.311 +
   1.312 +  // remove tabs
   1.313 +  gTestWin.gBrowser.removeCurrentTab();
   1.314 +  test3C();
   1.315 +}
   1.316 +
   1.317 +function test3C() {
   1.318 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test3D) };
   1.319 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.320 +
   1.321 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.322 +  let targetElt = gTestWin.content.document.getElementById("Test3");
   1.323 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.324 +}
   1.325 +
   1.326 +function test3D() {
   1.327 +  // we need this indirection because the page is reloaded caused by meta-refresh
   1.328 +  gTestWin.gBrowser.removeEventListener("load", test3D, true);
   1.329 +  gTestWin.gBrowser.addEventListener("load", test3E, true);
   1.330 +}
   1.331 +
   1.332 +function test3E() {
   1.333 +  gTestWin.gBrowser.removeEventListener("load", test3E, true);
   1.334 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.335 +
   1.336 +  // The Doorhanger should >> NOT << appear!
   1.337 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.338 +  ok(!notification, "OK: Mixed Content Doorhanger did appear again in Test 3E!");
   1.339 +
   1.340 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.341 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 3E");
   1.342 +
   1.343 +  // remove tabs
   1.344 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
   1.345 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
   1.346 +  gTestWin.gBrowser.selectTabAtIndex(0);
   1.347 +
   1.348 +  var childTabLink = gHttpTestRoot1 + "file_bug906190_3_4.html";
   1.349 +  setUpTest("Test4", "linkForTest4", test4, childTabLink);
   1.350 +}
   1.351 +
   1.352 +//------------------------ Test 4 ------------------------------
   1.353 +
   1.354 +function test4() {
   1.355 +  curClickHandler = function (e) { clickHandler(e, test4A) };
   1.356 +  gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
   1.357 +
   1.358 +  // simulating |CTRL-CLICK|
   1.359 +  let targetElt = gTestWin.content.document.getElementById("Test4");
   1.360 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.361 +}
   1.362 +
   1.363 +function test4A() {
   1.364 +  // we need this indirection because the page is reloaded caused by meta-refresh
   1.365 +  gTestWin.gBrowser.removeEventListener("load", test4A, true);
   1.366 +  gTestWin.gBrowser.addEventListener("load", test4B, true);
   1.367 +}
   1.368 +
   1.369 +function test4B() {
   1.370 +  gTestWin.gBrowser.removeEventListener("load", test4B, true);
   1.371 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.372 +
   1.373 +  // The Doorhanger >> SHOULD << appear!
   1.374 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.375 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4B!");
   1.376 +
   1.377 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.378 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4B");
   1.379 +
   1.380 +  // remove tabs
   1.381 +  gTestWin.gBrowser.removeCurrentTab();
   1.382 +  test4C();
   1.383 +}
   1.384 +
   1.385 +function test4C() {
   1.386 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test4D) };
   1.387 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.388 +
   1.389 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.390 +  let targetElt = gTestWin.content.document.getElementById("Test4");
   1.391 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.392 +}
   1.393 +
   1.394 +function test4D() {
   1.395 +  // we need this indirection because the page is reloaded caused by meta-refresh
   1.396 +  gTestWin.gBrowser.removeEventListener("load", test4D, true);
   1.397 +  gTestWin.gBrowser.addEventListener("load", test4E, true);
   1.398 +}
   1.399 +
   1.400 +function test4E() {
   1.401 +  gTestWin.gBrowser.removeEventListener("load", test4E, true);
   1.402 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.403 +
   1.404 +  // The Doorhanger >> SHOULD << appear!
   1.405 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.406 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 4E!");
   1.407 +
   1.408 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.409 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 4E");
   1.410 +
   1.411 +  // remove tabs
   1.412 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
   1.413 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
   1.414 +  gTestWin.gBrowser.selectTabAtIndex(0);
   1.415 +
   1.416 +  // the sjs files returns a 302 redirect- note, same origins
   1.417 +  var childTabLink = gHttpTestRoot1 + "file_bug906190.sjs";
   1.418 +  setUpTest("Test5", "linkForTest5", test5, childTabLink);
   1.419 +}
   1.420 +
   1.421 +//------------------------ Test 5 ------------------------------
   1.422 +
   1.423 +function test5() {
   1.424 +  curClickHandler = function (e) { clickHandler(e, test5A) };
   1.425 +  gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
   1.426 +
   1.427 +  // simulating |CTRL-CLICK|
   1.428 +  let targetElt = gTestWin.content.document.getElementById("Test5");
   1.429 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.430 +}
   1.431 +
   1.432 +function test5A() {
   1.433 +  gTestWin.gBrowser.removeEventListener("load", test5A, true);
   1.434 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.435 +
   1.436 +  // The Doorhanger should >> NOT << appear
   1.437 +  // Currently it >> APPEARS << - see follow up bug 914860
   1.438 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.439 +  todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5A!");
   1.440 +
   1.441 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.442 +  todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5A!");
   1.443 +
   1.444 +  // remove tabs
   1.445 +  gTestWin.gBrowser.removeCurrentTab();
   1.446 +  test5B();
   1.447 +}
   1.448 +
   1.449 +function test5B() {
   1.450 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test5C) };
   1.451 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.452 +
   1.453 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.454 +  let targetElt = gTestWin.content.document.getElementById("Test5");
   1.455 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.456 +}
   1.457 +
   1.458 +function test5C() {
   1.459 +  gTestWin.gBrowser.removeEventListener("load", test5C, true);
   1.460 +  // move the tab again
   1.461 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.462 +
   1.463 +  // The Doorhanger should >> NOT << appear
   1.464 +  // Currently it >> APPEARS << - see follow up bug 914860
   1.465 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.466 +  todo(!notification, "OK: Mixed Content Doorhanger did not appear again in Test 5C!");
   1.467 +
   1.468 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.469 +  todo_is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 5C!");
   1.470 +
   1.471 +  // remove tabs
   1.472 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[2], {animate: false});
   1.473 +  gTestWin.gBrowser.removeTab(gTestWin.gBrowser.tabs[1], {animate: false});
   1.474 +  gTestWin.gBrowser.selectTabAtIndex(0);
   1.475 +
   1.476 +  // the sjs files returns a 302 redirect - note, different origins
   1.477 +  var childTabLink = gHttpTestRoot2 + "file_bug906190.sjs";
   1.478 +  setUpTest("Test6", "linkForTest6", test6, childTabLink);
   1.479 +}
   1.480 +
   1.481 +//------------------------ Test 6 ------------------------------
   1.482 +
   1.483 +function test6() {
   1.484 +  curClickHandler = function (e) { clickHandler(e, test6A) };
   1.485 +  gTestWin.gBrowser.addEventListener("click", curClickHandler, true);
   1.486 +
   1.487 +  // simulating |CTRL-CLICK|
   1.488 +  let targetElt = gTestWin.content.document.getElementById("Test6");
   1.489 +  EventUtils.synthesizeMouseAtCenter(targetElt, { button: 1 }, gTestWin.content);
   1.490 +}
   1.491 +
   1.492 +function test6A() {
   1.493 +  gTestWin.gBrowser.removeEventListener("load", test6A, true);
   1.494 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.495 +
   1.496 +  // The Doorhanger >> SHOULD << appear!
   1.497 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.498 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6A!");
   1.499 +
   1.500 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.501 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6A");
   1.502 +
   1.503 +  // done
   1.504 +  gTestWin.gBrowser.removeCurrentTab();
   1.505 +  test6B();
   1.506 +}
   1.507 +
   1.508 +function test6B() {
   1.509 +  curContextMenu = function (e) { contextMenuOpenHandler(e, test6C) };
   1.510 +  gTestWin.document.addEventListener("popupshown", curContextMenu, false);
   1.511 +
   1.512 +  // simulating |RIGHT-CLICK -> OPEN LINK IN TAB|
   1.513 +  let targetElt = gTestWin.content.document.getElementById("Test6");
   1.514 +  EventUtils.synthesizeMouseAtCenter(targetElt, { type : "contextmenu", button : 2 } , gTestWin.content);
   1.515 +}
   1.516 +
   1.517 +function test6C() {
   1.518 +  gTestWin.gBrowser.removeEventListener("load", test6C, true);
   1.519 +  gTestWin.gBrowser.selectTabAtIndex(2);
   1.520 +
   1.521 +  // The Doorhanger >> SHOULD << appear!
   1.522 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestWin.gBrowser.selectedBrowser);
   1.523 +  ok(notification, "OK: Mixed Content Doorhanger did appear again in Test 6C!");
   1.524 +
   1.525 +  var actual = gTestWin.content.document.getElementById('mctestdiv').innerHTML;
   1.526 +  is(actual, "Mixed Content Blocker enabled", "OK: Blocked mixed script in Test 6C");
   1.527 +
   1.528 +  gTestWin.close();
   1.529 +  finish();
   1.530 +}
   1.531 +
   1.532 +//------------------------ SETUP ------------------------------
   1.533 +
   1.534 +function setupTestBrowserWindow() {
   1.535 +  // Inject links in content.
   1.536 +  let doc = gTestWin.content.document;
   1.537 +  let mainDiv = doc.createElement("div");
   1.538 +  mainDiv.innerHTML =
   1.539 +    '<p><a id="linkForTest1" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 1</a></p>' +
   1.540 +    '<p><a id="linkForTest2" href="'+ gHttpTestRoot1 + 'file_bug906190_2.html">Test 2</a></p>' +
   1.541 +    '<p><a id="linkForTest3" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 3</a></p>' +
   1.542 +    '<p><a id="linkForTest4" href="'+ gHttpTestRoot2 + 'file_bug906190_1.html">Test 4</a></p>' +
   1.543 +    '<p><a id="linkForTest5" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 5</a></p>' +
   1.544 +    '<p><a id="linkForTest6" href="'+ gHttpTestRoot1 + 'file_bug906190_1.html">Test 6</a></p>';
   1.545 +  doc.body.appendChild(mainDiv);
   1.546 +}
   1.547 +
   1.548 +function startTests() {
   1.549 +  mainTab = gTestWin.gBrowser.selectedTab;
   1.550 +  var childTabLink = gHttpTestRoot1 + "file_bug906190_2.html";
   1.551 +  setUpTest("Test1", "linkForTest1", test1, childTabLink);
   1.552 +}
   1.553 +
   1.554 +function test() {
   1.555 +  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
   1.556 +  waitForExplicitFinish();
   1.557 +
   1.558 +  // Store original preferences so we can restore settings after testing
   1.559 +  origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
   1.560 +  Services.prefs.setBoolPref(PREF_ACTIVE, true);
   1.561 +
   1.562 +  gTestWin = openDialog(location, "", "chrome,all,dialog=no", "about:blank");
   1.563 +  whenDelayedStartupFinished(gTestWin, function () {
   1.564 +    info("browser window opened");
   1.565 +    waitForFocus(function() {
   1.566 +      info("browser window focused");
   1.567 +      waitForFocus(function() {
   1.568 +        info("setting up browser...");
   1.569 +        setupTestBrowserWindow();
   1.570 +        info("running tests...");
   1.571 +        executeSoon(startTests);
   1.572 +      }, gTestWin.content, true);
   1.573 +    }, gTestWin);
   1.574 +  });
   1.575 +}

mercurial