Bug 982816 - Remove extra calls to nextTest in test_hawkrequest.js. r=ckarlof, a=test-only
authorSteve Workman <sworkman@mozilla.com>
Tue, 08 Jul 2014 11:44:03 -0700
changeset 207759 6480a800ede873fefb68ea4dce5de18ac2f2fd3d
parent 207758 15c397ebfd145299c9b240785d347bcf1f0435b6
child 207760 ceb34c8aeb95d09d8bf9cccdc247f335955a2c20
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckarlof, test-only
bugs982816
milestone32.0a2
Bug 982816 - Remove extra calls to nextTest in test_hawkrequest.js. r=ckarlof, a=test-only
services/common/tests/unit/test_hawkrequest.js
--- a/services/common/tests/unit/test_hawkrequest.js
+++ b/services/common/tests/unit/test_hawkrequest.js
@@ -26,40 +26,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;