From 858bbaf880c149c0ab2a093ae7cc3fbdb30ce44c Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 30 Oct 2023 11:38:24 +0000 Subject: [PATCH] Bug 1859251 - Do not show confirmation popup when users click cancel button in the address/credit card doorhanger r=issammani Differential Revision: https://phabricator.services.mozilla.com/D191073 UltraBlame original commit: 07ff1e2e4f656661631e6746f339e6232b59ebfd --- .../formautofill/test/browser/browser.toml | 7 + .../browser/browser_confirmation_popup.js | 689 ++++++++++++++++++ .../formautofill/test/browser/head.js | 201 +++++ .../default/FormAutofillPrompter.sys.mjs | 53 +- 4 files changed, 936 insertions(+), 14 deletions(-) create mode 100644 browser/extensions/formautofill/test/browser/browser_confirmation_popup.js diff --git a/browser/extensions/formautofill/test/browser/browser.toml b/browser/extensions/formautofill/test/browser/browser.toml index 67167bfc8f401..6bb963febf3dd 100644 --- a/browser/extensions/formautofill/test/browser/browser.toml +++ b/browser/extensions/formautofill/test/browser/browser.toml @@ -137,6 +137,13 @@ js ] [ " +browser_confirmation_popup +. +js +" +] +[ +" browser_dropdown_layout . js diff --git a/browser/extensions/formautofill/test/browser/browser_confirmation_popup.js b/browser/extensions/formautofill/test/browser/browser_confirmation_popup.js new file mode 100644 index 0000000000000..9b5281bc7ea92 --- /dev/null +++ b/browser/extensions/formautofill/test/browser/browser_confirmation_popup.js @@ -0,0 +1,689 @@ +/ +* +Any +copyright +is +dedicated +to +the +Public +Domain +. +http +: +/ +/ +creativecommons +. +org +/ +publicdomain +/ +zero +/ +1 +. +0 +/ +* +/ +" +use +strict +" +; +async +function +expectSavedAddresses +( +expectedCount +) +{ +const +addresses += +await +getAddresses +( +) +; +is +( +addresses +. +length +expectedCount +{ +addresses +. +length +} +address +in +the +storage +) +; +return +addresses +; +} +add_setup +( +async +function +( +) +{ +await +SpecialPowers +. +pushPrefEnv +( +{ +set +: +[ +[ +" +extensions +. +formautofill +. +addresses +. +capture +. +v2 +. +enabled +" +true +] +[ +" +extensions +. +formautofill +. +addresses +. +supported +" +" +on +" +] +[ +" +extensions +. +formautofill +. +loglevel +" +" +debug +" +] +] +} +) +; +} +) +; +add_task +( +async +function +test_save_doorhanger_show_confirmation +( +) +{ +await +expectSavedAddresses +( +0 +) +; +await +BrowserTestUtils +. +withNewTab +( +{ +gBrowser +url +: +ADDRESS_FORM_URL +} +async +function +( +browser +) +{ +/ +/ +Show +the +save +doorhanger +const +onSavePopupShown += +waitForPopupShown +( +) +; +await +focusUpdateSubmitForm +( +browser +{ +focusSelector +: +" +# +given +- +name +" +newValues +: +{ +" +# +given +- +name +" +: +" +Test +User +" +" +# +organization +" +: +" +Sesame +Street +" +" +# +street +- +address +" +: +" +123 +Sesame +Street +" +" +# +tel +" +: +" +1 +- +345 +- +345 +- +3456 +" +} +} +) +; +await +onSavePopupShown +; +/ +/ +click +the +main +button +and +expect +seeing +the +confirmation +const +hintShownAndVerified += +verifyConfirmationHint +( +browser +false +) +; +await +clickDoorhangerButton +( +MAIN_BUTTON +0 +) +; +info +( +" +waiting +for +verifyConfirmationHint +" +) +; +await +hintShownAndVerified +; +info +( +" +waiting +for +verifyConfirmationHint +< +< +" +) +; +} +) +; +await +expectSavedAddresses +( +1 +) +; +await +removeAllRecords +( +) +; +} +) +; +add_task +( +async +function +test_update_doorhanger_show_confirmation +( +) +{ +await +setStorage +( +TEST_ADDRESS_3 +) +; +await +expectSavedAddresses +( +1 +) +; +await +BrowserTestUtils +. +withNewTab +( +{ +gBrowser +url +: +ADDRESS_FORM_URL +} +async +function +( +browser +) +{ +/ +/ +Show +the +update +doorhanger +const +onUpdatePopupShown += +waitForPopupShown +( +) +; +await +focusUpdateSubmitForm +( +browser +{ +focusSelector +: +" +# +given +- +name +" +newValues +: +{ +" +# +given +- +name +" +: +TEST_ADDRESS_3 +[ +" +given +- +name +" +] +" +# +street +- +address +" +: +{ +TEST_ADDRESS_3 +[ +" +street +- +address +" +] +} +4F +" +# +postal +- +code +" +: +TEST_ADDRESS_3 +[ +" +postal +- +code +" +] +} +} +) +; +await +onUpdatePopupShown +; +await +sleep +( +5000 +) +; +/ +/ +click +the +main +button +and +expect +seeing +the +confirmation +const +hintShownAndVerified += +verifyConfirmationHint +( +browser +false +) +; +await +clickDoorhangerButton +( +MAIN_BUTTON +0 +) +; +info +( +" +waiting +for +verifyConfirmationHint +" +) +; +await +hintShownAndVerified +; +} +) +; +await +expectSavedAddresses +( +1 +) +; +await +removeAllRecords +( +) +; +} +) +; +add_task +( +async +function +test_edit_doorhanger_show_confirmation +( +) +{ +await +expectSavedAddresses +( +0 +) +; +await +BrowserTestUtils +. +withNewTab +( +{ +gBrowser +url +: +ADDRESS_FORM_URL +} +async +function +( +browser +) +{ +/ +/ +Show +the +save +doorhanger +const +onSavePopupShown += +waitForPopupShown +( +) +; +await +focusUpdateSubmitForm +( +browser +{ +focusSelector +: +" +# +given +- +name +" +newValues +: +{ +" +# +given +- +name +" +: +" +Test +User +" +" +# +organization +" +: +" +Sesame +Street +" +" +# +street +- +address +" +: +" +123 +Sesame +Street +" +" +# +tel +" +: +" +1 +- +345 +- +345 +- +3456 +" +} +} +) +; +await +onSavePopupShown +; +/ +/ +Show +the +edit +doorhanger +const +onEditPopupShown += +waitForPopupShown +( +) +; +await +clickAddressDoorhangerButton +( +EDIT_ADDRESS_BUTTON +) +; +await +onEditPopupShown +; +/ +/ +click +the +main +button +and +expect +seeing +the +confirmation +const +hintShownAndVerified += +verifyConfirmationHint +( +browser +false +) +; +await +clickDoorhangerButton +( +MAIN_BUTTON +0 +) +; +info +( +" +waiting +for +verifyConfirmationHint +" +) +; +await +hintShownAndVerified +; +} +) +; +await +expectSavedAddresses +( +1 +) +; +await +removeAllRecords +( +) +; +} +) +; diff --git a/browser/extensions/formautofill/test/browser/head.js b/browser/extensions/formautofill/test/browser/head.js index ac8e49853f842..634cf23faf85b 100644 --- a/browser/extensions/formautofill/test/browser/head.js +++ b/browser/extensions/formautofill/test/browser/head.js @@ -7385,6 +7385,207 @@ return normalized ; } +async +function +verifyConfirmationHint +( +browser +forceClose +anchorID += +" +identity +- +icon +" +) +{ +let +hintElem += +browser +. +ownerGlobal +. +ConfirmationHint +. +_panel +; +await +BrowserTestUtils +. +waitForPopupEvent +( +hintElem +" +shown +" +) +; +try +{ +Assert +. +equal +( +hintElem +. +state +" +open +" +" +hint +popup +is +open +" +) +; +Assert +. +ok +( +BrowserTestUtils +. +is_visible +( +hintElem +. +anchorNode +) +" +hint +anchorNode +is +visible +" +) +; +Assert +. +equal +( +hintElem +. +anchorNode +. +id +anchorID +" +Hint +should +be +anchored +on +the +expected +notification +icon +" +) +; +info +( +" +verifyConfirmationHint +hint +is +shown +and +has +its +anchorNode +" +) +; +if +( +forceClose +) +{ +await +closePopup +( +hintElem +) +; +} +else +{ +info +( +" +verifyConfirmationHint +assertion +ok +wait +for +poopuphidden +" +) +; +await +BrowserTestUtils +. +waitForPopupEvent +( +hintElem +" +hidden +" +) +; +info +( +" +verifyConfirmationHint +hintElem +popup +is +hidden +" +) +; +} +} +catch +( +ex +) +{ +Assert +. +ok +( +false +" +Confirmation +hint +not +shown +: +" ++ +ex +. +message +) +; +} +finally +{ +info +( +" +verifyConfirmationHint +promise +finalized +" +) +; +} +} add_setup ( function diff --git a/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs b/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs index d6eafd5b180c3..d7d0be656c405 100644 --- a/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs +++ b/toolkit/components/formautofill/default/FormAutofillPrompter.sys.mjs @@ -3699,9 +3699,12 @@ DEFAULT_REGION Address edit doorhanger -has -different +changes layout +according +to +the +country # layout = @@ -8176,12 +8179,18 @@ flowId isCapture ) ; +if +( +confirmationHintId +) +{ showConfirmation ( browser confirmationHintId ) ; +} return state ; @@ -8659,6 +8668,9 @@ resolve = > { +let +doorhanger +; const editAddressCb = @@ -8749,25 +8761,32 @@ resolve { state : -isSave -? -" -create -" -: -" -update -" -confimationHintId +doorhanger +. +ui +. +footer +. +mainAction +. +callbackState +confirmationHintId : -null +doorhanger +. +ui +. +footer +. +mainAction +. +confirmationHintId } ) ; } } ; -const doorhanger = isSave @@ -8847,12 +8866,18 @@ flowId isSave ) ; +if +( +confirmationHintId +) +{ showConfirmation ( browser confirmationHintId ) ; +} return { state