diff --git a/autofill/META.yml b/autofill/META.yml new file mode 100644 index 00000000000000..1d905001ba7e2b --- /dev/null +++ b/autofill/META.yml @@ -0,0 +1,2 @@ +spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill + diff --git a/autofill/basic_form.html b/autofill/basic_form.html new file mode 100644 index 00000000000000..72683198b85113 --- /dev/null +++ b/autofill/basic_form.html @@ -0,0 +1,27 @@ + + + + +Basic Autofill Form Test + + + + + + + +
+ +
+ + + + diff --git a/autofill/colocated-hidden-fields.html b/autofill/colocated-hidden-fields.html new file mode 100644 index 00000000000000..9536dcc61e187a --- /dev/null +++ b/autofill/colocated-hidden-fields.html @@ -0,0 +1,73 @@ + + + + +Colocated Hidden Fields Autofill Test + + + + + + + + +
+

Delivery Address

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + diff --git a/autofill/full_address_form.html b/autofill/full_address_form.html new file mode 100644 index 00000000000000..8a6d7edcb8e8b0 --- /dev/null +++ b/autofill/full_address_form.html @@ -0,0 +1,67 @@ + + + + +Full Address Autofill Test + + + + + + + + +
+

Delivery Address

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + diff --git a/autofill/resources/autofill-bidi-helpers.js b/autofill/resources/autofill-bidi-helpers.js new file mode 100644 index 00000000000000..4102a59e031672 --- /dev/null +++ b/autofill/resources/autofill-bidi-helpers.js @@ -0,0 +1,93 @@ +/** + * Helper functions for autofill tests using WebDriver BiDi. + * + * These helpers use the WebDriver BiDi autofill.trigger command to test + * browser autofill behavior. + * + * BiDi API: https://w3c.github.io/webdriver-bidi/#module-autofill + */ + +/** + * Trigger autofill on a form element using WebDriver BiDi. + * + * @param {Element} element - The form element to trigger autofill on + * @param {Object} data - Autofill data mapping autocomplete field names to values + * @returns {Promise} Resolves when autofill is complete + * + * @example + * await triggerAutofill(document.getElementById('name'), { + * 'name': 'John Doe', + * 'address-line1': '123 Main St', + * 'country': 'US' + * }); + */ +async function triggerAutofill(element, data) { + if (!window.test_driver) { + throw new Error('test_driver not available'); + } + + // Convert data object to fields array format expected by BiDi + const fields = Object.entries(data).map(([name, value]) => ({ + name: name, + value: value + })); + + // Use the WebDriver BiDi autofill.trigger command via test_driver + return await test_driver.bidi.autofill.trigger(element, fields); +} + +/** + * Assert that a form element has the expected value. + * + * @param {string} elementId - The ID of the element to check + * @param {string} expectedValue - The expected value + * @param {string} [message] - Optional assertion message + */ +function assertElementHasValue(elementId, expectedValue, message) { + const element = document.getElementById(elementId); + assert_not_equals(element, null, `Element with id '${elementId}' should exist`); + const msg = message || `Element '${elementId}' should have value '${expectedValue}'`; + assert_equals(element.value, expectedValue, msg); +} + +/** + * Standard address data for testing. + */ +const DEFAULT_ADDRESS_DATA = { + 'name': 'Max Mustermann', + 'address-line1': '1 Main St', + 'address-level2': 'Springfield', + 'postal-code': 'H0H 0H0', + 'address-level1': 'Ontario', + 'country': 'CA' +}; + +/** + * Create a simple form with autofill fields for testing. + * + * @param {Object} fields - Object mapping field IDs to autocomplete values + * @returns {HTMLFormElement} The created form element + * + * @example + * const form = createAutofillForm({ + * 'name': 'name', + * 'email': 'email' + * }); + */ +function createAutofillForm(fields) { + const form = document.createElement('form'); + form.id = 'test_form'; + + for (const [id, autocomplete] of Object.entries(fields)) { + const input = document.createElement('input'); + input.type = 'text'; + input.id = id; + input.name = id; + input.autocomplete = autocomplete; + form.appendChild(input); + } + + document.body.appendChild(form); + return form; +} + diff --git a/autofill/scoped-fields.html b/autofill/scoped-fields.html new file mode 100644 index 00000000000000..f66d88cacc37eb --- /dev/null +++ b/autofill/scoped-fields.html @@ -0,0 +1,69 @@ + + + + +Scoped Autofill Fields Test + + + + + + + +
+ + + + + +
+ + + + diff --git a/autofill/select-input.html b/autofill/select-input.html new file mode 100644 index 00000000000000..6cc79cebd0aeaf --- /dev/null +++ b/autofill/select-input.html @@ -0,0 +1,50 @@ + + + + +Select Input Autofill Test + + + + + + + + +
+
+ + +
+
+ + +
+
+ + + + diff --git a/autofill/state-code-mismatch.html b/autofill/state-code-mismatch.html new file mode 100644 index 00000000000000..24f81817842c1d --- /dev/null +++ b/autofill/state-code-mismatch.html @@ -0,0 +1,56 @@ + + + + +State Code Mismatch Autofill Test + + + + + + + + +
+

Delivery Address

+
+ + +
+
+ + +
+
+ + + +