Bug 762452 - file filtering behaves strangely; r=past
authorVictor Porof <vporof@mozilla.com>
Tue, 19 Jun 2012 18:11:27 +0300
changeset 101923 543030f7b43be697999cef6ddfeb9a7131798ff3
parent 101922 3e8a7c61048abcdfe4fd6ed176f5d8e5e8133f55
child 101924 7808db2872b64909f5b02bdf4c88ec057d73bd1b
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs762452
milestone16.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 762452 - file filtering behaves strangely; r=past
browser/devtools/debugger/debugger-view.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
--- a/browser/devtools/debugger/debugger-view.js
+++ b/browser/devtools/debugger/debugger-view.js
@@ -131,16 +131,17 @@ RemoteDebuggerPrompt.prototype = {
 };
 
 /**
  * Functions handling the scripts UI.
  */
 function ScriptsView() {
   this._onScriptsChange = this._onScriptsChange.bind(this);
   this._onScriptsSearch = this._onScriptsSearch.bind(this);
+  this._onScriptsKeyUp = this._onScriptsKeyUp.bind(this);
 }
 
 ScriptsView.prototype = {
 
   /**
    * Removes all elements from the scripts container, leaving it empty.
    */
   empty: function DVS_empty() {
@@ -383,57 +384,69 @@ ScriptsView.prototype = {
     scriptItem.setUserData("sourceScript", aScript, null);
 
     if (this._scripts.itemCount == 1 && aSelectIfEmptyFlag) {
       this._scripts.selectedItem = scriptItem;
     }
   },
 
   /**
+   * Gets the entered file, line and token entered in the searchbox.
+   *
+   * @return array
+   *         A [file, line, token] array.
+   */
+  _getSearchboxInfo: function DVS__getSearchboxInfo() {
+    let rawValue = this._searchbox.value.toLowerCase();
+
+    let rawLength = rawValue.length;
+    let lastColon = rawValue.lastIndexOf(":");
+    let lastAt = rawValue.lastIndexOf("#");
+
+    let fileEnd = lastColon != -1 ? lastColon : lastAt != -1 ? lastAt : rawLength;
+    let lineEnd = lastAt != -1 ? lastAt : rawLength;
+
+    let file = rawValue.slice(0, fileEnd);
+    let line = window.parseInt(rawValue.slice(fileEnd + 1, lineEnd)) || -1;
+    let token = rawValue.slice(lineEnd + 1);
+
+    return [file, line, token];
+  },
+
+  /**
    * The click listener for the scripts container.
    */
   _onScriptsChange: function DVS__onScriptsChange() {
     let script = this._scripts.selectedItem.getUserData("sourceScript");
     this._preferredScript = script;
     DebuggerController.SourceScripts.showScript(script);
   },
 
   /**
    * The search listener for the scripts search box.
    */
   _onScriptsSearch: function DVS__onScriptsSearch(e) {
     let editor = DebuggerView.editor;
     let scripts = this._scripts;
-    let rawValue = this._searchbox.value.toLowerCase();
-
-    let rawLength = rawValue.length;
-    let lastColon = rawValue.lastIndexOf(":");
-    let lastAt = rawValue.lastIndexOf("#");
-
-    let fileEnd = lastColon != -1 ? lastColon : lastAt != -1 ? lastAt : rawLength;
-    let lineEnd = lastAt != -1 ? lastAt : rawLength;
-
-    let file = rawValue.slice(0, fileEnd);
-    let line = window.parseInt(rawValue.slice(fileEnd + 1, lineEnd)) || -1;
-    let token = rawValue.slice(lineEnd + 1);
+    let [file, line, token] = this._getSearchboxInfo();
 
     // Presume we won't find anything.
     scripts.selectedItem = this._preferredScript;
 
     // If we're not searching for a file anymore, unhide all the scripts.
     if (!file) {
       for (let i = 0, l = scripts.itemCount; i < l; i++) {
         scripts.getItemAtIndex(i).hidden = false;
       }
     } else {
       for (let i = 0, l = scripts.itemCount, found = false; i < l; i++) {
         let item = scripts.getItemAtIndex(i);
-        let target = item.value.toLowerCase();
+        let target = item.label.toLowerCase();
 
-        // Search is not case sensitive, and is tied to the url not the label.
+        // Search is not case sensitive, and is tied to the label not the url.
         if (target.match(file)) {
           item.hidden = false;
 
           if (!found) {
             found = true;
             scripts.selectedItem = item;
           }
         }
@@ -444,37 +457,36 @@ ScriptsView.prototype = {
       }
     }
     if (line > -1) {
       editor.setCaretPosition(line - 1);
     }
     if (token) {
       let offset = editor.find(token, { ignoreCase: true });
       if (offset > -1) {
-        editor.setCaretPosition(0);
-        editor.setCaretOffset(offset);
+        editor.setSelection(offset, offset + token.length)
       }
     }
   },
 
   /**
    * The keyup listener for the scripts search box.
    */
   _onScriptsKeyUp: function DVS__onScriptsKeyUp(e) {
     if (e.keyCode === e.DOM_VK_ESCAPE) {
       DebuggerView.editor.focus();
       return;
     }
 
     if (e.keyCode === e.DOM_VK_RETURN || e.keyCode === e.DOM_VK_ENTER) {
+      let token = this._getSearchboxInfo()[2];
       let editor = DebuggerView.editor;
       let offset = editor.findNext(true);
       if (offset > -1) {
-        editor.setCaretPosition(0);
-        editor.setCaretOffset(offset);
+        editor.setSelection(offset, offset + token.length)
       }
     }
   },
 
   /**
    * The cached scripts container and search box.
    */
   _scripts: null,
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
@@ -40,124 +40,130 @@ function test()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
 function testScriptSearching() {
+  var token;
+
   gDebugger.DebuggerController.activeThread.resume(function() {
     gEditor = gDebugger.DebuggerView.editor;
     gScripts = gDebugger.DebuggerView.Scripts;
     gSearchBox = gScripts._searchbox;
     gMenulist = gScripts._scripts;
 
     write(":12");
     ok(gEditor.getCaretPosition().line == 11 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line.");
 
-    write("#debugger");
+    token = "debugger";
+    write("#" + token);
     ok(gEditor.getCaretPosition().line == 2 &&
-       gEditor.getCaretPosition().col == 44,
+       gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (1)");
 
     EventUtils.sendKey("RETURN");
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (2)");
 
     EventUtils.sendKey("ENTER");
     ok(gEditor.getCaretPosition().line == 12 &&
-       gEditor.getCaretPosition().col == 8,
+       gEditor.getCaretPosition().col == 8 + token.length,
       "The editor didn't jump to the correct token. (3)");
 
     EventUtils.sendKey("ENTER");
     ok(gEditor.getCaretPosition().line == 19 &&
-       gEditor.getCaretPosition().col == 4,
+       gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (4)");
 
     EventUtils.sendKey("RETURN");
     ok(gEditor.getCaretPosition().line == 2 &&
-       gEditor.getCaretPosition().col == 44,
+       gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (5)");
 
 
-    write(":bogus#debugger;");
+    token = "debugger;";
+    write(":bogus#" + token);
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
-      "The editor didn't jump to the correct token. (7)");
+       gEditor.getCaretPosition().col == 2 + token.length,
+      "The editor didn't jump to the correct token. (6)");
 
-    write(":13#debugger;");
+    write(":13#" + token);
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (7)");
 
-    write(":#debugger;");
+    write(":#" + token);
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (8)");
 
-    write("::#debugger;");
+    write("::#" + token.length);
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (9)");
 
-    write(":::#debugger;");
+    write(":::#" + token.length);
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (10)");
 
 
     write(":i am not a number");
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't remain at the correct token. (11)");
 
     write("#__i do not exist__");
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't remain at the correct token. (12)");
 
 
+    token = "debugger";
     write(":1:2:3:a:b:c:::12");
     ok(gEditor.getCaretPosition().line == 11 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line. (13)");
 
-    write("#don't#find#me#instead#find#debugger");
+    write("#don't#find#me#instead#find#" + token);
     ok(gEditor.getCaretPosition().line == 2 &&
-       gEditor.getCaretPosition().col == 44,
+       gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (14)");
 
+
     EventUtils.sendKey("RETURN");
     ok(gEditor.getCaretPosition().line == 8 &&
-       gEditor.getCaretPosition().col == 2,
+       gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (15)");
 
     EventUtils.sendKey("ENTER");
     ok(gEditor.getCaretPosition().line == 12 &&
-       gEditor.getCaretPosition().col == 8,
+       gEditor.getCaretPosition().col == 8 + token.length,
       "The editor didn't jump to the correct token. (16)");
 
     EventUtils.sendKey("RETURN");
     ok(gEditor.getCaretPosition().line == 19 &&
-       gEditor.getCaretPosition().col == 4,
+       gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (17)");
 
     EventUtils.sendKey("ENTER");
     ok(gEditor.getCaretPosition().line == 2 &&
-       gEditor.getCaretPosition().col == 44,
+       gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (18)");
 
 
     clear();
     ok(gEditor.getCaretPosition().line == 2 &&
-       gEditor.getCaretPosition().col == 44,
+       gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't remain at the correct token. (19)");
     is(gScripts.visibleItemsCount, 1,
       "Not all the scripts are shown after the search. (20)");
 
     closeDebuggerAndFinish();
   });
 }
 
@@ -167,17 +173,17 @@ function clear() {
 }
 
 function write(text) {
   clear();
 
   for (let i = 0; i < text.length; i++) {
     EventUtils.sendChar(text[i]);
   }
-  dump("editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
+  info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebuggee = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
@@ -57,85 +57,99 @@ function testScriptSearching() {
     gMenulist = gScripts._scripts;
 
     firstSearch();
   });
 }
 
 function firstSearch() {
   window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
-    dump("Current script url:\n" + aEvent.detail.url + "\n");
-    dump("Debugger editor text:\n" + gEditor.getText() + "\n");
+    info("Current script url:\n" + aEvent.detail.url + "\n");
+    info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
       window.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
-        dump("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
+        info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 4 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line. (1)");
         is(gScripts.visibleItemsCount, 1,
           "Not all the correct scripts are shown after the search. (1)");
 
         secondSearch();
       });
     }
   });
   write(".*-01\.js:5");
 }
 
 function secondSearch() {
+  let token = "deb";
+
   window.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) {
-    dump("Current script url:\n" + aEvent.detail.url + "\n");
-    dump("Debugger editor text:\n" + gEditor.getText() + "\n");
+    info("Current script url:\n" + aEvent.detail.url + "\n");
+    info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
       window.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
-        dump("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
+        info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
-           gEditor.getCaretPosition().col == 8,
+           gEditor.getCaretPosition().col == 8 + token.length,
           "The editor didn't jump to the correct line. (2)");
         is(gScripts.visibleItemsCount, 1,
           "Not all the correct scripts are shown after the search. (2)");
 
-        finalCheck();
+        finalCheck(0, "ugger;", token);
       });
     }
   });
-  write(".*-02\.js#debugger;");
+  write(".*-02\.js#" + token);
 }
 
-function finalCheck() {
-  clear();
+function finalCheck(i, string, token) {
+  info("Searchbox value: " + gSearchBox.value);
+
   ok(gEditor.getCaretPosition().line == 5 &&
-     gEditor.getCaretPosition().col == 8,
+     gEditor.getCaretPosition().col == 8 + token.length + i,
     "The editor didn't remain at the correct token. (3)");
-  is(gScripts.visibleItemsCount, 2,
-    "Not all the scripts are shown after the search. (3)");
+
+  if (string[i]) {
+    EventUtils.sendChar(string[i]);
+    finalCheck(i + 1, string, token);
+    return;
+  }
 
-  closeDebuggerAndFinish();
+  clear();
+
+  executeSoon(function() {
+    is(gScripts.visibleItemsCount, 2,
+      "Not all the scripts are shown after the searchbox was emptied.");
+
+    closeDebuggerAndFinish();
+  });
 }
 
 function clear() {
   gSearchBox.focus();
   gSearchBox.value = "";
 }
 
 function write(text) {
   clear();
 
   for (let i = 0; i < text.length; i++) {
     EventUtils.sendChar(text[i]);
   }
-  dump("editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
+  info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebuggee = null;
   gDebugger = null;