4 <link rel=
"help" href=
"http://www.w3.org/TR/2012/WD-dom-20121206/#interface-domimplementation">
5 <script src=
"../../resources/js-test.js"></script>
9 description("Checks that the DOMImplementation api arguments are correctly validated")
11 var testDocument
, testPrototype
, testNamespace
, testQualifiedName
, testDocType
;
12 function validateDocument(document
, prototype, namespace, qualifiedName
, docType
)
14 testDocument
= document
;
15 testPrototype
= prototype;
16 testNamespace
= namespace;
17 testQualifiedName
= qualifiedName
;
18 testDocType
= docType
;
20 shouldBe('testDocument.__proto__', 'window["' + prototype + '"].prototype');
21 if (!testQualifiedName
|| testQualifiedName
== "") {
22 shouldBeNull('testDocument.documentElement');
24 shouldBeEqualToString('testDocument.documentElement.tagName', '' + qualifiedName
);
26 shouldBeEqualToString('testDocument.documentElement.namespaceURI', '' + namespace);
28 shouldBeNull('testDocument.documentElement.namespaceURI');
32 shouldBe('testDocument.doctype', 'testDocType');
34 shouldBeNull('testDocument.doctype');
37 debug('\nDocumentType createDocumentType(DOMString qualifiedName, DOMString publicId, DOMString systemId);');
38 shouldThrow('document.implementation.createDocumentType()', '"TypeError: Failed to execute \'createDocumentType\' on \'DOMImplementation\': 3 arguments required, but only 0 present."');
39 shouldThrow('document.implementation.createDocumentType("qualifiedName")', '"TypeError: Failed to execute \'createDocumentType\' on \'DOMImplementation\': 3 arguments required, but only 1 present."');
40 shouldThrow('document.implementation.createDocumentType("qualifiedName", "publicId")', '"TypeError: Failed to execute \'createDocumentType\' on \'DOMImplementation\': 3 arguments required, but only 2 present."');
42 shouldNotThrow('docType = document.implementation.createDocumentType("qualifiedName", "publicId", "systemId")');
43 shouldBe('docType.__proto__', 'DocumentType.prototype');
44 shouldBeEqualToString('docType.name', 'qualifiedName');
45 shouldBeEqualToString('docType.publicId', 'publicId');
46 shouldBeEqualToString('docType.systemId', 'systemId');
48 debug('\nXMLDocument createDocument(DOMString? namespace, [TreatNullAs=EmptyString] DOMString qualifiedName, DocumentType? doctype);');
49 shouldThrow('document.implementation.createDocument()', '"TypeError: Failed to execute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but only 0 present."');
50 shouldThrow('document.implementation.createDocument("namespace")', '"TypeError: Failed to execute \'createDocument\' on \'DOMImplementation\': 2 arguments required, but only 1 present."');
51 shouldNotThrow('document.implementation.createDocument("namespace", "qualifiedName")');
53 shouldNotThrow('doc = document.implementation.createDocument("namespace", "qualifiedName", null)');
54 validateDocument(doc
, 'XMLDocument', 'namespace', 'qualifiedName', null);
55 shouldNotThrow('doc = document.implementation.createDocument(null, "qualifiedName", null)');
56 validateDocument(doc
, 'XMLDocument', null, 'qualifiedName', null);
57 shouldNotThrow('doc = document.implementation.createDocument("", null, null)')
58 validateDocument(doc
, 'XMLDocument', "", null, null);
59 shouldNotThrow('doc = document.implementation.createDocument("", "", null)')
60 validateDocument(doc
, 'XMLDocument', "", "", null);
61 shouldNotThrow('doc = document.implementation.createDocument("namespace", "qualifiedName")');
62 validateDocument(doc
, 'XMLDocument', "namespace", "qualifiedName", null);
63 shouldNotThrow('doc = document.implementation.createDocument("namespace", "qualifiedName", docType)');
64 validateDocument(doc
, 'XMLDocument', "namespace", "qualifiedName", docType
);
66 debug('\nDocument createHTMLDocument(optional DOMString title);');
67 shouldNotThrow('doc = document.implementation.createHTMLDocument()');
68 validateDocument(doc
, 'HTMLDocument', "http://www.w3.org/1999/xhtml", "HTML", doc
.doctype
);
69 shouldNotThrow('doc = document.implementation.createHTMLDocument("title")');
70 validateDocument(doc
, 'HTMLDocument', "http://www.w3.org/1999/xhtml", "HTML", doc
.doctype
);