content/base/test/test_mixed_content_blocker_frameNavigation.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_mixed_content_blocker_frameNavigation.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +Tests for Mixed Content Blocker
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=840388
     1.9 +-->
    1.10 +<head>
    1.11 +  <meta charset="utf-8">
    1.12 +  <title>Tests for Bug 840388</title>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +
    1.16 +  <script>
    1.17 +  var counter = 0;
    1.18 +  var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
    1.19 +
    1.20 +  SpecialPowers.setBoolPref("security.mixed_content.block_active_content", true);
    1.21 +  var blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
    1.22 +
    1.23 +
    1.24 +  var testsToRunInsecure = {
    1.25 +    insecurePage_navigate_child: false,
    1.26 +    insecurePage_navigate_grandchild: false,
    1.27 +  };
    1.28 +
    1.29 +  var testsToRunSecure = {
    1.30 +    securePage_navigate_child: false,
    1.31 +    blankTarget: false,
    1.32 +  };
    1.33 +
    1.34 +  function log(msg) {
    1.35 +    document.getElementById("log").textContent += "\n" + msg;
    1.36 +  }
    1.37 +
    1.38 +  var secureTestsStarted = false;
    1.39 +  function checkTestsCompleted() {
    1.40 +    for (var prop in testsToRunInsecure) {
    1.41 +      // some test hasn't run yet so we're not done
    1.42 +      if (!testsToRunInsecure[prop])
    1.43 +        return;
    1.44 +    }
    1.45 +    // If we are here, all the insecure tests have run.
    1.46 +    // If we haven't changed the iframe to run the secure tests, change it now.
    1.47 +    if (!secureTestsStarted) {
    1.48 +      document.getElementById('testing_frame').src = "https://example.com/tests/content/base/test/file_mixed_content_frameNavigation_secure.html";
    1.49 +      secureTestsStarted = true;
    1.50 +    }
    1.51 +    for (var prop in testsToRunSecure) {
    1.52 +      // some test hasn't run yet so we're not done
    1.53 +      if (!testsToRunSecure[prop])
    1.54 +        return;
    1.55 +    }
    1.56 +    //if the secure and insecure testsToRun are all completed, change the block mixed active content pref and run the tests again.
    1.57 +    if(counter < 1) {
    1.58 +       for (var prop in testsToRunSecure) {
    1.59 +         testsToRunSecure[prop] = false;
    1.60 +       }
    1.61 +       for (var prop in testsToRunInsecure) {
    1.62 +         testsToRunInsecure[prop] = false;
    1.63 +       }
    1.64 +      //call to change the preferences
    1.65 +      counter++;
    1.66 +      SpecialPowers.setBoolPref("security.mixed_content.block_active_content", false);
    1.67 +      blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content");
    1.68 +      log("blockActive set to "+blockActive+".");
    1.69 +      secureTestsStarted = false;
    1.70 +      document.getElementById('framediv').innerHTML = '<iframe src="http://example.com/tests/content/base/test/file_mixed_content_frameNavigation.html" id="testing_frame"></iframe>';
    1.71 +    }
    1.72 +    else {
    1.73 +      //set the prefs back to what they were set to originally
    1.74 +      SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive);
    1.75 +      SimpleTest.finish();
    1.76 +    }
    1.77 +  }
    1.78 +
    1.79 +  var firstTestDebugMessage = true;
    1.80 +
    1.81 +  // listen for a messages from the mixed content test harness
    1.82 +  window.addEventListener("message", receiveMessage, false);
    1.83 +  function receiveMessage(event) {
    1.84 +    if(firstTestDebugMessage) {
    1.85 +      log("blockActive set to "+blockActive);
    1.86 +      firstTestDebugMessage = false;
    1.87 +    }
    1.88 +
    1.89 +    log("test: "+event.data.test+", msg: "+event.data.msg + ".");
    1.90 +    // test that the load type matches the pref for this type of content
    1.91 +    // (i.e. active vs. display)
    1.92 +
    1.93 +    switch(event.data.test) {
    1.94 +
    1.95 +      case "insecurePage_navigate_child":
    1.96 +        ok((event.data.msg == "navigated to insecure iframe on insecure page"), "navigating to insecure iframe blocked on insecure page");
    1.97 +        testsToRunInsecure["insecurePage_navigate_child"] = true;
    1.98 +        break;
    1.99 +
   1.100 +      case "insecurePage_navigate_grandchild":
   1.101 +        ok((event.data.msg == "navigated to insecure grandchild iframe on insecure page"), "navigating to insecure grandchild iframe blocked on insecure page");
   1.102 +        testsToRunInsecure["insecurePage_navigate_grandchild"] = true;
   1.103 +        break;
   1.104 +
   1.105 +      case "securePage_navigate_child":
   1.106 +        ok(blockActive == (event.data.msg == "navigating to insecure iframe blocked on secure page"), "navigated to insecure iframe on secure page");
   1.107 +        testsToRunSecure["securePage_navigate_child"] = true;
   1.108 +        break;
   1.109 +
   1.110 +      case "blankTarget":
   1.111 +        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");
   1.112 +        testsToRunSecure["blankTarget"] = true;
   1.113 +        break;
   1.114 +
   1.115 +    }
   1.116 +    checkTestsCompleted();
   1.117 +  }
   1.118 +
   1.119 +  SimpleTest.waitForExplicitFinish();
   1.120 +  </script>
   1.121 +</head>
   1.122 +
   1.123 +<body>
   1.124 +  <div id="framediv">
   1.125 +    <iframe src="http://example.com/tests/content/base/test/file_mixed_content_frameNavigation.html" id="testing_frame"></iframe>
   1.126 +  </div>
   1.127 +
   1.128 +  <pre id="log"></pre>
   1.129 +</body>
   1.130 +</html>

mercurial