зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1330567 - Part 2: Add xpcshell test for the autofill pref fallback, r=MattN
MozReview-Commit-ID: BmjcwiW0EcN --HG-- extra : rebase_source : dbe1c2380190cdb7109e0d4e43d36af140dd9855
This commit is contained in:
Родитель
918291a57e
Коммит
09ed010c4f
|
@ -13,12 +13,12 @@ do_get_profile(); // fxa needs a profile directory for storage.
|
||||||
|
|
||||||
// Create a window polyfill so sinon can load
|
// Create a window polyfill so sinon can load
|
||||||
let window = {
|
let window = {
|
||||||
document: {},
|
document: {},
|
||||||
location: {},
|
location: {},
|
||||||
setTimeout,
|
setTimeout,
|
||||||
setInterval,
|
setInterval,
|
||||||
clearTimeout,
|
clearTimeout,
|
||||||
clearinterval: clearInterval
|
clearInterval,
|
||||||
};
|
};
|
||||||
let self = window;
|
let self = window;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Provides infrastructure for automated formautofill components tests.
|
* Provides infrastructure for automated formautofill components tests.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* exported loadFormAutofillContent, getTempFile */
|
/* exported loadFormAutofillContent, getTempFile, sinon */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
@ -18,6 +18,14 @@ XPCOMUtils.defineLazyModuleGetter(this, "DownloadPaths",
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||||
"resource://gre/modules/FileUtils.jsm");
|
"resource://gre/modules/FileUtils.jsm");
|
||||||
|
|
||||||
|
do_get_profile();
|
||||||
|
|
||||||
|
// Setup the environment for sinon.
|
||||||
|
Cu.import("resource://gre/modules/Timer.jsm");
|
||||||
|
let self = {}; // eslint-disable-line no-unused-vars
|
||||||
|
var sinon;
|
||||||
|
Services.scriptloader.loadSubScript("resource://testing-common/sinon-1.16.1.js");
|
||||||
|
|
||||||
// Load our bootstrap extension manifest so we can access our chrome/resource URIs.
|
// Load our bootstrap extension manifest so we can access our chrome/resource URIs.
|
||||||
const EXTENSION_ID = "formautofill@mozilla.org";
|
const EXTENSION_ID = "formautofill@mozilla.org";
|
||||||
let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile);
|
let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile);
|
||||||
|
@ -85,12 +93,12 @@ function getTempFile(leafName) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_task(function* test_common_initialize() {
|
add_task(function* head_initialize() {
|
||||||
Services.prefs.setBoolPref("browser.formautofill.experimental", true);
|
Services.prefs.setBoolPref("browser.formautofill.experimental", true);
|
||||||
Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", true);
|
Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", true);
|
||||||
|
|
||||||
// Clean up after every test.
|
// Clean up after every test.
|
||||||
do_register_cleanup(() => {
|
do_register_cleanup(function head_cleanup() {
|
||||||
Services.prefs.clearUserPref("browser.formautofill.experimental");
|
Services.prefs.clearUserPref("browser.formautofill.experimental");
|
||||||
Services.prefs.clearUserPref("dom.forms.autocomplete.experimental");
|
Services.prefs.clearUserPref("dom.forms.autocomplete.experimental");
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Test for status handling in Form Autofill Parent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Cu.import("resource://formautofill/FormAutofillParent.jsm");
|
||||||
|
|
||||||
|
add_task(function* test_enabledStatus_init() {
|
||||||
|
let formAutofillParent = new FormAutofillParent();
|
||||||
|
sinon.spy(formAutofillParent, "_onStatusChanged");
|
||||||
|
|
||||||
|
// Default status is false before initialization
|
||||||
|
do_check_eq(formAutofillParent._enabled, false);
|
||||||
|
|
||||||
|
formAutofillParent.init();
|
||||||
|
do_check_eq(formAutofillParent._onStatusChanged.called, true);
|
||||||
|
|
||||||
|
formAutofillParent._uninit();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* test_enabledStatus_observe() {
|
||||||
|
let formAutofillParent = new FormAutofillParent();
|
||||||
|
sinon.stub(formAutofillParent, "_getStatus");
|
||||||
|
sinon.spy(formAutofillParent, "_onStatusChanged");
|
||||||
|
|
||||||
|
// _enabled = _getStatus() => No need to trigger onStatusChanged
|
||||||
|
formAutofillParent._enabled = true;
|
||||||
|
formAutofillParent._getStatus.returns(true);
|
||||||
|
formAutofillParent.observe();
|
||||||
|
do_check_eq(formAutofillParent._onStatusChanged.called, false);
|
||||||
|
|
||||||
|
// _enabled != _getStatus() => Need to trigger onStatusChanged
|
||||||
|
formAutofillParent._getStatus.returns(false);
|
||||||
|
formAutofillParent.observe();
|
||||||
|
do_check_eq(formAutofillParent._onStatusChanged.called, true);
|
||||||
|
|
||||||
|
formAutofillParent._uninit();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* test_enabledStatus_getStatus() {
|
||||||
|
let formAutofillParent = new FormAutofillParent();
|
||||||
|
do_register_cleanup(function cleanup() {
|
||||||
|
Services.prefs.clearUserPref("browser.formautofill.enabled");
|
||||||
|
});
|
||||||
|
|
||||||
|
Services.prefs.setBoolPref("browser.formautofill.enabled", true);
|
||||||
|
do_check_eq(formAutofillParent._getStatus(), true);
|
||||||
|
|
||||||
|
Services.prefs.setBoolPref("browser.formautofill.enabled", false);
|
||||||
|
do_check_eq(formAutofillParent._getStatus(), false);
|
||||||
|
});
|
|
@ -34,9 +34,10 @@ const TEST_PROFILE = {
|
||||||
};
|
};
|
||||||
|
|
||||||
add_task(function* test_populateFieldValues() {
|
add_task(function* test_populateFieldValues() {
|
||||||
FormAutofillParent.init();
|
let formAutofillParent = new FormAutofillParent();
|
||||||
|
formAutofillParent.init();
|
||||||
|
|
||||||
let store = FormAutofillParent.getProfileStore();
|
let store = formAutofillParent.getProfileStore();
|
||||||
do_check_neq(store, null);
|
do_check_neq(store, null);
|
||||||
|
|
||||||
store.get = function(guid) {
|
store.get = function(guid) {
|
||||||
|
@ -51,7 +52,7 @@ add_task(function* test_populateFieldValues() {
|
||||||
};
|
};
|
||||||
|
|
||||||
yield new Promise((resolve) => {
|
yield new Promise((resolve) => {
|
||||||
FormAutofillParent.receiveMessage({
|
formAutofillParent.receiveMessage({
|
||||||
name: "FormAutofill:PopulateFieldValues",
|
name: "FormAutofill:PopulateFieldValues",
|
||||||
data: {
|
data: {
|
||||||
guid: TEST_GUID,
|
guid: TEST_GUID,
|
||||||
|
@ -78,15 +79,16 @@ add_task(function* test_populateFieldValues() {
|
||||||
|
|
||||||
do_check_eq(notifyUsedCalledCount, 1);
|
do_check_eq(notifyUsedCalledCount, 1);
|
||||||
|
|
||||||
FormAutofillParent._uninit();
|
formAutofillParent._uninit();
|
||||||
do_check_null(FormAutofillParent.getProfileStore());
|
do_check_null(formAutofillParent.getProfileStore());
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_populateFieldValues_with_invalid_guid() {
|
add_task(function* test_populateFieldValues_with_invalid_guid() {
|
||||||
FormAutofillParent.init();
|
let formAutofillParent = new FormAutofillParent();
|
||||||
|
formAutofillParent.init();
|
||||||
|
|
||||||
Assert.throws(() => {
|
Assert.throws(() => {
|
||||||
FormAutofillParent.receiveMessage({
|
formAutofillParent.receiveMessage({
|
||||||
name: "FormAutofill:PopulateFieldValues",
|
name: "FormAutofill:PopulateFieldValues",
|
||||||
data: {
|
data: {
|
||||||
guid: "invalid-guid",
|
guid: "invalid-guid",
|
||||||
|
@ -96,5 +98,5 @@ add_task(function* test_populateFieldValues_with_invalid_guid() {
|
||||||
});
|
});
|
||||||
}, /No matching profile\./);
|
}, /No matching profile\./);
|
||||||
|
|
||||||
FormAutofillParent._uninit();
|
formAutofillParent._uninit();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ support-files =
|
||||||
|
|
||||||
[test_autofillFormFields.js]
|
[test_autofillFormFields.js]
|
||||||
[test_collectFormFields.js]
|
[test_collectFormFields.js]
|
||||||
|
[test_enabledStatus.js]
|
||||||
[test_getFormInputDetails.js]
|
[test_getFormInputDetails.js]
|
||||||
[test_markAsAutofillField.js]
|
[test_markAsAutofillField.js]
|
||||||
[test_populateFieldValues.js]
|
[test_populateFieldValues.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче