From 3cfd824081f20d63b61aedf3b72a993f92a9956e Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Mon, 5 Mar 2018 12:20:56 -0800 Subject: [PATCH] Bug 1443277 - ensure TPS initializes formAutofillStorage in autofill tests r=eoger MozReview-Commit-ID: 1iGnX2f3JzU --HG-- extra : rebase_source : 2ac41f995a677cb5484e6c48b6e3e5228a00d12f --- .../tps/resource/modules/formautofill.jsm | 43 +++++++++++-------- .../sync/tps/extensions/tps/resource/tps.jsm | 28 ++++++------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm b/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm index a17c40a747e0..23feb3f8027d 100644 --- a/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm +++ b/services/sync/tps/extensions/tps/resource/modules/formautofill.jsm @@ -28,32 +28,38 @@ class FormAutofillBase { } } - 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) { @@ -82,8 +88,8 @@ class Address extends FormAutofillBase { } } -function DumpAddresses() { - DumpStorage("addresses"); +async function DumpAddresses() { + await DumpStorage("addresses"); } const CREDIT_CARD_FIELDS = [ @@ -98,14 +104,15 @@ class CreditCard extends FormAutofillBase { 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"); } diff --git a/services/sync/tps/extensions/tps/resource/tps.jsm b/services/sync/tps/extensions/tps/resource/tps.jsm index 7fcf9c3506fc..e7b1bf4f91ce 100644 --- a/services/sync/tps/extensions/tps/resource/tps.jsm +++ b/services/sync/tps/extensions/tps/resource/tps.jsm @@ -585,21 +585,21 @@ var TPS = { 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); @@ -608,7 +608,7 @@ var TPS = { Logger.logPass("executing action " + action.toUpperCase() + " on addresses"); } catch (e) { - DumpAddresses(); + await DumpAddresses(); throw (e); } }, @@ -621,21 +621,21 @@ var TPS = { 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); @@ -644,7 +644,7 @@ var TPS = { Logger.logPass("executing action " + action.toUpperCase() + " on creditCards"); } catch (e) { - DumpCreditCards(); + await DumpCreditCards(); throw (e); } },