Backed out changesets a182935e2bd4 and 0735f44b742a (bug 1393374) for failures on Beta 57.

This commit is contained in:
Ryan VanderMeulen 2017-09-20 14:08:29 -04:00
Родитель 2ef8bd8a46
Коммит 1cb6096990
6 изменённых файлов: 128 добавлений и 456 удалений

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

@ -37,7 +37,7 @@ function clickOnElement(selector) {
SimpleTest.executeSoon(() => element.click());
}
async function onStorageChanged(type) {
async function onAddressChanged(type) {
return new Promise(resolve => {
formFillChromeScript.addMessageListener("formautofill-storage-changed", function onChanged(data) {
formFillChromeScript.removeMessageListener("formautofill-storage-changed", onChanged);
@ -58,58 +58,60 @@ function checkMenuEntries(expectedValues, isFormAutofillResult = true) {
}
}
function invokeAsyncChromeTask(message, response, payload = {}) {
async function addAddress(address) {
return new Promise(resolve => {
formFillChromeScript.sendAsyncMessage(message, payload);
formFillChromeScript.addMessageListener(response, function onReceived(data) {
formFillChromeScript.removeMessageListener(response, onReceived);
formFillChromeScript.sendAsyncMessage("FormAutofillTest:AddAddress", {address});
formFillChromeScript.addMessageListener("FormAutofillTest:AddressAdded", function onAdded(data) {
formFillChromeScript.removeMessageListener("FormAutofillTest:AddressAdded", onAdded);
SimpleTest.requestFlakyTimeout("Ensure ProfileAutocomplete is registered");
setTimeout(resolve, 500);
});
});
}
async function removeAddress(guid) {
return new Promise(resolve => {
formFillChromeScript.sendAsyncMessage("FormAutofillTest:RemoveAddress", {guid});
formFillChromeScript.addMessageListener("FormAutofillTest:AddressRemoved", function onDeleted(data) {
formFillChromeScript.removeMessageListener("FormAutofillTest:AddressRemoved", onDeleted);
resolve();
});
});
}
async function updateAddress(guid, address) {
return new Promise(resolve => {
formFillChromeScript.sendAsyncMessage("FormAutofillTest:UpdateAddress", {address, guid});
formFillChromeScript.addMessageListener("FormAutofillTest:AddressUpdated", function onUpdated(data) {
formFillChromeScript.removeMessageListener("FormAutofillTest:AddressUpdated", onUpdated);
resolve();
});
});
}
async function checkAddresses(expectedAddresses) {
return new Promise(resolve => {
formFillChromeScript.sendAsyncMessage("FormAutofillTest:CheckAddresses", {expectedAddresses});
formFillChromeScript.addMessageListener("FormAutofillTest:areAddressesMatching", function onChecked(data) {
formFillChromeScript.removeMessageListener("FormAutofillTest:areAddressesMatching", onChecked);
resolve(data);
});
});
}
async function addAddress(address) {
await invokeAsyncChromeTask("FormAutofillTest:AddAddress", "FormAutofillTest:AddressAdded", {address});
await sleep();
}
async function cleanUpAddress() {
return new Promise(resolve => {
formFillChromeScript.sendAsyncMessage("FormAutofillTest:CleanUpAddress", {});
formFillChromeScript.addMessageListener("FormAutofillTest:AddressCleanedUp", function onCleanedUp(data) {
formFillChromeScript.removeMessageListener("FormAutofillTest:AddressCleanedUp", onCleanedUp);
async function removeAddress(guid) {
return invokeAsyncChromeTask("FormAutofillTest:RemoveAddress", "FormAutofillTest:AddressRemoved", {guid});
}
async function updateAddress(guid, address) {
return invokeAsyncChromeTask("FormAutofillTest:UpdateAddress", "FormAutofillTest:AddressUpdated", {address, guid});
}
async function checkAddresses(expectedAddresses) {
return invokeAsyncChromeTask("FormAutofillTest:CheckAddresses", "FormAutofillTest:areAddressesMatching", {expectedAddresses});
}
async function cleanUpAddresses() {
return invokeAsyncChromeTask("FormAutofillTest:CleanUpAddresses", "FormAutofillTest:AddressesCleanedUp");
}
async function addCreditCard(creditcard) {
await invokeAsyncChromeTask("FormAutofillTest:AddCreditCard", "FormAutofillTest:CreditCardAdded", {creditcard});
await sleep();
}
async function removeCreditCard(guid) {
return invokeAsyncChromeTask("FormAutofillTest:RemoveCreditCard", "FormAutofillTest:CreditCardRemoved", {guid});
}
async function checkCreditCards(expectedCreditCards) {
return invokeAsyncChromeTask("FormAutofillTest:CheckCreditCards", "FormAutofillTest:areCreditCardsMatching", {expectedCreditCards});
}
async function cleanUpCreditCards() {
return invokeAsyncChromeTask("FormAutofillTest:CleanUpCreditCards", "FormAutofillTest:CreditCardsCleanedUp");
}
async function cleanUpStorage() {
await cleanUpAddresses();
await cleanUpCreditCards();
resolve(data);
});
});
}
// Utils for registerPopupShownListener(in satchel_common.js) that handles dropdown popup

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

@ -7,192 +7,113 @@
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://formautofill/FormAutofillUtils.jsm");
let {profileStorage} = Cu.import("resource://formautofill/ProfileStorage.jsm", {});
const {ADDRESSES_COLLECTION_NAME, CREDITCARDS_COLLECTION_NAME} = FormAutofillUtils;
var ParentUtils = {
async _getRecords(collectionName) {
return new Promise(resolve => {
Services.cpmm.addMessageListener("FormAutofill:Records", function getResult({data}) {
Services.cpmm.removeMessageListener("FormAutofill:Records", getResult);
resolve(data);
});
Services.cpmm.sendAsyncMessage("FormAutofill:GetRecords", {searchString: "", collectionName});
cleanUpAddress() {
Services.cpmm.addMessageListener("FormAutofill:Records", function getResult(result) {
Services.cpmm.removeMessageListener("FormAutofill:Records", getResult);
let addresses = result.data;
Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses",
{guids: addresses.map(address => address.guid)});
let count = addresses.length;
Services.obs.addObserver(function observer(subject, topic, data) {
if (!--count) {
Services.obs.removeObserver(observer, topic);
sendAsyncMessage("FormAutofillTest:AddressCleanedUp");
}
}, "formautofill-storage-changed");
});
Services.cpmm.sendAsyncMessage("FormAutofill:GetRecords", {searchString: "", collectionName: "addresses"});
},
async _storageChangeObserved({topic = "formautofill-storage-changed", type, times = 1}) {
let count = times;
return new Promise(resolve => {
Services.obs.addObserver(function observer(subject, obsTopic, data) {
if (type && data != type || !!--count) {
return;
}
Services.obs.removeObserver(observer, obsTopic);
resolve();
}, topic);
});
},
async _operateRecord(collectionName, type, msgData, contentMsg) {
let times, topic;
if (collectionName == ADDRESSES_COLLECTION_NAME) {
switch (type) {
case "add": {
Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", msgData);
break;
}
case "update": {
Services.cpmm.sendAsyncMessage("FormAutofill:SaveAddress", msgData);
break;
}
case "remove": {
times = msgData.guids.length;
Services.cpmm.sendAsyncMessage("FormAutofill:RemoveAddresses", msgData);
break;
}
updateAddress(type, chromeMsg, msgData, contentMsg) {
Services.cpmm.sendAsyncMessage(chromeMsg, msgData);
Services.obs.addObserver(function observer(subject, topic, data) {
if (data != type) {
return;
}
} else {
switch (type) {
case "add": {
const msgDataCloned = Object.assign({}, msgData);
Services.cpmm.sendAsyncMessage("FormAutofill:SaveCreditCard", msgDataCloned);
break;
}
case "remove": {
times = msgData.guids.length;
Services.cpmm.sendAsyncMessage("FormAutofill:RemoveCreditCards", msgData);
break;
}
}
}
await this._storageChangeObserved({type, times, topic});
sendAsyncMessage(contentMsg);
},
async operateAddress(type, msgData, contentMsg) {
await this._operateRecord(ADDRESSES_COLLECTION_NAME, ...arguments);
},
async operateCreditCard(type, msgData, contentMsg) {
await this._operateRecord(CREDITCARDS_COLLECTION_NAME, ...arguments);
},
async cleanUpAddresses() {
const guids = (await this._getRecords(ADDRESSES_COLLECTION_NAME)).map(record => record.guid);
await this.operateAddress("remove", {guids}, "FormAutofillTest:AddressesCleanedUp");
},
async cleanUpCreditCards() {
const guids = (await this._getRecords(CREDITCARDS_COLLECTION_NAME)).map(record => record.guid);
await this.operateCreditCard("remove", {guids}, "FormAutofillTest:CreditCardsCleanedUp");
},
async cleanup() {
Services.obs.removeObserver(this, "formautofill-storage-changed");
await this.cleanUpAddresses();
await this.cleanUpCreditCards();
},
_areRecordsMatching(recordA, recordB, collectionName) {
for (let field of profileStorage[collectionName].VALID_FIELDS) {
if (recordA[field] !== recordB[field]) {
return false;
}
}
// Check the internal field if both addresses have valid value.
for (let field of profileStorage.INTERNAL_FIELDS) {
if (field in recordA && field in recordB && (recordA[field] !== recordB[field])) {
return false;
}
}
return true;
},
async _checkRecords(collectionName, expectedRecords) {
const records = await this._getRecords(collectionName);
if (records.length !== expectedRecords.length) {
return false;
}
for (let record of records) {
let matching = expectedRecords.some(expectedRecord => {
return ParentUtils._areRecordsMatching(record, expectedRecord, collectionName);
});
if (!matching) {
return false;
}
}
return true;
},
async checkAddresses({expectedAddresses}) {
const areMatched = await this._checkRecords(ADDRESSES_COLLECTION_NAME, expectedAddresses);
sendAsyncMessage("FormAutofillTest:areAddressesMatching", areMatched);
},
async checkCreditCards({expectedCreditCards}) {
const areMatched = await this._checkRecords(CREDITCARDS_COLLECTION_NAME, expectedCreditCards);
sendAsyncMessage("FormAutofillTest:areCreditCardsMatching", areMatched);
Services.obs.removeObserver(observer, topic);
sendAsyncMessage(contentMsg);
}, "formautofill-storage-changed");
},
observe(subject, topic, data) {
assert.ok(topic === "formautofill-storage-changed");
sendAsyncMessage("formautofill-storage-changed", {subject: null, topic, data});
},
cleanup() {
Services.obs.removeObserver(this, "formautofill-storage-changed");
this.cleanUpAddress();
},
areAddressesMatching(addressA, addressB) {
for (let field of profileStorage.addresses.VALID_FIELDS) {
if (addressA[field] !== addressB[field]) {
return false;
}
}
// Check the internal field if both addresses have valid value.
for (let field of profileStorage.INTERNAL_FIELDS) {
if (field in addressA && field in addressB && (addressA[field] !== addressB[field])) {
return false;
}
}
return true;
},
checkAddresses({expectedAddresses}) {
Services.cpmm.addMessageListener("FormAutofill:Records", function getResult(result) {
Services.cpmm.removeMessageListener("FormAutofill:Records", getResult);
let addresses = result.data;
if (addresses.length !== expectedAddresses.length) {
sendAsyncMessage("FormAutofillTest:areAddressesMatching", false);
return;
}
for (let address of addresses) {
let matching = expectedAddresses.some((expectedAddress) => {
return ParentUtils.areAddressesMatching(address, expectedAddress);
});
if (!matching) {
sendAsyncMessage("FormAutofillTest:areAddressesMatching", false);
return;
}
}
sendAsyncMessage("FormAutofillTest:areAddressesMatching", true);
});
Services.cpmm.sendAsyncMessage("FormAutofill:GetRecords", {searchString: "", collectionName: "addresses"});
},
};
Services.obs.addObserver(ParentUtils, "formautofill-storage-changed");
addMessageListener("FormAutofillTest:AddAddress", (msg) => {
ParentUtils.operateAddress("add", msg, "FormAutofillTest:AddressAdded");
ParentUtils.updateAddress("add", "FormAutofill:SaveAddress", msg, "FormAutofillTest:AddressAdded");
});
addMessageListener("FormAutofillTest:RemoveAddress", (msg) => {
ParentUtils.operateAddress("remove", msg, "FormAutofillTest:AddressRemoved");
ParentUtils.updateAddress("remove", "FormAutofill:RemoveAddress", msg, "FormAutofillTest:AddressRemoved");
});
addMessageListener("FormAutofillTest:UpdateAddress", (msg) => {
ParentUtils.operateAddress("update", msg, "FormAutofillTest:AddressUpdated");
ParentUtils.updateAddress("update", "FormAutofill:SaveAddress", msg, "FormAutofillTest:AddressUpdated");
});
addMessageListener("FormAutofillTest:CheckAddresses", (msg) => {
ParentUtils.checkAddresses(msg);
});
addMessageListener("FormAutofillTest:CleanUpAddresses", (msg) => {
ParentUtils.cleanUpAddresses();
});
addMessageListener("FormAutofillTest:AddCreditCard", (msg) => {
ParentUtils.operateCreditCard("add", msg, "FormAutofillTest:CreditCardAdded");
});
addMessageListener("FormAutofillTest:RemoveCreditCard", (msg) => {
ParentUtils.operateCreditCard("remove", msg, "FormAutofillTest:CreditCardRemoved");
});
addMessageListener("FormAutofillTest:CheckCreditCards", (msg) => {
ParentUtils.checkCreditCards(msg);
});
addMessageListener("FormAutofillTest:CleanUpCreditCards", (msg) => {
ParentUtils.cleanUpCreditCards();
addMessageListener("FormAutofillTest:CleanUpAddress", (msg) => {
ParentUtils.cleanUpAddress();
});
addMessageListener("cleanup", () => {

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

@ -7,9 +7,6 @@ support-files =
[test_autofocus_form.html]
[test_basic_autocomplete_form.html]
[test_basic_creditcard_autocomplete_form.html]
scheme=https
skip-if = debug # Bug 1401454
[test_formautofill_preview_highlight.html]
[test_multiple_forms.html]
[test_on_address_submission.html]

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

@ -117,7 +117,7 @@ add_task(async function all_saved_fields_less_than_threshold() {
await expectPopup();
checkMenuEntries(["foo@mozilla.com"], false);
await cleanUpAddresses();
await cleanUpAddress();
});
// Form with both history and address storage.

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

@ -1,248 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form credit card autofill
<script>
/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/SpawnTask.js */
/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
/* import-globals-from formautofill_common.js */
"use strict";
const {FormAutofillUtils} = SpecialPowers.Cu.import("resource://formautofill/FormAutofillUtils.jsm");
const MOCK_STORAGE = [{
"cc-name": "John Doe",
"cc-number": "1234567812345678",
"cc-exp-month": 4,
"cc-exp-year": 2017,
}, {
"cc-name": "Timothy Berners-Lee",
"cc-number": "1111222233334444",
"cc-exp-month": 12,
"cc-exp-year": 2022,
}];
const reducedMockRecord = {
"cc-name": "John Doe",
"cc-number": "1234123456785678",
};
function patchRecordCCNumber(record) {
const ccNumber = record["cc-number"];
const normalizedCCNumber = "*".repeat(ccNumber.length - 4) + ccNumber.substr(-4);
const ccNumberFmt = FormAutofillUtils.fmtMaskedCreditCardLabel(normalizedCCNumber);
return Object.assign({}, record, {ccNumberFmt});
}
function checkElementFilled(element, expectedvalue) {
const focusedElem = document.activeElement;
const promises = [];
promises.push(new Promise(resolve => {
element.addEventListener("input", function onInput() {
ok(true, "Checking " + element.name + " field fires input event");
resolve();
}, {once: true});
}));
// Don't expect that focused input will receive "change" event since focus never move away.
if (element !== focusedElem) {
promises.push(new Promise(resolve => {
element.addEventListener("change", function onChange() {
ok(true, "Checking " + element.name + " field fires change event");
is(element.value, expectedvalue, "Checking " + element.name + " field");
resolve();
}, {once: true});
}));
}
return promises;
}
function checkFormFilled(creditCard) {
let promises = [];
for (let prop in creditCard) {
let element = document.getElementById(prop);
let converted = String(creditCard[prop]); // Convert potential number to string
promises.push(...checkElementFilled(element, converted));
}
doKey("return");
return Promise.all(promises);
}
async function setupCreditCardStorage() {
await addCreditCard(MOCK_STORAGE[0]);
await addCreditCard(MOCK_STORAGE[1]);
}
async function setupFormHistory() {
await updateFormHistory([
{op: "add", fieldname: "cc-name", value: "John Smith"},
{op: "add", fieldname: "cc-exp-year", value: 2023},
]);
}
initPopupListener();
// Form with history only.
add_task(async function history_only_menu_checking() {
await setupFormHistory();
await setInput("#cc-exp-year", "");
doKey("down");
await expectPopup();
checkMenuEntries(["2023"], false);
});
// Display credit card result even if the number of fillable fields is less than the threshold.
add_task(async function all_saved_fields_less_than_threshold() {
await addCreditCard(reducedMockRecord);
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries([reducedMockRecord].map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await cleanUpCreditCards();
});
// Form with both history and credit card storage.
add_task(async function check_menu_when_both_existed() {
await setupCreditCardStorage();
await setInput("#cc-number", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primaryAffix: cc.ccNumberFmt.affix,
primary: cc.ccNumberFmt.label,
secondary: cc["cc-name"],
})));
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await setInput("#cc-exp-year", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-year"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await setInput("#cc-exp-month", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-month"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await cleanUpCreditCards();
});
// Display history search result if no matched data in credit card.
add_task(async function check_fallback_for_mismatched_field() {
await addCreditCard(reducedMockRecord);
await setInput("#cc-exp-year", "");
doKey("down");
await expectPopup();
checkMenuEntries(["2023"], false);
await cleanUpCreditCards();
});
// Display history search result if credit card autofill is disabled.
add_task(async function check_search_result_for_pref_off() {
await setupCreditCardStorage();
await SpecialPowers.pushPrefEnv({
set: [["extensions.formautofill.creditCards.enabled", false]],
});
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries(["John Smith"], false);
await SpecialPowers.popPrefEnv();
});
// Autofill the credit card from dropdown menu.
add_task(async function check_fields_after_form_autofill() {
await setInput("#cc-exp-year", 202);
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.slice(1).map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-year"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
doKey("down");
await checkFormFilled(MOCK_STORAGE[1]);
});
// Fallback to history search after autofill address.
add_task(async function check_fallback_after_form_autofill() {
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries(["John Smith"], false);
});
// Resume form autofill once all the autofilled fileds are changed.
add_task(async function check_form_autofill_resume() {
document.querySelector("#cc-name").blur();
document.querySelector("#form1").reset();
await setInput("#cc-name", "");
doKey("down");
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
});
</script>
<p id="display"></p>
<div id="content">
<form id="form1">
<p>This is a basic form.</p>
<p><label>Name: <input id="cc-name" autocomplete="cc-name"></label></p>
<p><label>Card Number: <input id="cc-number" autocomplete="cc-number"></label></p>
<p><label>Expiration month: <input id="cc-exp-month" autocomplete="cc-exp-month"></label></p>
<p><label>Expiration year: <input id="cc-exp-year" autocomplete="cc-exp-year"></label></p>
<p><label>CSC: <input id="cc-csc" autocomplete="cc-csc"></label></p>
</form>
</div>
<pre id="test"></pre>
</body>
</html>

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

@ -45,7 +45,7 @@ add_task(async function check_storage_after_form_submitted() {
clickOnElement("input[type=submit]");
let expectedAddresses = TEST_ADDRESSES.slice(0, 1);
await onStorageChanged("add");
await onAddressChanged("add");
// Check if timesUsed is set correctly
expectedAddresses[0].timesUsed = 1;
let matching = await checkAddresses(expectedAddresses);
@ -67,7 +67,7 @@ add_task(async function check_storage_after_another_address_submitted() {
addressesInMenu.push(TEST_ADDRESSES[0]);
// let expectedAddresses = TEST_ADDRESSES.slice(0);
await onStorageChanged("add");
await onAddressChanged("add");
let matching = await checkAddresses(TEST_ADDRESSES);
ok(matching, "New address saved as expected");
@ -93,7 +93,7 @@ add_task(async function new_address_submitted_and_merged() {
let expectedAddresses = TEST_ADDRESSES.slice(0);
// Check if timesUsed is set correctly
expectedAddresses[0].timesUsed = 2;
await onStorageChanged("merge");
await onAddressChanged("merge");
let matching = await checkAddresses(expectedAddresses);
ok(matching, "Address merged as expected");
delete expectedAddresses[0].timesUsed;
@ -114,7 +114,7 @@ add_task(async function check_storage_after_form_submitted() {
clickOnElement("input[type=submit]");
let expectedAddresses = TEST_ADDRESSES.slice(0);
await onStorageChanged("merge");
await onAddressChanged("merge");
let matching = await checkAddresses(expectedAddresses);
ok(matching, "Updated address merged as expected");
});