Bug 1529797 [wpt PR 15123] - html,custom-elements: Add tests for HTMLElement.attachInternals(), a=testonly
☠☠ backed out by 66b1aba3fb43 ☠ ☠
authorTAMURA, Kent <tkent@chromium.org>
Wed, 06 Mar 2019 12:32:42 +0000
changeset 522250 2f7275c284b18453bbbbfc0eb474542588bcb65e
parent 522249 d6a61db637182d6005a71fae0df9e6a730f8fff8
child 522251 6b7cb75d72aa2ccdff93521cf3ee16c14dfeaf8e
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1529797, 15123
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529797 [wpt PR 15123] - html,custom-elements: Add tests for HTMLElement.attachInternals(), a=testonly Automatic update from web-platform-tests html,custom-elements: Add tests for HTMLElement.attachInternals() (#15123) Specification PR: https://github.com/whatwg/html/pull/4324 -- wpt-commits: 4c70b5a6f3169400dc809ba540b8e4e425396b2d wpt-pr: 15123
testing/web-platform/tests/custom-elements/HTMLElement-attachInternals.html
testing/web-platform/tests/interfaces/html.idl
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/HTMLElement-attachInternals.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<body>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals">
+<div id="container"></div>
+<script>
+test(() => {
+  class MyElement1 extends HTMLElement {
+  }
+  customElements.define('my-element1', MyElement1);
+  const container = document.querySelector('#container');
+
+  let element = new MyElement1();
+  assert_true(element.attachInternals() instanceof ElementInternals,
+              'New - 1st call');
+  assert_throws('InvalidStateError', () => { element.attachInternals(); },
+                'New - 2nd call');
+
+  element = document.createElement('my-element1');
+  assert_true(element.attachInternals() instanceof ElementInternals,
+              'createElement - 1st call');
+  assert_throws('InvalidStateError', () => { element.attachInternals(); },
+                'createElement - 2nd call');
+
+  container.innerHTML = '<my-element1></my-element1>';
+  assert_true(container.firstChild.attachInternals() instanceof ElementInternals,
+              'Parser - 1st call');
+  assert_throws('InvalidStateError', () => {
+    container.firstChild.attachInternals();
+  }, 'Parser - 2nd call');
+}, 'Successful attachInternals() and the second call.');
+
+test(() => {
+  class MyDiv extends HTMLDivElement {}
+  customElements.define('my-div', MyDiv, { extends: 'div' });
+  const customizedBuiltin = document.createElement('div', { is: 'my-div'});
+  assert_throws('NotSupportedError', () => { customizedBuiltin.attachInternals() });
+}, 'attachInternals() throws a NotSupportedError if it is called for ' +
+     'a customized built-in element');
+
+test(() => {
+  const builtin = document.createElement('div');
+  assert_throws('InvalidStateError', () => { builtin.attachInternals() });
+
+  const doc = document.implementation.createDocument('foo', null);
+  const span = doc.appendChild(doc.createElementNS('http://www.w3.org/1999/xhtml', 'html:span'));
+  assert_true(span instanceof HTMLElement);
+  assert_throws('InvalidStateError', () => { span.attachInternals(); });
+
+  const undefinedCustom = document.createElement('undefined-element');
+  assert_throws('InvalidStateError', () => { undefinedCustom.attachInternals() });
+}, 'If a custom element definition for the local name of the element doesn\'t' +
+     ' exist, throw an InvalidStateError');
+
+test(() => {
+  class MyElement2 extends HTMLElement {
+    static get disabledFeatures() { return ['internals']; }
+  }
+  customElements.define('my-element2', MyElement2);
+  const container = document.querySelector('#container');
+
+  assert_throws('NotSupportedError', () => {
+    (new MyElement2).attachInternals();
+  });
+  assert_throws('NotSupportedError', () => {
+    document.createElement('my-element2').attachInternals();
+  });
+  assert_throws('NotSupportedError', () => {
+    container.innerHTML = '<my-element2></my-element2>';
+    container.firstChild.attachInternals();
+  });
+
+  class MyElement3 extends HTMLElement {
+    static get disabledFeatures() { return ['INTERNALS']; }
+  }
+  customElements.define('my-element3', MyElement3);
+  assert_true((new MyElement3).attachInternals() instanceof ElementInternals);
+}, 'If a custom element definition for the local name of the element has ' +
+     'disable internals flag, throw a NotSupportedError');
+</script>
+</body>
--- a/testing/web-platform/tests/interfaces/html.idl
+++ b/testing/web-platform/tests/interfaces/html.idl
@@ -109,16 +109,18 @@ interface HTMLElement : Element {
   void click();
   [CEReactions] attribute DOMString accessKey;
   readonly attribute DOMString accessKeyLabel;
   [CEReactions] attribute boolean draggable;
   [CEReactions] attribute boolean spellcheck;
   [CEReactions] attribute DOMString autocapitalize;
 
   [CEReactions] attribute [TreatNullAs=EmptyString] DOMString innerText;
+
+  ElementInternals attachInternals();
 };
 
 HTMLElement includes GlobalEventHandlers;
 HTMLElement includes DocumentAndElementEventHandlers;
 HTMLElement includes ElementContentEditable;
 HTMLElement includes HTMLOrSVGElement;
 
 // Note: intentionally not [HTMLConstructor]
@@ -1405,16 +1407,21 @@ interface CustomElementRegistry {
 };
 
 callback CustomElementConstructor = any ();
 
 dictionary ElementDefinitionOptions {
   DOMString extends;
 };
 
+[Exposed=Window]
+interface ElementInternals {
+
+};
+
 dictionary FocusOptions {
   boolean preventScroll = false;
 };
 
 interface mixin ElementContentEditable {
   [CEReactions] attribute DOMString contentEditable;
   [CEReactions] attribute DOMString enterKeyHint;
   readonly attribute boolean isContentEditable;