Bug 1443277 - ensure TPS initializes formAutofillStorage in autofill tests r?eoger draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 05 Mar 2018 12:20:56 -0800
changeset 764979 3d8228f78c501b632c9431d282680e4cb8bd5967
parent 764977 55d91695f4bb951c224005155baef054a786c1f7
push id101910
push userbmo:tchiovoloni@mozilla.com
push dateThu, 08 Mar 2018 18:30:16 +0000
reviewerseoger
bugs1443277
milestone60.0a1
Bug 1443277 - ensure TPS initializes formAutofillStorage in autofill tests r?eoger MozReview-Commit-ID: 1iGnX2f3JzU
services/sync/tps/extensions/tps/resource/modules/formautofill.jsm
services/sync/tps/extensions/tps/resource/tps.jsm
--- a/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm
@@ -23,42 +23,48 @@ class FormAutofillBase {
     if ("changes" in props) {
       this.updateProps = props.changes;
     }
     for (const field of this._fields) {
       this.props[field] = (field in props) ? props[field] : null;
     }
   }
 
-  get storage() {
+  async getStorage() {
+    await formAutofillStorage.initialize();
     return formAutofillStorage[this._subStorageName];
   }
 
-  Create() {
-    this.storage.add(this.props);
+  async Create() {
+    const storage = await this.getStorage();
+    storage.add(this.props);
   }
 
-  Find() {
-    return this.storage._data.find(entry =>
+  async Find() {
+    const storage = await this.getStorage();
+    return storage._data.find(entry =>
       this._fields.every(field => entry[field] === this.props[field])
     );
   }
 
-  Update() {
-    const {guid} = this.Find();
-    this.storage.update(guid, this.updateProps, true);
+  async Update() {
+    const storage = await this.getStorage();
+    const {guid} = await this.Find();
+    storage.update(guid, this.updateProps, true);
   }
 
-  Remove() {
-    const {guid} = this.Find();
-    this.storage.remove(guid);
+  async Remove() {
+    const storage = await this.getStorage();
+    const {guid} = await this.Find();
+    storage.remove(guid);
   }
 }
 
-function DumpStorage(subStorageName) {
+async function DumpStorage(subStorageName) {
+  await formAutofillStorage.initialize();
   Logger.logInfo(`\ndumping ${subStorageName} list\n`, true);
   const entries = formAutofillStorage[subStorageName]._data;
   for (const entry of entries) {
     Logger.logInfo(JSON.stringify(entry), true);
   }
   Logger.logInfo(`\n\nend ${subStorageName} list\n`, true);
 }
 
@@ -77,35 +83,36 @@ const ADDRESS_FIELDS = [
 ];
 
 class Address extends FormAutofillBase {
   constructor(props) {
     super(props, "addresses", ADDRESS_FIELDS);
   }
 }
 
-function DumpAddresses() {
-  DumpStorage("addresses");
+async function DumpAddresses() {
+  await DumpStorage("addresses");
 }
 
 const CREDIT_CARD_FIELDS = [
   "cc-name",
   "cc-number",
   "cc-exp-month",
   "cc-exp-year",
 ];
 
 class CreditCard extends FormAutofillBase {
   constructor(props) {
     super(props, "creditCards", CREDIT_CARD_FIELDS);
   }
 
-  Find() {
-    return this.storage._data.find(entry => {
+  async Find() {
+    const storage = await this.getStorage();
+    return storage._data.find(entry => {
       entry["cc-number"] = MasterPassword.decryptSync(entry["cc-number-encrypted"]);
       return this._fields.every(field => entry[field] === this.props[field]);
     });
   }
 }
 
-function DumpCreditCards() {
-  DumpStorage("creditCards");
+async function DumpCreditCards() {
+  await DumpStorage("creditCards");
 }
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -580,76 +580,76 @@ var TPS = {
   async HandleAddresses(addresses, action) {
     try {
       for (let address of addresses) {
         Logger.logInfo("executing action " + action.toUpperCase() +
                       " on address " + JSON.stringify(address));
         let addressOb = new Address(address);
         switch (action) {
           case ACTION_ADD:
-            addressOb.Create();
+            await addressOb.Create();
             break;
           case ACTION_MODIFY:
-            addressOb.Update();
+            await addressOb.Update();
             break;
           case ACTION_VERIFY:
-            Logger.AssertTrue(addressOb.Find(), "address not found");
+            Logger.AssertTrue(await addressOb.Find(), "address not found");
             break;
           case ACTION_VERIFY_NOT:
-            Logger.AssertTrue(!addressOb.Find(),
+            Logger.AssertTrue(!await addressOb.Find(),
               "address found, but it shouldn't exist");
             break;
           case ACTION_DELETE:
-            Logger.AssertTrue(addressOb.Find(), "address not found");
-            addressOb.Remove();
+            Logger.AssertTrue(await addressOb.Find(), "address not found");
+            await addressOb.Remove();
             break;
           default:
             Logger.AssertTrue(false, "invalid action: " + action);
         }
       }
       Logger.logPass("executing action " + action.toUpperCase() +
                      " on addresses");
     } catch (e) {
-      DumpAddresses();
+      await DumpAddresses();
       throw (e);
     }
   },
 
   async HandleCreditCards(creditCards, action) {
     try {
       for (let creditCard of creditCards) {
         Logger.logInfo("executing action " + action.toUpperCase() +
                       " on creditCard " + JSON.stringify(creditCard));
         let creditCardOb = new CreditCard(creditCard);
         switch (action) {
           case ACTION_ADD:
-            creditCardOb.Create();
+            await creditCardOb.Create();
             break;
           case ACTION_MODIFY:
-            creditCardOb.Update();
+            await creditCardOb.Update();
             break;
           case ACTION_VERIFY:
-            Logger.AssertTrue(creditCardOb.Find(), "creditCard not found");
+            Logger.AssertTrue(await creditCardOb.Find(), "creditCard not found");
             break;
           case ACTION_VERIFY_NOT:
-            Logger.AssertTrue(!creditCardOb.Find(),
+            Logger.AssertTrue(!await creditCardOb.Find(),
               "creditCard found, but it shouldn't exist");
             break;
           case ACTION_DELETE:
-            Logger.AssertTrue(creditCardOb.Find(), "creditCard not found");
-            creditCardOb.Remove();
+            Logger.AssertTrue(await creditCardOb.Find(), "creditCard not found");
+            await creditCardOb.Remove();
             break;
           default:
             Logger.AssertTrue(false, "invalid action: " + action);
         }
       }
       Logger.logPass("executing action " + action.toUpperCase() +
                      " on creditCards");
     } catch (e) {
-      DumpCreditCards();
+      await DumpCreditCards();
       throw (e);
     }
   },
 
   async Cleanup() {
     try {
       await this.WipeServer();
     } catch (ex) {