Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / text-iterator / findString-shadow-roots.html
blob8fdbef5ae75a0a9fd087cb6b1775b7be6b05890e
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <!-- Description and console is hidden until the test ends so that the content of the console cannot be searchable. -->
8 <p id="description" style="visibility: hidden;"></p>
9 <pre id="console" style="visibility: hidden;"></pre>
10 <script>
11 description("Find text in shadow roots.");
13 function testSimpleShadow()
15 debug('Starting testSimpleShadow()...');
16 var container = document.createElement('div');
17 document.body.appendChild(container);
18 container.innerHTML = 'BEFORE<span id="host">DOCUMENT</span>AFTER';
19 document.getElementById('host').createShadowRoot().innerHTML = '<span>SHADOW</span>';
21 var selection = getSelection();
22 selection.empty();
23 shouldBeTrue('testRunner.findString("SHADOW", [])');
24 selection.empty();
25 shouldBeTrue('testRunner.findString("HADO", [])');
26 selection.empty();
27 shouldBeTrue('testRunner.findString("SHA", [])');
28 selection.empty();
29 shouldBeTrue('testRunner.findString("DOW", [])');
30 selection.empty();
31 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
32 selection.empty();
33 shouldBeFalse('testRunner.findString("DOC", [])');
34 selection.empty();
35 shouldBeFalse('testRunner.findString("CUM", [])');
36 selection.empty();
37 shouldBeFalse('testRunner.findString("ENT", [])');
38 selection.empty();
39 shouldBeTrue('testRunner.findString("BEFORE", [])');
40 selection.empty();
41 shouldBeTrue('testRunner.findString("AFTER", [])');
42 selection.empty();
43 shouldBeFalse('testRunner.findString("BEFOREDOC", [])');
44 selection.empty();
45 shouldBeFalse('testRunner.findString("ENTAFTER", [])');
46 selection.empty();
47 shouldBeFalse('testRunner.findString("ORESHADOW", [])'); // FIXME: Should find text spanning over multiple trees.
48 selection.empty();
49 shouldBeFalse('testRunner.findString("SHADOWAFTER", [])');
51 document.body.removeChild(container);
52 debug('Finished testSimpleShadow().\n');
55 function testMultipleShadows()
57 debug('Starting testMultipleShadows()...');
58 var container = document.createElement('div');
59 document.body.appendChild(container);
60 container.innerHTML = '<span id="host">DOCUMENT</span>';
61 document.getElementById('host').createShadowRoot().innerHTML = '<span>YOUNGER</span>';
62 document.getElementById('host').createShadowRoot().innerHTML = '<span>OLDER</span>';
64 var selection = getSelection();
65 selection.empty();
66 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
67 selection.empty();
68 shouldBeFalse('testRunner.findString("YOUNGER", [])');
69 selection.empty();
70 shouldBeTrue('testRunner.findString("OLDER", [])');
72 document.body.removeChild(container);
73 debug('Finished testMultipleShadows().\n');
76 function testNestedShadows()
78 debug('Starting testNestedShadows()...');
79 var container = document.createElement('div');
80 document.body.appendChild(container);
81 container.innerHTML = '<span id="host">DOCUMENT</span>';
82 var outerShadowRoot = document.getElementById('host').createShadowRoot();
83 outerShadowRoot.innerHTML = '<span>OUTER<span id="host">SHADOW</span></span>';
84 outerShadowRoot.getElementById('host').createShadowRoot().innerHTML = '<span>INNER</span>';
86 var selection = getSelection();
87 selection.empty();
88 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
89 selection.empty();
90 shouldBeTrue('testRunner.findString("OUTER", [])');
91 selection.empty();
92 shouldBeFalse('testRunner.findString("SHADOW", [])');
93 selection.empty();
94 shouldBeTrue('testRunner.findString("INNER", [])');
96 document.body.removeChild(container);
97 debug('Finished testNestedShadows().\n');
100 function testDistribution()
102 debug('Starting testDistribution()...');
103 var container = document.createElement('div');
104 document.body.appendChild(container);
105 container.innerHTML = '<span id="host">DOCUMENT</span>';
106 document.getElementById('host').createShadowRoot().innerHTML = '<span>BEFORE<content></content>AFTER</span>';
108 var selection = getSelection();
109 selection.empty();
110 shouldBeTrue('testRunner.findString("BEFORE", [])');
111 selection.empty();
112 shouldBeTrue('testRunner.findString("DOCUMENT", [])');
113 selection.empty();
114 shouldBeTrue('testRunner.findString("AFTER", [])');
115 selection.empty();
116 shouldBeTrue('testRunner.findString("BEFOREDOCUMENTAFTER", [])'); // Visited in composed tree order
117 selection.empty();
118 shouldBeFalse('testRunner.findString("DOCUMENTBEFORE", [])');
119 selection.empty();
120 shouldBeFalse('testRunner.findString("AFTERDOCUMENT", [])');
122 document.body.removeChild(container);
123 debug('Finished testDistribution().\n');
126 if (window.testRunner) {
127 testSimpleShadow();
128 testMultipleShadows();
129 testNestedShadows();
130 testDistribution();
131 } else {
132 testFailed('This test requires testRunner.');
135 // Post-test clean-up.
136 document.getElementById('description').style.removeProperty('visibility');
137 document.getElementById('console').style.removeProperty('visibility');
138 </script>
139 </body>
140 </html>