Bug 982816 - Remove extra calls to nextTest in test_hawkrequest.js r=ckarlof

This commit is contained in:
Steve Workman 2014-07-08 11:44:03 -07:00
parent 2a1f3ed8fe
commit 1f442e1878

View File

@ -43,7 +43,7 @@ add_test(function test_intl_accept_language() {
"fa-CG;ik", // Congolese dialect of Farsei, defaulting to Inupiaq "fa-CG;ik", // Congolese dialect of Farsei, defaulting to Inupiaq
]; ];
function setLanguage(lang) { function setLanguagePref(lang) {
let acceptLanguage = Cc["@mozilla.org/supports-string;1"] let acceptLanguage = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString); .createInstance(Ci.nsISupportsString);
acceptLanguage.data = lang; acceptLanguage.data = lang;
@ -53,20 +53,27 @@ add_test(function test_intl_accept_language() {
let hawk = new HAWKAuthenticatedRESTRequest("https://example.com"); let hawk = new HAWKAuthenticatedRESTRequest("https://example.com");
Services.prefs.addObserver("intl.accept_languages", nextTest, false); Services.prefs.addObserver("intl.accept_languages", checkLanguagePref, false);
setLanguage(languages[testCount]); setLanguagePref(languages[testCount]);
function nextTest() { function checkLanguagePref() {
var _done = false;
CommonUtils.nextTick(function() { CommonUtils.nextTick(function() {
if (testCount < 2) { // Ensure we're only called for the number of entries in languages[].
do_check_eq(hawk._intl.accept_languages, languages[testCount]); do_check_true(testCount < languages.length);
testCount += 1; do_check_eq(hawk._intl.accept_languages, languages[testCount]);
setLanguage(languages[testCount]);
nextTest(); testCount++;
if (testCount < languages.length) {
// Set next language in prefs; Pref service will call checkNextLanguage.
setLanguagePref(languages[testCount]);
return; return;
} }
Services.prefs.removeObserver("intl.accept_languages", nextTest);
// We've checked all the entries in languages[]. Cleanup and move on.
do_print("Checked " + testCount + " languages. Removing checkLanguagePref as pref observer.");
Services.prefs.removeObserver("intl.accept_languages", checkLanguagePref);
run_next_test(); run_next_test();
return; return;
}); });