blob: 7465d9d9fbac9d9af1f33b6251df4671bf7af030 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<!-- Description and console is hidden until the test ends so that the content of the console cannot be searchable. -->
<p id="description" style="visibility: hidden;"></p>
<pre id="console" style="visibility: hidden;"></pre>
<script>
description("Find text in shadow roots.");
function testSimpleShadow()
{
debug('Starting testSimpleShadow()...');
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = 'BEFORE<span id="host">DOCUMENT</span>AFTER';
document.getElementById('host').createShadowRoot().innerHTML = '<span>SHADOW</span>';
var selection = getSelection();
selection.empty();
shouldBeTrue('testRunner.findString("SHADOW", [])');
selection.empty();
shouldBeTrue('testRunner.findString("HADO", [])');
selection.empty();
shouldBeTrue('testRunner.findString("SHA", [])');
selection.empty();
shouldBeTrue('testRunner.findString("DOW", [])');
selection.empty();
shouldBeFalse('testRunner.findString("DOCUMENT", [])');
selection.empty();
shouldBeFalse('testRunner.findString("DOC", [])');
selection.empty();
shouldBeFalse('testRunner.findString("CUM", [])');
selection.empty();
shouldBeFalse('testRunner.findString("ENT", [])');
selection.empty();
shouldBeTrue('testRunner.findString("BEFORE", [])');
selection.empty();
shouldBeTrue('testRunner.findString("AFTER", [])');
selection.empty();
shouldBeFalse('testRunner.findString("BEFOREDOC", [])');
selection.empty();
shouldBeFalse('testRunner.findString("ENTAFTER", [])');
selection.empty();
shouldBeFalse('testRunner.findString("ORESHADOW", [])'); // FIXME: Should find text spanning over multiple trees.
selection.empty();
shouldBeFalse('testRunner.findString("SHADOWAFTER", [])');
document.body.removeChild(container);
debug('Finished testSimpleShadow().\n');
}
function testMultipleShadows()
{
debug('Starting testMultipleShadows()...');
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<span id="host">DOCUMENT</span>';
document.getElementById('host').createShadowRoot().innerHTML = '<span>YOUNGER</span>';
document.getElementById('host').createShadowRoot().innerHTML = '<span>OLDER</span>';
var selection = getSelection();
selection.empty();
shouldBeFalse('testRunner.findString("DOCUMENT", [])');
selection.empty();
shouldBeFalse('testRunner.findString("YOUNGER", [])');
selection.empty();
shouldBeTrue('testRunner.findString("OLDER", [])');
document.body.removeChild(container);
debug('Finished testMultipleShadows().\n');
}
function testNestedShadows()
{
debug('Starting testNestedShadows()...');
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<span id="host">DOCUMENT</span>';
var outerShadowRoot = document.getElementById('host').createShadowRoot();
outerShadowRoot.innerHTML = '<span>OUTER<span id="host">SHADOW</span></span>';
outerShadowRoot.getElementById('host').createShadowRoot().innerHTML = '<span>INNER</span>';
var selection = getSelection();
selection.empty();
shouldBeFalse('testRunner.findString("DOCUMENT", [])');
selection.empty();
shouldBeTrue('testRunner.findString("OUTER", [])');
selection.empty();
shouldBeFalse('testRunner.findString("SHADOW", [])');
selection.empty();
shouldBeTrue('testRunner.findString("INNER", [])');
document.body.removeChild(container);
debug('Finished testNestedShadows().\n');
}
function testDistribution()
{
debug('Starting testDistribution()...');
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<span id="host">DOCUMENT</span>';
document.getElementById('host').createShadowRoot().innerHTML = '<span>BEFORE<content></content>AFTER</span>';
var selection = getSelection();
selection.empty();
shouldBeTrue('testRunner.findString("BEFORE", [])');
selection.empty();
shouldBeTrue('testRunner.findString("DOCUMENT", [])');
selection.empty();
shouldBeTrue('testRunner.findString("AFTER", [])');
selection.empty();
shouldBeTrue('testRunner.findString("BEFOREDOCUMENTAFTER", [])'); // Visited in flat tree order
selection.empty();
shouldBeFalse('testRunner.findString("DOCUMENTBEFORE", [])');
selection.empty();
shouldBeFalse('testRunner.findString("AFTERDOCUMENT", [])');
document.body.removeChild(container);
debug('Finished testDistribution().\n');
}
if (window.testRunner) {
testSimpleShadow();
testMultipleShadows();
testNestedShadows();
testDistribution();
} else {
testFailed('This test requires testRunner.');
}
// Post-test clean-up.
document.getElementById('description').style.removeProperty('visibility');
document.getElementById('console').style.removeProperty('visibility');
</script>
</body>
</html>