chromium/third_party/blink/web_tests/fast/dom/global-constructors.html

<html>
<head>
<style>
  * {
    color: black;
  }
</style>
<script>
function print(message, color)
{
    var paragraph = document.createElement("div");
    paragraph.appendChild(document.createTextNode(message));
    paragraph.style.fontFamily = "monospace";
    if (color)
        paragraph.style.color = color;
    document.getElementById("console").appendChild(paragraph);
}

function shouldBe(a, b)
{
    var evalA;
    try {
        evalA = eval(a);
    } catch(e) {
        evalA = e;
    }
    if (evalA != b)
        print("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
}

function test()
{
    if (window.testRunner)
        testRunner.dumpAsText();

    domParser = new DOMParser();
    shouldBe("DOMParser.prototype.isPrototypeOf(domParser)", true);

    xmlHttpRequest = new XMLHttpRequest();
    shouldBe("XMLHttpRequest.prototype.isPrototypeOf(xmlHttpRequest)", true);

    xmlSerializer = new XMLSerializer();
    shouldBe("XMLSerializer.prototype.isPrototypeOf(xmlSerializer)", true);

    xsltProcessor = new XSLTProcessor();
    shouldBe("XSLTProcessor.prototype.isPrototypeOf(xsltProcessor)", true);

    shouldBe("window.Document.prototype.isPrototypeOf(document)", true);
    shouldBe("window.HTMLDocument.prototype.isPrototypeOf(document)", true);

    element = document.body;
    shouldBe("window.Node.prototype.isPrototypeOf(element)", true);
    shouldBe("window.Element.prototype.isPrototypeOf(element)", true);
    shouldBe("window.HTMLElement.prototype.isPrototypeOf(element)", true);

    range = document.createRange();
    shouldBe("window.Range.prototype.isPrototypeOf(range)", true);

    cssRule = document.styleSheets[0].cssRules[0];
    shouldBe("window.CSSRule.prototype.isPrototypeOf(cssRule)", true);

    cssStyleDeclaration = cssRule.style;
    shouldBe("window.CSSStyleDeclaration.prototype.isPrototypeOf(cssStyleDeclaration)", true);

    event = document.createEvent("MutationEvents");
    shouldBe("window.Event.prototype.isPrototypeOf(event)", true);
    shouldBe("window.MutationEvent.prototype.isPrototypeOf(event)", true);

    xmldoc = document.implementation.createDocument(null, null, null);
    shouldBe("window.XMLDocument.prototype.isPrototypeOf(xmldoc)", true);

    fragment = document.createDocumentFragment();
    shouldBe("window.DocumentFragment.prototype.isPrototypeOf(fragment)", true);

    xpathevaluator = new XPathEvaluator();
    shouldBe("window.XPathEvaluator.prototype.isPrototypeOf(xpathevaluator)", true);

    xpathresult = xpathevaluator.evaluate('/', document, null, 0, null);
    shouldBe("window.XPathResult.prototype.isPrototypeOf(xpathresult)", true);

    originalNodePrototype = window.Node.prototype;

    deleteResult = delete window.Node.prototype;
    print("[Deleted window.Node.prototype]");
    shouldBe("window.Node.prototype", originalNodePrototype);
    shouldBe("deleteResult", false);

    originalNodeConstructor = window.Node;

    // Attempt to shadow window.Node with a frame named 'Node'
    var iframe = document.createElement('iframe');
    iframe.setAttribute('name', 'Node');
    document.body.appendChild(iframe);
    print("[Added an iframe named 'Node']");
    shouldBe("window.Node", originalNodeConstructor);

    // Shadow window.Node
    window.Node = 1;
    print("[Set window.Node = 1]");
    shouldBe("window.Node", 1);

    // Delete window.Node
    deleteResult = delete window.Node;
    print("[Deleted window.Node]");
    shouldBe("window.Node", iframe.contentWindow);
    shouldBe("deleteResult", true);

    // Delete window.Element
    deleteResult = delete window.Element;
    print("[Deleted window.Element]");
    shouldBe("window.Element", undefined);
    shouldBe("deleteResult", true);
}
</script>
</head>

<body onload="test();">
<p>This page tests global constructor objects like window.HTMLDocument. If it passes, you'll
   see no lines with the text FAIL below.
</p>
<hr>
<div id='console'></div>

</body>
</html>