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