content/base/test/test_bug450160.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug450160.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=450160
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 450160</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450160">Mozilla Bug 450160</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 450160 **/
    1.24 +
    1.25 +
    1.26 +function testHTMLDocuments(ids, isXHTML) {
    1.27 +  for (var i = 0; i < ids.length; ++i) {
    1.28 +    var docType1 =
    1.29 +      document.implementation.createDocumentType(isXHTML ? "html" : "HTML",
    1.30 +                                                 ids[i],
    1.31 +                                                 null);
    1.32 +    ok(docType1, "No doctype?");
    1.33 +    ok(docType1.ownerDocument, "docType should have ownerDocument!");
    1.34 +    var doc1 = document.implementation.createDocument(null, null, docType1);
    1.35 +    is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
    1.36 +    ok(!doc1.documentElement, "Document shouldn't have document element!");
    1.37 +    is(doc1.body, null, "Shouldn't have .body!");
    1.38 +    ok(doc1 instanceof HTMLDocument,
    1.39 +       "Document should be an HTML document!");
    1.40 +    ok(!(doc1 instanceof SVGDocument),
    1.41 +       "Document shouldn't be an SVG document!");
    1.42 +
    1.43 +    var docType2 =
    1.44 +      document.implementation.createDocumentType(isXHTML ? "html" : "HTML",
    1.45 +                                                 ids[i],
    1.46 +                                                 null);
    1.47 +    var doc2 = document.implementation.createDocument(
    1.48 +      "http://www.w3.org/1999/xhtml", "html", docType2);
    1.49 +    is(docType2.ownerDocument, doc2, "docType should have ownerDocument!");
    1.50 +    ok(doc2.documentElement, "Document should have document element!");
    1.51 +    is(doc2.documentElement.localName, "html", "Wrong document element!");
    1.52 +    is(doc2.body, null, "Shouldn't have .body!");
    1.53 +    doc2.documentElement.appendChild(doc2.createElement("body"));
    1.54 +    is(doc2.body, doc2.documentElement.firstChild, "Should have .body!");
    1.55 +    if (isXHTML) {
    1.56 +      doc2.body.appendChild(doc2.createElementNS("http://www.w3.org/1999/xhtml", "form"));
    1.57 +    } else {
    1.58 +      doc2.body.appendChild(doc2.createElement("form"));
    1.59 +    }
    1.60 +    is(doc2.forms.length, 1, "Form wasn't added .forms");
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +function testSVGDocument() {
    1.65 +  var docType1 =
    1.66 +      document.implementation.createDocumentType("svg",
    1.67 +                                                 "-//W3C//DTD SVG 1.1//EN",
    1.68 +                                                 null);
    1.69 +  ok(docType1, "No doctype?");
    1.70 +  ok(docType1.ownerDocument, "docType should have ownerDocument!");
    1.71 +  var doc1 = document.implementation.createDocument(null, null, docType1);
    1.72 +  is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
    1.73 +  ok(!doc1.documentElement, "Document shouldn't have document element!");
    1.74 +  ok(!(doc1 instanceof HTMLDocument),
    1.75 +     "Document shouldn't be an HTML document!");
    1.76 +  ok(doc1 instanceof SVGDocument,
    1.77 +     "Document should be an SVG document!");
    1.78 +
    1.79 +  // SVG documents have .rootElement.
    1.80 +  ok("rootElement" in doc1, "No .rootElement in document");
    1.81 +
    1.82 +  var docType2 =
    1.83 +      document.implementation.createDocumentType("svg",
    1.84 +                                                 "-//W3C//DTD SVG 1.1//EN",
    1.85 +                                                 null);
    1.86 +  var doc2 = document.implementation.createDocument("http://www.w3.org/2000/svg",
    1.87 +                                                    "svg", docType2);
    1.88 +  ok(doc2.documentElement, "Document should have document element!");
    1.89 +  ok(doc2.rootElement, "Should have .rootElement in document");
    1.90 +  is(doc2.rootElement.localName, "svg", "Wrong .rootElement!");
    1.91 +}
    1.92 +
    1.93 +function testFooBarDocument() {
    1.94 +  var docType1 =
    1.95 +      document.implementation.createDocumentType("FooBar", "FooBar", null);
    1.96 +  ok(docType1, "No doctype?");
    1.97 +  ok(docType1.ownerDocument, "docType should have ownerDocument!");
    1.98 +  var doc1 = document.implementation.createDocument(null, null, docType1);
    1.99 +  is(docType1.ownerDocument, doc1, "docType should have ownerDocument!");
   1.100 +  ok(!doc1.documentElement, "Document shouldn't have document element!");
   1.101 +  ok(!(doc1 instanceof HTMLDocument),
   1.102 +     "Document shouldn't be an HTML document!");
   1.103 +  ok(!(doc1 instanceof SVGDocument),
   1.104 +     "Document shouldn't be an SVG document!");
   1.105 +
   1.106 +  var docType2 =
   1.107 +      document.implementation.createDocumentType("FooBar", "FooBar", null);
   1.108 +  var doc2 = document.implementation.createDocument("FooBarNS",
   1.109 +                                                    "FooBar", docType2);
   1.110 +  ok(doc2.documentElement, "Document should have document element!");
   1.111 +  is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!");
   1.112 +  is(doc2.documentElement.localName, "FooBar", "Wrong localName!");
   1.113 +}
   1.114 +
   1.115 +function testNullDocTypeDocument() {
   1.116 +  var doc1 = document.implementation.createDocument(null, null, null);
   1.117 +  ok(!doc1.documentElement, "Document shouldn't have document element!");
   1.118 +  ok(!(doc1 instanceof HTMLDocument),
   1.119 +     "Document shouldn't be an HTML document!");
   1.120 +  ok(!(doc1 instanceof SVGDocument),
   1.121 +     "Document shouldn't be an SVG document!");
   1.122 +
   1.123 +  var doc2 = document.implementation.createDocument("FooBarNS",
   1.124 +                                                    "FooBar", null);
   1.125 +  ok(doc2.documentElement, "Document should have document element!");
   1.126 +  is(doc2.documentElement.namespaceURI, "FooBarNS", "Wrong namespaceURI!");
   1.127 +  is(doc2.documentElement.localName, "FooBar", "Wrong localName!");
   1.128 +}
   1.129 +
   1.130 +var htmlPublicIDs = 
   1.131 +  [ "-//W3C//DTD HTML 4.01//EN",
   1.132 +    "-//W3C//DTD HTML 4.01 Transitional//EN",
   1.133 +    "-//W3C//DTD HTML 4.01 Frameset//EN",
   1.134 +    "-//W3C//DTD HTML 4.0//EN",
   1.135 +    "-//W3C//DTD HTML 4.0 Transitional//EN",
   1.136 +    "-//W3C//DTD HTML 4.0 Frameset//EN" ];
   1.137 +
   1.138 +var xhtmlPublicIDs =
   1.139 + [ "-//W3C//DTD XHTML 1.0 Strict//EN",
   1.140 +   "-//W3C//DTD XHTML 1.0 Transitional//EN",
   1.141 +   "-//W3C//DTD XHTML 1.0 Frameset//EN" ];
   1.142 +
   1.143 +testHTMLDocuments(htmlPublicIDs, false);
   1.144 +testHTMLDocuments(xhtmlPublicIDs, true);
   1.145 +testSVGDocument();
   1.146 +testFooBarDocument();
   1.147 +testNullDocTypeDocument();
   1.148 +
   1.149 +</script>
   1.150 +</pre>
   1.151 +</body>
   1.152 +</html>

mercurial