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:
steveck-chung 2017-02-09 18:10:11 +08:00
Родитель 918291a57e
Коммит 09ed010c4f
5 изменённых файлов: 80 добавлений и 17 удалений

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

@ -13,12 +13,12 @@ do_get_profile(); // fxa needs a profile directory for storage.
// Create a window polyfill so sinon can load
let window = {
document: {},
location: {},
setTimeout,
setInterval,
clearTimeout,
clearinterval: clearInterval
document: {},
location: {},
setTimeout,
setInterval,
clearTimeout,
clearInterval,
};
let self = window;

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

@ -2,7 +2,7 @@
* Provides infrastructure for automated formautofill components tests.
*/
/* exported loadFormAutofillContent, getTempFile */
/* exported loadFormAutofillContent, getTempFile, sinon */
"use strict";
@ -18,6 +18,14 @@ XPCOMUtils.defineLazyModuleGetter(this, "DownloadPaths",
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"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.
const EXTENSION_ID = "formautofill@mozilla.org";
let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile);
@ -85,12 +93,12 @@ function getTempFile(leafName) {
return file;
}
add_task(function* test_common_initialize() {
add_task(function* head_initialize() {
Services.prefs.setBoolPref("browser.formautofill.experimental", true);
Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", true);
// Clean up after every test.
do_register_cleanup(() => {
do_register_cleanup(function head_cleanup() {
Services.prefs.clearUserPref("browser.formautofill.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() {
FormAutofillParent.init();
let formAutofillParent = new FormAutofillParent();
formAutofillParent.init();
let store = FormAutofillParent.getProfileStore();
let store = formAutofillParent.getProfileStore();
do_check_neq(store, null);
store.get = function(guid) {
@ -51,7 +52,7 @@ add_task(function* test_populateFieldValues() {
};
yield new Promise((resolve) => {
FormAutofillParent.receiveMessage({
formAutofillParent.receiveMessage({
name: "FormAutofill:PopulateFieldValues",
data: {
guid: TEST_GUID,
@ -78,15 +79,16 @@ add_task(function* test_populateFieldValues() {
do_check_eq(notifyUsedCalledCount, 1);
FormAutofillParent._uninit();
do_check_null(FormAutofillParent.getProfileStore());
formAutofillParent._uninit();
do_check_null(formAutofillParent.getProfileStore());
});
add_task(function* test_populateFieldValues_with_invalid_guid() {
FormAutofillParent.init();
let formAutofillParent = new FormAutofillParent();
formAutofillParent.init();
Assert.throws(() => {
FormAutofillParent.receiveMessage({
formAutofillParent.receiveMessage({
name: "FormAutofill:PopulateFieldValues",
data: {
guid: "invalid-guid",
@ -96,5 +98,5 @@ add_task(function* test_populateFieldValues_with_invalid_guid() {
});
}, /No matching profile\./);
FormAutofillParent._uninit();
formAutofillParent._uninit();
});

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

@ -5,6 +5,7 @@ support-files =
[test_autofillFormFields.js]
[test_collectFormFields.js]
[test_enabledStatus.js]
[test_getFormInputDetails.js]
[test_markAsAutofillField.js]
[test_populateFieldValues.js]