dom/bindings/test/test_InstanceOf.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=748983
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 748983</title>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=748983">Mozilla Bug 748983</a>
    14 <p id="display"></p>
    15 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 <script type="application/javascript">
    20 /** Test for Bug 748983 **/
    22 SimpleTest.waitForExplicitFinish();
    24 function runTest()
    25 {
    26     ok(document instanceof EventTarget, "document is an event target")
    27     ok(new XMLHttpRequest() instanceof XMLHttpRequest, "instanceof should work on XHR");
    28     ok(HTMLElement.prototype instanceof Node, "instanceof needs to walk the prototype chain")
    30     var otherWin = document.getElementById("testFrame").contentWindow;
    32     ok(otherWin.HTMLElement.prototype instanceof otherWin.Node, "Same-origin instanceof of a interface prototype object should work, even if called cross-origin");
    33     ok(!(otherWin.HTMLElement.prototype instanceof Node), "Cross-origin instanceof of a interface prototype object shouldn't work");
    35     // We need to reset HTMLElement.prototype.__proto__ to the original value
    36     // before using anything from the harness, otherwise the harness code breaks
    37     // in weird ways.
    38     HTMLElement.prototype.__proto__ = otherWin.Element.prototype;
    39     var [ shouldSucceed, shouldFail ] = otherWin.runTest();
    40     shouldSucceed = shouldSucceed && HTMLElement.prototype instanceof otherWin.Element;
    41     shouldFail = shouldFail && HTMLElement.prototype instanceof Element;
    42     HTMLElement.prototype.__proto__ = Element.prototype;
    44     ok(shouldSucceed, "If an interface prototype object is on the protochain then instanceof with the interface object should succeed");
    45     ok(!shouldFail, "If an interface prototype object is not on the protochain then instanceof with the interface object should succeed");
    47     SimpleTest.finish();
    48 }
    50 </script>
    51 </pre>
    52 <iframe id="testFrame" src="file_InstanceOf.html" onload="runTest()"></iframe>
    53 </body>
    54 </html>

mercurial