Bug 1154371 - Avoid displaying autocomplete popup when ',' is pressed. r=ttromey
authorMatteo Ferretti <mferretti@mozilla.com>
Wed, 13 May 2015 12:26:47 +0200
changeset 269625 d597146748b9a448298854a4249858a030970707
parent 269624 41ed2dac1b3c152db5ebdb82125ccc6596a5171f
child 269626 51a031e1159572b52f36c868a2da4e358a71f521
push id2540
push userwcosta@mozilla.com
push dateWed, 03 Jun 2015 20:55:41 +0000
reviewersttromey
bugs1154371
milestone41.0a1
Bug 1154371 - Avoid displaying autocomplete popup when ',' is pressed. r=ttromey
browser/devtools/sourceeditor/css-autocompleter.js
browser/devtools/sourceeditor/test/browser_editor_autocomplete_events.js
--- a/browser/devtools/sourceeditor/css-autocompleter.js
+++ b/browser/devtools/sourceeditor/css-autocompleter.js
@@ -700,16 +700,20 @@ CSSCompleter.prototype = {
     if (!walker)
       return Promise.resolve([]);
 
     let query = this.selector;
     // Even though the selector matched atleast one node, there is still
     // possibility of suggestions.
     switch(this.selectorState) {
       case SELECTOR_STATES.null:
+        if (this.completing === ",") {
+          return Promise.resolve([]);
+        }
+
         query += "*";
         break;
 
       case SELECTOR_STATES.tag:
         query = query.slice(0, query.length - this.completing.length);
         break;
 
       case SELECTOR_STATES.id:
--- a/browser/devtools/sourceeditor/test/browser_editor_autocomplete_events.js
+++ b/browser/devtools/sourceeditor/test/browser_editor_autocomplete_events.js
@@ -3,16 +3,18 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const {InspectorFront} = require("devtools/server/actors/inspector");
 const AUTOCOMPLETION_PREF = "devtools.editor.autocomplete";
 const TEST_URI = "data:text/html;charset=UTF-8,<html><body><bar></bar><div id='baz'></div><body></html>";
 
+const wait = (delay) => new Promise(resolve => setTimeout(resolve, delay));
+
 add_task(function*() {
   yield promiseTab(TEST_URI);
   yield runTests();
 });
 
 function* runTests() {
   let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
   yield target.makeRemote();
@@ -22,16 +24,17 @@ function* runTests() {
     autocomplete: true,
     mode: Editor.modes.css,
     autocompleteOpts: {walker: walker}
   });
   yield testMouse(ed, edWin);
   yield testKeyboard(ed, edWin);
   yield testKeyboardCycle(ed, edWin);
   yield testKeyboardCycleForPrefixedString(ed, edWin);
+  yield testKeyboardCSSComma(ed, edWin);
   teardown(ed, win);
 }
 
 function* testKeyboard(ed, win) {
   ed.focus();
   ed.setText("b");
   ed.setCursor({line: 1, ch: 1});
 
@@ -82,16 +85,32 @@ function* testKeyboardCycleForPrefixedSt
 
   info ("Waiting for popup to be opened");
   yield popupOpened;
 
   EventUtils.synthesizeKey("VK_DOWN", { }, win);
   is (ed.getText(), "#baz", "Editor text has been updated");
 }
 
+function* testKeyboardCSSComma(ed, win) {
+  ed.focus();
+  ed.setText("b");
+  ed.setCursor({line: 1, ch: 1});
+
+  let isPopupOpened = false;
+  let popupOpened = ed.getAutocompletionPopup().once("popup-opened");
+  popupOpened.then(() => isPopupOpened = true);
+
+  EventUtils.synthesizeKey(",", { }, win);
+
+  yield wait(500);
+
+  ok(!isPopupOpened, "Autocompletion shouldn't be opened");
+}
+
 function* testMouse(ed, win) {
   ed.focus();
   ed.setText("b");
   ed.setCursor({line: 1, ch: 1});
 
   let popupOpened = ed.getAutocompletionPopup().once("popup-opened");
 
   let autocompleteKey = Editor.keyFor("autocompletion", { noaccel: true }).toUpperCase();