Skip to content

Commit

Permalink
Bug 1395028 - Part 3: Hide the sync checkbox if credit card sync is u…
Browse files Browse the repository at this point in the history
…navailable. r=lchang

MozReview-Commit-ID: KOdNkwdzWDN

--HG--
extra : rebase_source : 1aaade752f7cadebd2ff1d720b3c46a777aba17e
  • Loading branch information
steveck-chung committed Oct 26, 2017
1 parent 5e0a5c9 commit 6926e37
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
8 changes: 6 additions & 2 deletions browser/extensions/formautofill/FormAutofillDoorhanger.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ const CONTENT = {
return Services.prefs.getBoolPref("services.sync.engine.creditcards");
},
get label() {
// Only set the label when sync account is set and credit card sync is disabled,
// Only set the label when the fallowing conditions existed:
// - sync account is set
// - credit card sync is disabled
// - credit card sync is available
// otherwise return null label to hide checkbox.
return Services.prefs.prefHasUserValue("services.sync.username") &&
!Services.prefs.getBoolPref("services.sync.engine.creditcards") ?
!Services.prefs.getBoolPref("services.sync.engine.creditcards") &&
Services.prefs.getBoolPref("services.sync.engine.creditcards.available") ?
GetStringFromName("creditCardsSyncCheckbox") : null;
},
callback(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,47 @@ add_task(async function test_submit_creditCard_saved_with_mp_enabled_but_cancele
LoginTestUtils.masterPassword.disable();
});

add_task(async function test_submit_creditCard_unavailable_with_sync_account() {
await SpecialPowers.pushPrefEnv({
"set": [
[SYNC_USERNAME_PREF, "[email protected]"],
],
});

await BrowserTestUtils.withNewTab({gBrowser, url: CREDITCARD_FORM_URL},
async function(browser) {
let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
"popupshown");
is(SpecialPowers.getBoolPref(SYNC_CREDITCARDS_AVAILABLE_PREF), false,
"creditCards sync should be unavailable by default");
await ContentTask.spawn(browser, null, async function() {
let form = content.document.getElementById("form");
let name = form.querySelector("#cc-name");
name.focus();
name.setUserInput("User 2");

let number = form.querySelector("#cc-number");
number.setUserInput("1234123412341234");

// Wait 500ms before submission to make sure the input value applied
await new Promise(resolve => setTimeout(resolve, 500));
form.querySelector("input[type=submit]").click();
});

await promiseShown;
let cb = getDoorhangerCheckbox();
ok(cb.hidden, "Sync checkbox should be hidden");

await clickDoorhangerButton(SECONDARY_BUTTON);
}
);
});

add_task(async function test_submit_creditCard_with_sync_account() {
await SpecialPowers.pushPrefEnv({
"set": [
[SYNC_USERNAME_PREF, "[email protected]"],
[SYNC_CREDITCARDS_AVAILABLE_PREF, true],
],
});

Expand Down Expand Up @@ -222,6 +259,7 @@ add_task(async function test_submit_creditCard_with_synced_already() {
"set": [
[SYNC_CREDITCARDS_PREF, true],
[SYNC_USERNAME_PREF, "[email protected]"],
[SYNC_CREDITCARDS_AVAILABLE_PREF, true],
],
});

Expand Down
3 changes: 2 additions & 1 deletion browser/extensions/formautofill/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BASE_URL, TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3, TEST_ADDRESS_4, TEST_ADDRESS_5,
TEST_CREDIT_CARD_1, TEST_CREDIT_CARD_2, TEST_CREDIT_CARD_3, FORM_URL, CREDITCARD_FORM_URL,
FTU_PREF, ENABLED_AUTOFILL_ADDRESSES_PREF, AUTOFILL_CREDITCARDS_AVAILABLE_PREF, ENABLED_AUTOFILL_CREDITCARDS_PREF,
SYNC_USERNAME_PREF, SYNC_ADDRESSES_PREF, SYNC_CREDITCARDS_PREF,
SYNC_USERNAME_PREF, SYNC_ADDRESSES_PREF, SYNC_CREDITCARDS_PREF, SYNC_CREDITCARDS_AVAILABLE_PREF,
sleep, expectPopupOpen, openPopupOn, expectPopupClose, closePopup, clickDoorhangerButton,
getAddresses, saveAddress, removeAddresses, saveCreditCard,
getDisplayedPopupItems, getDoorhangerCheckbox, waitForMasterPasswordDialog,
Expand All @@ -27,6 +27,7 @@ const ENABLED_AUTOFILL_CREDITCARDS_PREF = "extensions.formautofill.creditCards.e
const SYNC_USERNAME_PREF = "services.sync.username";
const SYNC_ADDRESSES_PREF = "services.sync.engine.addresses";
const SYNC_CREDITCARDS_PREF = "services.sync.engine.creditcards";
const SYNC_CREDITCARDS_AVAILABLE_PREF = "services.sync.engine.creditcards.available";

const TEST_ADDRESS_1 = {
"given-name": "John",
Expand Down

0 comments on commit 6926e37

Please sign in to comment.