docshell/test/iframesandbox/test_our_auxiliary_navigation_by_location.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/iframesandbox/test_our_auxiliary_navigation_by_location.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=785310
     1.8 +html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
     1.9 +-->
    1.10 +<head>
    1.11 +<meta charset="utf-8">
    1.12 +<title>Test for Bug 785310 - iframe sandbox our auxiliary navigation by location tests</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 +  SimpleTest.waitForExplicitFinish();
    1.18 +
    1.19 +  function runScriptNavigationTest(testCase) {
    1.20 +    window.onmessage = function(event) {
    1.21 +      if (event.data != "ourWindow") {
    1.22 +        ok(false, "event.data: got '" + event.data + "', expected 'ourWindow'");
    1.23 +      }
    1.24 +      ok(!testCase.shouldBeBlocked, testCase.desc, "auxiliary navigation was NOT blocked");
    1.25 +      runNextTest();
    1.26 +    };
    1.27 +    try {
    1.28 +      SpecialPowers.wrap(window["testIframe"]).eval(testCase.script);
    1.29 +    } catch(e) {
    1.30 +      ok(testCase.shouldBeBlocked, testCase.desc, SpecialPowers.wrap(e).message);
    1.31 +      runNextTest();
    1.32 +    }
    1.33 +  }
    1.34 +
    1.35 +  var testCaseIndex = -1;
    1.36 +  testCases = [
    1.37 +    {
    1.38 +      desc: "Test 1: location.replace on auxiliary opened by us should NOT be blocked",
    1.39 +      script: "openedWindow.location.replace('file_our_auxiliary_navigation_by_location.html')",
    1.40 +      shouldBeBlocked: false
    1.41 +    },
    1.42 +    {
    1.43 +      desc: "Test 2: location.assign on auxiliary opened by us should be blocked without allow-same-origin",
    1.44 +      script: "openedWindow.location.assign('file_our_auxiliary_navigation_by_location.html')",
    1.45 +      shouldBeBlocked: true
    1.46 +    },
    1.47 +    {
    1.48 +      desc: "Test 3: location.href on auxiliary opened by us should NOT be blocked",
    1.49 +      script: "openedWindow.location.href = 'file_our_auxiliary_navigation_by_location.html'",
    1.50 +      shouldBeBlocked: false
    1.51 +    },
    1.52 +    {
    1.53 +      desc: "Test 4: location.hash on auxiliary opened by us should be blocked without allow-same-origin",
    1.54 +      script: "openedWindow.location.hash = 'wibble'",
    1.55 +      shouldBeBlocked: true
    1.56 +    }
    1.57 +  ];
    1.58 +
    1.59 +  function runNextTest() {
    1.60 +    ++testCaseIndex;
    1.61 +    if (testCaseIndex == testCases.length) {
    1.62 +      SpecialPowers.wrap(window["testIframe"]).eval("openedWindow.close()");
    1.63 +      SimpleTest.finish();
    1.64 +      return;
    1.65 +    }
    1.66 +
    1.67 +    runScriptNavigationTest(testCases[testCaseIndex]);
    1.68 +  }
    1.69 +
    1.70 +  window.onmessage = runNextTest;
    1.71 +
    1.72 +  window.onload = function() {
    1.73 +    SpecialPowers.wrap(window["testIframe"]).eval("var openedWindow = window.open('file_our_auxiliary_navigation_by_location.html', 'ourWindow')");
    1.74 +  }
    1.75 +</script>
    1.76 +
    1.77 +</head>
    1.78 +<body>
    1.79 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
    1.80 +<p id="display"></p>
    1.81 +<div id="content">
    1.82 +Tests for Bug 785310
    1.83 +</div>
    1.84 +
    1.85 +<iframe name="testIframe" sandbox="allow-scripts allow-popups"></iframe>
    1.86 +</body>
    1.87 +</html>

mercurial