content/base/test/test_mixed_content_blocker.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 Tests for Mixed Content Blocker
     5 https://bugzilla.mozilla.org/show_bug.cgi?id=62178
     6 -->
     7 <head>
     8   <meta charset="utf-8">
     9   <title>Tests for Bug 62178</title>
    10   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    11   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    13   <script>
    14   var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
    15                         .getService(SpecialPowers.Ci.nsIPluginHost);
    16   var tags = ph.getPluginTags();
    17   for (var tag of tags) {
    18     if (tag.name == "Test Plug-in") {
    19       tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;;
    20     }
    21   }
    24   var origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content");
    25   var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
    27   var counter = 0;
    28   var settings = [ [true, true], [true, false], [false, true], [false, false] ];
    30   var blockActive;
    31   var blockDisplay;
    33   //Cycle through 4 different preference settings.
    34   function changePrefs(x) {
    35     SpecialPowers.setBoolPref("security.mixed_content.block_display_content", settings[x][0]);
    36     SpecialPowers.setBoolPref("security.mixed_content.block_active_content", settings[x][1]);
    37     blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content");
    38     blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
    39   }
    41   //Set the first set of settings (true, true) and increment the counter.
    42   changePrefs(counter);
    43   counter++;
    45   var testsToRun = {
    46     iframe: false,
    47     image: false,
    48     script: false,
    49     stylesheet: false,
    50     object: false,
    51     media: false,
    52     xhr: false,
    53   };
    55   function log(msg) {
    56     document.getElementById("log").textContent += "\n" + msg;
    57   }
    59   function checkTestsCompleted() {
    60     for (var prop in testsToRun) {
    61       // some test hasn't run yet so we're not done
    62       if (!testsToRun[prop])
    63         return;
    64     }
    65     //if the testsToRun are all completed, chnage the pref and run the tests again until we have cycled through all the prefs.
    66     if(counter < 4) {
    67        for (var prop in testsToRun) {
    68          testsToRun[prop] = false;
    69        }
    70       //call to change the preferences
    71       changePrefs(counter);
    72       counter++;
    73       log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+".");
    74       document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main.html"></iframe>';
    75     }
    76     else {
    77       //set the prefs back to what they were set to originally
    78       SpecialPowers.setBoolPref("security.mixed_content.block_display_content", origBlockDisplay);
    79       SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive);
    80       SimpleTest.finish();
    81     }
    82   }
    84   var firstTest = true;
    86   // listen for a messages from the mixed content test harness
    87   window.addEventListener("message", receiveMessage, false);
    88   function receiveMessage(event) {
    89     if(firstTest) {
    90       log("blockActive set to "+blockActive+", blockDisplay set to "+blockDisplay+".");
    91       firstTest = false;
    92     }
    94     log("test: "+event.data.test+", msg: "+event.data.msg + " logging message.");
    95     // test that the load type matches the pref for this type of content
    96     // (i.e. active vs. display)
    98     switch(event.data.test) {
   100       /* Mixed Script tests */
   101       case "iframe":
   102         ok(blockActive == (event.data.msg == "insecure iframe blocked"), "iframe did not follow block_active_content pref");
   103         testsToRun["iframe"] = true;
   104         break;
   106       case "object":
   107         ok(blockActive == (event.data.msg == "insecure object blocked"), "object did not follow block_active_content pref");
   108         testsToRun["object"] = true;
   109         break;
   111       case "script":
   112         ok(blockActive == (event.data.msg == "insecure script blocked"), "script did not follow block_active_content pref");
   113         testsToRun["script"] = true;
   114         break;
   116       case "stylesheet":
   117         ok(blockActive == (event.data.msg == "insecure stylesheet blocked"), "stylesheet did not follow block_active_content pref");
   118         testsToRun["stylesheet"] = true;
   119         break;
   121       case "xhr":
   122         ok(blockActive == (event.data.msg == "insecure xhr blocked"), "xhr did not follow block_active_content pref");
   123         testsToRun["xhr"] = true;
   124         break;
   126       /* Mixed Display tests */
   127       case "image":
   128         //test that the image load matches the pref for dipslay content
   129         ok(blockDisplay == (event.data.msg == "insecure image blocked"), "image did not follow block_display_content pref");
   130         testsToRun["image"] = true;
   131         break;
   133       case "media":
   134         ok(blockDisplay == (event.data.msg == "insecure media blocked"), "media did not follow block_display_content pref");
   135         testsToRun["media"] = true;
   136         break;
   137     }
   138     checkTestsCompleted();
   139   }
   141   SimpleTest.waitForExplicitFinish();
   142   </script>
   143 </head>
   145 <body>
   146   <div id="framediv">
   147     <iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main.html"></iframe>
   148   </div>
   149   <pre id="log"></pre>
   150 </body>
   151 </html>

mercurial