dom/bindings/test/test_InstanceOf.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/test/test_InstanceOf.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=748983
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 748983</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=748983">Mozilla Bug 748983</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 748983 **/
    1.24 +
    1.25 +SimpleTest.waitForExplicitFinish();
    1.26 +
    1.27 +function runTest()
    1.28 +{
    1.29 +    ok(document instanceof EventTarget, "document is an event target")
    1.30 +    ok(new XMLHttpRequest() instanceof XMLHttpRequest, "instanceof should work on XHR");
    1.31 +    ok(HTMLElement.prototype instanceof Node, "instanceof needs to walk the prototype chain")
    1.32 +
    1.33 +    var otherWin = document.getElementById("testFrame").contentWindow;
    1.34 +
    1.35 +    ok(otherWin.HTMLElement.prototype instanceof otherWin.Node, "Same-origin instanceof of a interface prototype object should work, even if called cross-origin");
    1.36 +    ok(!(otherWin.HTMLElement.prototype instanceof Node), "Cross-origin instanceof of a interface prototype object shouldn't work");
    1.37 +
    1.38 +    // We need to reset HTMLElement.prototype.__proto__ to the original value
    1.39 +    // before using anything from the harness, otherwise the harness code breaks
    1.40 +    // in weird ways.
    1.41 +    HTMLElement.prototype.__proto__ = otherWin.Element.prototype;
    1.42 +    var [ shouldSucceed, shouldFail ] = otherWin.runTest();
    1.43 +    shouldSucceed = shouldSucceed && HTMLElement.prototype instanceof otherWin.Element;
    1.44 +    shouldFail = shouldFail && HTMLElement.prototype instanceof Element;
    1.45 +    HTMLElement.prototype.__proto__ = Element.prototype;
    1.46 +
    1.47 +    ok(shouldSucceed, "If an interface prototype object is on the protochain then instanceof with the interface object should succeed");
    1.48 +    ok(!shouldFail, "If an interface prototype object is not on the protochain then instanceof with the interface object should succeed");
    1.49 +
    1.50 +    SimpleTest.finish();
    1.51 +}
    1.52 +
    1.53 +</script>
    1.54 +</pre>
    1.55 +<iframe id="testFrame" src="file_InstanceOf.html" onload="runTest()"></iframe>
    1.56 +</body>
    1.57 +</html>

mercurial