Bug 1395123 - Unhide credit cards sync engine by default. r=lchang,markh
authorsteveck-chung <schung@mozilla.com>
Mon, 11 Sep 2017 11:55:05 +0800
changeset 390329 5f3d73530ca852d7425b7779f4559758e3dd77c8
parent 390328 59856e397ead753be46684b9a0498d3214bcdee4
child 390330 ac985ab9e0429690a115583db8ad000b00237cde
push id32827
push userccoroiu@mozilla.com
push dateMon, 06 Nov 2017 23:02:00 +0000
treeherdermozilla-central@62aeebcc676e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslchang, markh
bugs1395123
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395123 - Unhide credit cards sync engine by default. r=lchang,markh MozReview-Commit-ID: 4WzzW327PTe
browser/extensions/formautofill/bootstrap.js
browser/extensions/formautofill/test/browser/browser_creditCard_doorhanger.js
--- a/browser/extensions/formautofill/bootstrap.js
+++ b/browser/extensions/formautofill/bootstrap.js
@@ -13,16 +13,18 @@ const CACHED_STYLESHEETS = new WeakMap()
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
                                   "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent",
                                   "resource://formautofill/FormAutofillParent.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillUtils",
+                                  "resource://formautofill/FormAutofillUtils.jsm");
 
 function insertStyleSheet(domWindow, url) {
   let doc = domWindow.document;
   let styleSheetAttr = `href="${url}" type="text/css"`;
   let styleSheet = doc.createProcessingInstruction("xml-stylesheet", styleSheetAttr);
 
   doc.insertBefore(styleSheet, doc.documentElement);
 
@@ -63,16 +65,17 @@ function isAvailable() {
 }
 
 function startup(data) {
   if (!isAvailable()) {
     Services.prefs.clearUserPref("dom.forms.autocomplete.formautofill");
     // reset the sync related prefs incase the feature was previously available
     // but isn't now.
     Services.prefs.clearUserPref("services.sync.engine.addresses.available");
+    Services.prefs.clearUserPref("services.sync.engine.creditcards.available");
     Services.telemetry.scalarSet("formautofill.availability", false);
     return;
   }
 
   if (data.hasOwnProperty("instanceID") && data.instanceID) {
     if (AddonManagerPrivate.isDBLoaded()) {
       addUpgradeListener(data.instanceID);
     } else {
@@ -87,20 +90,25 @@ function startup(data) {
   }
 
   // This pref is used for web contents to detect the autocomplete feature.
   // When it's true, "element.autocomplete" will return tokens we currently
   // support -- otherwise it'll return an empty string.
   Services.prefs.setBoolPref("dom.forms.autocomplete.formautofill", true);
   Services.telemetry.scalarSet("formautofill.availability", true);
 
-  // This pref determines whether the "addresses" sync engine is available
-  // (ie, whether it is shown in any UI etc) - it *does not* determine whether
-  // the engine is actually enabled or not.
+  // This pref determines whether the "addresses"/"creditcards" sync engine is
+  // available (ie, whether it is shown in any UI etc) - it *does not* determine
+  // whether the engine is actually enabled or not.
   Services.prefs.setBoolPref("services.sync.engine.addresses.available", true);
+  if (FormAutofillUtils.isAutofillCreditCardsAvailable) {
+    Services.prefs.setBoolPref("services.sync.engine.creditcards.available", true);
+  } else {
+    Services.prefs.clearUserPref("services.sync.engine.creditcards.available");
+  }
 
   // Listen for the autocomplete popup message to lazily append our stylesheet related to the popup.
   Services.mm.addMessageListener("FormAutoComplete:MaybeOpenPopup", onMaybeOpenPopup);
 
   let parent = new FormAutofillParent();
   parent.init().catch(Cu.reportError);
   Services.ppmm.loadProcessScript("data:,new " + function() {
     Components.utils.import("resource://formautofill/FormAutofillContent.jsm");
--- a/browser/extensions/formautofill/test/browser/browser_creditCard_doorhanger.js
+++ b/browser/extensions/formautofill/test/browser/browser_creditCard_doorhanger.js
@@ -15,16 +15,20 @@ add_task(async function test_submit_cred
         let number = form.querySelector("#cc-number");
         number.setUserInput("1111222233334444");
 
         // Wait 1000ms before submission to make sure the input value applied
         await new Promise(resolve => setTimeout(resolve, 1000));
         form.querySelector("input[type=submit]").click();
       });
 
+      ok(!SpecialPowers.Services.prefs.prefHasUserValue(SYNC_USERNAME_PREF),
+         "Sync account should not exist by default");
+      let cb = getDoorhangerCheckbox();
+      ok(cb.hidden, "Sync checkbox should be hidden");
       await promiseShown;
       await clickDoorhangerButton(SECONDARY_BUTTON);
     }
   );
 
   await sleep(1000);
   let creditCards = await getCreditCards();
   is(creditCards.length, 0, "No credit card saved");
@@ -158,52 +162,16 @@ add_task(async function test_submit_cred
   );
 
   await sleep(1000);
   let creditCards = await getCreditCards();
   is(creditCards.length, 2, "Still 2 credit cards in storage");
   LoginTestUtils.masterPassword.disable();
 });
 
-add_task(async function test_submit_creditCard_unavailable_with_sync_account() {
-  await SpecialPowers.pushPrefEnv({
-    "set": [
-      [SYNC_USERNAME_PREF, "foo@bar.com"],
-    ],
-  });
-
-  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, "foo@bar.com"],
       [SYNC_CREDITCARDS_AVAILABLE_PREF, true],
     ],
   });