Document-constructor.html (2205B)
1 <!doctype html> 2 <meta charset=windows-1252> 3 <!-- Using windows-1252 to ensure that new Document() doesn't inherit utf-8 4 from the parent document. --> 5 <title>Document constructor</title> 6 <link rel=help href="https://dom.spec.whatwg.org/#dom-document"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <div id="log"></div> 10 <script> 11 test(function() { 12 var doc = new Document(); 13 assert_true(doc instanceof Node, "Should be a Node"); 14 assert_true(doc instanceof Document, "Should be a Document"); 15 assert_false(doc instanceof XMLDocument, "Should not be an XMLDocument"); 16 assert_equals(Object.getPrototypeOf(doc), Document.prototype, 17 "Document should be the primary interface"); 18 }, "new Document(): interfaces") 19 20 test(function() { 21 var doc = new Document(); 22 assert_equals(doc.firstChild, null, "firstChild"); 23 assert_equals(doc.lastChild, null, "lastChild"); 24 assert_equals(doc.doctype, null, "doctype"); 25 assert_equals(doc.documentElement, null, "documentElement"); 26 assert_array_equals(doc.childNodes, [], "childNodes"); 27 }, "new Document(): children") 28 29 test(function() { 30 var doc = new Document(); 31 assert_equals(doc.location, null); 32 assert_equals(doc.URL, "about:blank"); 33 assert_equals(doc.documentURI, "about:blank"); 34 assert_equals(doc.compatMode, "CSS1Compat"); 35 assert_equals(doc.characterSet, "UTF-8"); 36 assert_equals(doc.contentType, "application/xml"); 37 assert_equals(doc.createElement("DIV").localName, "DIV"); 38 assert_equals(doc.createElement("a").constructor, Element); 39 }, "new Document(): metadata") 40 41 test(function() { 42 var doc = new Document(); 43 assert_equals(doc.characterSet, "UTF-8", "characterSet"); 44 assert_equals(doc.charset, "UTF-8", "charset"); 45 assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding"); 46 }, "new Document(): characterSet aliases") 47 48 test(function() { 49 var doc = new Document(); 50 var a = doc.createElementNS("http://www.w3.org/1999/xhtml", "a"); 51 assert_equals(a.constructor, HTMLAnchorElement); 52 // In UTF-8: 0xC3 0xA4 53 a.href = "http://example.org/?\u00E4"; 54 assert_equals(a.href, "http://example.org/?%C3%A4"); 55 }, "new Document(): URL parsing") 56 </script>