Bug 469422 - tag autocomplete disappears on every other character that is typed, r=mak77
authorDietrich Ayala <dietrich@mozilla.com>
Thu, 05 Mar 2009 13:07:15 +0100
changeset 25758 85cad64285f9a8bef04f33f341c3771f6b39837c
parent 25757 3a31158051a4c47cbbcd35e528abbcf154bb7c87
child 25759 82d502128473889bcd0779e25c9a801bbeffbb33
push id5729
push usermak77@bonardo.net
push dateThu, 05 Mar 2009 12:09:27 +0000
treeherdermozilla-central@255494d09521 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak77
bugs469422
milestone1.9.2a1pre
Bug 469422 - tag autocomplete disappears on every other character that is typed, r=mak77
toolkit/components/places/src/nsTaggingService.js
toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
--- a/toolkit/components/places/src/nsTaggingService.js
+++ b/toolkit/components/places/src/nsTaggingService.js
@@ -540,53 +540,47 @@ TagAutoCompleteSearch.prototype = {
         // for each match, prepend what the user has typed so far
         if (searchResults[i].indexOf(searchString) == 0 &&
             comments.indexOf(searchResults[i]) == -1) {
           results.push(before + searchResults[i]);
           comments.push(searchResults[i]);
         }
     
         ++i;
+
+        /* TODO: bug 481451
+         * For each yield we pass a new result to the autocomplete
+         * listener. The listener appends instead of replacing previous results,
+         * causing invalid matchCount values.
+         *
+         * As a workaround, all tags are searched through in a single batch,
+         * making this synchronous until the above issue is fixed.
+         */
+
+        /*
         // 100 loops per yield
         if ((i % 100) == 0) {
           var newResult = new TagAutoCompleteResult(searchString,
             Ci.nsIAutoCompleteResult.RESULT_SUCCESS_ONGOING, 0, "", results, comments);
           listener.onSearchResult(self, newResult);
           yield true;
-        } 
+        }
+        */
       }
 
       var newResult = new TagAutoCompleteResult(searchString,
         Ci.nsIAutoCompleteResult.RESULT_SUCCESS, 0, "", results, comments);
       listener.onSearchResult(self, newResult);
       yield false;
     }
     
-    // chunk the search results via a generator
+    // chunk the search results via the generator
     var gen = doSearch();
-    function driveGenerator() {
-      if (gen.next()) { 
-        var timer = Cc["@mozilla.org/timer;1"]
-          .createInstance(Components.interfaces.nsITimer);
-        self._callback = driveGenerator;
-        timer.initWithCallback(self, 0, timer.TYPE_ONE_SHOT);
-      }
-      else {
-        gen.close();	
-      }
-    }
-    driveGenerator();
-  },
-
-  /**
-   * nsITimer callback
-   */
-  notify: function PTACS_notify(timer) {
-    if (this._callback) 
-      this._callback();
+    while (gen.next());
+    gen.close();
   },
 
   /**
    * Stop an asynchronous search that is in progress
    */
   stopSearch: function PTACS_stopSearch() {
     this._stopped = true;
   },
--- a/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
+++ b/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
@@ -130,23 +130,22 @@ function ensure_tag_results(results, sea
     for (var i=0; i<controller.matchCount; i++) {
       do_check_eq(controller.getValueAt(i), results[i]);
     }
    
     if (current_test < (tests.length - 1)) {
       current_test++;
       tests[current_test]();
     }
-
-    do_test_finished();
+    else {
+      // finish once all tests have run
+      do_test_finished();
+    }
   };
 
-  // Search is asynchronous, so don't let the test finish immediately
-  do_test_pending();
-
   controller.startSearch(searchTerm);
 }
 
 var uri1 = uri("http://site.tld/1");
   
 var tests = [
   function test1() { ensure_tag_results(["bar", "baz", "boo"], "b"); },
   function test2() { ensure_tag_results(["bar", "baz"], "ba"); },
@@ -156,12 +155,15 @@ var tests = [
   function test6() { ensure_tag_results(["first tag, bar", "first tag, baz"], "first tag, ba"); },
   function test7() { ensure_tag_results(["first tag;  bar", "first tag;  baz"], "first tag;  ba"); }
 ];
 
 /** 
  * Test tag autocomplete
  */
 function run_test() {
+  // Search is asynchronous, so don't let the test finish immediately
+  do_test_pending();
+
   tagssvc.tagURI(uri1, ["bar", "baz", "boo", "*nix"]);
 
   tests[0]();
 }