--- 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,54 +6,56 @@
// 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],
- ["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", "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],
+ ["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();
@@ -78,20 +80,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");
@@ -110,17 +114,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, 16, 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");
}
}