Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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=840388 |
michael@0 | 6 | --> |
michael@0 | 7 | <head> |
michael@0 | 8 | <meta charset="utf-8"> |
michael@0 | 9 | <title>Tests for Bug 840388</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 counter = 0; |
michael@0 | 15 | var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
michael@0 | 16 | |
michael@0 | 17 | SpecialPowers.setBoolPref("security.mixed_content.block_active_content", true); |
michael@0 | 18 | var blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | var testsToRunInsecure = { |
michael@0 | 22 | insecurePage_navigate_child: false, |
michael@0 | 23 | insecurePage_navigate_grandchild: false, |
michael@0 | 24 | }; |
michael@0 | 25 | |
michael@0 | 26 | var testsToRunSecure = { |
michael@0 | 27 | securePage_navigate_child: false, |
michael@0 | 28 | blankTarget: false, |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | function log(msg) { |
michael@0 | 32 | document.getElementById("log").textContent += "\n" + msg; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | var secureTestsStarted = false; |
michael@0 | 36 | function checkTestsCompleted() { |
michael@0 | 37 | for (var prop in testsToRunInsecure) { |
michael@0 | 38 | // some test hasn't run yet so we're not done |
michael@0 | 39 | if (!testsToRunInsecure[prop]) |
michael@0 | 40 | return; |
michael@0 | 41 | } |
michael@0 | 42 | // If we are here, all the insecure tests have run. |
michael@0 | 43 | // If we haven't changed the iframe to run the secure tests, change it now. |
michael@0 | 44 | if (!secureTestsStarted) { |
michael@0 | 45 | document.getElementById('testing_frame').src = "https://example.com/tests/content/base/test/file_mixed_content_frameNavigation_secure.html"; |
michael@0 | 46 | secureTestsStarted = true; |
michael@0 | 47 | } |
michael@0 | 48 | for (var prop in testsToRunSecure) { |
michael@0 | 49 | // some test hasn't run yet so we're not done |
michael@0 | 50 | if (!testsToRunSecure[prop]) |
michael@0 | 51 | return; |
michael@0 | 52 | } |
michael@0 | 53 | //if the secure and insecure testsToRun are all completed, change the block mixed active content pref and run the tests again. |
michael@0 | 54 | if(counter < 1) { |
michael@0 | 55 | for (var prop in testsToRunSecure) { |
michael@0 | 56 | testsToRunSecure[prop] = false; |
michael@0 | 57 | } |
michael@0 | 58 | for (var prop in testsToRunInsecure) { |
michael@0 | 59 | testsToRunInsecure[prop] = false; |
michael@0 | 60 | } |
michael@0 | 61 | //call to change the preferences |
michael@0 | 62 | counter++; |
michael@0 | 63 | SpecialPowers.setBoolPref("security.mixed_content.block_active_content", false); |
michael@0 | 64 | blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
michael@0 | 65 | log("blockActive set to "+blockActive+"."); |
michael@0 | 66 | secureTestsStarted = false; |
michael@0 | 67 | document.getElementById('framediv').innerHTML = '<iframe src="http://example.com/tests/content/base/test/file_mixed_content_frameNavigation.html" id="testing_frame"></iframe>'; |
michael@0 | 68 | } |
michael@0 | 69 | else { |
michael@0 | 70 | //set the prefs back to what they were set to originally |
michael@0 | 71 | SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); |
michael@0 | 72 | SimpleTest.finish(); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | var firstTestDebugMessage = true; |
michael@0 | 77 | |
michael@0 | 78 | // listen for a messages from the mixed content test harness |
michael@0 | 79 | window.addEventListener("message", receiveMessage, false); |
michael@0 | 80 | function receiveMessage(event) { |
michael@0 | 81 | if(firstTestDebugMessage) { |
michael@0 | 82 | log("blockActive set to "+blockActive); |
michael@0 | 83 | firstTestDebugMessage = false; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | log("test: "+event.data.test+", msg: "+event.data.msg + "."); |
michael@0 | 87 | // test that the load type matches the pref for this type of content |
michael@0 | 88 | // (i.e. active vs. display) |
michael@0 | 89 | |
michael@0 | 90 | switch(event.data.test) { |
michael@0 | 91 | |
michael@0 | 92 | case "insecurePage_navigate_child": |
michael@0 | 93 | ok((event.data.msg == "navigated to insecure iframe on insecure page"), "navigating to insecure iframe blocked on insecure page"); |
michael@0 | 94 | testsToRunInsecure["insecurePage_navigate_child"] = true; |
michael@0 | 95 | break; |
michael@0 | 96 | |
michael@0 | 97 | case "insecurePage_navigate_grandchild": |
michael@0 | 98 | ok((event.data.msg == "navigated to insecure grandchild iframe on insecure page"), "navigating to insecure grandchild iframe blocked on insecure page"); |
michael@0 | 99 | testsToRunInsecure["insecurePage_navigate_grandchild"] = true; |
michael@0 | 100 | break; |
michael@0 | 101 | |
michael@0 | 102 | case "securePage_navigate_child": |
michael@0 | 103 | ok(blockActive == (event.data.msg == "navigating to insecure iframe blocked on secure page"), "navigated to insecure iframe on secure page"); |
michael@0 | 104 | testsToRunSecure["securePage_navigate_child"] = true; |
michael@0 | 105 | break; |
michael@0 | 106 | |
michael@0 | 107 | case "blankTarget": |
michael@0 | 108 | ok((event.data.msg == "opened an http link with target=_blank from a secure page"), "couldn't open an http link in a new window from a secure page"); |
michael@0 | 109 | testsToRunSecure["blankTarget"] = true; |
michael@0 | 110 | break; |
michael@0 | 111 | |
michael@0 | 112 | } |
michael@0 | 113 | checkTestsCompleted(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 117 | </script> |
michael@0 | 118 | </head> |
michael@0 | 119 | |
michael@0 | 120 | <body> |
michael@0 | 121 | <div id="framediv"> |
michael@0 | 122 | <iframe src="http://example.com/tests/content/base/test/file_mixed_content_frameNavigation.html" id="testing_frame"></iframe> |
michael@0 | 123 | </div> |
michael@0 | 124 | |
michael@0 | 125 | <pre id="log"></pre> |
michael@0 | 126 | </body> |
michael@0 | 127 | </html> |