diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/extensions/formautofill/test/unit/test_populateFieldValues.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/extensions/formautofill/test/unit/test_populateFieldValues.js')
-rw-r--r-- | browser/extensions/formautofill/test/unit/test_populateFieldValues.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/browser/extensions/formautofill/test/unit/test_populateFieldValues.js b/browser/extensions/formautofill/test/unit/test_populateFieldValues.js new file mode 100644 index 000000000..1215cbd16 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_populateFieldValues.js @@ -0,0 +1,106 @@ +/* + * Test for populating field values in Form Autofill Parent. + */ + +/* global FormAutofillParent */ + +"use strict"; + +importAutofillModule("FormAutofillParent.jsm"); + +do_get_profile(); + +const TEST_FIELDS = [ + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "organization"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level1"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "postal-code"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel"}, + {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email"}, +]; + +const TEST_GUID = "test-guid"; + +const TEST_PROFILE = { + guid: TEST_GUID, + organization: "World Wide Web Consortium", + streetAddress: "32 Vassar Street\nMIT Room 32-G524", + addressLevel2: "Cambridge", + addressLevel1: "MA", + postalCode: "02139", + country: "US", + tel: "+1 617 253 5702", + email: "timbl@w3.org", +}; + +function camelCase(str) { + return str.toLowerCase().replace(/-([a-z])/g, s => s[1].toUpperCase()); +} + +add_task(function* test_populateFieldValues() { + FormAutofillParent.init(); + + let store = FormAutofillParent.getProfileStore(); + do_check_neq(store, null); + + store.get = function(guid) { + do_check_eq(guid, TEST_GUID); + return store._clone(TEST_PROFILE); + }; + + let notifyUsedCalledCount = 0; + store.notifyUsed = function(guid) { + do_check_eq(guid, TEST_GUID); + notifyUsedCalledCount++; + }; + + yield new Promise((resolve) => { + FormAutofillParent.receiveMessage({ + name: "FormAutofill:PopulateFieldValues", + data: { + guid: TEST_GUID, + fields: TEST_FIELDS, + }, + target: { + sendAsyncMessage: function(name, data) { + do_check_eq(name, "FormAutofill:fillForm"); + + let fields = data.fields; + do_check_eq(fields.length, TEST_FIELDS.length); + + for (let i = 0; i < fields.length; i++) { + do_check_eq(fields[i].fieldName, TEST_FIELDS[i].fieldName); + do_check_eq(fields[i].value, + TEST_PROFILE[camelCase(fields[i].fieldName)]); + } + + resolve(); + }, + }, + }); + }); + + do_check_eq(notifyUsedCalledCount, 1); + + FormAutofillParent._uninit(); + do_check_null(FormAutofillParent.getProfileStore()); +}); + +add_task(function* test_populateFieldValues_with_invalid_guid() { + FormAutofillParent.init(); + + Assert.throws(() => { + FormAutofillParent.receiveMessage({ + name: "FormAutofill:PopulateFieldValues", + data: { + guid: "invalid-guid", + fields: TEST_FIELDS, + }, + target: {}, + }); + }, /No matching profile\./); + + FormAutofillParent._uninit(); +}); |