Bug 1256658 - Make inspector search next/previous based on ctrl-g by default, and cmd-g on osx;r=bgrins
authorSteve Melia <steve.j.melia@gmail.com>
Sat, 26 Mar 2016 15:21:23 +0000
changeset 290529 678ddeb8eb8483540c58ce4ad54248a2429cb6b7
parent 290528 6e36e9a374f2564f27a40c0b1f8ba222a62909b0
child 290530 ae98422622f7f75e608621c7291b27b94e2eddce
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1256658
milestone48.0a1
Bug 1256658 - Make inspector search next/previous based on ctrl-g by default, and cmd-g on osx;r=bgrins MozReview-Commit-ID: F5NsNGmoeL8
devtools/client/inspector/inspector-search.js
devtools/client/inspector/test/browser.ini
devtools/client/inspector/test/browser_inspector_search-05.js
devtools/client/inspector/test/browser_inspector_search-selection.js
--- a/devtools/client/inspector/inspector-search.js
+++ b/devtools/client/inspector/inspector-search.js
@@ -2,23 +2,24 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {Cu, Ci} = require("chrome");
 
 const promise = require("promise");
+
+loader.lazyGetter(this, "system", () => require("devtools/shared/system"));
 loader.lazyGetter(this, "EventEmitter", () => require("devtools/shared/event-emitter"));
 loader.lazyGetter(this, "AutocompletePopup", () => require("devtools/client/shared/autocomplete-popup").AutocompletePopup);
 
 // Maximum number of selector suggestions shown in the panel.
 const MAX_SUGGESTIONS = 15;
 
-
 /**
  * Converts any input field into a document search box.
  *
  * @param {InspectorPanel} inspector The InspectorPanel whose `walker` attribute
  * should be used for document traversal.
  * @param {DOMNode} input The input element to which the panel will be attached
  * and from where search input will be taken.
  *
@@ -103,17 +104,21 @@ InspectorSearch.prototype = {
   _onKeyDown: function(event) {
     if (this.searchBox.value.length === 0) {
       this.searchBox.removeAttribute("filled");
     } else {
       this.searchBox.setAttribute("filled", true);
     }
     if (event.keyCode === event.DOM_VK_RETURN) {
       this._onSearch(event.shiftKey);
-    } if (event.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_G && event.metaKey) {
+    }
+
+    const modifierKey = system.constants.platform === "macosx" ? event.metaKey :
+event.ctrlKey;
+    if (event.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_G && modifierKey) {
       this._onSearch(event.shiftKey);
       event.preventDefault();
     }
   }
 };
 
 /**
  * Converts any input box on a page to a CSS selector search and suggestion box.
--- a/devtools/client/inspector/test/browser.ini
+++ b/devtools/client/inspector/test/browser.ini
@@ -106,13 +106,14 @@ skip-if = (e10s && debug) # Bug 1250058 
 [browser_inspector_search-01.js]
 [browser_inspector_search-02.js]
 [browser_inspector_search-03.js]
 [browser_inspector_search-04.js]
 [browser_inspector_search-05.js]
 [browser_inspector_search-06.js]
 [browser_inspector_search-07.js]
 [browser_inspector_search-reserved.js]
+[browser_inspector_search-selection.js]
 [browser_inspector_select-docshell.js]
 [browser_inspector_select-last-selected.js]
 [browser_inspector_search-navigation.js]
 [browser_inspector_sidebarstate.js]
 [browser_inspector_switch-to-inspector-on-pick.js]
--- a/devtools/client/inspector/test/browser_inspector_search-05.js
+++ b/devtools/client/inspector/test/browser_inspector_search-05.js
@@ -48,30 +48,16 @@ add_task(function* () {
 
   info("Press enter to cycle through multiple nodes matching this suggestion");
   onSelect = inspector.once("inspector-updated");
   EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
   yield onSelect;
 
   yield checkCorrectButton(inspector, "#iframe-2");
 
-  info("Press shift-enter to select the previous node matching this suggestion");
-  onSelect = inspector.once("inspector-updated");
-  EventUtils.synthesizeKey("VK_RETURN",  { shiftKey: true }, inspector.panelWin);
-  yield onSelect;
-
-  yield checkCorrectButton(inspector, "#iframe-1");
-
-  info("Press enter to cycle through multiple nodes matching this suggestion");
-  onSelect = inspector.once("inspector-updated");
-  EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
-  yield onSelect;
-
-  yield checkCorrectButton(inspector, "#iframe-2");
-
   info("Press enter to cycle through multiple nodes matching this suggestion");
   onSelect = inspector.once("inspector-updated");
   EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin);
   yield onSelect;
 
   yield checkCorrectButton(inspector, "#iframe-3");
 
   info("Press enter to cycle through multiple nodes matching this suggestion");
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/test/browser_inspector_search-selection.js
@@ -0,0 +1,59 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Testing navigation between nodes in search results
+var {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm");
+
+const TEST_URL = URL_ROOT + "doc_inspector_search.html";
+
+add_task(function* () {
+  let {inspector} = yield openInspectorForURL(TEST_URL);
+
+  info("Focus the search box");
+  yield focusSearchBoxUsingShortcut(inspector.panelWin);
+
+  info("Enter body > p to search");
+  let processingDone = once(inspector.searchSuggestions, "processing-done");
+  EventUtils.sendString("body > p", inspector.panelWin);
+  yield processingDone;
+
+  info("Wait for search query to complete");
+  yield inspector.searchSuggestions._lastQuery;
+
+  let msg = "Press enter and expect a new selection";
+  yield sendKeyAndCheck(inspector, msg, "VK_RETURN", {}, "#p1");
+
+  msg = "Press enter to cycle through multiple nodes";
+  yield sendKeyAndCheck(inspector, msg, "VK_RETURN", {}, "#p2");
+
+  msg = "Press shift-enter to select the previous node";
+  yield sendKeyAndCheck(inspector, msg, "VK_RETURN", { shiftKey: true }, "#p1");
+
+  if (AppConstants.platform === "macosx") {
+    msg = "Press meta-g to cycle through multiple nodes";
+    yield sendKeyAndCheck(inspector, msg, "VK_G", { metaKey: true }, "#p2");
+
+    msg = "Press shift+meta-g to select the previous node";
+    yield sendKeyAndCheck(inspector, msg, "VK_G", { metaKey: true, shiftKey: true }, "#p1");
+  } else {
+    msg = "Press ctrl-g to cycle through multiple nodes";
+    yield sendKeyAndCheck(inspector, msg, "VK_G", { ctrlKey: true }, "#p2");
+
+    msg = "Press shift+ctrl-g to select the previous node";
+    yield sendKeyAndCheck(inspector, msg, "VK_G", { ctrlKey: true, shiftKey: true }, "#p1");
+  }
+});
+
+let sendKeyAndCheck = Task.async(function*(inspector, description, key, modifiers, expectedId) {
+  info(description);
+  let onSelect = inspector.once("inspector-updated");
+  EventUtils.synthesizeKey(key, modifiers, inspector.panelWin);
+  yield onSelect;
+
+  let selectedNode = inspector.selection.nodeFront;
+  info(selectedNode.id + " is selected with text " + inspector.searchBox.value);
+  let targetNode = yield getNodeFront(expectedId, inspector);
+  is(selectedNode, targetNode, "Correct node " + expectedId + " is selected");
+});