michael@0: /* michael@0: * User Override Mixed Content Block - Tests for Bug 822367 michael@0: */ michael@0: michael@0: michael@0: const PREF_DISPLAY = "security.mixed_content.block_display_content"; 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 gHttpTestRoot = "https://example.com/browser/browser/base/content/test/general/"; michael@0: const gHttpTestRoot2 = "https://test1.example.com/browser/browser/base/content/test/general/"; michael@0: michael@0: var origBlockDisplay; 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_DISPLAY, origBlockDisplay); michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive); michael@0: }); michael@0: michael@0: function MixedTestsCompleted() { michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: finish(); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: origBlockDisplay = Services.prefs.getBoolPref(PREF_DISPLAY); michael@0: origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE); michael@0: michael@0: Services.prefs.setBoolPref(PREF_DISPLAY, true); michael@0: Services.prefs.setBoolPref(PREF_ACTIVE, true); michael@0: 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: // Mixed Script Test michael@0: gTestBrowser.addEventListener("load", MixedTest1A, true); michael@0: var url = gHttpTestRoot + "file_bug822367_1.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: // Mixed Script Test michael@0: function MixedTest1A() { michael@0: gTestBrowser.removeEventListener("load", MixedTest1A, true); michael@0: gTestBrowser.addEventListener("load", MixedTest1B, true); michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger didn't appear"); michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: function MixedTest1B() { michael@0: waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest1C, "Waited too long for mixed script to run in Test 1"); michael@0: } michael@0: function MixedTest1C() { michael@0: ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 1"); michael@0: gTestBrowser.removeEventListener("load", MixedTest1B, true); michael@0: MixedTest2(); michael@0: } michael@0: michael@0: //Mixed Display Test - Doorhanger should not appear michael@0: function MixedTest2() { michael@0: gTestBrowser.addEventListener("load", MixedTest2A, true); michael@0: var url = gHttpTestRoot2 + "file_bug822367_2.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: function MixedTest2A() { michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(!notification, "Mixed Content Doorhanger appears for mixed display content!"); michael@0: MixedTest3(); michael@0: } michael@0: michael@0: // Mixed Script and Display Test - User Override should cause both the script and the image to load. michael@0: function MixedTest3() { michael@0: gTestBrowser.removeEventListener("load", MixedTest2A, true); michael@0: gTestBrowser.addEventListener("load", MixedTest3A, true); michael@0: var url = gHttpTestRoot + "file_bug822367_3.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: function MixedTest3A() { michael@0: gTestBrowser.removeEventListener("load", MixedTest3A, true); michael@0: gTestBrowser.addEventListener("load", MixedTest3B, true); michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger doesn't appear for test 3"); michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: function MixedTest3B() { michael@0: waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest3C, "Waited too long for mixed script to run in Test 3"); michael@0: } michael@0: function MixedTest3C() { michael@0: waitForCondition(function() content.document.getElementById('p2').innerHTML == "bye", MixedTest3D, "Waited too long for mixed image to load in Test 3"); michael@0: } michael@0: function MixedTest3D() { michael@0: ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 3"); michael@0: ok(content.document.getElementById('p2').innerHTML == "bye","Mixed image didn't load in Test 3"); michael@0: MixedTest4(); michael@0: } michael@0: michael@0: // Location change - User override on one page doesn't propogate to another page after location change. michael@0: function MixedTest4() { michael@0: gTestBrowser.removeEventListener("load", MixedTest3B, true); michael@0: gTestBrowser.addEventListener("load", MixedTest4A, true); michael@0: var url = gHttpTestRoot2 + "file_bug822367_4.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: function MixedTest4A() { michael@0: gTestBrowser.removeEventListener("load", MixedTest4A, true); michael@0: gTestBrowser.addEventListener("load", MixedTest4B, true); michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger doesn't appear for Test 4"); michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: function MixedTest4B() { michael@0: waitForCondition(function() content.document.location == gHttpTestRoot + "file_bug822367_4B.html", MixedTest4C, "Waited too long for mixed script to run in Test 4"); michael@0: } michael@0: function MixedTest4C() { michael@0: ok(content.document.location == gHttpTestRoot + "file_bug822367_4B.html", "Location didn't change in test 4"); michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger doesn't appear after location change in Test 4"); michael@0: waitForCondition(function() content.document.getElementById('p1').innerHTML == "", MixedTest4D, "Mixed script loaded in test 4 after location change!"); michael@0: } michael@0: function MixedTest4D() { michael@0: ok(content.document.getElementById('p1').innerHTML == "","p1.innerHTML changed; mixed script loaded after location change in Test 4"); michael@0: MixedTest5(); michael@0: } michael@0: michael@0: // Mixed script attempts to load in a document.open() michael@0: function MixedTest5() { michael@0: gTestBrowser.removeEventListener("load", MixedTest4B, true); michael@0: gTestBrowser.addEventListener("load", MixedTest5A, true); michael@0: var url = gHttpTestRoot + "file_bug822367_5.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: function MixedTest5A() { michael@0: gTestBrowser.removeEventListener("load", MixedTest5A, true); michael@0: gTestBrowser.addEventListener("load", MixedTest5B, true); michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger doesn't appear for Test 5"); michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: function MixedTest5B() { michael@0: waitForCondition(function() content.document.getElementById('p1').innerHTML == "hello", MixedTest5C, "Waited too long for mixed script to run in Test 5"); michael@0: } michael@0: function MixedTest5C() { michael@0: ok(content.document.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 5"); michael@0: MixedTest6(); michael@0: } michael@0: michael@0: // Mixed script attempts to load in a document.open() that is within an iframe. michael@0: function MixedTest6() { michael@0: gTestBrowser.removeEventListener("load", MixedTest5B, true); michael@0: gTestBrowser.addEventListener("load", MixedTest6A, true); michael@0: var url = gHttpTestRoot2 + "file_bug822367_6.html"; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: function MixedTest6A() { michael@0: gTestBrowser.removeEventListener("load", MixedTest6A, true); michael@0: waitForCondition(function() PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser), MixedTest6B, "waited to long for doorhanger"); michael@0: } michael@0: michael@0: function MixedTest6B() { michael@0: var notification = PopupNotifications.getNotification("mixed-content-blocked", gTestBrowser); michael@0: ok(notification, "Mixed Content Doorhanger doesn't appear for Test 6"); michael@0: gTestBrowser.addEventListener("load", MixedTest6C, true); michael@0: notification.secondaryActions[0].callback(); michael@0: } michael@0: michael@0: function MixedTest6C() { michael@0: gTestBrowser.removeEventListener("load", MixedTest6C, true); michael@0: 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: } michael@0: function MixedTest6D() { michael@0: ok(content.document.getElementById('f1').contentDocument.getElementById('p1').innerHTML == "hello","Mixed script didn't load in Test 6"); michael@0: MixedTestsCompleted(); michael@0: }