4 <script src=
"../../resources/js-test.js"></script>
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>
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();
23 shouldBeTrue('testRunner.findString("SHADOW", [])');
25 shouldBeTrue('testRunner.findString("HADO", [])');
27 shouldBeTrue('testRunner.findString("SHA", [])');
29 shouldBeTrue('testRunner.findString("DOW", [])');
31 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
33 shouldBeFalse('testRunner.findString("DOC", [])');
35 shouldBeFalse('testRunner.findString("CUM", [])');
37 shouldBeFalse('testRunner.findString("ENT", [])');
39 shouldBeTrue('testRunner.findString("BEFORE", [])');
41 shouldBeTrue('testRunner.findString("AFTER", [])');
43 shouldBeFalse('testRunner.findString("BEFOREDOC", [])');
45 shouldBeFalse('testRunner.findString("ENTAFTER", [])');
47 shouldBeFalse('testRunner.findString("ORESHADOW", [])'); // FIXME: Should find text spanning over multiple trees.
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();
66 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
68 shouldBeFalse('testRunner.findString("YOUNGER", [])');
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();
88 shouldBeFalse('testRunner.findString("DOCUMENT", [])');
90 shouldBeTrue('testRunner.findString("OUTER", [])');
92 shouldBeFalse('testRunner.findString("SHADOW", [])');
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();
110 shouldBeTrue('testRunner.findString("BEFORE", [])');
112 shouldBeTrue('testRunner.findString("DOCUMENT", [])');
114 shouldBeTrue('testRunner.findString("AFTER", [])');
116 shouldBeTrue('testRunner.findString("BEFOREDOCUMENTAFTER", [])'); // Visited in composed tree order
118 shouldBeFalse('testRunner.findString("DOCUMENTBEFORE", [])');
120 shouldBeFalse('testRunner.findString("AFTERDOCUMENT", [])');
122 document
.body
.removeChild(container
);
123 debug('Finished testDistribution().\n');
126 if (window
.testRunner
) {
128 testMultipleShadows();
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');