OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <!-- |
| 3 Distributed under both the W3C Test Suite License [1] and the W3C |
| 4 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
| 5 policies and contribution forms [3]. |
| 6 |
| 7 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
| 8 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
| 9 [3] http://www.w3.org/2004/10/27-testcases |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 <title>Shadow DOM Test: Upper-boundary encapsuration on ownerDocument: basic tes
ts</title> |
| 14 <link rel="author" title="Aleksei Yu. Semenov" href="mailto:sgrekhov@unipro.ru"> |
| 15 <link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> |
| 16 <link rel="author" title="Mikhail Fursov" href="mailto:mfursov@unipro.ru"> |
| 17 <link rel="author" title="Yuta Kitamura" href="mailto:yutak@google.com"> |
| 18 <link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#upper-b
oundary-encapsulation"> |
| 19 <meta name="assert" content="Upper-boundary encapsulation: The ownerDocument pro
perty of all nodes in shadow tree refers to the document of the shadow host."> |
| 20 <script src="../../../../../resources/testharness.js"></script> |
| 21 <script src="../../../../../resources/testharnessreport.js"></script> |
| 22 <script src="../../testcommon.js"></script> |
| 23 <link rel="stylesheet" href="../../../../../resources/testharness.css"> |
| 24 </head> |
| 25 <body> |
| 26 <div id="log"></div> |
| 27 <script> |
| 28 test(function () { |
| 29 var doc = document.implementation.createHTMLDocument('Test'); |
| 30 doc.body.innerHTML = '<div>A<div>B</div>C<div><span>D</span></div>E</div>'; |
| 31 var nodeIterator = doc.createNodeIterator(doc.documentElement, |
| 32 NodeFilter.SHOW_ELEMENT, null); |
| 33 var node; |
| 34 while (node = nodeIterator.nextNode()) { |
| 35 var shadowRoot = node.createShadowRoot(); |
| 36 assert_equals(shadowRoot.ownerDocument, doc); |
| 37 } |
| 38 }, 'ownerDocument property of a shadow root should be the document of the ' + |
| 39 'shadow host, regardless of the location of the shadow host.'); |
| 40 |
| 41 test(function () { |
| 42 var MAX_DEPTH = 16; |
| 43 var doc = document.implementation.createHTMLDocument('Test'); |
| 44 var tail = doc.body; |
| 45 for (var depth = 1; depth <= MAX_DEPTH; ++depth) { |
| 46 var div = doc.createElement('div'); |
| 47 div.id = 'depth-' + depth; |
| 48 tail.appendChild(div); |
| 49 tail = div; |
| 50 } |
| 51 |
| 52 for (var depth = 1; depth <= MAX_DEPTH; ++depth) { |
| 53 var host = doc.getElementById('depth-' + depth); |
| 54 var shadowRoot = host.createShadowRoot(); |
| 55 assert_equals(shadowRoot.ownerDocument, doc, |
| 56 'ownerDocument mismatch for #depth-' + depth); |
| 57 } |
| 58 }, 'ownerDocument property of elements in a shadow tree should match ' + |
| 59 'the document of the shadow host, regardless of the element\'s location ' + |
| 60 'in a shadow tree.'); |
| 61 |
| 62 test(function () { |
| 63 var doc = document.implementation.createHTMLDocument('Test'); |
| 64 var shadowRoot = doc.body.createShadowRoot(); |
| 65 var div = doc.createElement('div'); |
| 66 shadowRoot.appendChild(div); |
| 67 assert_equals(div.ownerDocument, doc); |
| 68 }, 'Elements added to a shadow tree should automatically get a valid ' + |
| 69 'ownerDocument.'); |
| 70 |
| 71 test(function () { |
| 72 var doc1 = document.implementation.createHTMLDocument('Test 1'); |
| 73 var doc2 = document.implementation.createHTMLDocument('Test 2'); |
| 74 var shadowRoot = doc1.body.createShadowRoot(); |
| 75 var div = doc2.createElement('div'); |
| 76 shadowRoot.appendChild(div); |
| 77 assert_equals(div.ownerDocument, doc1); |
| 78 }, 'ownerDocument property of an element in a shadow tree should be the ' + |
| 79 'document of the shadow host, even if the host element is created from ' + |
| 80 'another document.'); |
| 81 |
| 82 test(function () { |
| 83 var doc1 = document.implementation.createHTMLDocument('Test 1'); |
| 84 var doc2 = document.implementation.createHTMLDocument('Test 2'); |
| 85 var shadowRoot = doc1.body.createShadowRoot(); |
| 86 doc2.body.innerHTML = |
| 87 '<div id="root">A<div>B</div>C<div><span>D</span></div>E</div>'; |
| 88 shadowRoot.appendChild(doc2.getElementById('root')); |
| 89 var nodeIterator = doc1.createNodeIterator( |
| 90 shadowRoot.getElementById('root'), 0xFFFFFFFF, null); |
| 91 var node; |
| 92 while (node = nodeIterator.nextNode()) { |
| 93 assert_equals(node.ownerDocument, doc1); |
| 94 } |
| 95 }, 'All children nodes of a shadow root get a valid ownerDocument when ' + |
| 96 'added to a shadow tree.'); |
| 97 |
| 98 test(function () { |
| 99 var doc1 = document.implementation.createHTMLDocument('Test 1'); |
| 100 var doc2 = document.implementation.createHTMLDocument('Test 2'); |
| 101 var shadowRoot = doc1.body.createShadowRoot(); |
| 102 doc2.body.innerHTML = '<div id="parent"><div id="child"></div></div>'; |
| 103 shadowRoot.appendChild(doc2.getElementById('child')); |
| 104 assert_equals(doc2.getElementById('parent').ownerDocument, doc2); |
| 105 }, 'ownerDocument property of a node should remain the same, even if its ' + |
| 106 'child is adopted into a shadow tree.'); |
| 107 </script> |
| 108 </body> |
| 109 </html> |
OLD | NEW |