docshell/test/chrome/test_principalInherit.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <!-- Any copyright is dedicated to the Public Domain.
     3    - http://creativecommons.org/publicdomain/zero/1.0/ -->
     4 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     5 <?xml-stylesheet
     6   href="chrome://mochikit/content/tests/SimpleTest/test.css"
     7   type="text/css"?>
     8 <!--
     9 https://bugzilla.mozilla.org/show_bug.cgi?id=719994
    10 -->
    11 <window title="Test principal inheriting"
    12   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    14   <script type="application/javascript"
    15           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    17 <body xmlns="http://www.w3.org/1999/xhtml">
    18 <p id="display"></p>
    19 <div id="content" style="display: none">
    20 </div>
    21 <pre id="test">
    22 </pre>
    23 </body>
    25 <script class="testbody" type="application/javascript">
    26 <![CDATA[
    28 /** Test for Bug 719994 **/
    30 SimpleTest.waitForExplicitFinish();
    32 var gFrame;
    34 // This test file is loaded in a type=content docshell whose principal is
    35 // the system principal.
    37 // Using data: URIs here instead of javascript: URIs, since javascript: URIs
    38 // fail to load when there's no principal to load them against. This only
    39 // matters when these tests fail (produces better error messages).
    40 var tests = [
    41   function testInheritFromParent(cb) {
    42     gFrame = document.createElement("iframe");
    43     loadListener(gFrame, function () {
    44       is(window.inheritedFromParent, true, "load in type=content iframe inherited principal of same type parent");
    45       cb();
    46     });
    47     gFrame.setAttribute("type", "content");
    48     gFrame.setAttribute("src", "data:text/html,<script>parent.inheritedFromParent = true;</script>");
    49     document.documentElement.appendChild(gFrame);
    50   },
    51   function testInheritFromCurrent_system(cb) {
    52     loadListener(gFrame, function () {
    53       is(window.inheritedSystem, undefined, "load in type=content iframe shouldn't inherit system principal from current document");
    54       cb();
    55     }, true);
    56     gFrame.setAttribute("src", "data:text/html,<script>parent.inheritedSystem = true;</script>");
    57   },
    58   function testInheritFromCreated(cb) {
    59     // Open a new chrome window with a type="content" iframe, so that it has no
    60     // same-type parent.
    61     // Load a javascript: URI in it to ensure that GetInheritedPrincipal will
    62     // force creation of a content viewer.
    63     let xulWinURL = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?>' +
    64                     '<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>';
    65     let newWin = window.openDialog(xulWinURL, "chrome_window", "chrome");
    66     loadListener(newWin, function () {
    67       let frame = newWin.document.createElement("iframe");
    68       frame.setAttribute("type", "content");
    69       frame.setAttribute("src", "javascript:'1';");
    70       loadListener(frame, function () {
    71         is(frame.contentWindow.document.body.textContent, "1", "content viewer was created");
    72         SimpleTest.executeSoon(function () {
    73           newWin.close();
    74           cb();
    75         })
    76       });
    77       newWin.document.documentElement.appendChild(frame);
    78     });
    79   }
    80 ];
    82 addLoadEvent(function onLoad() {
    83   ok(Components.stack, "this test must be run with the system principal");
    84   SimpleTest.executeSoon(nextTest);
    85 });
    87 function loadListener(target, func) {
    88   target.addEventListener("load", function lis() {
    89     target.removeEventListener("load", lis, true);
    90     func();
    91   }, true);
    92 }
    94 function nextTest() {
    95   if (tests.length) {
    96     let test = tests.shift();
    97     SimpleTest.executeSoon(function () {
    98       info("running " + test.name);
    99       test(nextTest);
   100     });
   101   } else
   102     SimpleTest.executeSoon(SimpleTest.finish);
   103 }
   105 ]]>
   106 </script>
   108 </window>

mercurial