Bug 500978 - Download Manager treats search terms as regular expressions. r=sdwilsh
authorDão Gottwald <dao@mozilla.com>
Sun, 28 Jun 2009 18:03:01 +0200
changeset 29790 fd0b25ac9f0d
parent 29789 b4b7eb4407c3
child 29791 48161673b084
push id106
push userhsivonen@iki.fi
push dateSun, 28 Jun 2009 17:44:42 +0000
reviewerssdwilsh
bugs500978
milestone1.9.2a1pre
Bug 500978 - Download Manager treats search terms as regular expressions. r=sdwilsh
toolkit/mozapps/downloads/content/downloads.js
toolkit/mozapps/downloads/tests/chrome/test_multiword_search.xul
--- a/toolkit/mozapps/downloads/content/downloads.js
+++ b/toolkit/mozapps/downloads/content/downloads.js
@@ -1290,17 +1290,17 @@ function downloadMatchesSearch(aItem)
   // Search through the download attributes that are shown to the user and
   // make it into one big string for easy combined searching
   let combinedSearch = "";
   for each (let attr in gSearchAttributes)
     combinedSearch += aItem.getAttribute(attr).toLowerCase() + " ";
 
   // Make sure each of the terms are found
   for each (let term in gSearchTerms)
-    if (combinedSearch.search(term) == -1)
+    if (combinedSearch.indexOf(term) == -1)
       return false;
 
   return true;
 }
 
 // we should be using real URLs all the time, but until
 // bug 239948 is fully fixed, this will do...
 //
--- a/toolkit/mozapps/downloads/tests/chrome/test_multiword_search.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_multiword_search.xul
@@ -105,50 +105,63 @@ function test()
            getService(Ci.nsIWindowMediator);
   let win = wm.getMostRecentWindow("Download:Manager");
   if (win) win.close();
 
   let obs = Cc["@mozilla.org/observer-service;1"].
             getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
-  let testPhase = 0;
+  let testPhase = -1;
   let testObs = {
     observe: function(aSubject, aTopic, aData) {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
       let $ = function(aId) win.document.getElementById(aId);
       let downloadView = $("downloadView");
       let searchbox = $("searchbox");
 
       let search = function(aTerms) {
         searchbox.value = aTerms;
         searchbox.doCommand();
       };
 
+      let testResults = function(aExpected) {
+        is(downloadView.itemCount, aExpected,
+           "Phase " + testPhase + ": search matched " + aExpected + " download(s)");
+      };
+
       // The list must have built, so figure out what test to do
-      switch (testPhase++) {
+      switch (++testPhase) {
         case 0:
           // Search for multiple words in any order in all places
           search("download super pimped 104 GB august 2");
 
           break;
         case 1:
           // Done populating the two items
-          ok(downloadView.itemCount == 2, "Search matched both downloads");
+          testResults(2);
 
           // Do partial word matches including the site
-          search("agadak aug 2 downl 104");
+          search("Agadak.net aug 2 downl 104");
 
           break;
         case 2:
           // Done populating the one result
-          ok(downloadView.itemCount == 1, "Found the single download");
+          testResults(1);
+
+          // The search term shouldn't be treated like a regular expression,
+          // e.g. "D.wnload" shouldn't match "Download".
+          search("D.wnload");
+
+          break;
+        case 3:
+          testResults(0);
 
           // We're done!
           win.close();
           obs.removeObserver(testObs, DLMGR_UI_DONE);
           SimpleTest.finish();
 
           break;
       }