Bug 1443277 - ensure TPS initializes formAutofillStorage in autofill tests r=eoger

MozReview-Commit-ID: 1iGnX2f3JzU

--HG--
extra : rebase_source : 2ac41f995a677cb5484e6c48b6e3e5228a00d12f
This commit is contained in:
Thom Chiovoloni 2018-03-05 12:20:56 -08:00
Родитель 686d0472da
Коммит 3cfd824081
2 изменённых файлов: 39 добавлений и 32 удалений

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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);
}
},