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.

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

mercurial