browser/base/content/test/general/browser_bug822367.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_bug822367.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     1.4 +/*
     1.5 + * User Override Mixed Content Block - Tests for Bug 822367
     1.6 + */
     1.7 +
     1.8 +
     1.9 +const PREF_DISPLAY = "security.mixed_content.block_display_content";
    1.10 +const PREF_ACTIVE = "security.mixed_content.block_active_content";
    1.11 +
    1.12 +// We alternate for even and odd test cases to simulate different hosts
    1.13 +const gHttpTestRoot = "https://example.com/browser/browser/base/content/test/general/";
    1.14 +const gHttpTestRoot2 = "https://test1.example.com/browser/browser/base/content/test/general/";
    1.15 +
    1.16 +var origBlockDisplay;
    1.17 +var origBlockActive;
    1.18 +var gTestBrowser = null;
    1.19 +
    1.20 +registerCleanupFunction(function() {
    1.21 +  // Set preferences back to their original values
    1.22 +  Services.prefs.setBoolPref(PREF_DISPLAY, origBlockDisplay);
    1.23 +  Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
    1.24 +});
    1.25 +
    1.26 +function MixedTestsCompleted() {
    1.27 +  gBrowser.removeCurrentTab();
    1.28 +  window.focus();
    1.29 +  finish();
    1.30 +}
    1.31 +
    1.32 +function test() {
    1.33 +  waitForExplicitFinish();
    1.34 +
    1.35 +  origBlockDisplay = Services.prefs.getBoolPref(PREF_DISPLAY);
    1.36 +  origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
    1.37 +
    1.38 +  Services.prefs.setBoolPref(PREF_DISPLAY, true);
    1.39 +  Services.prefs.setBoolPref(PREF_ACTIVE, true);
    1.40 +
    1.41 +  var newTab = gBrowser.addTab();
    1.42 +  gBrowser.selectedTab = newTab;
    1.43 +  gTestBrowser = gBrowser.selectedBrowser;
    1.44 +  newTab.linkedBrowser.stop()
    1.45 +
    1.46 +  // Mixed Script Test
    1.47 +  gTestBrowser.addEventListener("load", MixedTest1A, true);
    1.48 +  var url = gHttpTestRoot + "file_bug822367_1.html";
    1.49 +  gTestBrowser.contentWindow.location = url;
    1.50 +}
    1.51 +
    1.52 +// Mixed Script Test
    1.53 +function MixedTest1A() {
    1.54 +  gTestBrowser.removeEventListener("load", MixedTest1A, true);
    1.55 +  gTestBrowser.addEventListener("load", MixedTest1B, true);
    1.56 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    1.57 +  ok(notification, "Mixed Content Doorhanger didn't appear");
    1.58 +  notification.secondaryActions[0].callback();
    1.59 +}
    1.60 +function MixedTest1B() {
    1.61 +  waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest1C, "Waited too long for mixed script to run in Test 1");
    1.62 +}
    1.63 +function MixedTest1C() {
    1.64 +  ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 1");
    1.65 +  gTestBrowser.removeEventListener("load", MixedTest1B, true);
    1.66 +  MixedTest2();
    1.67 +}
    1.68 +
    1.69 +//Mixed Display Test - Doorhanger should not appear
    1.70 +function MixedTest2() {
    1.71 +  gTestBrowser.addEventListener("load", MixedTest2A, true);
    1.72 +  var url = gHttpTestRoot2 + "file_bug822367_2.html";
    1.73 +  gTestBrowser.contentWindow.location = url;
    1.74 +}
    1.75 +
    1.76 +function MixedTest2A() {
    1.77 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    1.78 +  ok(!notification, "Mixed Content Doorhanger appears for mixed display content!");
    1.79 +  MixedTest3();
    1.80 +}
    1.81 +
    1.82 +// Mixed Script and Display Test - User Override should cause both the script and the image to load.
    1.83 +function MixedTest3() {
    1.84 +  gTestBrowser.removeEventListener("load", MixedTest2A, true);
    1.85 +  gTestBrowser.addEventListener("load", MixedTest3A, true);
    1.86 +  var url = gHttpTestRoot + "file_bug822367_3.html";
    1.87 +  gTestBrowser.contentWindow.location = url;
    1.88 +}
    1.89 +function MixedTest3A() {
    1.90 +  gTestBrowser.removeEventListener("load", MixedTest3A, true);
    1.91 +  gTestBrowser.addEventListener("load", MixedTest3B, true);
    1.92 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    1.93 +  ok(notification, "Mixed Content Doorhanger doesn't appear for test 3");
    1.94 +  notification.secondaryActions[0].callback();
    1.95 +}
    1.96 +function MixedTest3B() {
    1.97 +  waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest3C, "Waited too long for mixed script to run in Test 3");
    1.98 +}
    1.99 +function MixedTest3C() {
   1.100 +  waitForCondition(function() content.document.getElementById('p2').innerHTML == "bye", MixedTest3D, "Waited too long for mixed image to load in Test 3");
   1.101 +}
   1.102 +function MixedTest3D() {
   1.103 +  ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 3");
   1.104 +  ok(content.document.getElementById('p2').innerHTML == "bye","Mixed image didn't load in Test 3");
   1.105 +  MixedTest4();
   1.106 +}
   1.107 +
   1.108 +// Location change - User override on one page doesn't propogate to another page after location change.
   1.109 +function MixedTest4() {
   1.110 +  gTestBrowser.removeEventListener("load", MixedTest3B, true);
   1.111 +  gTestBrowser.addEventListener("load", MixedTest4A, true);
   1.112 +  var url = gHttpTestRoot2 + "file_bug822367_4.html";
   1.113 +  gTestBrowser.contentWindow.location = url;
   1.114 +}
   1.115 +function MixedTest4A() {
   1.116 +  gTestBrowser.removeEventListener("load", MixedTest4A, true);
   1.117 +  gTestBrowser.addEventListener("load", MixedTest4B, true);
   1.118 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.119 +  ok(notification, "Mixed Content Doorhanger doesn't appear for Test 4");
   1.120 +  notification.secondaryActions[0].callback();
   1.121 +}
   1.122 +function MixedTest4B() {
   1.123 +  waitForCondition(function() content.document.location == gHttpTestRoot + "file_bug822367_4B.html", MixedTest4C, "Waited too long for mixed script to run in Test 4");
   1.124 +}
   1.125 +function MixedTest4C() {
   1.126 +  ok(content.document.location == gHttpTestRoot + "file_bug822367_4B.html", "Location didn't change in test 4");
   1.127 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.128 +  ok(notification, "Mixed Content Doorhanger doesn't appear after location change in Test 4");
   1.129 +  waitForCondition(function() content.document.getElementById('p1').innerHTML == "", MixedTest4D, "Mixed script loaded in test 4 after location change!");
   1.130 +}
   1.131 +function MixedTest4D() {
   1.132 +  ok(content.document.getElementById('p1').innerHTML == "","p1.innerHTML changed; mixed script loaded after location change in Test 4");
   1.133 +  MixedTest5();
   1.134 +}
   1.135 +
   1.136 +// Mixed script attempts to load in a document.open()
   1.137 +function MixedTest5() {
   1.138 +  gTestBrowser.removeEventListener("load", MixedTest4B, true);
   1.139 +  gTestBrowser.addEventListener("load", MixedTest5A, true);
   1.140 +  var url = gHttpTestRoot + "file_bug822367_5.html";
   1.141 +  gTestBrowser.contentWindow.location = url;
   1.142 +}
   1.143 +function MixedTest5A() {
   1.144 +  gTestBrowser.removeEventListener("load", MixedTest5A, true);
   1.145 +  gTestBrowser.addEventListener("load", MixedTest5B, true);
   1.146 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.147 +  ok(notification, "Mixed Content Doorhanger doesn't appear for Test 5");
   1.148 +  notification.secondaryActions[0].callback();
   1.149 +}
   1.150 +function MixedTest5B() {
   1.151 +  waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest5C, "Waited too long for mixed script to run in Test 5");
   1.152 +}
   1.153 +function MixedTest5C() {
   1.154 +  ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 5");
   1.155 +  MixedTest6();
   1.156 +}
   1.157 +
   1.158 +// Mixed script attempts to load in a document.open() that is within an iframe.
   1.159 +function MixedTest6() {
   1.160 +  gTestBrowser.removeEventListener("load", MixedTest5B, true);
   1.161 +  gTestBrowser.addEventListener("load", MixedTest6A, true);
   1.162 +  var url = gHttpTestRoot2 + "file_bug822367_6.html";
   1.163 +  gTestBrowser.contentWindow.location = url;
   1.164 +}
   1.165 +function MixedTest6A() {
   1.166 +  gTestBrowser.removeEventListener("load", MixedTest6A, true);
   1.167 +  waitForCondition(function() PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser), MixedTest6B, "waited to long for doorhanger");
   1.168 +}
   1.169 +
   1.170 +function MixedTest6B() {
   1.171 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.172 +  ok(notification, "Mixed Content Doorhanger doesn't appear for Test 6");
   1.173 +  gTestBrowser.addEventListener("load", MixedTest6C, true);
   1.174 +  notification.secondaryActions[0].callback();
   1.175 +}
   1.176 +
   1.177 +function MixedTest6C() {
   1.178 +  gTestBrowser.removeEventListener("load", MixedTest6C, true);
   1.179 +  waitForCondition(function() content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello", MixedTest6D, "Waited too long for mixed script to run in Test 6");
   1.180 +}
   1.181 +function MixedTest6D() {
   1.182 +  ok(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 6");
   1.183 +  MixedTestsCompleted();
   1.184 +}

mercurial