browser/base/content/test/general/browser_bug902156.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_bug902156.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,193 @@
     1.4 +/*
     1.5 + * Description of the Tests for
     1.6 + *  - Bug 902156: Persist "disable protection" option for Mixed Content Blocker
     1.7 + *
     1.8 + * 1. Navigate to the same domain via document.location
     1.9 + *    - Load a html page which has mixed content
    1.10 + *    - Doorhanger to disable protection appears - we disable it
    1.11 + *    - Load a new page from the same origin using document.location
    1.12 + *    - Doorhanger should not appear anymore!
    1.13 + * 
    1.14 + * 2. Navigate to the same domain via simulateclick for a link on the page
    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 the same origin simulating a click
    1.18 + *    - Doorhanger should not appear anymore!
    1.19 + *
    1.20 + * 3. Navigate to a differnet domain and show the content is still blocked
    1.21 + *    - Load a different html page which has mixed content
    1.22 + *    - Doorhanger to disable protection should appear again because
    1.23 + *      we navigated away from html page where we disabled the protection.
    1.24 + *
    1.25 + * Note, for all tests we set gHttpTestRoot to use 'https'.
    1.26 + */
    1.27 +
    1.28 +const PREF_ACTIVE = "security.mixed_content.block_active_content";
    1.29 +
    1.30 +// We alternate for even and odd test cases to simulate different hosts
    1.31 +const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/";
    1.32 +const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/";
    1.33 +
    1.34 +var origBlockActive;
    1.35 +var gTestBrowser = null;
    1.36 +
    1.37 +registerCleanupFunction(function() {
    1.38 +  // Set preferences back to their original values
    1.39 +  Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
    1.40 +});
    1.41 +
    1.42 +function cleanUpAfterTests() {
    1.43 +  gBrowser.removeCurrentTab();
    1.44 +  window.focus();
    1.45 +  finish();
    1.46 +}
    1.47 +
    1.48 +//------------------------ Test 1 ------------------------------
    1.49 +
    1.50 +function test1A() {
    1.51 +  // Removing EventListener because we have to register a new
    1.52 +  // one once the page is loaded with mixed content blocker disabled
    1.53 +  gTestBrowser.removeEventListener("load", test1A, true);
    1.54 +  gTestBrowser.addEventListener("load", test1B, true);
    1.55 +  
    1.56 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    1.57 +  ok(notification, "OK: Mixed Content Doorhanger appeared in Test1A!");
    1.58 +
    1.59 +  // Disable Mixed Content Protection for the page 
    1.60 +  notification.secondaryActions[0].callback();
    1.61 +}
    1.62 +
    1.63 +function test1B() {
    1.64 +  var expected = "Mixed Content Blocker disabled";
    1.65 +  waitForCondition(
    1.66 +    function() content.document.getElementById('mctestdiv').innerHTML == expected,
    1.67 +    test1C, "Error: Waited too long for mixed script to run in Test 1B");
    1.68 +}
    1.69 +
    1.70 +function test1C() {
    1.71 +  gTestBrowser.removeEventListener("load", test1B, true);
    1.72 +  var actual = content.document.getElementById('mctestdiv').innerHTML;
    1.73 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C");
    1.74 +
    1.75 +  // The Script loaded after we disabled the page, now we are going to reload the
    1.76 +  // page and see if our decision is persistent
    1.77 +  gTestBrowser.addEventListener("load", test1D, true);
    1.78 +
    1.79 +  var url = gHttpTestRoot1 + "file_bug902156_2.html";
    1.80 +  gTestBrowser.contentWindow.location = url;
    1.81 +}
    1.82 +
    1.83 +function test1D() {
    1.84 +  gTestBrowser.removeEventListener("load", test1D, true);
    1.85 +
    1.86 +  // The Doorhanger should not appear, because our decision of disabling the
    1.87 +  // mixed content blocker is persistent.
    1.88 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    1.89 +  ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test1D!");
    1.90 +
    1.91 +  var actual = content.document.getElementById('mctestdiv').innerHTML;
    1.92 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1D");
    1.93 +
    1.94 +  // move on to Test 2
    1.95 +  test2();
    1.96 +}
    1.97 +
    1.98 +//------------------------ Test 2 ------------------------------
    1.99 +
   1.100 +function test2() {
   1.101 +  gTestBrowser.addEventListener("load", test2A, true);
   1.102 +  var url = gHttpTestRoot2 + "file_bug902156_2.html";
   1.103 +  gTestBrowser.contentWindow.location = url;
   1.104 +}
   1.105 +
   1.106 +function test2A() {
   1.107 +  // Removing EventListener because we have to register a new
   1.108 +  // one once the page is loaded with mixed content blocker disabled
   1.109 +  gTestBrowser.removeEventListener("load", test2A, true);
   1.110 +  gTestBrowser.addEventListener("load", test2B, true);
   1.111 +  
   1.112 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.113 +  ok(notification, "OK: Mixed Content Doorhanger appeared in Test 2A!");
   1.114 +
   1.115 +  // Disable Mixed Content Protection for the page 
   1.116 +  notification.secondaryActions[0].callback();
   1.117 +}
   1.118 +
   1.119 +function test2B() {
   1.120 +  var expected = "Mixed Content Blocker disabled";
   1.121 +  waitForCondition(
   1.122 +    function() content.document.getElementById('mctestdiv').innerHTML == expected,
   1.123 +    test2C, "Error: Waited too long for mixed script to run in Test 2B");
   1.124 +}
   1.125 +
   1.126 +function test2C() {
   1.127 +  gTestBrowser.removeEventListener("load", test2B, true);
   1.128 +  var actual = content.document.getElementById('mctestdiv').innerHTML;
   1.129 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2C");
   1.130 +
   1.131 +  // The Script loaded after we disabled the page, now we are going to reload the
   1.132 +  // page and see if our decision is persistent
   1.133 +  gTestBrowser.addEventListener("load", test2D, true);
   1.134 +
   1.135 +  // reload the page using the provided link in the html file
   1.136 +  var mctestlink = content.document.getElementById("mctestlink");
   1.137 +  mctestlink.click();
   1.138 +}
   1.139 +
   1.140 +function test2D() {
   1.141 +  gTestBrowser.removeEventListener("load", test2D, true);
   1.142 +
   1.143 +  // The Doorhanger should not appear, because our decision of disabling the
   1.144 +  // mixed content blocker is persistent.
   1.145 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.146 +  ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test2D!");
   1.147 +
   1.148 +  var actual = content.document.getElementById('mctestdiv').innerHTML;
   1.149 +  is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2D");
   1.150 +
   1.151 +  // move on to Test 3
   1.152 +  test3();
   1.153 +}
   1.154 +
   1.155 +//------------------------ Test 3 ------------------------------
   1.156 +
   1.157 +function test3() {
   1.158 +  gTestBrowser.addEventListener("load", test3A, true);
   1.159 +  var url = gHttpTestRoot1 + "file_bug902156_3.html";
   1.160 +  gTestBrowser.contentWindow.location = url;
   1.161 +}
   1.162 +
   1.163 +function test3A() {
   1.164 +  // Removing EventListener because we have to register a new
   1.165 +  // one once the page is loaded with mixed content blocker disabled
   1.166 +  gTestBrowser.removeEventListener("load", test3A, true);
   1.167 +  
   1.168 +  var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   1.169 +  ok(notification, "OK: Mixed Content Doorhanger appeared in Test 3A!");
   1.170 +
   1.171 +  // We are done with tests, clean up
   1.172 +  cleanUpAfterTests();
   1.173 +}
   1.174 +
   1.175 +//------------------------------------------------------
   1.176 +
   1.177 +function test() {
   1.178 +  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
   1.179 +  waitForExplicitFinish();
   1.180 +
   1.181 +  // Store original preferences so we can restore settings after testing
   1.182 +  origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
   1.183 +
   1.184 +  Services.prefs.setBoolPref(PREF_ACTIVE, true);
   1.185 +
   1.186 +  // Not really sure what this is doing
   1.187 +  var newTab = gBrowser.addTab();
   1.188 +  gBrowser.selectedTab = newTab;
   1.189 +  gTestBrowser = gBrowser.selectedBrowser;
   1.190 +  newTab.linkedBrowser.stop()
   1.191 +
   1.192 +  // Starting Test Number 1:
   1.193 +  gTestBrowser.addEventListener("load", test1A, true);
   1.194 +  var url = gHttpTestRoot1 + "file_bug902156_1.html";
   1.195 +  gTestBrowser.contentWindow.location = url;
   1.196 +}

mercurial