Commit b7e8e902 authored by kochi's avatar kochi Committed by Commit bot

Use Shadow DOM v1 APIs for Shadow DOM v1 tests

Use Shadow DOM v1 APIs where possible for layout tests in //shadow-dom
directory, e.g. Event.path -> Event.deepPath(), createShadowRoot({mode: 'open'})
-> attachShadow({mode: 'open'}).

BUG=592371

Review URL: https://codereview.chromium.org/1777833002

Cr-Commit-Position: refs/heads/master@{#380097}
parent 6ede907a
Attach open shadow root.
PASS [object ShadowRoot] is non-null.
PASS host1.attachShadow({mode: 'open'}) is non-null.
Attach closed shadow root.
PASS host2.createShadowRoot({mode: 'closed'}) is non-null.
Create shadow root with empty parameter.
PASS [object ShadowRoot] is non-null.
PASS host2.attachShadow({mode: 'closed'}) is non-null.
Attach shadow root whose mode is neither open nor closed.
PASS host4.attachShadow({mode: 'illegal'}) threw exception TypeError: Failed to execute 'attachShadow' on 'Element': The provided value 'illegal' is not a valid enum value of type ShadowRootMode..
Attach open shadow root with shadow-dom.js utility.
......
<!doctype html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../fast/dom/shadow/resources/shadow-dom.js"></script>
</head>
<body>
<div id="host1"></div>
<div id="host2"></div>
<div id="host3"></div>
<div id="host4"></div>
</body>
<script>
debug('Attach open shadow root.');
var host1 = document.querySelector('#host1');
var root1 = host1.attachShadow({mode: 'open'});
shouldBeNonNull(root1);
shouldBeNonNull("host1.attachShadow({mode: 'open'})");
debug('Attach closed shadow root.');
var host2 = document.querySelector('#host2');
shouldBeNonNull("host2.createShadowRoot({mode: 'closed'})");
debug('Create shadow root with empty parameter.');
var host3 = document.querySelector('#host3');
var root3 = host3.createShadowRoot({});
shouldBeNonNull(root3);
shouldBeNonNull("host2.attachShadow({mode: 'closed'})");
debug('Attach shadow root whose mode is neither open nor closed.');
var host4 = document.querySelector('#host4');
var host4 = document.querySelector('#host3');
shouldThrow("host4.attachShadow({mode: 'illegal'})");
debug('Attach open shadow root with shadow-dom.js utility.');
document.body.appendChild(
createDOM('div', {id: 'host5'},
createShadowRoot({mode: 'open'})));
attachShadow({mode: 'open'})));
var host5 = document.querySelector('#host5');
var root5 = host5.shadowRoot;
shouldBeNonNull(root5);
......@@ -40,4 +30,3 @@ shouldBeNonNull(root5);
debug('Attach shadow root on already shadowed host will raise InvalidStateError exception.');
shouldThrow("host1.attachShadow({mode: 'open'})");
</script>
</html>
Event.path should include only unclosed nodes.
Event.deepPath() should include only unclosed nodes.
Dispaching a click event on #target_open, listening on #target_open.
PASS eventPath.length is 9
event.path for #target_open:
event.deepPath() for #target_open:
#target_open, #open_shadow_in_open_shadow, #inner_open, #open_shadow, #host_open, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 9
Dispaching a click event on #target_closed, listening on #target_closed.
PASS eventPath.length is 9
event.path for #target_closed:
event.deepPath() for #target_closed:
#target_closed, #open_shadow_in_closed_shadow, #inner_closed, #closed_shadow, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 9
Dispaching a click event on #target_open, listening on document.body.
PASS eventPath.length is 9
event.path for #target_open:
event.deepPath() for #target_open:
#target_open, #open_shadow_in_open_shadow, #inner_open, #open_shadow, #host_open, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 9
Dispaching a click event on #target_closed, listening on document.body.
PASS eventPath.length is 5
event.path for #target_closed:
event.deepPath() for #target_closed:
#host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 5
PASS successfullyParsed is true
......
......@@ -6,26 +6,26 @@
function prepareTree() {
document.body.appendChild(
createDOM('div', {id: 'host_open'},
createShadowRoot({mode: 'open', id: 'open_shadow'},
attachShadow({mode: 'open', id: 'open_shadow'},
createDOM('div', {id: 'inner_open'},
createShadowRoot({mode: 'open', id: 'open_shadow_in_open_shadow'},
attachShadow({mode: 'open', id: 'open_shadow_in_open_shadow'},
createDOM('span', {id: 'target_open', tabindex: '0'},
document.createTextNode('open')))))));
document.body.appendChild(
createDOM('div', {id: 'host_closed'},
createShadowRoot({mode: 'closed', id: 'closed_shadow'},
attachShadow({mode: 'closed', id: 'closed_shadow'},
createDOM('div', {id: 'inner_closed'},
createShadowRoot({mode: 'open', id: 'open_shadow_in_closed_shadow'},
attachShadow({mode: 'open', id: 'open_shadow_in_closed_shadow'},
createDOM('span', {id: 'target_closed', tabindex: '0'},
document.createTextNode('closed')))))));
}
function clickHandler(e) {
eventPath = e.path;
eventPath = e.deepPath();
}
debug('Event.path should include only unclosed nodes.');
debug('Event.deepPath() should include only unclosed nodes.');
prepareTree();
......@@ -41,7 +41,7 @@ targetOpen.click();
// Expected: <span#target_open>, #open_shadow_in_open_shadow, <div#inner_open>,
// #open_shadow, <div#host_open>, <body>, <html>, #document, window
shouldBe('eventPath.length', '9');
debug("\nevent.path for #target_open:");
debug("\nevent.deepPath() for #target_open:");
debug(dumpNodeList(eventPath));
debug("\nDispaching a click event on #target_closed, listening on #target_closed.");
......@@ -50,7 +50,7 @@ targetClosed.click();
// Expected: <span#target_closed>, #open_shadow_in_closed_shadow, <div#inner_closed>,
// #closed_shadow, <div#host_closed>, <body>, <html>, #document, window
shouldBe('eventPath.length', '9');
debug("\nevent.path for #target_closed:");
debug("\nevent.deepPath() for #target_closed:");
debug(dumpNodeList(eventPath));
......@@ -64,7 +64,7 @@ targetOpen.click();
// Expected: <span#target_open>, #open_shadow_in_open_shadow, <div#inner_open>,
// #open_shadow, <div#host_open>, <body>, <html>, #document, window
shouldBe('eventPath.length', '9');
debug("\nevent.path for #target_open:");
debug("\nevent.deepPath() for #target_open:");
debug(dumpNodeList(eventPath));
debug("\nDispaching a click event on #target_closed, listening on document.body.");
......@@ -74,6 +74,6 @@ targetClosed.click();
// thus 9 - 4 = 5.
// Expected: <div#host_closed>, <body>, <html>, #document, window
shouldBe('eventPath.length', '5');
debug("\nevent.path for #target_closed:");
debug("\nevent.deepPath() for #target_closed:");
debug(dumpNodeList(eventPath));
</script>
Event.path should include only unclosed nodes.
Event.deepPath() should include only unclosed nodes.
The full event path should be (length=12):
div#target, #shadow-root (open), div#div3_open, #shadow-root (closed),
div#div2_closed, #shadow-root (open), div#host_open, div#host_closed,
......@@ -10,23 +10,23 @@ will be trimmed (length=8).
Dispaching a click event on #target, listening on #host_closed.
Got event.path for #host_closed:
Got event.deepPath() for #host_closed:
#div2_closed, [object ShadowRoot], #host_open, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 8
Dispaching a click event on #target, listening on #host_open.
Got event.path for #host_open:
Got event.deepPath() for #host_open:
#div2_closed, [object ShadowRoot], #host_open, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 8
Dispaching a click event on #target, listening on #div2_closed.
Got event.path for #div2_closed:
Got event.deepPath() for #div2_closed:
#div2_closed, [object ShadowRoot], #host_open, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 8
Dispaching a click event on #target, listening on #div3_open.
Got event.path for #div3_open:
Got event.deepPath() for #div3_open:
#target, [object ShadowRoot], #div3_open, [object ShadowRoot], #div2_closed, [object ShadowRoot], #host_open, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 12
Dispaching a click event on #target, listening on #target.
Got event.path for #target:
Got event.deepPath() for #target:
#target, [object ShadowRoot], #div3_open, [object ShadowRoot], #div2_closed, [object ShadowRoot], #host_open, #host_closed, [object HTMLBodyElement], [object HTMLHtmlElement], [object HTMLDocument], [object Window], length: 12
PASS successfullyParsed is true
......
......@@ -7,21 +7,21 @@ function prepareTree() {
// Note: #target will be distributed to furthest <content>.
document.body.appendChild(
createDOM('div', {id: 'host_closed'},
createShadowRoot({mode: 'closed'},
attachShadow({mode: 'closed'},
createDOM('div', {id: 'div1_open'},
createDOM('content', {id: 'c1'}),
createShadowRoot({mode: 'open'},
attachShadow({mode: 'open'},
createDOM('content', {id: 'c2'})))),
createDOM('div', {id: 'host_open'},
createShadowRoot({mode: 'open'},
attachShadow({mode: 'open'},
createDOM('div', {id: 'div2_closed'},
createShadowRoot({mode: 'closed'},
attachShadow({mode: 'closed'},
createDOM('div', {id: 'div3_open'},
createShadowRoot({mode: 'open'},
attachShadow({mode: 'open'},
createDOM('div', {id: 'target'})))))))));
}
debug('Event.path should include only unclosed nodes.');
debug('Event.deepPath() should include only unclosed nodes.');
prepareTree();
......@@ -40,13 +40,13 @@ debug('On #host_closed, #host_open, and #div2_closed,\n' +
var node = getNodeInComposedTree(nodePath);
var eventPath;
var clickHandler = function(e) { eventPath = e.path; };
var clickHandler = function(e) { eventPath = e.deepPath(); };
node.addEventListener('click', clickHandler, false);
debug('\nDispaching a click event on #target, listening on #' + node.id + '.');
eventPath = null;
target.click();
debug('Got event.path for #' + node.id + ':');
debug('Got event.deepPath() for #' + node.id + ':');
debug(dumpNodeList(eventPath));
node.removeEventListener('click', clickHandler, false);
......
......@@ -43,7 +43,7 @@ test(function() {
var shadowRoot = host1.shadowRoot;
input1.onfocus = function(e) {
var expected_array1 = [input1, slot1, shadowRoot, host1, document.body, document.documentElement, document, window];
assert_array_equals(e.path, expected_array1);
assert_array_equals(e.deepPath(), expected_array1);
};
input1.focus();
}, 'Triggered in a slotted element, eventPath should go through shadow tree.');
......@@ -62,7 +62,7 @@ test(function() {
input2.onfocus = function(e) {
var expected_array2 = [input2, slot2, slotParent, content, shadowRootV0, host3, shadowRootV1, host2, document.body, document.documentElement, document, window];
assert_array_equals(e.path, expected_array2);
assert_array_equals(e.deepPath(), expected_array2);
};
input2.focus();
}, 'EventPath works fine with v0 insertion points & v1 slots.');
......@@ -76,7 +76,7 @@ test(function() {
var inputParent = document.getElementById('input-parent');
input3.onfocus = function(e) {
var expected_array3 = [input3, inputParent, slot3, shadowRoot2, host4, document.body, document.documentElement, document, window];
assert_array_equals(e.path, expected_array3);
assert_array_equals(e.deepPath(), expected_array3);
};
input3.focus();
}, 'EventPath works fine when event happens to a descendant of a slotted element.');
......
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../fast/dom/shadow/resources/shadow-dom.js"></script>
</head>
<body>
<body></body>
<script>
description("Tests for getDestinationInsertionPoints() which involves re-distribution.");
......@@ -26,7 +23,7 @@ document.body.appendChild(
createDOM('div', {'id': 'host-10'},
createShadowRoot(
createDOM('div', {'id': 'host-20'},
createShadowRoot(
attachShadow(
{'mode': 'open'},
createDOM('content', {'id': 'content-20'})),
createDOM('content', {'id': 'content-10'}))),
......@@ -40,7 +37,7 @@ document.body.appendChild(
createDOM('div', {'id': 'host-11'},
createShadowRoot(
createDOM('div', {'id': 'host-21'},
createShadowRoot(
attachShadow(
{'mode': 'closed'},
createDOM('content', {'id': 'content-21'})),
createDOM('content', {'id': 'content-11'}))),
......@@ -52,7 +49,7 @@ shouldBeEqualAsArray(document.getElementById('child-11').getDestinationInsertion
document.body.appendChild(
createDOM('div', {},
createDOM('div', {'id': 'host-12'},
createShadowRoot(
attachShadow(
{'mode': 'closed'},
createDOM('div', {'id': 'host-22'},
createShadowRoot(
......@@ -62,5 +59,3 @@ document.body.appendChild(
shouldBe('document.getElementById("child-12").getDestinationInsertionPoints().length', '0');
</script>
</body>
</html>
......@@ -20,7 +20,7 @@ debug('Insertion points should be inactive in v1 shadow trees.');
document.body.appendChild(
createDOM('div', {},
createDOM('div', {'id': 'host-2'},
createShadowRoot(
attachShadow(
{'mode': 'open'},
createDOM('content', {'id': 'content-2'})),
createDOM('div', {'id': 'child-2'}))));
......@@ -30,7 +30,7 @@ shouldBe('document.getElementById("child-2").getDestinationInsertionPoints().len
document.body.appendChild(
createDOM('div', {},
createDOM('div', {'id': 'host-3'},
createShadowRoot(
attachShadow(
{'mode': 'closed'},
createDOM('content', {'id': 'content-3'})),
createDOM('div', {'id': 'child-3'}))));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment