Bug 1443277 - ensure TPS initializes formAutofillStorage in autofill tests r=eoger
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 05 Mar 2018 12:20:56 -0800
changeset 407228 144f1e24df60507c7af072a446baaab39c1270a7
parent 407227 564cb9725e123d59f6f12bd8af3625dcee32a292
child 407229 8d62a6ff5d9aa2ebfce7bf90a044bc6caaa7840e
child 407271 31a33fc619562e5b326585c6864d86832dac5126
push id60850
push usertchiovoloni@mozilla.com
push dateThu, 08 Mar 2018 18:37:47 +0000
treeherderautoland@144f1e24df60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger
bugs1443277
milestone60.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 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) {