Bug 909920 - Mixed content warning should not show on a HTTP site - tests (r=tanvi,smaug)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 23 Sep 2013 08:52:53 -0700
changeset 167036 fc2ee998c7863ca0c1675ad0468284e63720d512
parent 167035 f7dcf8411463884295269ab7fe2369d8f782133a
child 167037 41d2964e223132a40490a210e674b81dd93e2ed8
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstanvi, smaug
bugs909920
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 909920 - Mixed content warning should not show on a HTTP site - tests (r=tanvi,smaug)
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_no_mcb_on_http_site.js
browser/base/content/test/general/test_no_mcb_on_http_site_font.css
browser/base/content/test/general/test_no_mcb_on_http_site_font.html
browser/base/content/test/general/test_no_mcb_on_http_site_font2.css
browser/base/content/test/general/test_no_mcb_on_http_site_font2.html
browser/base/content/test/general/test_no_mcb_on_http_site_img.css
browser/base/content/test/general/test_no_mcb_on_http_site_img.html
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -73,16 +73,22 @@ support-files =
   test_bug435035.html
   test_bug462673.html
   test_bug628179.html
   test_bug839103.html
   test_wyciwyg_copying.html
   title_test.svg
   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
 
 [browser_CTP_data_urls.js]
 [browser_CTP_drag_drop.js]
 [browser_CTP_iframe.js]
 [browser_CTP_nonplugins.js]
 [browser_CTP_resize.js]
 [browser_URLBarSetURI.js]
 [browser_aboutHealthReport.js]
@@ -283,8 +289,9 @@ support-files =
 [browser_visibleTabs_bookmarkAllPages.js]
 [browser_visibleTabs_bookmarkAllTabs.js]
 [browser_visibleTabs_contextMenu.js]
 [browser_visibleTabs_tabPreview.js]
 [browser_wyciwyg_urlbarCopying.js]
 [browser_zbug569342.js]
 [browser_registerProtocolHandler_notification.js]
 [browser_registerProtocolHandler_notification.html]
+[browser_no_mcb_on_http_site.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_no_mcb_on_http_site.js
@@ -0,0 +1,138 @@
+/*
+ * Description of the Tests for
+ *  - Bug 909920 - Mixed content warning should not show on a HTTP site
+ *
+ * Description of the tests:
+ *   Test 1:
+ *     1) Load an http page
+ *     2) The page includes a css file using https
+ *     3) The css file loads an |IMAGE| << over http
+ *
+ *   Test 2:
+ *     1) Load an http page
+ *     2) The page includes a css file using https
+ *     3) The css file loads a |FONT| over http
+ *
+ *   Test 3:
+ *     1) Load an http page
+ *     2) The page includes a css file using https
+ *     3) The css file imports (@import) another css file using http
+ *     3) The imported css file loads a |FONT| over http
+*
+ * Since the top-domain is >> NOT << served using https, the MCB
+ * should >> NOT << trigger a warning.
+ */
+
+const PREF_ACTIVE = "security.mixed_content.block_active_content";
+const PREF_DISPLAY = "security.mixed_content.block_display_content";
+
+const gHttpTestRoot = "http://example.com/browser/browser/base/content/test/general/";
+
+var origBlockActive, origBlockDisplay;
+var gTestBrowser = null;
+
+registerCleanupFunction(function() {
+  // Set preferences back to their original values
+  Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
+  Services.prefs.setBoolPref(PREF_DISPLAY, origBlockDisplay);
+});
+
+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 test1A() {
+  gTestBrowser.removeEventListener("load", test1A, true);
+
+  var expected = "Verifying MCB does not trigger warning/error for an http page ";
+  expected += "with https css that includes http image";
+  waitForCondition(
+    function() content.document.getElementById('testDiv').innerHTML == expected,
+    test1B, "Error: Waited too long for status in Test 1!",
+    "OK: Expected result in innerHTML!");
+}
+
+function test1B() {
+  // set up test 2
+  gTestBrowser.addEventListener("load", test2A, true);
+  var url = gHttpTestRoot + "test_no_mcb_on_http_site_font.html";
+  gTestBrowser.contentWindow.location = url;
+}
+
+//------------- TEST 2 -----------------------------------------
+
+function test2A() {
+  gTestBrowser.removeEventListener("load", test2A, true);
+
+  var expected = "Verifying MCB does not trigger warning/error for an http page ";
+  expected += "with https css that includes http font";
+  waitForCondition(
+    function() content.document.getElementById('testDiv').innerHTML == expected,
+    test2B, "Error: Waited too long for status in Test 2!",
+    "OK: Expected result in innerHTML!");
+}
+
+function test2B() {
+  // set up test 3
+  gTestBrowser.addEventListener("load", test3, true);
+  var url = gHttpTestRoot + "test_no_mcb_on_http_site_font2.html";
+  gTestBrowser.contentWindow.location = url;
+}
+
+//------------- TEST 3 -----------------------------------------
+
+function test3() {
+  gTestBrowser.removeEventListener("load", test3, true);
+
+  var expected = "Verifying MCB does not trigger warning/error for an http page "
+  expected += "with https css that imports another http css which includes http font";
+  waitForCondition(
+    function() content.document.getElementById('testDiv').innerHTML == expected,
+    cleanUpAfterTests, "Error: Waited too long for status in Test 3!",
+    "OK: Expected result in innerHTML!");
+}
+
+//------------------------------------------------------
+
+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);
+  origBlockDisplay = Services.prefs.getBoolPref(PREF_DISPLAY);
+
+  Services.prefs.setBoolPref(PREF_ACTIVE, true);
+  Services.prefs.setBoolPref(PREF_DISPLAY, true);
+
+  var newTab = gBrowser.addTab();
+  gBrowser.selectedTab = newTab;
+  gTestBrowser = gBrowser.selectedBrowser;
+  newTab.linkedBrowser.stop();
+
+  gTestBrowser.addEventListener("load", test1A, true);
+  var url = gHttpTestRoot + "test_no_mcb_on_http_site_img.html";
+  gTestBrowser.contentWindow.location = url;
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_font.css
@@ -0,0 +1,10 @@
+@font-face {
+  font-family: testFont;
+  src: url(http://example.com/browser/browser/devtools/fontinspector/test/browser_font.woff);
+}
+body {
+  font-family: Arial;
+}
+div {
+  font-family: testFont;
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_font.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+  Test 2 for Bug 909920 - See file browser_no_mcb_on_http_site.js for description.
+  https://bugzilla.mozilla.org/show_bug.cgi?id=909920
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test 2 for Bug 909920</title>
+  <link rel="stylesheet" type="text/css" href="https://example.com/browser/browser/base/content/test/general/test_no_mcb_on_http_site_font.css" />
+<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+
+<script type="text/javascript">
+  function checkLoadStates() {
+   var ui = SpecialPowers.wrap(window)
+            .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+             .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+             .QueryInterface(SpecialPowers.Ci.nsIDocShell)
+             .securityUI;
+
+   var loadedMixedActive = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT);
+   is(loadedMixedActive, false, "OK: Should not load mixed active content!");
+
+   var blockedMixedActive = ui &&
+       (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_ACTIVE_CONTENT);
+   is(blockedMixedActive, false, "OK: Should not block mixed active content!");
+
+   var loadedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_DISPLAY_CONTENT);
+   is(loadedMixedDisplay, false, "OK: Should not load mixed display content!");
+
+   var blockedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_DISPLAY_CONTENT);
+   is(blockedMixedDisplay, false, "OK: Should not block mixed display content!");
+
+   var newValue = "Verifying MCB does not trigger warning/error for an http page with https css that includes http font";
+   document.getElementById("testDiv").innerHTML = newValue;
+  }
+</script>
+</head>
+<body onload="checkLoadStates()">
+  <div class="testDiv" id="testDiv">
+    Testing MCB does not trigger warning/error for an http page with https css that includes http font
+  </div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_font2.css
@@ -0,0 +1,1 @@
+@import url(http://example.com/browser/browser/base/content/test/general/test_no_mcb_on_http_site_font.css);
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_font2.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+  Test 3 for Bug 909920 - See file browser_no_mcb_on_http_site.js for description.
+  https://bugzilla.mozilla.org/show_bug.cgi?id=909920
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test 3 for Bug 909920</title>
+  <link rel="stylesheet" type="text/css" href="https://example.com/browser/browser/base/content/test/general/test_no_mcb_on_http_site_font2.css" />
+<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+
+<script type="text/javascript">
+  function checkLoadStates() {
+   var ui = SpecialPowers.wrap(window)
+        .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+             .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+             .QueryInterface(SpecialPowers.Ci.nsIDocShell)
+             .securityUI;
+
+   var loadedMixedActive = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT);
+   is(loadedMixedActive, false, "OK: Should not load mixed active content!");
+
+   var blockedMixedActive = ui &&
+       (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_ACTIVE_CONTENT);
+   is(blockedMixedActive, false, "OK: Should not block mixed active content!");
+
+   var loadedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_DISPLAY_CONTENT);
+   is(loadedMixedDisplay, false, "OK: Should not load mixed display content!");
+
+   var blockedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_DISPLAY_CONTENT);
+   is(blockedMixedDisplay, false, "OK: Should not block mixed display content!");
+
+   var newValue = "Verifying MCB does not trigger warning/error for an http page ";
+    newValue += "with https css that imports another http css which includes http font";
+   document.getElementById("testDiv").innerHTML = newValue;
+  }
+</script>
+</head>
+<body onload="checkLoadStates()">
+  <div class="testDiv" id="testDiv">
+    Testing MCB does not trigger warning/error for an http page with https css that imports another http css which includes http font
+  </div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_img.css
@@ -0,0 +1,3 @@
+#testDiv {
+  background: url(http://example.com/tests/image/test/mochitest/blue.png)
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/test_no_mcb_on_http_site_img.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+  Test 1 for Bug 909920 - See file browser_no_mcb_on_http_site.js for description.
+  https://bugzilla.mozilla.org/show_bug.cgi?id=909920
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test 1 for Bug 909920</title>
+  <link rel="stylesheet" type="text/css" href="https://example.com/browser/browser/base/content/test/general/test_no_mcb_on_http_site_img.css" />
+<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+
+<script type="text/javascript">
+  function checkLoadStates() {
+   var ui = SpecialPowers.wrap(window)
+            .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+             .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+             .QueryInterface(SpecialPowers.Ci.nsIDocShell)
+             .securityUI;
+
+   var loadedMixedActive = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT);
+   is(loadedMixedActive, false, "OK: Should not load mixed active content!");
+
+   var blockedMixedActive = ui &&
+       (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_ACTIVE_CONTENT);
+   is(blockedMixedActive, false, "OK: Should not block mixed active content!");
+
+   var loadedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_LOADED_MIXED_DISPLAY_CONTENT);
+   is(loadedMixedDisplay, false, "OK: Should not load mixed display content!");
+
+   var blockedMixedDisplay = ui &&
+     (ui.state & SpecialPowers.Ci.nsIWebProgressListener.STATE_BLOCKED_MIXED_DISPLAY_CONTENT);
+   is(blockedMixedDisplay, false, "OK: Should not block mixed display content!");
+
+   var newValue = "Verifying MCB does not trigger warning/error for an http page with https css that includes http image";
+   document.getElementById("testDiv").innerHTML = newValue;
+  }
+</script>
+</head>
+<body onload="checkLoadStates()">
+  <div class="testDiv" id="testDiv">
+    Testing MCB does not trigger warning/error for an http page with https css that includes http image
+  </div>
+</body>
+</html>