diff --git a/custom-elements/CustomElementRegistry.html b/custom-elements/CustomElementRegistry.html index d6fda892c38bd2..10582210f2082f 100644 --- a/custom-elements/CustomElementRegistry.html +++ b/custom-elements/CustomElementRegistry.html @@ -330,7 +330,8 @@ assert_array_equals(prototypeCalls, [1, 'connectedCallback', 2, 'disconnectedCallback', 3, 'adoptedCallback', 4, 'attributeChangedCallback']); assert_array_equals(constructorCalls, [0, 'prototype', 5, 'observedAttributes', - 6, 'disabledFeatures']); + 6, 'disabledFeatures', + 7, 'formAssociated']); }, 'customElements.define must get "observedAttributes" property on the constructor prototype when "attributeChangedCallback" is present'); test(function () { @@ -437,6 +438,102 @@ assert_throws({'name': 'TypeError'}, () => customElements.define('element-with-disabled-features-with-uncallable-iterator', constructor)); }, 'customElements.define must rethrow an exception thrown while retrieving Symbol.iterator on disabledFeatures'); +test(function () { + var constructor = function () {} + var calls = []; + var proxy = new Proxy(constructor, { + get: function (target, name) { + calls.push(name); + if (name == 'formAssociated') + throw {name: 'expectedError'}; + return target[name]; + } + }); + assert_throws({'name': 'expectedError'}, + () => customElements.define('element-with-throwing-form-associated', proxy)); + assert_array_equals(calls, ['prototype', 'disabledFeatures', 'formAssociated'], + 'customElements.define must get "prototype", "disabledFeatures", and ' + + '"formAssociated" on the constructor'); +}, 'customElements.define must rethrow an exception thrown while getting ' + + 'formAssociated on the constructor prototype'); + +test(function () { + var constructor = function () {} + var prototypeCalls = []; + constructor.prototype = new Proxy(constructor.prototype, { + get: function(target, name) { + prototypeCalls.push(name) + return target[name]; + } + }); + var constructorCalls = []; + var proxy = new Proxy(constructor, { + get: function (target, name) { + constructorCalls.push(name); + if (name == 'formAssociated') + return 1; + return target[name]; + } + }); + customElements.define('element-with-form-associated-true', proxy); + assert_array_equals(constructorCalls, + ['prototype', 'disabledFeatures', 'formAssociated'], + 'customElements.define must get "prototype", "disabledFeatures", and ' + + '"formAssociated" on the constructor'); + assert_array_equals( + prototypeCalls, + ['connectedCallback', 'disconnectedCallback', 'adoptedCallback', + 'attributeChangedCallback', 'formAssociatedCallback', + 'formResetCallback', 'disabledStateChangedCallback', + 'restoreValueCallback'], + 'customElements.define must get 8 callbacks on the prototype'); +}, 'customElements.define must get four additional callbacks on the prototype' + + ' if formAssociated is converted to true'); + +test(function () { + var constructor = function() {}; + var proxy = new Proxy(constructor, { + get: function(target, name) { + if (name == 'formAssociated') + return {}; // Any object is converted to 'true'. + return target[name]; + } + }); + var calls = []; + constructor.prototype = new Proxy(constructor.prototype, { + get: function (target, name) { + calls.push(name); + if (name == 'disabledStateChangedCallback') + throw {name: 'expectedError'}; + return target[name]; + } + }); + assert_throws({'name': 'expectedError'}, + () => customElements.define('element-with-throwing-callback-2', proxy)); + assert_array_equals(calls, ['connectedCallback', 'disconnectedCallback', + 'adoptedCallback', 'attributeChangedCallback', + 'formAssociatedCallback', 'formResetCallback', + 'disabledStateChangedCallback'], + 'customElements.define must not get callbacks after one of the get throws'); + + var calls2 = []; + constructor.prototype = new Proxy(constructor.prototype, { + get: function (target, name) { + calls2.push(name); + if (name == 'formResetCallback') + return 43; // Can't convert to a Function. + return target[name]; + } + }); + assert_throws({'name': 'TypeError'}, + () => customElements.define('element-with-throwing-callback-3', proxy)); + assert_array_equals(calls2, ['connectedCallback', 'disconnectedCallback', + 'adoptedCallback', 'attributeChangedCallback', + 'formAssociatedCallback', 'formResetCallback'], + 'customElements.define must not get callbacks after one of the get throws'); +}, 'customElements.define must rethrow an exception thrown while getting ' + + 'additional formAssociated callbacks on the constructor prototype'); + test(function () { class MyCustomElement extends HTMLElement {}; customElements.define('my-custom-element', MyCustomElement); diff --git a/custom-elements/form-associated/ElementInternals-NotSupportedError.html b/custom-elements/form-associated/ElementInternals-NotSupportedError.html new file mode 100644 index 00000000000000..ead82ea6d97a9d --- /dev/null +++ b/custom-elements/form-associated/ElementInternals-NotSupportedError.html @@ -0,0 +1,24 @@ + + + + + + diff --git a/custom-elements/form-associated/ElementInternals-labels.html b/custom-elements/form-associated/ElementInternals-labels.html new file mode 100644 index 00000000000000..61bcbd8ba0f73d --- /dev/null +++ b/custom-elements/form-associated/ElementInternals-labels.html @@ -0,0 +1,50 @@ + +labels attribute of ElementInternals, and label association + + + +
+ + diff --git a/custom-elements/form-associated/ElementInternals-setFormValue.html b/custom-elements/form-associated/ElementInternals-setFormValue.html new file mode 100644 index 00000000000000..964cc4e3a8c06a --- /dev/null +++ b/custom-elements/form-associated/ElementInternals-setFormValue.html @@ -0,0 +1,119 @@ + + + +
+ diff --git a/custom-elements/form-associated/ElementInternals-validation.html b/custom-elements/form-associated/ElementInternals-validation.html new file mode 100644 index 00000000000000..6107df6fd4b8b0 --- /dev/null +++ b/custom-elements/form-associated/ElementInternals-validation.html @@ -0,0 +1,225 @@ + +Form validation features of ElementInternals, and :valid :invalid pseudo classes + + + +
+ + diff --git a/custom-elements/form-associated/disabled-state-changed-callback.html b/custom-elements/form-associated/disabled-state-changed-callback.html new file mode 100644 index 00000000000000..7d3782059d7b2d --- /dev/null +++ b/custom-elements/form-associated/disabled-state-changed-callback.html @@ -0,0 +1,105 @@ + +disabledStateChangedCallback, and :disabled :enabled pseudo classes + + + + + diff --git a/custom-elements/form-associated/form-associated-callback.html b/custom-elements/form-associated/form-associated-callback.html new file mode 100644 index 00000000000000..3a6a86dd0d00a4 --- /dev/null +++ b/custom-elements/form-associated/form-associated-callback.html @@ -0,0 +1,195 @@ + +formAssociatedCallback, and form IDL attribute of ElementInternals + + + + +
+ +
+
+ + + +
+
+ +
+ +
+ + +
+
+ + + +
+
+
+ + + + +
+ + + + + diff --git a/custom-elements/form-associated/form-reset-callback.html b/custom-elements/form-associated/form-reset-callback.html new file mode 100644 index 00000000000000..eb343982943a7c --- /dev/null +++ b/custom-elements/form-associated/form-reset-callback.html @@ -0,0 +1,53 @@ + + + + + +