Bug 1259908 - split plugin to own test and run in clipboard job temporarily. r?tanvi draft
authorJoel Maher <jmaher@mozilla.com>
Thu, 18 Aug 2016 13:44:47 -0400
changeset 404338 074aad8bfdc54263b383c4c7706ac65a5dfb6bc1
parent 404231 4d707b97319298b5deb6c38dca81ccf17bdef8f9
child 529157 3f3d5152e06290d0b90e859db923e8e1a8ad6804
push id27181
push userjmaher@mozilla.com
push dateTue, 23 Aug 2016 08:29:55 +0000
reviewerstanvi
bugs1259908
milestone51.0a1
Bug 1259908 - split plugin to own test and run in clipboard job temporarily. r?tanvi MozReview-Commit-ID: g5SNAK4XeW
dom/security/test/mixedcontentblocker/file_main.html
dom/security/test/mixedcontentblocker/file_main_plugin.html
dom/security/test/mixedcontentblocker/mochitest.ini
dom/security/test/mixedcontentblocker/test_main.html
dom/security/test/mixedcontentblocker/test_main_plugin.html
--- a/dom/security/test/mixedcontentblocker/file_main.html
+++ b/dom/security/test/mixedcontentblocker/file_main.html
@@ -10,17 +10,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
 </head>
 <body>
 <div id="testContent"></div>
 
 <!-- types the Mixed Content Blocker can block
      /*
   switch (aContentType) {
-  case nsIContentPolicy::TYPE_OBJECT:
   case nsIContentPolicy::TYPE_SCRIPT:
   case nsIContentPolicy::TYPE_STYLESHEET:
   case nsIContentPolicy::TYPE_SUBDOCUMENT:
   case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
 
   case nsIContentPolicy::TYPE_FONT: - NO TEST:
     Load events for external fonts are not detectable by javascript.
   case nsIContentPolicy::TYPE_WEBSOCKET: - NO TEST:
@@ -43,50 +42,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   //For tests that require setTimeout, set the maximum polling time to 100 x 100ms = 10 seconds.
   var MAX_COUNT = 100;
   var TIMEOUT_INTERVAL = 100;
 
   var testContent = document.getElementById("testContent");
 
   /* Part 1: Mixed Script tests */
 
-  // Test 1a: insecure object
-  var object = document.createElement("object");
-  object.data = baseUrl + "?type=object";
-  object.type = "application/x-test";
-  object.width = "200";
-  object.height = "200";
-
-  testContent.appendChild(object);
-
-  var objectCount = 0;
-
-  function objectStatus(object) {
-    // Expose our privileged bits on the object
-    object = SpecialPowers.wrap(object);
-
-    if (object.displayedType != SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_NULL) {
-      //object loaded
-      parent.postMessage({"test": "object", "msg": "insecure object loaded"}, "http://mochi.test:8888");
-    }
-    else {
-      if(objectCount < MAX_COUNT) {
-        objectCount++;
-        setTimeout(objectStatus, TIMEOUT_INTERVAL, object);
-      }
-      else {
-        //After we have called setTimeout the maximum number of times, assume object is blocked
-        parent.postMessage({"test": "object", "msg": "insecure object blocked"}, "http://mochi.test:8888");
-      }
-    }
-  }
-
-  // object does not have onload and onerror events. Hence we need a setTimeout to check the object's status
-  setTimeout(objectStatus, TIMEOUT_INTERVAL, object);
-
   // Test 1b: insecure script
   var script = document.createElement("script");
   var scriptLoad = false;
   var scriptCount = 0;
   script.src = baseUrl + "?type=script";
   script.onload = function() {
     parent.postMessage({"test": "script", "msg": "insecure script loaded"}, "http://mochi.test:8888");
     scriptLoad = true;
new file mode 100644
--- /dev/null
+++ b/dom/security/test/mixedcontentblocker/file_main_plugin.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests for Mixed Content Blocker
+https://bugzilla.mozilla.org/show_bug.cgi?id=62178
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Tests for Bug 62178</title>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+<div id="testContent"></div>
+
+<!-- types the Mixed Content Blocker can block
+     /*
+  switch (aContentType) {
+  case nsIContentPolicy::TYPE_OBJECT:
+  }
+     */
+-->
+
+<script>
+  var baseUrl = "http://example.com/tests/dom/security/test/mixedcontentblocker/file_server.sjs";
+
+  //For tests that require setTimeout, set the maximum polling time to 100 x 100ms = 10 seconds.
+  var MAX_COUNT = 100;
+  var TIMEOUT_INTERVAL = 100;
+
+  var testContent = document.getElementById("testContent");
+
+  /* Part 1: Mixed Script tests */
+
+  // Test 1a: insecure object
+  var object = document.createElement("object");
+  object.data = baseUrl + "?type=object";
+  object.type = "application/x-test";
+  object.width = "200";
+  object.height = "200";
+
+  testContent.appendChild(object);
+
+  var objectCount = 0;
+
+  function objectStatus(object) {
+    // Expose our privileged bits on the object
+    object = SpecialPowers.wrap(object);
+
+    if (object.displayedType != SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_NULL) {
+      //object loaded
+      parent.postMessage({"test": "object", "msg": "insecure object loaded"}, "http://mochi.test:8888");
+    }
+    else {
+      if(objectCount < MAX_COUNT) {
+        objectCount++;
+        setTimeout(objectStatus, TIMEOUT_INTERVAL, object);
+      }
+      else {
+        //After we have called setTimeout the maximum number of times, assume object is blocked
+        parent.postMessage({"test": "object", "msg": "insecure object blocked"}, "http://mochi.test:8888");
+      }
+    }
+  }
+
+  // object does not have onload and onerror events. Hence we need a setTimeout to check the object's status
+  setTimeout(objectStatus, TIMEOUT_INTERVAL, object);
+
+</script>
+</body>
+</html>
--- a/dom/security/test/mixedcontentblocker/mochitest.ini
+++ b/dom/security/test/mixedcontentblocker/mochitest.ini
@@ -4,20 +4,24 @@ support-files =
   file_bug803225_test_mailto.html
   file_frameNavigation.html
   file_frameNavigation_blankTarget.html
   file_frameNavigation_grandchild.html
   file_frameNavigation_innermost.html
   file_frameNavigation_secure.html
   file_frameNavigation_secure_grandchild.html
   file_main.html
+  file_main_plugin.html
   file_main_bug803225.html
   file_main_bug803225_websocket_wsh.py
   file_server.sjs
   !/dom/media/test/320x240.ogv
   !/image/test/mochitest/blue.png
 
 [test_main.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT, SSL_REQUIRED # Bug 1141029 Mulet parity with B2G Desktop for TC
+[test_main_plugin.html]
+skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT, SSL_REQUIRED # Bug 1141029 Mulet parity with B2G Desktop for TC
+subsuite = clipboard
 [test_bug803225.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT, SSL_REQUIRED # Bug 1141029 Mulet parity with B2G Desktop for TC
 [test_frameNavigation.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT, SSL_REQUIRED
--- a/dom/security/test/mixedcontentblocker/test_main.html
+++ b/dom/security/test/mixedcontentblocker/test_main.html
@@ -6,17 +6,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Tests for Bug 62178</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 
   <script>
-  SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
 
   var counter = 0;
   var settings = [ [true, true], [true, false], [false, true], [false, false] ];
 
   var blockActive;
   var blockDisplay;
 
   //Cycle through 4 different preference settings.
@@ -38,17 +37,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     image: false,
     imageSrcset: false,
     imageSrcsetFallback: false,
     imagePicture: false,
     imageJoinPicture: false,
     imageLeavePicture: false,
     script: false,
     stylesheet: false,
-    object: false,
     media: false,
     xhr: false,
   };
 
   function log(msg) {
     document.getElementById("log").textContent += "\n" + msg;
   }
 
@@ -93,21 +91,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     switch(event.data.test) {
 
       /* Mixed Script tests */
       case "iframe":
         ok(blockActive == (event.data.msg == "insecure iframe blocked"), "iframe did not follow block_active_content pref");
         testsToRun["iframe"] = true;
         break;
 
-      case "object":
-        ok(blockActive == (event.data.msg == "insecure object blocked"), "object did not follow block_active_content pref");
-        testsToRun["object"] = true;
-        break;
-
       case "script":
         ok(blockActive == (event.data.msg == "insecure script blocked"), "script did not follow block_active_content pref");
         testsToRun["script"] = true;
         break;
 
       case "stylesheet":
         ok(blockActive == (event.data.msg == "insecure stylesheet blocked"), "stylesheet did not follow block_active_content pref");
         testsToRun["stylesheet"] = true;
new file mode 100644
--- /dev/null
+++ b/dom/security/test/mixedcontentblocker/test_main_plugin.html
@@ -0,0 +1,117 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests for Mixed Content Blocker
+https://bugzilla.mozilla.org/show_bug.cgi?id=62178
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Tests for Bug 62178</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+  <script>
+  SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
+
+  var counter = 0;
+  var settings = [ [true, true], [true, false], [false, true], [false, false] ];
+
+  var blockActive;
+  var blockDisplay;
+
+  //Cycle through 4 different preference settings.
+  function changePrefs(otherPrefs, callback) {
+    let basePrefs = [["security.mixed_content.block_display_content", settings[counter][0]],
+                     ["security.mixed_content.block_active_content", settings[counter][1]]];
+    let newPrefs = basePrefs.concat(otherPrefs);
+
+    SpecialPowers.pushPrefEnv({"set": newPrefs}, function () {
+      blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content");
+      blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
+      counter++;
+      callback();
+    });
+  }
+
+  var testsToRun = {
+    object: false,
+  };
+
+  function log(msg) {
+    document.getElementById("log").textContent += "\n" + msg;
+  }
+
+  function reloadFrame() {
+    document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/dom/security/test/mixedcontentblocker/file_main_plugin.html"></iframe>';
+  }
+
+  function checkTestsCompleted() {
+    for (var prop in testsToRun) {
+      // some test hasn't run yet so we're not done
+      if (!testsToRun[prop])
+        return;
+    }
+    //if the testsToRun are all completed, chnage the pref and run the tests again until we have cycled through all the prefs.
+    if(counter < 4) {
+       for (var prop in testsToRun) {
+         testsToRun[prop] = false;
+       }
+      //call to change the preferences
+      changePrefs([], function() {
+        log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+".");
+        reloadFrame();
+      });
+    }
+    else {
+      SimpleTest.finish();
+    }
+  }
+
+  var firstTest = true;
+
+  function receiveMessage(event) {
+    if(firstTest) {
+      log("blockActive set to "+blockActive+", blockDisplay set to "+blockDisplay+".");
+      firstTest = false;
+    }
+
+    log("test: "+event.data.test+", msg: "+event.data.msg + " logging message.");
+    // test that the load type matches the pref for this type of content
+    // (i.e. active vs. display)
+
+    switch(event.data.test) {
+
+      /* Mixed Script tests */
+      case "object":
+        ok(blockActive == (event.data.msg == "insecure object blocked"), "object did not follow block_active_content pref");
+        testsToRun["object"] = true;
+        break;
+
+    }
+    checkTestsCompleted();
+  }
+
+  function startTest() {
+    //Set the first set of mixed content settings and increment the counter.
+    //Enable <picture> and <img srcset> for the test.
+    changePrefs([[ "dom.image.srcset.enabled", true ], [ "dom.image.picture.enabled", true ]],
+      function() {
+        //listen for a messages from the mixed content test harness
+        window.addEventListener("message", receiveMessage, false);
+
+        //Kick off test
+        reloadFrame();
+      }
+    );
+  }
+
+  SimpleTest.waitForExplicitFinish();
+
+  </script>
+</head>
+
+<body onload='startTest()'>
+  <div id="framediv"></div>
+  <pre id="log"></pre>
+</body>
+</html>