blob: 3aa6c3099c249873157ead19de7371544ff9c54a [file] [log] [blame]
<!DOCTYPE html>
<script src='../../../resources/testharness.js'></script>
<script src='../../../resources/testharnessreport.js'></script>
<script>
'use strict';
const safelist = ['custom-element',
'article', 'aside', 'blockquote', 'body', 'div', 'footer',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'header', 'nav', 'p', 'section', 'span'];
test(() => {
safelist.forEach((tag) => {
['open', 'closed'].forEach((mode) => {
const sr = document.createElement(tag).attachShadow({mode: mode});
assert_true(sr instanceof ShadowRoot, "attachShadow is supported for " + tag);
});
});
}, 'attachShadow should not fail for an element in the safelist');
test(() => {
// Retrieve possible tag names from window object's own property names
Object.getOwnPropertyNames(window).forEach((p) => {
const res = /^HTML(.*)Element$/.exec(p);
if (!res)
return;
const maybeTagName = res[1].toLowerCase();
if (safelist.includes(maybeTagName) || maybeTagName.indexOf('-') != -1)
return;
var element;
try {
element = document.createElement(maybeTagName);
} catch (e) {
// Okay to ignore when document.createElement fails
return;
}
['open', 'closed'].forEach((mode) => {
assert_throws({name: 'NotSupportedError'}, () => {
element.attachShadow({mode: mode});
}), 'attachShadow should throw NotSupportdeError for ' + maybeTagName;
});
});
}, 'attachShadow should throw an exception for an element which is not in the safelist');
</script>