blob: a06786ced5b1d9d0a62829c87405851c346232f8 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="resources/shadow-dom.js"></script>
<img id="img" src="../../images/resources/test-load.jpg">
<div id="sandbox">
<div id = "host">
<template>
<img id="target" src="../../images/resources/test-load.jpg">
</template>
</div>
</div>
<script>
setup({ explicit_done: true });
var e;
test(function() {
e = new Event('test');
assert_equals(e.scoped, false);
}, "A new event's scoped value should be set to false by default.");
test(function() {
e = new Event('test', { scoped: true });
assert_equals(e.scoped, true);
}, 'Users should be able to set a scoped value.');
img.onload = function(e) {
test(function() {
assert_equals(e.scoped, true);
}, "UA load event's scoped should be set to true");
};
var resultNonTrusted = [];
function addEventListeners(nodes)
{
for (var i = 0; i < nodes.length; ++i) {
var node = getNodeInTreeOfTrees(nodes[i]);
node.addEventListener('load', recordEvent, false);
node.addEventListener('error', recordEvent, false);
}
}
function recordEvent(event)
{
if (event.type == 'load') {
if (event.currentTarget.id == 'host'){
test(function() {
assert_true(false);
}, "Load event should be stopped if created by UAs.");
} else {
test(function() {
assert_equals(event.currentTarget.id, 'target');
}, "Event fired in the right place.");
}
}
if (event.type == 'error') {
resultNonTrusted.push(event.currentTarget.id);
if (resultNonTrusted.length == 2) {
test(function() {
assert_array_equals(resultNonTrusted, ['target', 'host']);
}, "Only certain trusted events should stop in bubbling.");
done();
}
}
}
var sandbox = document.getElementById('sandbox');
convertTemplatesToShadowRootsWithin(sandbox);
var targetImg = getNodeInTreeOfTrees('host/target');
addEventListeners(['host', 'host/target']);
targetImg.setAttribute('src', '../../images/resources/lenna.jpg');
var userError = new Event('error');
targetImg.dispatchEvent(userError);
</script>