Bug 1275081 - Part 1: Remove hardcoded number of "displayed" suggestions in devtools tests. r=tromey
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 26 May 2016 18:15:12 +0200
changeset 299122 48f6dbdcd9d2d642b1a47ef77ca73694ff33c874
parent 299121 db599457058b23ffdc6c29c17881e09772020d41
child 299123 ed8629e891d9e655af2e1e79fe8c32e8cbcf44b5
push id30290
push userryanvm@gmail.com
push dateFri, 27 May 2016 01:44:20 +0000
treeherdermozilla-central@34ac60e5b29c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1275081
milestone49.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 1275081 - Part 1: Remove hardcoded number of "displayed" suggestions in devtools tests. r=tromey Several devtools autocomplete tests are checking that the popup displays an exact number of suggestion, and that the selected suggestion is exactly at the expected index. Since devtools do not control the list of CSS properties used for the autocomplete, we should not assert anything based on it in tests. MozReview-Commit-ID: H4Azyx0UgpX
devtools/client/inspector/rules/test/browser_rules_completion-existing-property_01.js
devtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js
devtools/client/inspector/rules/test/browser_rules_completion-new-property_01.js
devtools/client/inspector/rules/test/browser_rules_completion-new-property_02.js
--- a/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_01.js
@@ -6,67 +6,69 @@
 
 // Tests that CSS property names are autocompleted and cycled correctly when
 // editing an existing property in the rule view.
 
 // format :
 //  [
 //    what key to press,
 //    expected input box value after keypress,
-//    selectedIndex of the popup,
-//    total items in the popup
+//    is the popup open,
+//    is a suggestion selected in the popup,
 //  ]
+
+const OPEN = true, SELECTED = true;
 var testData = [
-  ["VK_RIGHT", "font", -1, 0],
-  ["-", "font-size", 4, 17],
-  ["f", "font-family", 0, 2],
-  ["VK_BACK_SPACE", "font-f", -1, 0],
-  ["VK_BACK_SPACE", "font-", -1, 0],
-  ["VK_BACK_SPACE", "font", -1, 0],
-  ["VK_BACK_SPACE", "fon", -1, 0],
-  ["VK_BACK_SPACE", "fo", -1, 0],
-  ["VK_BACK_SPACE", "f", -1, 0],
-  ["VK_BACK_SPACE", "", -1, 0],
-  ["d", "display", 1, 3],
-  ["VK_DOWN", "dominant-baseline", 2, 3],
-  ["VK_DOWN", "direction", 0, 3],
-  ["VK_DOWN", "display", 1, 3],
-  ["VK_UP", "direction", 0, 3],
-  ["VK_UP", "dominant-baseline", 2, 3],
-  ["VK_UP", "display", 1, 3],
-  ["VK_BACK_SPACE", "d", -1, 0],
-  ["i", "display", 1, 2],
-  ["s", "display", -1, 0],
-  ["VK_BACK_SPACE", "dis", -1, 0],
-  ["VK_BACK_SPACE", "di", -1, 0],
-  ["VK_BACK_SPACE", "d", -1, 0],
-  ["VK_BACK_SPACE", "", -1, 0],
-  ["VK_HOME", "", -1, 0],
-  ["VK_END", "", -1, 0],
-  ["VK_PAGE_UP", "", -1, 0],
-  ["VK_PAGE_DOWN", "", -1, 0],
-  ["d", "display", 1, 3],
-  ["VK_HOME", "display", -1, 0],
-  ["VK_END", "display", -1, 0],
+  ["VK_RIGHT", "font", !OPEN, !SELECTED],
+  ["-", "font-size", OPEN, SELECTED],
+  ["f", "font-family", OPEN, SELECTED],
+  ["VK_BACK_SPACE", "font-f", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "font-", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "font", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "fon", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "fo", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "f", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "", !OPEN, !SELECTED],
+  ["d", "display", OPEN, SELECTED],
+  ["VK_DOWN", "dominant-baseline", OPEN, SELECTED],
+  ["VK_DOWN", "direction", OPEN, SELECTED],
+  ["VK_DOWN", "display", OPEN, SELECTED],
+  ["VK_UP", "direction", OPEN, SELECTED],
+  ["VK_UP", "dominant-baseline", OPEN, SELECTED],
+  ["VK_UP", "display", OPEN, SELECTED],
+  ["VK_BACK_SPACE", "d", !OPEN, !SELECTED],
+  ["i", "display", OPEN, SELECTED],
+  ["s", "display", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "dis", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "di", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "d", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "", !OPEN, !SELECTED],
+  ["VK_HOME", "", !OPEN, !SELECTED],
+  ["VK_END", "", !OPEN, !SELECTED],
+  ["VK_PAGE_UP", "", !OPEN, !SELECTED],
+  ["VK_PAGE_DOWN", "", !OPEN, !SELECTED],
+  ["d", "display", OPEN, SELECTED],
+  ["VK_HOME", "display", !OPEN, !SELECTED],
+  ["VK_END", "display", !OPEN, !SELECTED],
   // Press right key to ensure caret move to end of the input on Mac OS since
   // Mac OS doesn't move caret after pressing HOME / END.
-  ["VK_RIGHT", "display", -1, 0],
-  ["VK_BACK_SPACE", "displa", -1, 0],
-  ["VK_BACK_SPACE", "displ", -1, 0],
-  ["VK_BACK_SPACE", "disp", -1, 0],
-  ["VK_BACK_SPACE", "dis", -1, 0],
-  ["VK_BACK_SPACE", "di", -1, 0],
-  ["VK_BACK_SPACE", "d", -1, 0],
-  ["VK_BACK_SPACE", "", -1, 0],
-  ["f", "font-size", 19, 32],
-  ["i", "filter", 3, 4],
-  ["VK_LEFT", "filter", -1, 0],
-  ["VK_LEFT", "filter", -1, 0],
-  ["i", "fiilter", -1, 0],
-  ["VK_ESCAPE", null, -1, 0],
+  ["VK_RIGHT", "display", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "displa", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "displ", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "disp", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "dis", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "di", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "d", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "", !OPEN, !SELECTED],
+  ["f", "font-size", OPEN, SELECTED],
+  ["i", "filter", OPEN, SELECTED],
+  ["VK_LEFT", "filter", !OPEN, !SELECTED],
+  ["VK_LEFT", "filter", !OPEN, !SELECTED],
+  ["i", "fiilter", !OPEN, !SELECTED],
+  ["VK_ESCAPE", null, !OPEN, !SELECTED],
 ];
 
 const TEST_URI = "<h1 style='font: 24px serif'>Header</h1>";
 
 add_task(function* () {
   yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
   let {toolbox, inspector, view, testActor} = yield openRuleView();
 
@@ -91,20 +93,22 @@ function* runAutocompletionTest(toolbox,
   let previousPopupSize = 0;
   for (let i = 0; i < testData.length; i++) {
     let expectPopupHiddenEvent = previousPopupSize > 0 && testData[3] === 0;
     yield testCompletion(testData[i], expectPopupHiddenEvent, editor, view);
     previousPopupSize = testData[3];
   }
 }
 
-function* testCompletion([key, completion, index, total],
+function* testCompletion([key, completion, open, selected],
                          expectPopupHiddenEvent, editor, view) {
   info("Pressing key " + key);
-  info("Expecting " + completion + ", " + index + ", " + total);
+  info("Expecting " + completion);
+  info("Is popup opened: " + open);
+  info("Is item selected: " + selected);
 
   // Listening for the right event that will tell us when the key has been
   // entered and processed.
   let onSuggest;
   if (/(left|right|back_space|escape|home|end|page_up|page_down)/ig.test(key)) {
     info("Adding event listener for " +
       "left|right|back_space|escape|home|end|page_up|page_down keys");
     onSuggest = once(editor.input, "keypress");
@@ -123,17 +127,16 @@ function* testCompletion([key, completio
 
   yield onSuggest;
   yield onMaybePopupHidden;
 
   info("Checking the state");
   if (completion != null) {
     is(editor.input.value, completion, "Correct value is autocompleted");
   }
-  if (total == 0) {
+  if (!open) {
     ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
   } else {
     ok(editor.popup._panel.state == "open" ||
        editor.popup._panel.state == "showing", "Popup is open");
-    is(editor.popup.getItems().length, total, "Number of suggestions match");
-    is(editor.popup.selectedIndex, index, "Correct item is selected");
+    is(editor.popup.selectedIndex != -1, selected, "An item is selected");
   }
 }
--- a/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js
+++ b/devtools/client/inspector/rules/test/browser_rules_completion-existing-property_02.js
@@ -7,37 +7,39 @@
 // Tests that CSS property names and values are autocompleted and cycled
 // correctly when editing existing properties in the rule view.
 
 // format :
 //  [
 //    what key to press,
 //    modifers,
 //    expected input box value after keypress,
-//    selectedIndex of the popup,
-//    total items in the popup,
-//    expect ruleview-changed
+//    is the popup open,
+//    is a suggestion selected in the popup,
+//    expect ruleview-changed,
 //  ]
+
+const OPEN = true, SELECTED = true, CHANGE = true;
 var testData = [
-  ["b", {}, "beige", 0, 8, true],
-  ["l", {}, "black", 0, 4, true],
-  ["VK_DOWN", {}, "blanchedalmond", 1, 4, true],
-  ["VK_DOWN", {}, "blue", 2, 4, true],
-  ["VK_RIGHT", {}, "blue", -1, 0, false],
-  [" ", {}, "blue aliceblue", 0, 158, true],
-  ["!", {}, "blue !important", 0, 0, true],
-  ["VK_BACK_SPACE", {}, "blue !", -1, 0, true],
-  ["VK_BACK_SPACE", {}, "blue ", -1, 0, true],
-  ["VK_BACK_SPACE", {}, "blue", -1, 0, true],
-  ["VK_TAB", {shiftKey: true}, "color", -1, 0, true],
-  ["VK_BACK_SPACE", {}, "", -1, 0, false],
-  ["d", {}, "display", 1, 3, false],
-  ["VK_TAB", {}, "blue", -1, 0, true],
-  ["n", {}, "none", -1, 0, true],
-  ["VK_RETURN", {}, null, -1, 0, true]
+  ["b", {}, "beige", OPEN, SELECTED, CHANGE],
+  ["l", {}, "black", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "blanchedalmond", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "blue", OPEN, SELECTED, CHANGE],
+  ["VK_RIGHT", {}, "blue", !OPEN, !SELECTED, !CHANGE],
+  [" ", {}, "blue aliceblue", OPEN, SELECTED, CHANGE],
+  ["!", {}, "blue !important", !OPEN, !SELECTED, CHANGE],
+  ["VK_BACK_SPACE", {}, "blue !", !OPEN, !SELECTED, CHANGE],
+  ["VK_BACK_SPACE", {}, "blue ", !OPEN, !SELECTED, CHANGE],
+  ["VK_BACK_SPACE", {}, "blue", !OPEN, !SELECTED, CHANGE],
+  ["VK_TAB", {shiftKey: true}, "color", !OPEN, !SELECTED, CHANGE],
+  ["VK_BACK_SPACE", {}, "", !OPEN, !SELECTED, !CHANGE],
+  ["d", {}, "display", OPEN, SELECTED, !CHANGE],
+  ["VK_TAB", {}, "blue", !OPEN, !SELECTED, CHANGE],
+  ["n", {}, "none", !OPEN, !SELECTED, CHANGE],
+  ["VK_RETURN", {}, null, !OPEN, !SELECTED, CHANGE]
 ];
 
 const TEST_URI = "<h1 style='color: red'>Header</h1>";
 
 add_task(function* () {
   yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
   let {toolbox, inspector, view, testActor} = yield openRuleView();
 
@@ -63,23 +65,25 @@ function* runAutocompletionTest(toolbox,
   for (let i = 0; i < testData.length; i++) {
     // Re-define the editor at each iteration, because the focus may have moved
     // from property to value and back
     editor = inplaceEditor(view.styleDocument.activeElement);
     yield testCompletion(testData[i], editor, view);
   }
 }
 
-function* testCompletion([key, modifiers, completion, index, total, willChange],
+function* testCompletion([key, modifiers, completion, open, selected, change],
                          editor, view) {
   info("Pressing key " + key);
-  info("Expecting " + completion + ", " + index + ", " + total);
+  info("Expecting " + completion);
+  info("Is popup opened: " + open);
+  info("Is item selected: " + selected);
 
   let onDone;
-  if (willChange) {
+  if (change) {
     // If the key triggers a ruleview-changed, wait for that event, it will
     // always be the last to be triggered and tells us when the preview has
     // been done.
     onDone = view.once("ruleview-changed");
   } else {
     // Otherwise, expect an after-suggest event (except if the popup gets
     // closed).
     onDone = key !== "VK_RIGHT" && key !== "VK_BACK_SPACE"
@@ -94,17 +98,17 @@ function* testCompletion([key, modifiers
   // The key might have been a TAB or shift-TAB, in which case the editor will
   // be a new one
   editor = inplaceEditor(view.styleDocument.activeElement);
 
   info("Checking the state");
   if (completion != null) {
     is(editor.input.value, completion, "Correct value is autocompleted");
   }
-  if (total == 0) {
+
+  if (!open) {
     ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
   } else {
     ok(editor.popup._panel.state == "open" ||
        editor.popup._panel.state == "showing", "Popup is open");
-    is(editor.popup.getItems().length, total, "Number of suggestions match");
-    is(editor.popup.selectedIndex, index, "Correct item is selected");
+    is(editor.popup.selectedIndex != -1, selected, "An item is selected");
   }
 }
--- a/devtools/client/inspector/rules/test/browser_rules_completion-new-property_01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_completion-new-property_01.js
@@ -6,37 +6,38 @@
 
 // Tests that CSS property names are autocompleted and cycled correctly when
 // creating a new property in the rule view.
 
 // format :
 //  [
 //    what key to press,
 //    expected input box value after keypress,
-//    selectedIndex of the popup,
-//    total items in the popup
+//    is the popup open,
+//    is a suggestion selected in the popup,
 //  ]
+const OPEN = true, SELECTED = true;
 var testData = [
-  ["d", "display", 1, 3],
-  ["VK_DOWN", "dominant-baseline", 2, 3],
-  ["VK_DOWN", "direction", 0, 3],
-  ["VK_DOWN", "display", 1, 3],
-  ["VK_UP", "direction", 0, 3],
-  ["VK_UP", "dominant-baseline", 2, 3],
-  ["VK_UP", "display", 1, 3],
-  ["VK_BACK_SPACE", "d", -1, 0],
-  ["i", "display", 1, 2],
-  ["s", "display", -1, 0],
-  ["VK_BACK_SPACE", "dis", -1, 0],
-  ["VK_BACK_SPACE", "di", -1, 0],
-  ["VK_BACK_SPACE", "d", -1, 0],
-  ["VK_BACK_SPACE", "", -1, 0],
-  ["f", "font-size", 19, 32],
-  ["i", "filter", 3, 4],
-  ["VK_ESCAPE", null, -1, 0],
+  ["d", "display", OPEN, SELECTED],
+  ["VK_DOWN", "dominant-baseline", OPEN, SELECTED],
+  ["VK_DOWN", "direction", OPEN, SELECTED],
+  ["VK_DOWN", "display", OPEN, SELECTED],
+  ["VK_UP", "direction", OPEN, SELECTED],
+  ["VK_UP", "dominant-baseline", OPEN, SELECTED],
+  ["VK_UP", "display", OPEN, SELECTED],
+  ["VK_BACK_SPACE", "d", !OPEN, !SELECTED],
+  ["i", "display", OPEN, SELECTED],
+  ["s", "display", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "dis", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "di", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "d", !OPEN, !SELECTED],
+  ["VK_BACK_SPACE", "", !OPEN, !SELECTED],
+  ["f", "font-size", OPEN, SELECTED],
+  ["i", "filter", OPEN, SELECTED],
+  ["VK_ESCAPE", null, !OPEN, !SELECTED],
 ];
 
 const TEST_URI = "<h1 style='border: 1px solid red'>Header</h1>";
 
 add_task(function* () {
   yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
   let {toolbox, inspector, view, testActor} = yield openRuleView();
 
@@ -57,19 +58,21 @@ function* runAutocompletionTest(toolbox,
   let editor = yield focusNewRuleViewProperty(ruleEditor);
 
   info("Starting to test for css property completion");
   for (let i = 0; i < testData.length; i++) {
     yield testCompletion(testData[i], editor, view);
   }
 }
 
-function* testCompletion([key, completion, index, total], editor, view) {
+function* testCompletion([key, completion, isOpen, isSelected], editor, view) {
   info("Pressing key " + key);
-  info("Expecting " + completion + ", " + index + ", " + total);
+  info("Expecting " + completion);
+  info("Is popup opened: " + isOpen);
+  info("Is item selected: " + isSelected);
 
   let onSuggest;
 
   if (/(right|back_space|escape)/ig.test(key)) {
     info("Adding event listener for right|back_space|escape keys");
     onSuggest = once(editor.input, "keypress");
   } else {
     info("Waiting for after-suggest event on the editor");
@@ -81,17 +84,16 @@ function* testCompletion([key, completio
 
   yield onSuggest;
   yield waitForTick();
 
   info("Checking the state");
   if (completion != null) {
     is(editor.input.value, completion, "Correct value is autocompleted");
   }
-  if (total == 0) {
+  if (!isOpen) {
     ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
   } else {
     ok(editor.popup._panel.state == "open" ||
        editor.popup._panel.state == "showing", "Popup is open");
-    is(editor.popup.getItems().length, total, "Number of suggestions match");
-    is(editor.popup.selectedIndex, index, "Correct item is selected");
+    is(editor.popup.selectedIndex != -1, isSelected, "An item is selected");
   }
 }
--- a/devtools/client/inspector/rules/test/browser_rules_completion-new-property_02.js
+++ b/devtools/client/inspector/rules/test/browser_rules_completion-new-property_02.js
@@ -7,41 +7,43 @@
 // Tests that CSS property names and values are autocompleted and cycled
 // correctly when editing new properties in the rule view.
 
 // format :
 //  [
 //    what key to press,
 //    modifers,
 //    expected input box value after keypress,
-//    selectedIndex of the popup,
-//    total items in the popup,
-//    expect ruleview-changed
+//    is the popup open,
+//    is a suggestion selected in the popup,
+//    expect ruleview-changed,
 //  ]
-var testData = [
-  ["d", {}, "display", 1, 3, false],
-  ["VK_TAB", {}, "", -1, 43, true],
-  ["VK_DOWN", {}, "block", 0, 43, true],
-  ["n", {}, "none", -1, 0, true],
-  ["VK_TAB", {shiftKey: true}, "display", -1, 0, true],
-  ["VK_BACK_SPACE", {}, "", -1, 0, false],
-  ["o", {}, "overflow", 13, 17, false],
-  ["u", {}, "outline", 0, 5, false],
-  ["VK_DOWN", {}, "outline-color", 1, 5, false],
-  ["VK_TAB", {}, "none", -1, 0, true],
-  ["r", {}, "rebeccapurple", 0, 6, true],
-  ["VK_DOWN", {}, "red", 1, 6, true],
-  ["VK_DOWN", {}, "rgb", 2, 6, true],
-  ["VK_DOWN", {}, "rgba", 3, 6, true],
-  ["VK_DOWN", {}, "rosybrown", 4, 6, true],
-  ["VK_DOWN", {}, "royalblue", 5, 6, true],
-  ["VK_RIGHT", {}, "royalblue", -1, 0, false],
-  [" ", {}, "royalblue aliceblue", 0, 159, true],
-  ["!", {}, "royalblue !important", 0, 0, true],
-  ["VK_ESCAPE", {}, null, -1, 0, true]
+
+const OPEN = true, SELECTED = true, CHANGE = true;
+const testData = [
+  ["d", {}, "display", OPEN, SELECTED, !CHANGE],
+  ["VK_TAB", {}, "", OPEN, !SELECTED, CHANGE],
+  ["VK_DOWN", {}, "block", OPEN, SELECTED, CHANGE],
+  ["n", {}, "none", !OPEN, !SELECTED, CHANGE],
+  ["VK_TAB", {shiftKey: true}, "display", !OPEN, !SELECTED, CHANGE],
+  ["VK_BACK_SPACE", {}, "", !OPEN, !SELECTED, !CHANGE],
+  ["o", {}, "overflow", OPEN, SELECTED, !CHANGE],
+  ["u", {}, "outline", OPEN, SELECTED, !CHANGE],
+  ["VK_DOWN", {}, "outline-color", OPEN, SELECTED, !CHANGE],
+  ["VK_TAB", {}, "none", !OPEN, !SELECTED, CHANGE],
+  ["r", {}, "rebeccapurple", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "red", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "rgb", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "rgba", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "rosybrown", OPEN, SELECTED, CHANGE],
+  ["VK_DOWN", {}, "royalblue", OPEN, SELECTED, CHANGE],
+  ["VK_RIGHT", {}, "royalblue", !OPEN, !SELECTED, !CHANGE],
+  [" ", {}, "royalblue aliceblue", OPEN, SELECTED, CHANGE],
+  ["!", {}, "royalblue !important", !OPEN, !SELECTED, CHANGE],
+  ["VK_ESCAPE", {}, null, !OPEN, !SELECTED, CHANGE]
 ];
 
 const TEST_URI = `
   <style type="text/css">
     h1 {
       border: 1px solid red;
     }
   </style>
@@ -72,23 +74,25 @@ function* runAutocompletionTest(toolbox,
   for (let i = 0; i < testData.length; i++) {
     // Re-define the editor at each iteration, because the focus may have moved
     // from property to value and back
     editor = inplaceEditor(view.styleDocument.activeElement);
     yield testCompletion(testData[i], editor, view);
   }
 }
 
-function* testCompletion([key, modifiers, completion, index, total, willChange],
+function* testCompletion([key, modifiers, completion, open, selected, change],
                          editor, view) {
   info("Pressing key " + key);
-  info("Expecting " + completion + ", " + index + ", " + total);
+  info("Expecting " + completion);
+  info("Is popup opened: " + open);
+  info("Is item selected: " + selected);
 
   let onDone;
-  if (willChange) {
+  if (change) {
     // If the key triggers a ruleview-changed, wait for that event, it will
     // always be the last to be triggered and tells us when the preview has
     // been done.
     onDone = view.once("ruleview-changed");
   } else {
     // Otherwise, expect an after-suggest event (except if the popup gets
     // closed).
     onDone = key !== "VK_RIGHT" && key !== "VK_BACK_SPACE"
@@ -102,17 +106,16 @@ function* testCompletion([key, modifiers
 
   info("Checking the state");
   if (completion != null) {
     // The key might have been a TAB or shift-TAB, in which case the editor will
     // be a new one
     editor = inplaceEditor(view.styleDocument.activeElement);
     is(editor.input.value, completion, "Correct value is autocompleted");
   }
-  if (total == 0) {
+  if (!open) {
     ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
   } else {
     ok(editor.popup._panel.state == "open" ||
        editor.popup._panel.state == "showing", "Popup is open");
-    is(editor.popup.getItems().length, total, "Number of suggestions match");
-    is(editor.popup.selectedIndex, index, "Correct item is selected");
+    is(editor.popup.selectedIndex != -1, selected, "An item is selected");
   }
 }