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
Родитель e69d978552
Коммит 55ac136605
1 изменённых файлов: 17 добавлений и 10 удалений

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

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