Bug 1413600 - Add tests for basic AutoConfig function. r=kmag

MozReview-Commit-ID: DlSkKruv8qv

--HG--
extra : rebase_source : e1e4522f0ab2370fcc3eca3059f32870ddc935d1
This commit is contained in:
Michael Kaply 2018-04-18 11:29:35 -05:00
parent cf9dd5bc32
commit cb3b0651e7
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// # don't remove this comment! (the first line is ignored by Mozilla)
// Verify this one has a user value
pref("_autoconfig_.test.userpref", "userpref");
// Verify this one has a default pref
defaultPref("_autoconfig_.test.defaultpref", "defaultpref");
// Verify this one is locked
lockPref("_autoconfig_.test.lockpref", "lockpref");
lockPref("_autoconfig_.test.unlockpref", "unlockpref");
// Verify this one is unlocked
unlockPref("_autoconfig_.test.unlockpref");
pref("_autoconfig_.test.clearpref", "clearpref");
// Verify this one has no value
clearPref("_autoconfig_.test.clearpref");
// Verify this one is set to the correct value
pref("_autoconfig_.test.getpref.query", "getpref");
pref("_autoconfig_.test.getpref", getPref("_autoconfig_.test.getpref.query"));
// Verify this one is set to the correct value
pref("_autoconfig_.test.getenv", getenv("AUTOCONFIG_TEST_GETENV"));
// Since we can't test displayError directly, verify that it
// exists and is a function
pref("_autoconfig_.test.displayerror", typeof(displayError));
// We are not getPrefBranch because it is being removed

View File

@ -0,0 +1,82 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint no-unsafe-finally: "off"*/
/* Turning off this rule to allow control flow operations in finally block
* http://eslint.org/docs/rules/no-unsafe-finally */
ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
let env = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
let prefs = Services.prefs.getBranch(null);
let defPrefs = Services.prefs.getDefaultBranch(null);
let greD = Services.dirsvc.get("GreD", Ci.nsIFile);
let defaultPrefD = Services.dirsvc.get("PrfDef", Ci.nsIFile);
let testDir = do_get_cwd();
try {
let autoConfigJS = testDir.clone();
autoConfigJS.append("autoconfig.js");
autoConfigJS.copyTo(defaultPrefD, "autoconfig.js");
// Make sure nsReadConfig is initialized.
Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports);
Services.prefs.resetPrefs();
let autoConfigCfg = testDir.clone();
autoConfigCfg.append("autoconfig-all.cfg");
autoConfigCfg.copyTo(greD, "autoconfig.cfg");
env.set("AUTOCONFIG_TEST_GETENV", "getenv");
Services.obs.notifyObservers(Services.prefs, "prefservice:before-read-userprefs");
ok(prefs.prefHasUserValue("_autoconfig_.test.userpref"));
equal("userpref", prefs.getStringPref("_autoconfig_.test.userpref"));
equal("defaultpref", defPrefs.getStringPref("_autoconfig_.test.defaultpref"));
equal("defaultpref", prefs.getStringPref("_autoconfig_.test.defaultpref"));
ok(prefs.prefIsLocked("_autoconfig_.test.lockpref"));
equal("lockpref", prefs.getStringPref("_autoconfig_.test.lockpref"));
ok(!prefs.prefIsLocked("_autoconfig_.test.unlockpref"));
equal("unlockpref", prefs.getStringPref("_autoconfig_.test.unlockpref"));
ok(!prefs.prefHasUserValue("_autoconfig_.test.clearpref"));
equal("getpref", prefs.getStringPref("_autoconfig_.test.getpref"));
equal("getenv", prefs.getStringPref("_autoconfig_.test.getenv"));
equal("function", prefs.getStringPref("_autoconfig_.test.displayerror"));
Services.prefs.resetPrefs();
} finally {
try {
let autoConfigJS = defaultPrefD.clone();
autoConfigJS.append("autoconfig.js");
autoConfigJS.remove(false);
} catch (e) {
if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
throw e;
}
}
try {
let autoConfigCfg = greD.clone();
autoConfigCfg.append("autoconfig.cfg");
autoConfigCfg.remove(false);
} catch (e) {
if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
throw e;
}
}
Services.prefs.resetPrefs();
}
}

View File

@ -2,8 +2,10 @@
head =
skip-if = toolkit == 'android'
support-files =
autoconfig-all.cfg
autoconfig-latin1.cfg
autoconfig-utf8.cfg
autoconfig.js
[test_autoconfig.js]
[test_autoconfig_nonascii.js]