From 7560720fe183fded9815193b197ccee308568c3d Mon Sep 17 00:00:00 2001 From: Kent Tamura Date: Mon, 13 May 2019 14:17:35 +0900 Subject: [PATCH 1/3] shadow-dom: Add testcases for attachShadow() with disabledFeatures=['shadow'] --- ...interface-attachShadow-custom-element.html | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/shadow-dom/Element-interface-attachShadow-custom-element.html b/shadow-dom/Element-interface-attachShadow-custom-element.html index b59460e17b9735..cf70fac583fb4c 100644 --- a/shadow-dom/Element-interface-attachShadow-custom-element.html +++ b/shadow-dom/Element-interface-attachShadow-custom-element.html @@ -14,6 +14,44 @@ assert_true(document.createElement('my-custom').attachShadow({mode: "open"}) instanceof ShadowRoot); }, 'Element.attachShadow must create an instance of ShadowRoot for autonomous custom elements'); +test(() => { + assert_true(document.createElement('undefined-custom').attachShadow({mode: 'open'}) instanceof ShadowRoot); +}, 'Element.attachShadow must create an instance of ShadowRoot for undefined autonomous custom elements'); + +test(() => { + class ShadowDisabledElement extends HTMLElement { + static disabledFeatures = ['shadow']; + } + + // No definition. attachShadow() should succeed. + let element = document.createElement('shadow-disabled-element'); + element.attachShadow({mode: 'closed'}); + + // No definition and it's already a host. + assert_throws('InvalidStateError', () => { + element.attachShadow({mode: 'closed'}); + }); + + // The element has a definition, and it's already a host. + customElements.define('shadow-disabled-element', ShadowDisabledElement); + assert_throws('NotSupportedError', () => { + element.attachShadow({mode: 'closed'}); + }); +}, 'Element.attachShadow for a custom element with disabledFeatures=["shadow"] should throw a NotSupportedError'); + +test(() => { + class CapitalShadowDisabledElement extends HTMLElement { + static disabledFeatures = ['SHADOW']; + } + + customElements.define('capital-shadow-disabled-element', CapitalShadowDisabledElement); + try { + document.createElement('capital-shadow-disabled-element').attachShadow({mode: 'open'}); + } catch (e) { + assert_unreached('Should throw nothing'); + } +}, 'Element.attachShadow for a custom element with disabledFeatures=["SHADOW"] should not throw a NotSupportedError'); + class MyCustomizedBuiltinElement extends HTMLInputElement { } From 01eb2f0a0b279610e05665a2de20489f406bf384 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Wed, 15 May 2019 15:06:59 -0400 Subject: [PATCH 2/3] NotSupportedError --- .../Element-interface-attachShadow-custom-element.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/shadow-dom/Element-interface-attachShadow-custom-element.html b/shadow-dom/Element-interface-attachShadow-custom-element.html index cf70fac583fb4c..1444f7399ed47c 100644 --- a/shadow-dom/Element-interface-attachShadow-custom-element.html +++ b/shadow-dom/Element-interface-attachShadow-custom-element.html @@ -28,7 +28,7 @@ element.attachShadow({mode: 'closed'}); // No definition and it's already a host. - assert_throws('InvalidStateError', () => { + assert_throws('NotSupportedError', () => { element.attachShadow({mode: 'closed'}); }); @@ -45,11 +45,9 @@ } customElements.define('capital-shadow-disabled-element', CapitalShadowDisabledElement); - try { - document.createElement('capital-shadow-disabled-element').attachShadow({mode: 'open'}); - } catch (e) { - assert_unreached('Should throw nothing'); - } + + // Test fails if this throws + document.createElement('capital-shadow-disabled-element').attachShadow({mode: 'open'}); }, 'Element.attachShadow for a custom element with disabledFeatures=["SHADOW"] should not throw a NotSupportedError'); class MyCustomizedBuiltinElement extends HTMLInputElement { From 81bcfca2fef73a5e91e66a81f19a7429e73e44e5 Mon Sep 17 00:00:00 2001 From: Kent Tamura Date: Thu, 16 May 2019 09:52:56 +0900 Subject: [PATCH 3/3] Add a customized built-in testcase --- ...interface-attachShadow-custom-element.html | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/shadow-dom/Element-interface-attachShadow-custom-element.html b/shadow-dom/Element-interface-attachShadow-custom-element.html index cf70fac583fb4c..5d862c49244b4f 100644 --- a/shadow-dom/Element-interface-attachShadow-custom-element.html +++ b/shadow-dom/Element-interface-attachShadow-custom-element.html @@ -28,16 +28,52 @@ element.attachShadow({mode: 'closed'}); // No definition and it's already a host. - assert_throws('InvalidStateError', () => { + assert_throws('NotSupportedError', () => { element.attachShadow({mode: 'closed'}); - }); + }, 'No definition, host'); // The element has a definition, and it's already a host. customElements.define('shadow-disabled-element', ShadowDisabledElement); assert_throws('NotSupportedError', () => { element.attachShadow({mode: 'closed'}); - }); -}, 'Element.attachShadow for a custom element with disabledFeatures=["shadow"] should throw a NotSupportedError'); + }, 'Definition, host'); + + // The element has a definition, and it's not a host. + assert_throws('NotSupportedError', () => { + document.createElement('shadow-disabled-element').attachShadow({mode: 'closed'}); + }, 'Definition, not a host'); +}, 'Element.attachShadow for an autonomous custom element with ' + + 'disabledFeatures=["shadow"] should throw a NotSupportedError'); + +test(() => { + class ShadowDisabledHeadingElement extends HTMLHeadingElement { + static disabledFeatures = ['shadow']; + } + + // No definition. attachShadow() should succeed. + let element = document.createElement('h2', + {is: 'shadow-disabled-heading-element'}); + element.attachShadow({mode: 'closed'}); + + // No definition and it's already a host. + assert_throws('NotSupportedError', () => { + element.attachShadow({mode: 'closed'}); + }, 'No definition, host.'); + + // The element has a definition, and it's already a host. + customElements.define('shadow-disabled-heading-element', + ShadowDisabledHeadingElement, {extends: 'h2'}); + assert_throws('NotSupportedError', () => { + element.attachShadow({mode: 'closed'}); + }, 'Definition, host'); + + // The element has a definition, and it's not a host. + let h2 = document.createElement('h2', {is: 'shadow-disabled-heading-element'}); + assert_throws('NotSupportedError', () => { + h2.attachShadow({mode: 'closed'}); + }, 'Definition, not a host'); +}, 'Element.attachShadow for a customized built-in element with ' + + 'disabledFeatures=["shadow"] should throw a NotSupportedError'); test(() => { class CapitalShadowDisabledElement extends HTMLElement { @@ -45,11 +81,9 @@ } customElements.define('capital-shadow-disabled-element', CapitalShadowDisabledElement); - try { - document.createElement('capital-shadow-disabled-element').attachShadow({mode: 'open'}); - } catch (e) { - assert_unreached('Should throw nothing'); - } + + // Test fails if this throws + document.createElement('capital-shadow-disabled-element').attachShadow({mode: 'open'}); }, 'Element.attachShadow for a custom element with disabledFeatures=["SHADOW"] should not throw a NotSupportedError'); class MyCustomizedBuiltinElement extends HTMLInputElement {