Bug 593905 - Add the ability to search the URLs of tabs in Panorama UI r=iangilman, a=beltzner
authorMatthew Galloway <matt@silverbottle.net>
Tue, 23 Nov 2010 17:20:30 -0800
changeset 58335 ef059bdf7be395a0428d7e91d66d1aa9d454d44c
parent 58334 a4971d2602650deef68c08b6304f68f3049067d3
child 58336 3ee96c3879bcf556af46487d8521839ab620f5e5
push id17249
push userian@iangilman.com
push dateMon, 29 Nov 2010 17:59:45 +0000
treeherdermozilla-central@ef059bdf7be3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersiangilman, beltzner
bugs593905
milestone2.0b8pre
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 593905 - Add the ability to search the URLs of tabs in Panorama UI r=iangilman, a=beltzner
browser/base/content/tabview/search.js
browser/base/content/test/tabview/browser_tabview_search.js
--- a/browser/base/content/tabview/search.js
+++ b/browser/base/content/tabview/search.js
@@ -124,16 +124,26 @@ var TabUtils = {
     // because we have to deal with both tabs represented inside
     // of active Panoramas as well as for windows in which
     // Panorama has yet to be activated. We uses object sniffing to
     // determine the type of tab and then returns its name.     
     return tab.label != undefined ? tab.label : tab.nameEl.innerHTML;
   },
   
   // ---------
+  // Function: URLOf
+  // Given a <TabItem> or a <xul:tab> returns the URL of tab
+  URLOf: function TabUtils_URLOf(tab) {
+    // Convert a <TabItem> to <xul:tab>
+    if(tab.tab != undefined)
+      tab = tab.tab;
+    return tab.linkedBrowser.currentURI.spec;
+  },
+
+  // ---------
   // Function: favURLOf
   // Given a <TabItem> or a <xul:tab> returns the URL of tab's favicon.
   faviconURLOf: function TabUtils_faviconURLOf(tab) {
     return tab.image != undefined ? tab.image : tab.favImgEl.src;
   },
   
   // ---------
   // Function: focus
@@ -160,18 +170,19 @@ TabMatcher.prototype = {
   // ---------
   // Function: _filterAndSortMatches
   // Given an array of <TabItem>s and <xul:tab>s returns a new array
   // of tabs whose name matched the search term, sorted by lexical
   // closeness.  
   _filterAndSortForMatches: function TabMatcher__filterAndSortForMatches(tabs) {
     var self = this;
     tabs = tabs.filter(function(tab){
-      var name = TabUtils.nameOf(tab);
-      return name.match(self.term, "i");
+      let name = TabUtils.nameOf(tab);
+      let url = TabUtils.URLOf(tab);
+      return name.match(self.term, "i") || url.match(self.term, "i");
     });
 
     tabs.sort(function sorter(x, y){
       var yScore = scorePatternMatch(self.term, TabUtils.nameOf(y));
       var xScore = scorePatternMatch(self.term, TabUtils.nameOf(x));
       return yScore - xScore; 
     });
     
@@ -181,17 +192,18 @@ TabMatcher.prototype = {
   // ---------
   // Function: _filterForUnmatches
   // Given an array of <TabItem>s returns an unsorted array of tabs whose name
   // does not match the the search term.
   _filterForUnmatches: function TabMatcher__filterForUnmatches(tabs) {
     var self = this;
     return tabs.filter(function(tab) {
       var name = tab.nameEl.innerHTML;
-      return !name.match(self.term, "i");
+      let url = TabUtils.URLOf(tab);
+      return !name.match(self.term, "i") && !url.match(self.term, "i");
     });
   },
   
   // ---------
   // Function: _getTabsForOtherWindows
   // Returns an array of <TabItem>s and <xul:tabs>s representing that
   // tabs from all windows but the currently focused window. <TabItem>s
   // will be returned for windows in which Panorama has been activated at
--- a/browser/base/content/test/tabview/browser_tabview_search.js
+++ b/browser/base/content/test/tabview/browser_tabview_search.js
@@ -121,16 +121,30 @@ function searchTest(contentWindow) {
   
   // part of title
   searchBox.setAttribute("value", "search");
   contentWindow.performSearch();
   is(new contentWindow.TabMatcher(
       searchBox.getAttribute("value")).matched().length, 2,
      "Match something when a part of title exists");
 
+  // unique part of a url 
+  searchBox.setAttribute("value", "search1.html");
+  contentWindow.performSearch();
+  is(new contentWindow.TabMatcher(
+      searchBox.getAttribute("value")).matched().length, 1,
+     "Match something when a unique part of a url exists");
+   
+  // common part of a url
+  searchBox.setAttribute("value", "tabview");
+  contentWindow.performSearch();
+  is(new contentWindow.TabMatcher(
+      searchBox.getAttribute("value")).matched().length, 2,
+     "Match something when a common part of a url exists");
+     
   cleanup(contentWindow);
 }
 
 // ----------
 function cleanup(contentWindow) {       
   contentWindow.hideSearch(null);     
   let onTabViewHidden = function() {
     window.removeEventListener("tabviewhidden", onTabViewHidden, false);