Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event path attribute test for Shadow DOM. #194

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions shadow-dom/flatbird/events/api-partial-event-path.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<title>Shadow DOM Test: TODO</title>
<link rel="author" title="Masakazu Hattori" href="mailto:mshattori@gmail.com">
<!-- You must have at least one spec link, but may have as many as are covered in the test. -->
<!-- Be sure to make the main testing area first in the order -->
<link rel="help" href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html">
<link rel="help" href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#partial-event-attributes">
<meta name="assert" content="Event path attribute test for Shadow DOM">
<meta name="flags" content="dom">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<section id="shadow-host" style='display:none'>
<button id="a-child">test it</button>
</section>
<script>
var t = async_test("Event path attribute test for Shadow DOM");

var host = document.getElementById('shadow-host');
var child = document.getElementById('a-child');

var root = host.webkitCreateShadowRoot();
var shadowDiv = document.createElement('div');
shadowDiv.id = "shadow-div";
shadowDiv.innerHTML = '<content></content>';
root.appendChild(shadowDiv);

var verifyCount = 0;
host.addEventListener('click',
verifier(
[toName(child), toName(host)], // expected
[toName(shadowDiv)] // unexpected
),
false);
shadowDiv.addEventListener('click',
verifier(
[toName(child), toName(host), toName(shadowDiv)], // expected
[] // unexpected
),
false);
child.addEventListener('click',
verifier(
[toName(child), toName(host)], // expected
[toName(shadowDiv)] // unexpected
),
false);
child.click();

function verifier(expected, unexpected) {
verifyCount += 1;
return function (evt) {
var self = this;
t.step(function() {
var path = evt.path;
for (var i = 0; i < path.length; i++) {
var thisName = toName(self);
var p = path[i];
var pName = toName(p);
if (expected.indexOf(pName) >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good test.
Suppose that even.path is empty. The test doesn't fail. :)

You should make sure that each expected node is surely included in the event.path.

var msg = pName + ' is expected in path of ' + thisName;
assert_true(true, msg);
}
if (unexpected.indexOf(pName) >= 0) {
var msg = pName + ' is unexpected in path of ' + thisName;
assert_unreached(msg);
}
}
verifyCount -= 1;
if (verifyCount <= 0) {
t.done();
}
});
};
}
function toName(e) {
return e.localName + '#' + e.id;
}
</script>
</body>
</html>