forked from mirrors/gecko-dev
		
	Bug 1873215 - Display address capture prompt only for forms with all the required fields r=credential-management-reviewers,joschmidt
Differential Revision: https://phabricator.services.mozilla.com/D197882
This commit is contained in:
		
							parent
							
								
									1217633cd1
								
							
						
					
					
						commit
						e36744726b
					
				
					 9 changed files with 150 additions and 24 deletions
				
			
		|  | @ -1,6 +1,7 @@ | ||||||
| [DEFAULT] | [DEFAULT] | ||||||
| prefs = [ | prefs = [ | ||||||
|   "extensions.formautofill.addresses.enabled=true", |   "extensions.formautofill.addresses.enabled=true", | ||||||
|  |   "extensions.formautofill.addresses.capture.requiredFields=''", | ||||||
|   "toolkit.telemetry.ipcBatchTimeout=0", # lower the interval for event telemetry in the content process to update the parent process |   "toolkit.telemetry.ipcBatchTimeout=0", # lower the interval for event telemetry in the content process to update the parent process | ||||||
| ] | ] | ||||||
| support-files = [ | support-files = [ | ||||||
|  | @ -15,10 +16,14 @@ support-files = [ | ||||||
| 
 | 
 | ||||||
| ["browser_address_capture_page_navigation.js"] | ["browser_address_capture_page_navigation.js"] | ||||||
| 
 | 
 | ||||||
|  | ["browser_address_doorhanger_confirmation_popup.js"] | ||||||
|  | 
 | ||||||
| ["browser_address_doorhanger_display.js"] | ["browser_address_doorhanger_display.js"] | ||||||
| 
 | 
 | ||||||
| ["browser_address_doorhanger_invalid_fields.js"] | ["browser_address_doorhanger_invalid_fields.js"] | ||||||
| 
 | 
 | ||||||
|  | ["browser_address_doorhanger_multiple_tabs.js"] | ||||||
|  | 
 | ||||||
| ["browser_address_doorhanger_not_shown.js"] | ["browser_address_doorhanger_not_shown.js"] | ||||||
| 
 | 
 | ||||||
| ["browser_address_doorhanger_state.js"] | ["browser_address_doorhanger_state.js"] | ||||||
|  |  | ||||||
|  | @ -18,7 +18,6 @@ add_setup(async function () { | ||||||
|     set: [ |     set: [ | ||||||
|       ["extensions.formautofill.addresses.capture.v2.enabled", true], |       ["extensions.formautofill.addresses.capture.v2.enabled", true], | ||||||
|       ["extensions.formautofill.addresses.supported", "on"], |       ["extensions.formautofill.addresses.supported", "on"], | ||||||
|       ["extensions.formautofill.loglevel", "debug"], |  | ||||||
|     ], |     ], | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  | @ -75,7 +74,6 @@ add_task(async function test_update_doorhanger_show_confirmation() { | ||||||
|       }); |       }); | ||||||
|       await onUpdatePopupShown; |       await onUpdatePopupShown; | ||||||
| 
 | 
 | ||||||
|       await sleep(5000); |  | ||||||
|       // click the main button and expect seeing the confirmation
 |       // click the main button and expect seeing the confirmation
 | ||||||
|       const hintShownAndVerified = verifyConfirmationHint(browser, false); |       const hintShownAndVerified = verifyConfirmationHint(browser, false); | ||||||
|       await clickDoorhangerButton(MAIN_BUTTON, 0); |       await clickDoorhangerButton(MAIN_BUTTON, 0); | ||||||
|  | @ -235,3 +235,100 @@ add_task( | ||||||
|     await removeAllRecords(); |     await removeAllRecords(); | ||||||
|   } |   } | ||||||
| ); | ); | ||||||
|  | 
 | ||||||
|  | add_task( | ||||||
|  |   async function test_doorhanger_shown_when_contain_all_required_fields() { | ||||||
|  |     await SpecialPowers.pushPrefEnv({ | ||||||
|  |       set: [ | ||||||
|  |         [ | ||||||
|  |           "extensions.formautofill.addresses.capture.requiredFields", | ||||||
|  |           "street-address,postal-code,address-level1,address-level2", | ||||||
|  |         ], | ||||||
|  |       ], | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     await BrowserTestUtils.withNewTab( | ||||||
|  |       { gBrowser, url: ADDRESS_FORM_URL }, | ||||||
|  |       async function (browser) { | ||||||
|  |         let onPopupShown = waitForPopupShown(); | ||||||
|  | 
 | ||||||
|  |         await focusUpdateSubmitForm(browser, { | ||||||
|  |           focusSelector: "#street-address", | ||||||
|  |           newValues: { | ||||||
|  |             "#street-address": "32 Vassar Street\nMIT Room 32-G524", | ||||||
|  |             "#postal-code": "02139", | ||||||
|  |             "#address-level2": "Cambridge", | ||||||
|  |             "#address-level1": "MA", | ||||||
|  |           }, | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         await onPopupShown; | ||||||
|  |         await clickDoorhangerButton(MAIN_BUTTON, 0); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     await expectSavedAddresses(1); | ||||||
|  |     await SpecialPowers.popPrefEnv(); | ||||||
|  |   } | ||||||
|  | ); | ||||||
|  | 
 | ||||||
|  | add_task( | ||||||
|  |   async function test_doorhanger_not_shown_when_contain_required_invalid_fields() { | ||||||
|  |     await SpecialPowers.pushPrefEnv({ | ||||||
|  |       set: [ | ||||||
|  |         [ | ||||||
|  |           "extensions.formautofill.addresses.capture.requiredFields", | ||||||
|  |           "street-address,postal-code,address-level1,address-level2", | ||||||
|  |         ], | ||||||
|  |       ], | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     await BrowserTestUtils.withNewTab( | ||||||
|  |       { gBrowser, url: ADDRESS_FORM_URL }, | ||||||
|  |       async function (browser) { | ||||||
|  |         await focusUpdateSubmitForm(browser, { | ||||||
|  |           focusSelector: "#street-address", | ||||||
|  |           newValues: { | ||||||
|  |             "#street-address": "32 Vassar Street\nMIT Room 32-G524", | ||||||
|  |             "#postal-code": "000", // postal-code is invalid
 | ||||||
|  |             "#address-level2": "Cambridge", | ||||||
|  |             "#address-level1": "MA", | ||||||
|  |           }, | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden"); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | ); | ||||||
|  | 
 | ||||||
|  | add_task( | ||||||
|  |   async function test_doorhanger_not_shown_when_not_contain_all_required_fields() { | ||||||
|  |     await SpecialPowers.pushPrefEnv({ | ||||||
|  |       set: [ | ||||||
|  |         [ | ||||||
|  |           "extensions.formautofill.addresses.capture.requiredFields", | ||||||
|  |           "street-address,postal-code,address-level1,address-level2", | ||||||
|  |         ], | ||||||
|  |       ], | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     await BrowserTestUtils.withNewTab( | ||||||
|  |       { gBrowser, url: ADDRESS_FORM_URL }, | ||||||
|  |       async function (browser) { | ||||||
|  |         await focusUpdateSubmitForm(browser, { | ||||||
|  |           focusSelector: "#street-address", | ||||||
|  |           newValues: { | ||||||
|  |             "#given-name": "John", | ||||||
|  |             "#family-name": "Doe", | ||||||
|  |             "#postal-code": "02139", | ||||||
|  |             "#address-level2": "Cambridge", | ||||||
|  |             "#address-level1": "MA", | ||||||
|  |           }, | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden"); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | @ -25,10 +25,6 @@ skip-if = [ | ||||||
| 
 | 
 | ||||||
| ["browser_check_installed.js"] | ["browser_check_installed.js"] | ||||||
| 
 | 
 | ||||||
| ["browser_confirmation_popup.js"] |  | ||||||
| 
 |  | ||||||
| ["browser_doorhanger_multiple_tab.js"] |  | ||||||
| 
 |  | ||||||
| ["browser_dropdown_layout.js"] | ["browser_dropdown_layout.js"] | ||||||
| 
 | 
 | ||||||
| ["browser_editAddressDialog.js"] | ["browser_editAddressDialog.js"] | ||||||
|  |  | ||||||
|  | @ -9,6 +9,8 @@ add_task(async function setup_storage() { | ||||||
|       [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"], |       [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"], | ||||||
|       [ENABLED_AUTOFILL_ADDRESSES_PREF, true], |       [ENABLED_AUTOFILL_ADDRESSES_PREF, true], | ||||||
|       [ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF, true], |       [ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF, true], | ||||||
|  |       // set capture required fields to empty to make testcase simpler
 | ||||||
|  |       ["extensions.formautofill.addresses.capture.requiredFields", ""], | ||||||
|     ], |     ], | ||||||
|   }); |   }); | ||||||
|   await setStorage(TEST_ADDRESS_2, TEST_ADDRESS_4, TEST_ADDRESS_5); |   await setStorage(TEST_ADDRESS_2, TEST_ADDRESS_4, TEST_ADDRESS_5); | ||||||
|  | @ -51,7 +53,7 @@ add_task(async function test_iframe_autocomplete() { | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   let onPopupShown = waitForPopupShown(); |   const onPopupShown = waitForPopupShown(); | ||||||
|   await focusUpdateSubmitForm(iframeBC, { |   await focusUpdateSubmitForm(iframeBC, { | ||||||
|     focusSelector: "#organization", |     focusSelector: "#organization", | ||||||
|     newValues: { |     newValues: { | ||||||
|  |  | ||||||
|  | @ -3952,6 +3952,8 @@ pref("extensions.formautofill.addresses.enabled", true); | ||||||
| pref("extensions.formautofill.addresses.capture.enabled", false); | pref("extensions.formautofill.addresses.capture.enabled", false); | ||||||
| // This preference should be removed entirely once address capture v2 developing is finished
 | // This preference should be removed entirely once address capture v2 developing is finished
 | ||||||
| pref("extensions.formautofill.addresses.capture.v2.enabled", false); | pref("extensions.formautofill.addresses.capture.v2.enabled", false); | ||||||
|  | // Defies the required address form fields to trigger the display of the address capture doorhanger
 | ||||||
|  | pref("extensions.formautofill.addresses.capture.requiredFields", "street-address,postal-code,address-level1,address-level2"); | ||||||
| pref("extensions.formautofill.addresses.ignoreAutocompleteOff", true); | pref("extensions.formautofill.addresses.ignoreAutocompleteOff", true); | ||||||
| // Supported countries need to follow ISO 3166-1 to align with "browser.search.region"
 | // Supported countries need to follow ISO 3166-1 to align with "browser.search.region"
 | ||||||
| pref("extensions.formautofill.addresses.supportedCountries", "US,CA"); | pref("extensions.formautofill.addresses.supportedCountries", "US,CA"); | ||||||
|  |  | ||||||
|  | @ -19,6 +19,8 @@ const ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF = | ||||||
|   "extensions.formautofill.addresses.capture.enabled"; |   "extensions.formautofill.addresses.capture.enabled"; | ||||||
| const ENABLED_AUTOFILL_ADDRESSES_CAPTURE_V2_PREF = | const ENABLED_AUTOFILL_ADDRESSES_CAPTURE_V2_PREF = | ||||||
|   "extensions.formautofill.addresses.capture.v2.enabled"; |   "extensions.formautofill.addresses.capture.v2.enabled"; | ||||||
|  | const ENABLED_AUTOFILL_ADDRESSES_CAPTURE_REQUIRED_FIELDS_PREF = | ||||||
|  |   "extensions.formautofill.addresses.capture.requiredFields"; | ||||||
| const ENABLED_AUTOFILL_ADDRESSES_SUPPORTED_COUNTRIES_PREF = | const ENABLED_AUTOFILL_ADDRESSES_SUPPORTED_COUNTRIES_PREF = | ||||||
|   "extensions.formautofill.addresses.supportedCountries"; |   "extensions.formautofill.addresses.supportedCountries"; | ||||||
| const ENABLED_AUTOFILL_CREDITCARDS_PREF = | const ENABLED_AUTOFILL_CREDITCARDS_PREF = | ||||||
|  | @ -268,6 +270,14 @@ XPCOMUtils.defineLazyPreferenceGetter( | ||||||
|   "captureOnPageNavigation", |   "captureOnPageNavigation", | ||||||
|   ENABLED_AUTOFILL_CAPTURE_ON_PAGE_NAVIGATION |   ENABLED_AUTOFILL_CAPTURE_ON_PAGE_NAVIGATION | ||||||
| ); | ); | ||||||
|  | XPCOMUtils.defineLazyPreferenceGetter( | ||||||
|  |   FormAutofill, | ||||||
|  |   "addressCaptureRequiredFields", | ||||||
|  |   ENABLED_AUTOFILL_ADDRESSES_CAPTURE_REQUIRED_FIELDS_PREF, | ||||||
|  |   null, | ||||||
|  |   null, | ||||||
|  |   val => val?.split(",").filter(v => !!v) | ||||||
|  | ); | ||||||
| 
 | 
 | ||||||
| // XXX: This should be invalidated on intl:app-locales-changed.
 | // XXX: This should be invalidated on intl:app-locales-changed.
 | ||||||
| ChromeUtils.defineLazyGetter(FormAutofill, "countries", () => { | ChromeUtils.defineLazyGetter(FormAutofill, "countries", () => { | ||||||
|  |  | ||||||
|  | @ -568,23 +568,7 @@ export class FormAutofillParent extends JSWindowActorParent { | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if ( |     if (!this._shouldShowSaveAddressPrompt(newAddress.record)) { | ||||||
|       !FormAutofill.isAutofillAddressesCaptureEnabled && |  | ||||||
|       !FormAutofill.isAutofillAddressesCaptureV2Enabled |  | ||||||
|     ) { |  | ||||||
|       return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     // Do not save address for regions that we don't support
 |  | ||||||
|     if ( |  | ||||||
|       FormAutofill._isAutofillAddressesAvailable == "detect" && |  | ||||||
|       !FormAutofill.isAutofillAddressesAvailableInCountry( |  | ||||||
|         newAddress.record.country |  | ||||||
|       ) |  | ||||||
|     ) { |  | ||||||
|       lazy.log.debug( |  | ||||||
|         "Do not show the capture prompt for an unsupported region" |  | ||||||
|       ); |  | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -669,4 +653,36 @@ export class FormAutofillParent extends JSWindowActorParent { | ||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   _shouldShowSaveAddressPrompt(record) { | ||||||
|  |     if ( | ||||||
|  |       !FormAutofill.isAutofillAddressesCaptureEnabled && | ||||||
|  |       !FormAutofill.isAutofillAddressesCaptureV2Enabled | ||||||
|  |     ) { | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Do not save address for regions that we don't support
 | ||||||
|  |     if ( | ||||||
|  |       FormAutofill._isAutofillAddressesAvailable == "detect" && | ||||||
|  |       !FormAutofill.isAutofillAddressesAvailableInCountry(record.country) | ||||||
|  |     ) { | ||||||
|  |       lazy.log.debug( | ||||||
|  |         `Do not show the address capture prompt for unsupported regions - ${record.country}` | ||||||
|  |       ); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // Display the address capture doorhanger only when the submitted form contains all
 | ||||||
|  |     // the required fields. This approach is implemented to prevent excessive prompting.
 | ||||||
|  |     const requiredFields = FormAutofill.addressCaptureRequiredFields ?? []; | ||||||
|  |     if (!requiredFields.every(field => field in record)) { | ||||||
|  |       lazy.log.debug( | ||||||
|  |         "Do not show the address capture prompt when the submitted form doesn't contain all the required fields" | ||||||
|  |       ); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Dimi
						Dimi