browser/base/content/test/general/browser_bug902156.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.

     1 /*
     2  * Description of the Tests for
     3  *  - Bug 902156: Persist "disable protection" option for Mixed Content Blocker
     4  *
     5  * 1. Navigate to the same domain via document.location
     6  *    - Load a html page which has mixed content
     7  *    - Doorhanger to disable protection appears - we disable it
     8  *    - Load a new page from the same origin using document.location
     9  *    - Doorhanger should not appear anymore!
    10  * 
    11  * 2. Navigate to the same domain via simulateclick for a link on the page
    12  *    - Load a html page which has mixed content
    13  *    - Doorhanger to disable protection appears - we disable it
    14  *    - Load a new page from the same origin simulating a click
    15  *    - Doorhanger should not appear anymore!
    16  *
    17  * 3. Navigate to a differnet domain and show the content is still blocked
    18  *    - Load a different html page which has mixed content
    19  *    - Doorhanger to disable protection should appear again because
    20  *      we navigated away from html page where we disabled the protection.
    21  *
    22  * Note, for all tests we set gHttpTestRoot to use 'https'.
    23  */
    25 const PREF_ACTIVE = "security.mixed_content.block_active_content";
    27 // We alternate for even and odd test cases to simulate different hosts
    28 const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/";
    29 const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/";
    31 var origBlockActive;
    32 var gTestBrowser = null;
    34 registerCleanupFunction(function() {
    35   // Set preferences back to their original values
    36   Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
    37 });
    39 function cleanUpAfterTests() {
    40   gBrowser.removeCurrentTab();
    41   window.focus();
    42   finish();
    43 }
    45 //------------------------ Test 1 ------------------------------
    47 function test1A() {
    48   // Removing EventListener because we have to register a new
    49   // one once the page is loaded with mixed content blocker disabled
    50   gTestBrowser.removeEventListener("load", test1A, true);
    51   gTestBrowser.addEventListener("load", test1B, true);
    53   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    54   ok(notification, "OK: Mixed Content Doorhanger appeared in Test1A!");
    56   // Disable Mixed Content Protection for the page 
    57   notification.secondaryActions[0].callback();
    58 }
    60 function test1B() {
    61   var expected = "Mixed Content Blocker disabled";
    62   waitForCondition(
    63     function() content.document.getElementById('mctestdiv').innerHTML == expected,
    64     test1C, "Error: Waited too long for mixed script to run in Test 1B");
    65 }
    67 function test1C() {
    68   gTestBrowser.removeEventListener("load", test1B, true);
    69   var actual = content.document.getElementById('mctestdiv').innerHTML;
    70   is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C");
    72   // The Script loaded after we disabled the page, now we are going to reload the
    73   // page and see if our decision is persistent
    74   gTestBrowser.addEventListener("load", test1D, true);
    76   var url = gHttpTestRoot1 + "file_bug902156_2.html";
    77   gTestBrowser.contentWindow.location = url;
    78 }
    80 function test1D() {
    81   gTestBrowser.removeEventListener("load", test1D, true);
    83   // The Doorhanger should not appear, because our decision of disabling the
    84   // mixed content blocker is persistent.
    85   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    86   ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test1D!");
    88   var actual = content.document.getElementById('mctestdiv').innerHTML;
    89   is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1D");
    91   // move on to Test 2
    92   test2();
    93 }
    95 //------------------------ Test 2 ------------------------------
    97 function test2() {
    98   gTestBrowser.addEventListener("load", test2A, true);
    99   var url = gHttpTestRoot2 + "file_bug902156_2.html";
   100   gTestBrowser.contentWindow.location = url;
   101 }
   103 function test2A() {
   104   // Removing EventListener because we have to register a new
   105   // one once the page is loaded with mixed content blocker disabled
   106   gTestBrowser.removeEventListener("load", test2A, true);
   107   gTestBrowser.addEventListener("load", test2B, true);
   109   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   110   ok(notification, "OK: Mixed Content Doorhanger appeared in Test 2A!");
   112   // Disable Mixed Content Protection for the page 
   113   notification.secondaryActions[0].callback();
   114 }
   116 function test2B() {
   117   var expected = "Mixed Content Blocker disabled";
   118   waitForCondition(
   119     function() content.document.getElementById('mctestdiv').innerHTML == expected,
   120     test2C, "Error: Waited too long for mixed script to run in Test 2B");
   121 }
   123 function test2C() {
   124   gTestBrowser.removeEventListener("load", test2B, true);
   125   var actual = content.document.getElementById('mctestdiv').innerHTML;
   126   is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2C");
   128   // The Script loaded after we disabled the page, now we are going to reload the
   129   // page and see if our decision is persistent
   130   gTestBrowser.addEventListener("load", test2D, true);
   132   // reload the page using the provided link in the html file
   133   var mctestlink = content.document.getElementById("mctestlink");
   134   mctestlink.click();
   135 }
   137 function test2D() {
   138   gTestBrowser.removeEventListener("load", test2D, true);
   140   // The Doorhanger should not appear, because our decision of disabling the
   141   // mixed content blocker is persistent.
   142   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   143   ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test2D!");
   145   var actual = content.document.getElementById('mctestdiv').innerHTML;
   146   is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2D");
   148   // move on to Test 3
   149   test3();
   150 }
   152 //------------------------ Test 3 ------------------------------
   154 function test3() {
   155   gTestBrowser.addEventListener("load", test3A, true);
   156   var url = gHttpTestRoot1 + "file_bug902156_3.html";
   157   gTestBrowser.contentWindow.location = url;
   158 }
   160 function test3A() {
   161   // Removing EventListener because we have to register a new
   162   // one once the page is loaded with mixed content blocker disabled
   163   gTestBrowser.removeEventListener("load", test3A, true);
   165   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   166   ok(notification, "OK: Mixed Content Doorhanger appeared in Test 3A!");
   168   // We are done with tests, clean up
   169   cleanUpAfterTests();
   170 }
   172 //------------------------------------------------------
   174 function test() {
   175   // Performing async calls, e.g. 'onload', we have to wait till all of them finished
   176   waitForExplicitFinish();
   178   // Store original preferences so we can restore settings after testing
   179   origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
   181   Services.prefs.setBoolPref(PREF_ACTIVE, true);
   183   // Not really sure what this is doing
   184   var newTab = gBrowser.addTab();
   185   gBrowser.selectedTab = newTab;
   186   gTestBrowser = gBrowser.selectedBrowser;
   187   newTab.linkedBrowser.stop()
   189   // Starting Test Number 1:
   190   gTestBrowser.addEventListener("load", test1A, true);
   191   var url = gHttpTestRoot1 + "file_bug902156_1.html";
   192   gTestBrowser.contentWindow.location = url;
   193 }

mercurial