michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
michael@0: /* Any copyright is dedicated to the Public Domain.
michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0:
michael@0: "use strict";
michael@0:
michael@0: // Test that CSS property names are autocompleted and cycled correctly when
michael@0: // editing an existing property in the rule view
michael@0:
michael@0: const MAX_ENTRIES = 10;
michael@0:
michael@0: // format :
michael@0: // [
michael@0: // what key to press,
michael@0: // expected input box value after keypress,
michael@0: // selectedIndex of the popup,
michael@0: // total items in the popup
michael@0: // ]
michael@0: let testData = [
michael@0: ["VK_RIGHT", "border", -1, 0],
michael@0: ["-","border-bottom", 0, 10],
michael@0: ["b","border-bottom", 0, 6],
michael@0: ["VK_BACK_SPACE", "border-b", -1, 0],
michael@0: ["VK_BACK_SPACE", "border-", -1, 0],
michael@0: ["VK_BACK_SPACE", "border", -1, 0],
michael@0: ["VK_BACK_SPACE", "borde", -1, 0],
michael@0: ["VK_BACK_SPACE", "bord", -1, 0],
michael@0: ["VK_BACK_SPACE", "bor", -1, 0],
michael@0: ["VK_BACK_SPACE", "bo", -1, 0],
michael@0: ["VK_BACK_SPACE", "b", -1, 0],
michael@0: ["VK_BACK_SPACE", "", -1, 0],
michael@0: ["d", "direction", 0, 3],
michael@0: ["VK_DOWN", "display", 1, 3],
michael@0: ["VK_DOWN", "dominant-baseline", 2, 3],
michael@0: ["VK_DOWN", "direction", 0, 3],
michael@0: ["VK_DOWN", "display", 1, 3],
michael@0: ["VK_UP", "direction", 0, 3],
michael@0: ["VK_UP", "dominant-baseline", 2, 3],
michael@0: ["VK_UP", "display", 1, 3],
michael@0: ["VK_BACK_SPACE", "d", -1, 0],
michael@0: ["i", "direction", 0, 2],
michael@0: ["s", "display", -1, 0],
michael@0: ["VK_BACK_SPACE", "dis", -1, 0],
michael@0: ["VK_BACK_SPACE", "di", -1, 0],
michael@0: ["VK_BACK_SPACE", "d", -1, 0],
michael@0: ["VK_BACK_SPACE", "", -1, 0],
michael@0: ["f", "fill", 0, MAX_ENTRIES],
michael@0: ["i", "fill", 0, 4],
michael@0: ["VK_LEFT", "fill", -1, 0],
michael@0: ["VK_LEFT", "fill", -1, 0],
michael@0: ["i", "fiill", -1, 0],
michael@0: ["VK_ESCAPE", null, -1, 0],
michael@0: ];
michael@0:
michael@0: let TEST_URL = "data:text/html,
Filename" +
michael@0: ": browser_bug893965_css_property_completion_existing_property.js
";
michael@0:
michael@0: let test = asyncTest(function*() {
michael@0: yield addTab(TEST_URL);
michael@0: let {toolbox, inspector, view} = yield openRuleView();
michael@0:
michael@0: info("Selecting the test node");
michael@0: yield selectNode("h1", inspector);
michael@0:
michael@0: info("Focusing the css property editable field");
michael@0: let propertyName = view.doc.querySelectorAll(".ruleview-propertyname")[0];
michael@0: let editor = yield focusEditableField(propertyName);
michael@0:
michael@0: info("Starting to test for css property completion");
michael@0: for (let i = 0; i < testData.length; i ++) {
michael@0: yield testCompletion(testData[i], editor, view);
michael@0: }
michael@0: });
michael@0:
michael@0: function* testCompletion([key, completion, index, total], editor, view) {
michael@0: info("Pressing key " + key);
michael@0: info("Expecting " + completion + ", " + index + ", " + total);
michael@0:
michael@0: let onSuggest;
michael@0:
michael@0: if (/(left|right|back_space|escape)/ig.test(key)) {
michael@0: info("Adding event listener for left|right|back_space|escape keys");
michael@0: onSuggest = once(editor.input, "keypress");
michael@0: } else {
michael@0: info("Waiting for after-suggest event on the editor");
michael@0: onSuggest = editor.once("after-suggest");
michael@0: }
michael@0:
michael@0: info("Synthesizing key " + key);
michael@0: EventUtils.synthesizeKey(key, {}, view.doc.defaultView);
michael@0:
michael@0: yield onSuggest;
michael@0: yield wait(1); // Equivalent of executeSoon
michael@0:
michael@0: info("Checking the state");
michael@0: if (completion != null) {
michael@0: is(editor.input.value, completion, "Correct value is autocompleted");
michael@0: }
michael@0: if (total == 0) {
michael@0: ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
michael@0: } else {
michael@0: ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
michael@0: is(editor.popup.getItems().length, total, "Number of suggestions match");
michael@0: is(editor.popup.selectedIndex, index, "Correct item is selected");
michael@0: }
michael@0: }