michael@0: /* michael@0: * Description of the Tests for michael@0: * - Bug 902156: Persist "disable protection" option for Mixed Content Blocker michael@0: * michael@0: * 1. Navigate to the same domain via document.location michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin using document.location michael@0: * - Doorhanger should not appear anymore! michael@0: * michael@0: * 2. Navigate to the same domain via simulateclick for a link on the page michael@0: * - Load a html page which has mixed content michael@0: * - Doorhanger to disable protection appears - we disable it michael@0: * - Load a new page from the same origin simulating a click michael@0: * - Doorhanger should not appear anymore! michael@0: * michael@0: * 3. Navigate to a differnet domain and show the content is still blocked michael@0: * - Load a different html page which has mixed content michael@0: * - Doorhanger to disable protection should appear again because michael@0: * we navigated away from html page where we disabled the protection. michael@0: * michael@0: * Note, for all tests we set gHttpTestRoot to use 'https'. michael@0: */ michael@0: michael@0: const PREF_ACTIVE = "security.mixed_content.block_active_content"; michael@0: michael@0: // We alternate for even and odd test cases to simulate different hosts michael@0: const gHttpTestRoot1 = "https://test1.example.com/browser/browser/base/content/test/general/"; michael@0: const gHttpTestRoot2 = "https://test2.example.com/browser/browser/base/content/test/general/"; michael@0: michael@0: var origBlockActive; michael@0: var gTestBrowser = null; michael@0: michael@0: registerCleanupFunction(function() { michael@0: // Set preferences back to their original values michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive); michael@0: }); michael@0: michael@0: function cleanUpAfterTests() { michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: finish(); michael@0: } michael@0: michael@0: //------------------------ Test 1 ------------------------------ michael@0: michael@0: function test1A() { michael@0: // Removing EventListener because we have to register a new michael@0: // one once the page is loaded with mixed content blocker disabled michael@0: gTestBrowser.removeEventListener("load", test1A, true); michael@0: gTestBrowser.addEventListener("load", test1B, true); michael@0: michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger appeared in Test1A!"); michael@0: michael@0: // Disable Mixed Content Protection for the page michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: michael@0: function test1B() { michael@0: var expected = "Mixed Content Blocker disabled"; michael@0: waitForCondition( michael@0: function() content.document.getElementById('mctestdiv').innerHTML == expected, michael@0: test1C, "Error: Waited too long for mixed script to run in Test 1B"); michael@0: } michael@0: michael@0: function test1C() { michael@0: gTestBrowser.removeEventListener("load", test1B, true); michael@0: var actual = content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1C"); michael@0: michael@0: // The Script loaded after we disabled the page, now we are going to reload the michael@0: // page and see if our decision is persistent michael@0: gTestBrowser.addEventListener("load", test1D, true); michael@0: michael@0: var url = gHttpTestRoot1 + "file_bug902156_2.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: function test1D() { michael@0: gTestBrowser.removeEventListener("load", test1D, true); michael@0: michael@0: // The Doorhanger should not appear, because our decision of disabling the michael@0: // mixed content blocker is persistent. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test1D!"); michael@0: michael@0: var actual = content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 1D"); michael@0: michael@0: // move on to Test 2 michael@0: test2(); michael@0: } michael@0: michael@0: //------------------------ Test 2 ------------------------------ michael@0: michael@0: function test2() { michael@0: gTestBrowser.addEventListener("load", test2A, true); michael@0: var url = gHttpTestRoot2 + "file_bug902156_2.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: function test2A() { michael@0: // Removing EventListener because we have to register a new michael@0: // one once the page is loaded with mixed content blocker disabled michael@0: gTestBrowser.removeEventListener("load", test2A, true); michael@0: gTestBrowser.addEventListener("load", test2B, true); michael@0: michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger appeared in Test 2A!"); michael@0: michael@0: // Disable Mixed Content Protection for the page michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: michael@0: function test2B() { michael@0: var expected = "Mixed Content Blocker disabled"; michael@0: waitForCondition( michael@0: function() content.document.getElementById('mctestdiv').innerHTML == expected, michael@0: test2C, "Error: Waited too long for mixed script to run in Test 2B"); michael@0: } michael@0: michael@0: function test2C() { michael@0: gTestBrowser.removeEventListener("load", test2B, true); michael@0: var actual = content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2C"); michael@0: michael@0: // The Script loaded after we disabled the page, now we are going to reload the michael@0: // page and see if our decision is persistent michael@0: gTestBrowser.addEventListener("load", test2D, true); michael@0: michael@0: // reload the page using the provided link in the html file michael@0: var mctestlink = content.document.getElementById("mctestlink"); michael@0: mctestlink.click(); michael@0: } michael@0: michael@0: function test2D() { michael@0: gTestBrowser.removeEventListener("load", test2D, true); michael@0: michael@0: // The Doorhanger should not appear, because our decision of disabling the michael@0: // mixed content blocker is persistent. michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(!notification, "OK: Mixed Content Doorhanger did not appear again in Test2D!"); michael@0: michael@0: var actual = content.document.getElementById('mctestdiv').innerHTML; michael@0: is(actual, "Mixed Content Blocker disabled", "OK: Executed mixed script in Test 2D"); michael@0: michael@0: // move on to Test 3 michael@0: test3(); michael@0: } michael@0: michael@0: //------------------------ Test 3 ------------------------------ michael@0: michael@0: function test3() { michael@0: gTestBrowser.addEventListener("load", test3A, true); michael@0: var url = gHttpTestRoot1 + "file_bug902156_3.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: function test3A() { michael@0: // Removing EventListener because we have to register a new michael@0: // one once the page is loaded with mixed content blocker disabled michael@0: gTestBrowser.removeEventListener("load", test3A, true); michael@0: michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "OK: Mixed Content Doorhanger appeared in Test 3A!"); michael@0: michael@0: // We are done with tests, clean up michael@0: cleanUpAfterTests(); michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: function test() { michael@0: // Performing async calls, e.g. 'onload', we have to wait till all of them finished michael@0: waitForExplicitFinish(); michael@0: michael@0: // Store original preferences so we can restore settings after testing michael@0: origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE); michael@0: michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, true); michael@0: michael@0: // Not really sure what this is doing michael@0: var newTab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = newTab; michael@0: gTestBrowser = gBrowser.selectedBrowser; michael@0: newTab.linkedBrowser.stop() michael@0: michael@0: // Starting Test Number 1: michael@0: gTestBrowser.addEventListener("load", test1A, true); michael@0: var url = gHttpTestRoot1 + "file_bug902156_1.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: }