tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_InstanceOf.html (2185B)


      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 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">
     19 
     20 /** Test for Bug 748983 */
     21 
     22 SimpleTest.waitForExplicitFinish();
     23 
     24 function runTest() {
     25    ok(document instanceof EventTarget, "document is an event target");
     26    ok(new XMLHttpRequest() instanceof XMLHttpRequest, "instanceof should work on XHR");
     27    ok(HTMLElement.prototype instanceof Node, "instanceof needs to walk the prototype chain");
     28 
     29    var otherWin = document.getElementById("testFrame").contentWindow;
     30 
     31    ok(otherWin.HTMLElement.prototype instanceof otherWin.Node, "Same-origin instanceof of a interface prototype object should work, even if called cross-origin");
     32    ok(!(otherWin.HTMLElement.prototype instanceof Node), "Cross-origin instanceof of a interface prototype object shouldn't work");
     33 
     34    // We need to reset HTMLElement.prototype.__proto__ to the original value
     35    // before using anything from the harness, otherwise the harness code breaks
     36    // in weird ways.
     37    HTMLElement.prototype.__proto__ = otherWin.Element.prototype;
     38    var [ shouldSucceed, shouldFail ] = otherWin.runTest();
     39    shouldSucceed = shouldSucceed && HTMLElement.prototype instanceof otherWin.Element;
     40    shouldFail = shouldFail && HTMLElement.prototype instanceof Element;
     41    HTMLElement.prototype.__proto__ = Element.prototype;
     42 
     43    ok(shouldSucceed, "If an interface prototype object is on the protochain then instanceof with the interface object should succeed");
     44    ok(!shouldFail, "If an interface prototype object is not on the protochain then instanceof with the interface object should succeed");
     45 
     46    SimpleTest.finish();
     47 }
     48 
     49 </script>
     50 </pre>
     51 <iframe id="testFrame" src="file_InstanceOf.html" onload="runTest()"></iframe>
     52 </body>
     53 </html>