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.

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

mercurial