docshell/test/iframesandbox/test_parent_navigation_by_location.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 https://bugzilla.mozilla.org/show_bug.cgi?id=785310
     5 html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
     6 -->
     7 <head>
     8 <meta charset="utf-8">
     9 <title>Test for Bug 785310 - iframe sandbox parent navigation by location tests</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   SimpleTest.waitForExplicitFinish();
    16   function runScriptNavigationTest(testCase) {
    17     window.onmessage = function(event) {
    18       if (event.data != "parentIframe") {
    19         ok(false, "event.data: got '" + event.data + "', expected 'parentIframe'");
    20       }
    21       ok(false, testCase.desc, "parent navigation was NOT blocked");
    22       runNextTest();
    23     };
    24     try {
    25       window["parentIframe"]["childIframe"].eval(testCase.script);
    26     } catch(e) {
    27       ok(true, testCase.desc, e.message);
    28       runNextTest();
    29     }
    30   }
    32   var testCaseIndex = -1;
    33   testCases = [
    34     {
    35       desc: "Test 1: parent.location.replace should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
    36       script: "parent.location.replace('file_parent_navigation_by_location.html')"
    37     },
    38     {
    39       desc: "Test 2: parent.location.assign should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
    40       script: "parent.location.assign('file_parent_navigation_by_location.html')"
    41     },
    42     {
    43       desc: "Test 3: parent.location.href should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
    44       script: "parent.location.href = 'file_parent_navigation_by_location.html'"
    45     },
    46     {
    47       desc: "Test 4: parent.location.hash should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
    48       script: "parent.location.hash = 'wibble'"
    49     }
    50   ];
    52   function runNextTest() {
    53     ++testCaseIndex;
    54     if (testCaseIndex == testCases.length) {
    55       SimpleTest.finish();
    56       return;
    57     }
    59     runScriptNavigationTest(testCases[testCaseIndex]);
    60   }
    62   window.onmessage = runNextTest;
    63 </script>
    64 </head>
    65 <body>
    66 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
    67 <p id="display"></p>
    68 <div id="content">
    69 Tests for Bug 785310
    70 </div>
    72 <iframe name="parentIframe" src="file_parent_navigation_by_location.html"></iframe>
    74 </body>
    75 </html>

mercurial