Bug 982816 - Remove extra calls to nextTest in test_hawkrequest.js r=ckarlof
authorSteve Workman <sworkman@mozilla.com>
Tue, 08 Jul 2014 11:44:03 -0700
changeset 192964 5be37f43c77be2342506c6684beff522f8829a1c
parent 192963 8b8883e3b8b875dbf5cc9314ac343b596b293c3e
child 192965 20479ebf9be80a9d98cdbc4f527b390f59717d20
push id27103
push usercbook@mozilla.com
push dateWed, 09 Jul 2014 13:55:18 +0000
treeherdermozilla-central@f945d50e50fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckarlof
bugs982816
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 982816 - Remove extra calls to nextTest in test_hawkrequest.js r=ckarlof
services/common/tests/unit/test_hawkrequest.js
--- a/services/common/tests/unit/test_hawkrequest.js
+++ b/services/common/tests/unit/test_hawkrequest.js
@@ -38,40 +38,47 @@ function run_test() {
 
 add_test(function test_intl_accept_language() {
   let testCount = 0;
   let languages = [
     "zu-NP;vo",     // Nepalese dialect of Zulu, defaulting to Volap√ľk
     "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;
     Services.prefs.setComplexValue(
       "intl.accept_languages", Ci.nsISupportsString, acceptLanguage);
   }
 
   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);
+
+      do_check_eq(hawk._intl.accept_languages, languages[testCount]);
 
-        testCount += 1;
-        setLanguage(languages[testCount]);
-        nextTest();
+      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;
     });
   }
 });
 
 add_test(function test_hawk_authenticated_request() {
   let onProgressCalled = false;