dom/tests/mochitest/webcomponents/test_document_shared_registry.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=783129
     5 -->
     6 <head>
     7   <title>Test shared registry for associated HTML documents.</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body>
    12 <div id="container"></div>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=783129">Bug 783129</a>
    14 <script>
    15 var container = document.getElementById("container");
    17 function createdCallbackFromMainDoc() {
    18   var createdCallbackCalled = false;
    19   var assocDoc = document.implementation.createHTMLDocument();
    21   var proto = Object.create(HTMLElement.prototype);
    22   proto.createdCallback = function() {
    23     is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    24     createdCallbackCalled = true;
    25     runNextTest();
    26   };
    28   assocDoc.registerElement("x-associated-doc-callback-elem", { prototype: proto });
    29   document.createElement("x-associated-doc-callback-elem");
    30 }
    32 function createdCallbackFromAssociatedDoc() {
    33   var createdCallbackCalled = false;
    34   var assocDoc = document.implementation.createHTMLDocument();
    36   var proto = Object.create(HTMLElement.prototype);
    37   proto.createdCallback = function() {
    38     is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    39     createdCallbackCalled = true;
    40     runNextTest();
    41   };
    43   assocDoc.registerElement("x-main-doc-callback-elem", { prototype: proto });
    44   assocDoc.createElement("x-main-doc-callback-elem");
    45 }
    47 function createdCallbackFromDocHTMLNamespace() {
    48   var createdCallbackCalled = false;
    49   var assocDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
    50   var somediv = assocDoc.createElement("div");
    52   var proto = Object.create(HTMLElement.prototype);
    53   proto.createdCallback = function() {
    54     is(createdCallbackCalled, false, "created callback should only be called once in this tests.");
    55     createdCallbackCalled = true;
    56     runNextTest();
    57   };
    59   assocDoc.registerElement("x-assoc-doc-with-ns-callback-elem", { prototype: proto });
    60   document.createElement("x-assoc-doc-with-ns-callback-elem");
    61 }
    63 function registerNoRegistryDoc() {
    64   var assocDoc = document.implementation.createDocument(null, "html");
    65   try {
    66     assocDoc.registerElement("x-dummy", { prototype: Object.create(HTMLElement.prototype) });
    67     ok(false, "Registring element in document without registry should throw.");
    68   } catch (ex) {
    69     ok(true, "Registring element in document without registry should throw.");
    70   }
    72   runNextTest();
    73 }
    75 function runNextTest() {
    76   if (testFunctions.length > 0) {
    77     var nextTestFunction = testFunctions.shift();
    78     nextTestFunction();
    79   }
    80 }
    82 var testFunctions = [
    83   createdCallbackFromAssociatedDoc,
    84   createdCallbackFromMainDoc,
    85   createdCallbackFromDocHTMLNamespace,
    86   registerNoRegistryDoc,
    87   SimpleTest.finish
    88 ];
    90 SimpleTest.waitForExplicitFinish();
    92 runNextTest();
    93 </script>
    94 </body>
    95 </html>

mercurial