Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1980)

Unified Diff: third_party/WebKit/LayoutTests/fast/dom/shadow/v1-attachShadow-safelist.html

Issue 1698183003: Allow attachShadow only for elements in the safelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove expected.txt Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/dom/shadow/v1-attachShadow-safelist.html
diff --git a/third_party/WebKit/LayoutTests/fast/dom/shadow/v1-attachShadow-safelist.html b/third_party/WebKit/LayoutTests/fast/dom/shadow/v1-attachShadow-safelist.html
new file mode 100644
index 0000000000000000000000000000000000000000..3aa6c3099c249873157ead19de7371544ff9c54a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/dom/shadow/v1-attachShadow-safelist.html
@@ -0,0 +1,44 @@
+<!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>

Powered by Google App Engine
This is Rietveld 408576698