diff --git a/testing/web-platform/tests/custom-elements/CustomElementRegistry.html b/testing/web-platform/tests/custom-elements/CustomElementRegistry.html index d6fda892c38bd..2f7cf572b682d 100644 --- a/testing/web-platform/tests/custom-elements/CustomElementRegistry.html +++ b/testing/web-platform/tests/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', 'formDisabledCallback', + 'formStateRestoreCallback'], + '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 == 'formDisabledCallback') + 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', + 'formDisabledCallback'], + '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/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-NotSupportedError.html b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-NotSupportedError.html new file mode 100644 index 0000000000000..0d8a5ffc8c350 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-NotSupportedError.html @@ -0,0 +1,24 @@ + + + + + + diff --git a/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-labels.html b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-labels.html new file mode 100644 index 0000000000000..94e0a0457ef35 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-labels.html @@ -0,0 +1,50 @@ + +labels attribute of ElementInternals, and label association + + + +
+ + diff --git a/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-setFormValue.html b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-setFormValue.html new file mode 100644 index 0000000000000..0460c72acbb61 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-setFormValue.html @@ -0,0 +1,125 @@ + + + +
+ diff --git a/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-validation.html b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-validation.html new file mode 100644 index 0000000000000..d71161476918a --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/ElementInternals-validation.html @@ -0,0 +1,255 @@ + +Form validation features of ElementInternals, and :valid :invalid pseudo classes + + + +
+ + diff --git a/testing/web-platform/tests/custom-elements/form-associated/form-associated-callback.html b/testing/web-platform/tests/custom-elements/form-associated/form-associated-callback.html new file mode 100644 index 0000000000000..3a6a86dd0d00a --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/form-associated-callback.html @@ -0,0 +1,195 @@ + +formAssociatedCallback, and form IDL attribute of ElementInternals + + + + +
+ +
+
+ + + +
+
+ +
+ +
+ + +
+
+ + + +
+
+
+ + + + +
+ + + + + diff --git a/testing/web-platform/tests/custom-elements/form-associated/form-disabled-callback.html b/testing/web-platform/tests/custom-elements/form-associated/form-disabled-callback.html new file mode 100644 index 0000000000000..954c3f3f6eecc --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/form-disabled-callback.html @@ -0,0 +1,114 @@ + +formDisabledCallback, and :disabled :enabled pseudo classes + + + + + + diff --git a/testing/web-platform/tests/custom-elements/form-associated/form-reset-callback.html b/testing/web-platform/tests/custom-elements/form-associated/form-reset-callback.html new file mode 100644 index 0000000000000..8b8497f8b6c42 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/form-associated/form-reset-callback.html @@ -0,0 +1,58 @@ + + + + + + diff --git a/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js b/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js index 74d0f8c81eeeb..6b6685291d2bd 100644 --- a/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js +++ b/testing/web-platform/tests/html/semantics/forms/form-submission-0/resources/targetted-form.js @@ -11,3 +11,11 @@ function populateForm(optionalContentHtml) { ++frameCounter; return document.body.firstChild.nextSibling; } + +function submitPromise(form, iframe) { + return new Promise((resolve, reject) => { + iframe.onload = () => resolve(iframe.contentWindow.location.search); + iframe.onerror = () => reject(new Error('iframe onerror fired')); + form.submit(); + }); +}