Backed out 3 changesets (bug 990219) for browser_submission_in_private_mode.js leaks.

Backed out changeset c640813b5c4e (bug 990219)
Backed out changeset 51dd1439fb05 (bug 990219)
Backed out changeset ac22e8051ada (bug 990219)
This commit is contained in:
Ryan VanderMeulen 2017-05-24 10:54:36 -04:00
Родитель 907f0dc669
Коммит bf47da3039
6 изменённых файлов: 16 добавлений и 219 удалений

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

@ -14,7 +14,6 @@ this.EXPORTED_SYMBOLS = ["FormAutofillContent"];
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr, manager: Cm} = Components;
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://formautofill/FormAutofillUtils.jsm");
@ -320,53 +319,20 @@ var FormAutofillContent = {
Services.cpmm.initialProcessData.autofillSavedFieldNames;
},
/**
* Send the profile to parent for doorhanger and storage saving/updating.
*
* @param {Object} profile Submitted form's address/creditcard guid and record.
*/
_onFormSubmit(profile) {
Services.cpmm.sendAsyncMessage("FormAutofill:OnFormSubmit", profile);
_onFormSubmit(handler) {
// TODO: Handle form submit event for profile saving(bug 990219) and metrics(bug 1341569).
},
/**
* Handle earlyformsubmit event and early return when:
* 1. In private browsing mode.
* 2. Could not map any autofill handler by form element.
* 3. Number of filled fields is less than autofill threshold
*
* @param {HTMLElement} formElement Root element which receives earlyformsubmit event.
* @param {Object} domWin Content window
* @returns {boolean} Should always return true so form submission isn't canceled.
*/
notify(formElement, domWin) {
this.log.debug("Notifying form early submission");
if (domWin && PrivateBrowsingUtils.isContentWindowPrivate(domWin)) {
this.log.debug("Ignoring submission in a private window");
return true;
}
notify(formElement) {
this.log.debug("notified for form early submission");
let handler = this._formsDetails.get(formElement);
if (!handler) {
this.log.debug("Form element could not map to an existing handler");
return true;
} else {
this._onFormSubmit(handler);
}
let pendingAddress = handler.createProfile();
if (Object.keys(pendingAddress).length < AUTOFILL_FIELDS_THRESHOLD) {
this.log.debug(`Not saving since there are only ${Object.keys(pendingAddress).length} usable fields`);
return true;
}
this._onFormSubmit({
address: {
guid: handler.filledProfileGUID,
record: pendingAddress,
},
// creditCard: {}
});
return true;
},

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

@ -133,27 +133,4 @@ FormAutofillHandler.prototype = {
}
*/
},
/**
* Return the profile that is converted from fieldDetails and only non-empty fields
* are included.
*
* @returns {Object} The new profile that convert from details with trimmed result.
*/
createProfile() {
let profile = {};
this.fieldDetails.forEach(detail => {
let element = detail.elementWeakRef.get();
// Remove the unnecessary spaces
let value = element && element.value.trim();
if (!value) {
return;
}
profile[detail.fieldName] = value;
});
return profile;
},
};

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

@ -80,7 +80,6 @@ FormAutofillParent.prototype = {
Services.ppmm.addMessageListener("FormAutofill:GetAddresses", this);
Services.ppmm.addMessageListener("FormAutofill:SaveAddress", this);
Services.ppmm.addMessageListener("FormAutofill:RemoveAddresses", this);
Services.ppmm.addMessageListener("FormAutofill:OnFormSubmit", this);
// Observing the pref and storage changes
Services.prefs.addObserver(ENABLED_PREF, this);
@ -193,9 +192,6 @@ FormAutofillParent.prototype = {
data.guids.forEach(guid => this.profileStorage.addresses.remove(guid));
break;
}
case "FormAutofill:OnFormSubmit": {
this._onFormSubmit(data, target);
}
}
},
@ -265,17 +261,4 @@ FormAutofillParent.prototype = {
Services.ppmm.initialProcessData.autofillSavedFieldNames);
this._updateStatus();
},
_onFormSubmit(data, target) {
let {address} = data;
if (address.guid) {
// TODO: Show update doorhanger(bug 1303513) and set probe(bug 990200)
// if (!profileStorage.addresses.mergeIfPossible(address.guid, address.record)) {
// }
} else {
// TODO: Add first time use probe(bug 990199) and doorhanger(bug 1303510)
// profileStorage.addresses.add(address.record);
}
},
};

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

@ -1,11 +1,7 @@
[DEFAULT]
head = head.js
support-files =
../fixtures/autocomplete_basic.html
[browser_check_installed.js]
[browser_editProfileDialog.js]
[browser_privacyPreferences.js]
[browser_manageProfilesDialog.js]
[browser_submission_in_private_mode.js]

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

@ -1,31 +0,0 @@
"use strict";
const FORM_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/autocomplete_basic.html";
add_task(async function test_add_address() {
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
let addresses = await getAddresses();
is(addresses.length, 0, "No address in storage");
BrowserTestUtils.withNewTab(
{gBrowser: privateWin.gBrowser, url: FORM_URL},
async function(privateBrowser) {
await ContentTask.spawn(privateBrowser, null, async function() {
content.document.getElementById("organization").focus();
content.document.getElementById("organization").value = "Mozilla";
content.document.getElementById("street-address").value = "331 E. Evelyn Avenue";
content.document.getElementById("tel").value = "1-650-903-0800";
content.document.querySelector("input[type=submit]").click();
});
}
);
// Wait 1 second to make sure the profile has not been saved
await new Promise(resolve => setTimeout(resolve, 1000));
addresses = await getAddresses();
is(addresses.length, 0, "No address saved in private browsing mode");
await BrowserTestUtils.closeWindow(privateWin);
});

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

@ -12,113 +12,19 @@ const MOCK_DOC = MockDocument.createTestDocument("http://localhost:8080/test/",
<input id="submit" type="submit">
</form>`);
const TESTCASES = [
{
description: "Should not trigger saving if the number of fields is less than 3",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: false,
},
},
{
description: "Trigger profile saving",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
profile: {
address: {
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
},
},
},
},
{
description: "Profile saved with trimmed string",
formValue: {
"street-addr": "331 E. Evelyn Avenue ",
"country": "USA",
"tel": " 1-650-903-0800",
},
expectedResult: {
formSubmission: true,
profile: {
address: {
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
},
},
},
},
{
description: "Eliminate the field that is empty after trimmed",
formValue: {
"street-addr": "331 E. Evelyn Avenue",
"country": "USA",
"email": " ",
"tel": "1-650-903-0800",
},
expectedResult: {
formSubmission: true,
profile: {
address: {
guid: null,
record: {
"street-address": "331 E. Evelyn Avenue",
"country": "USA",
"tel": "1-650-903-0800",
},
},
},
},
},
];
add_task(function* () {
do_print("Starting testcase: Make sure content handle earlyformsubmit correctly");
add_task(async function handle_earlyformsubmit_event() {
do_print("Starting testcase: Test an invalid form element");
let fakeForm = MOCK_DOC.createElement("form");
let form = MOCK_DOC.getElementById("form1");
FormAutofillContent.identifyAutofillFields(MOCK_DOC);
sinon.spy(FormAutofillContent, "_onFormSubmit");
do_check_eq(FormAutofillContent.notify(form), true);
do_check_eq(FormAutofillContent._onFormSubmit.called, true);
let fakeForm = MOCK_DOC.createElement("form");
FormAutofillContent._onFormSubmit.reset();
do_check_eq(FormAutofillContent.notify(fakeForm), true);
do_check_eq(FormAutofillContent._onFormSubmit.called, false);
FormAutofillContent._onFormSubmit.restore();
});
TESTCASES.forEach(testcase => {
add_task(async function check_profile_saving_is_called_correctly() {
do_print("Starting testcase: " + testcase.description);
let form = MOCK_DOC.getElementById("form1");
for (let key in testcase.formValue) {
let input = MOCK_DOC.getElementById(key);
input.value = testcase.formValue[key];
}
sinon.spy(FormAutofillContent, "_onFormSubmit");
FormAutofillContent.identifyAutofillFields(MOCK_DOC);
FormAutofillContent.notify(form);
do_check_eq(FormAutofillContent._onFormSubmit.called,
testcase.expectedResult.formSubmission);
if (FormAutofillContent._onFormSubmit.called) {
Assert.deepEqual(FormAutofillContent._onFormSubmit.args[0][0],
testcase.expectedResult.profile);
}
FormAutofillContent._onFormSubmit.restore();
});
});