Bug 418354 - Allow Mixed Content Blocker to handle redirects - testcases. r=smaug
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -84,16 +84,19 @@ support-files =
video.ogg
zoom_test.html
test_no_mcb_on_http_site_img.html
test_no_mcb_on_http_site_img.css
test_no_mcb_on_http_site_font.html
test_no_mcb_on_http_site_font.css
test_no_mcb_on_http_site_font2.html
test_no_mcb_on_http_site_font2.css
+ test_mcb_redirect.html
+ test_mcb_redirect.js
+ test_mcb_redirect.sjs
xul_tooltiptext.xhtml
file_bug1045809_1.html
file_bug1045809_2.html
[browser_URLBarSetURI.js]
skip-if = (os == "linux" || os == "mac") && debug # bug 970052, bug 970053
[browser_aboutAccounts.js]
skip-if = os == "linux" # Bug 958026
@@ -498,8 +501,9 @@ skip-if = e10s
[browser_bug1025195_switchToTabHavingURI_ignoreFragment.js]
[browser_addCertException.js]
skip-if = e10s # Bug ?????? - test directly manipulates content (content.document.getElementById)
[browser_bug1045809.js]
skip-if = e10s # Bug 1068360 - [e10s] Mixed content blocker doorhanger doesn't work
[browser_e10s_switchbrowser.js]
[browser_blockHPKP.js]
skip-if = e10s # bug ?????? - test directly manipulates content (content.document.getElementById)
+[browser_mcb_redirect.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_mcb_redirect.js
@@ -0,0 +1,110 @@
+/*
+ * Description of the Tests for
+ * - Bug 418354 - Call Mixed content blocking on redirects
+ *
+ * 1. Load a script over https inside an https page
+ * - the server responds with a 302 redirect to a >> HTTP << script
+ * - the doorhanger should appear!
+ *
+ * 2. Load a script over https inside an http page
+ * - the server responds with a 302 redirect to a >> HTTP << script
+ * - the doorhanger should not appear!
+ */
+
+const PREF_ACTIVE = "security.mixed_content.block_active_content";
+const gHttpsTestRoot = "https://example.com/browser/browser/base/content/test/general/";
+const gHttpTestRoot = "http://example.com/browser/browser/base/content/test/general/";
+
+let origBlockActive;
+var gTestBrowser = null;
+
+//------------------------ Helper Functions ---------------------
+
+registerCleanupFunction(function() {
+ // Set preferences back to their original values
+ Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
+});
+
+function cleanUpAfterTests() {
+ gBrowser.removeCurrentTab();
+ window.focus();
+ finish();
+}
+
+function waitForCondition(condition, nextTest, errorMsg, okMsg) {
+ var tries = 0;
+ var interval = setInterval(function() {
+ if (tries >= 30) {
+ ok(false, errorMsg);
+ moveOn();
+ }
+ if (condition()) {
+ ok(true, okMsg)
+ moveOn();
+ }
+ tries++;
+ }, 100);
+ var moveOn = function() {
+ clearInterval(interval); nextTest();
+ };
+}
+
+//------------------------ Test 1 ------------------------------
+
+function test1() {
+ gTestBrowser.addEventListener("load", checkPopUpNotificationsForTest1, true);
+ var url = gHttpsTestRoot + "test_mcb_redirect.html"
+ gTestBrowser.contentWindow.location = url;
+}
+
+function checkPopUpNotificationsForTest1() {
+ gTestBrowser.removeEventListener("load", checkPopUpNotificationsForTest1, true);
+
+ var notification = PopupNotifications.getNotification("bad-content", gTestBrowser.selectedBrowser);
+ ok(notification, "OK: Mixed Content Doorhanger appeared in Test1!");
+
+ var expected = "script blocked";
+ waitForCondition(
+ function() content.document.getElementById('mctestdiv').innerHTML == expected,
+ test2, "Error: Waited too long for status in Test 1!",
+ "OK: Expected result in innerHTML for Test1!");
+}
+
+//------------------------ Test 2 ------------------------------
+
+function test2() {
+ gTestBrowser.addEventListener("load", checkPopUpNotificationsForTest2, true);
+ var url = gHttpTestRoot + "test_mcb_redirect.html"
+ gTestBrowser.contentWindow.location = url;
+}
+
+function checkPopUpNotificationsForTest2() {
+ gTestBrowser.removeEventListener("load", checkPopUpNotificationsForTest2, true);
+
+ var notification = PopupNotifications.getNotification("bad-content", gTestBrowser.selectedBrowser);
+ ok(!notification, "OK: Mixed Content Doorhanger did not appear in 2!");
+
+ var expected = "script executed";
+ waitForCondition(
+ function() content.document.getElementById('mctestdiv').innerHTML == expected,
+ cleanUpAfterTests, "Error: Waited too long for status in Test 2!",
+ "OK: Expected result in innerHTML for Test2!");
+}
+
+//------------------------ SETUP ------------------------------
+
+function test() {
+ // Performing async calls, e.g. 'onload', we have to wait till all of them finished
+ waitForExplicitFinish();
+
+ // Store original preferences so we can restore settings after testing
+ origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
+ Services.prefs.setBoolPref(PREF_ACTIVE, true);
+
+ var newTab = gBrowser.addTab();
+ gBrowser.selectedTab = newTab;
+ gTestBrowser = gBrowser.selectedBrowser;
+ newTab.linkedBrowser.stop();
+
+ executeSoon(test1);
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_mcb_redirect.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+ Test 1 for Bug 418354 - See file browser_mcb_redirect.js for description.
+ https://bugzilla.mozilla.org/show_bug.cgi?id=418354
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Bug 418354</title>
+</head>
+<body>
+ <div id="mctestdiv">script blocked</div>
+ <script src="https://example.com/browser/browser/base/content/test/general/test_mcb_redirect.sjs" ></script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_mcb_redirect.js
@@ -0,0 +1,5 @@
+/*
+ * Once the mixed content blocker is disabled for the page, this scripts loads
+ * and updates the text inside the div container.
+ */
+document.getElementById("mctestdiv").innerHTML = "script executed";
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_mcb_redirect.sjs
@@ -0,0 +1,11 @@
+function handleRequest(request, response) {
+ var page = "<!DOCTYPE html><html><body>bug 418354</body></html>";
+
+ var redirect = "http://example.com/browser/browser/base/content/test/general/test_mcb_redirect.js";
+
+ response.setHeader("Cache-Control", "no-cache", false);
+ response.setHeader("Content-Type", "text/html", false);
+ response.setStatusLine(request.httpVersion, "302", "Found");
+ response.setHeader("Location", redirect, false);
+ response.write(page);
+}