browser/base/content/test/general/browser_bug822367.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  * User Override Mixed Content Block - Tests for Bug 822367
     3  */
     6 const PREF_DISPLAY = "security.mixed_content.block_display_content";
     7 const PREF_ACTIVE = "security.mixed_content.block_active_content";
     9 // We alternate for even and odd test cases to simulate different hosts
    10 const gHttpTestRoot = "https://example.com/browser/browser/base/content/test/general/";
    11 const gHttpTestRoot2 = "https://test1.example.com/browser/browser/base/content/test/general/";
    13 var origBlockDisplay;
    14 var origBlockActive;
    15 var gTestBrowser = null;
    17 registerCleanupFunction(function() {
    18   // Set preferences back to their original values
    19   Services.prefs.setBoolPref(PREF_DISPLAY, origBlockDisplay);
    20   Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
    21 });
    23 function MixedTestsCompleted() {
    24   gBrowser.removeCurrentTab();
    25   window.focus();
    26   finish();
    27 }
    29 function test() {
    30   waitForExplicitFinish();
    32   origBlockDisplay = Services.prefs.getBoolPref(PREF_DISPLAY);
    33   origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
    35   Services.prefs.setBoolPref(PREF_DISPLAY, true);
    36   Services.prefs.setBoolPref(PREF_ACTIVE, true);
    38   var newTab = gBrowser.addTab();
    39   gBrowser.selectedTab = newTab;
    40   gTestBrowser = gBrowser.selectedBrowser;
    41   newTab.linkedBrowser.stop()
    43   // Mixed Script Test
    44   gTestBrowser.addEventListener("load", MixedTest1A, true);
    45   var url = gHttpTestRoot + "file_bug822367_1.html";
    46   gTestBrowser.contentWindow.location = url;
    47 }
    49 // Mixed Script Test
    50 function MixedTest1A() {
    51   gTestBrowser.removeEventListener("load", MixedTest1A, true);
    52   gTestBrowser.addEventListener("load", MixedTest1B, true);
    53   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    54   ok(notification, "Mixed Content Doorhanger didn't appear");
    55   notification.secondaryActions[0].callback();
    56 }
    57 function MixedTest1B() {
    58   waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest1C, "Waited too long for mixed script to run in Test 1");
    59 }
    60 function MixedTest1C() {
    61   ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 1");
    62   gTestBrowser.removeEventListener("load", MixedTest1B, true);
    63   MixedTest2();
    64 }
    66 //Mixed Display Test - Doorhanger should not appear
    67 function MixedTest2() {
    68   gTestBrowser.addEventListener("load", MixedTest2A, true);
    69   var url = gHttpTestRoot2 + "file_bug822367_2.html";
    70   gTestBrowser.contentWindow.location = url;
    71 }
    73 function MixedTest2A() {
    74   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    75   ok(!notification, "Mixed Content Doorhanger appears for mixed display content!");
    76   MixedTest3();
    77 }
    79 // Mixed Script and Display Test - User Override should cause both the script and the image to load.
    80 function MixedTest3() {
    81   gTestBrowser.removeEventListener("load", MixedTest2A, true);
    82   gTestBrowser.addEventListener("load", MixedTest3A, true);
    83   var url = gHttpTestRoot + "file_bug822367_3.html";
    84   gTestBrowser.contentWindow.location = url;
    85 }
    86 function MixedTest3A() {
    87   gTestBrowser.removeEventListener("load", MixedTest3A, true);
    88   gTestBrowser.addEventListener("load", MixedTest3B, true);
    89   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
    90   ok(notification, "Mixed Content Doorhanger doesn't appear for test 3");
    91   notification.secondaryActions[0].callback();
    92 }
    93 function MixedTest3B() {
    94   waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest3C, "Waited too long for mixed script to run in Test 3");
    95 }
    96 function MixedTest3C() {
    97   waitForCondition(function() content.document.getElementById('p2').innerHTML == "bye", MixedTest3D, "Waited too long for mixed image to load in Test 3");
    98 }
    99 function MixedTest3D() {
   100   ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 3");
   101   ok(content.document.getElementById('p2').innerHTML == "bye","Mixed image didn't load in Test 3");
   102   MixedTest4();
   103 }
   105 // Location change - User override on one page doesn't propogate to another page after location change.
   106 function MixedTest4() {
   107   gTestBrowser.removeEventListener("load", MixedTest3B, true);
   108   gTestBrowser.addEventListener("load", MixedTest4A, true);
   109   var url = gHttpTestRoot2 + "file_bug822367_4.html";
   110   gTestBrowser.contentWindow.location = url;
   111 }
   112 function MixedTest4A() {
   113   gTestBrowser.removeEventListener("load", MixedTest4A, true);
   114   gTestBrowser.addEventListener("load", MixedTest4B, true);
   115   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   116   ok(notification, "Mixed Content Doorhanger doesn't appear for Test 4");
   117   notification.secondaryActions[0].callback();
   118 }
   119 function MixedTest4B() {
   120   waitForCondition(function() content.document.location == gHttpTestRoot + "file_bug822367_4B.html", MixedTest4C, "Waited too long for mixed script to run in Test 4");
   121 }
   122 function MixedTest4C() {
   123   ok(content.document.location == gHttpTestRoot + "file_bug822367_4B.html", "Location didn't change in test 4");
   124   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   125   ok(notification, "Mixed Content Doorhanger doesn't appear after location change in Test 4");
   126   waitForCondition(function() content.document.getElementById('p1').innerHTML == "", MixedTest4D, "Mixed script loaded in test 4 after location change!");
   127 }
   128 function MixedTest4D() {
   129   ok(content.document.getElementById('p1').innerHTML == "","p1.innerHTML changed; mixed script loaded after location change in Test 4");
   130   MixedTest5();
   131 }
   133 // Mixed script attempts to load in a document.open()
   134 function MixedTest5() {
   135   gTestBrowser.removeEventListener("load", MixedTest4B, true);
   136   gTestBrowser.addEventListener("load", MixedTest5A, true);
   137   var url = gHttpTestRoot + "file_bug822367_5.html";
   138   gTestBrowser.contentWindow.location = url;
   139 }
   140 function MixedTest5A() {
   141   gTestBrowser.removeEventListener("load", MixedTest5A, true);
   142   gTestBrowser.addEventListener("load", MixedTest5B, true);
   143   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   144   ok(notification, "Mixed Content Doorhanger doesn't appear for Test 5");
   145   notification.secondaryActions[0].callback();
   146 }
   147 function MixedTest5B() {
   148   waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest5C, "Waited too long for mixed script to run in Test 5");
   149 }
   150 function MixedTest5C() {
   151   ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 5");
   152   MixedTest6();
   153 }
   155 // Mixed script attempts to load in a document.open() that is within an iframe.
   156 function MixedTest6() {
   157   gTestBrowser.removeEventListener("load", MixedTest5B, true);
   158   gTestBrowser.addEventListener("load", MixedTest6A, true);
   159   var url = gHttpTestRoot2 + "file_bug822367_6.html";
   160   gTestBrowser.contentWindow.location = url;
   161 }
   162 function MixedTest6A() {
   163   gTestBrowser.removeEventListener("load", MixedTest6A, true);
   164   waitForCondition(function() PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser), MixedTest6B, "waited to long for doorhanger");
   165 }
   167 function MixedTest6B() {
   168   var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser);
   169   ok(notification, "Mixed Content Doorhanger doesn't appear for Test 6");
   170   gTestBrowser.addEventListener("load", MixedTest6C, true);
   171   notification.secondaryActions[0].callback();
   172 }
   174 function MixedTest6C() {
   175   gTestBrowser.removeEventListener("load", MixedTest6C, true);
   176   waitForCondition(function() content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello", MixedTest6D, "Waited too long for mixed script to run in Test 6");
   177 }
   178 function MixedTest6D() {
   179   ok(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 6");
   180   MixedTestsCompleted();
   181 }

mercurial