OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 <head> |
| 4 <title>Node.nodeName</title> |
| 5 <link rel="author" title="Olli Pettay" href="mailto:Olli@Pettay.fi"/> |
| 6 <link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com"/> |
| 7 <script src="../../../../resources/testharness.js"></script> |
| 8 <script src="../../../../resources/testharnessreport.js"></script> |
| 9 </head> |
| 10 <body> |
| 11 <div id="log"/> |
| 12 <div id="test"> |
| 13 <input type="button" id="testbutton"/> |
| 14 <a id="link">Link text</a> |
| 15 </div> |
| 16 <script> |
| 17 <![CDATA[ |
| 18 test(function() { |
| 19 assert_throws(new TypeError(), function() { |
| 20 document.contains(); |
| 21 }); |
| 22 assert_throws(new TypeError(), function() { |
| 23 document.contains(9); |
| 24 }); |
| 25 }, "Should throw TypeError if the arguments are wrong."); |
| 26 |
| 27 test(function() { |
| 28 assert_equals(document.contains(null), false, "Document shouldn't contain null
."); |
| 29 }, "contains(null) should be false"); |
| 30 |
| 31 test(function() { |
| 32 assert_equals(document.contains(document), true, "Document should contain itse
lf!"); |
| 33 assert_equals(document.contains(document.createElement("foo")), false, "Docume
nt shouldn't contain element which is't in the document"); |
| 34 assert_equals(document.contains(document.createTextNode("foo")), false, "Docum
ent shouldn't contain text node which is't in the document"); |
| 35 }, "document.contains"); |
| 36 |
| 37 test(function() { |
| 38 var tb = document.getElementById("testbutton"); |
| 39 assert_equals(tb.contains(tb), true, "Element should contain itself.") |
| 40 assert_equals(document.contains(tb), true, "Document should contain element in
it!"); |
| 41 assert_equals(document.documentElement.contains(tb), true, "Element should con
tain element in it!"); |
| 42 }, "contains with a button"); |
| 43 |
| 44 test(function() { |
| 45 var link = document.getElementById("link"); |
| 46 var text = link.firstChild; |
| 47 assert_equals(document.contains(text), true, "Document should contain a text n
ode in it."); |
| 48 assert_equals(link.contains(text), true, "Element should contain a text node i
n it."); |
| 49 assert_equals(text.contains(text), true, "Text node should contain itself."); |
| 50 assert_equals(text.contains(link), false, "text node shouldn't contain its par
ent."); |
| 51 }, "contains with a text node"); |
| 52 |
| 53 test(function() { |
| 54 var pi = document.createProcessingInstruction("adf", "asd"); |
| 55 assert_equals(pi.contains(document), false, "Processing instruction shouldn't
contain document"); |
| 56 assert_equals(document.contains(pi), false, "Document shouldn't contain newly
created processing instruction"); |
| 57 document.documentElement.appendChild(pi); |
| 58 document.contains(pi, true, "Document should contain processing instruction"); |
| 59 }, "contains with a processing instruction"); |
| 60 |
| 61 test(function() { |
| 62 if ("createContextualFragment" in document.createRange()) { |
| 63 var df = document.createRange().createContextualFragment("<div>foo</div>"); |
| 64 assert_equals(df.contains(df.firstChild), true, "Document fragment should co
ntain its child"); |
| 65 assert_equals(df.contains(df.firstChild.firstChild), true, |
| 66 "Document fragment should contain its descendant"); |
| 67 assert_equals(df.contains(df), true, "Document fragment should contain itsel
f."); |
| 68 } |
| 69 }, "contains with a document fragment"); |
| 70 |
| 71 test(function() { |
| 72 var d = document.implementation.createHTMLDocument(""); |
| 73 assert_equals(document.contains(d), false, |
| 74 "Document shouldn't contain another document."); |
| 75 assert_equals(document.contains(d.createElement("div")), false, |
| 76 "Document shouldn't contain an element from another document."); |
| 77 assert_equals(document.contains(d.documentElement), false, |
| 78 "Document shouldn't contain an element from another document."); |
| 79 }, "contaibs with another document"); |
| 80 ]]> |
| 81 </script> |
| 82 </body> |
| 83 </html> |
OLD | NEW |