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 and values are autocompleted and cycled correctly michael@0: // when editing existing properties in the rule view michael@0: michael@0: // format : michael@0: // [ michael@0: // what key to press, michael@0: // modifers, 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: ["b", {}, "beige", 0, 8], michael@0: ["l", {}, "black", 0, 4], michael@0: ["VK_DOWN", {}, "blanchedalmond", 1, 4], michael@0: ["VK_DOWN", {}, "blue", 2, 4], michael@0: ["VK_RIGHT", {}, "blue", -1, 0], michael@0: [" ", {}, "blue !important", 0, 10], michael@0: ["!", {}, "blue !important", 0, 0], michael@0: ["VK_BACK_SPACE", {}, "blue !", -1, 0], michael@0: ["VK_BACK_SPACE", {}, "blue ", -1, 0], michael@0: ["VK_BACK_SPACE", {}, "blue", -1, 0], michael@0: ["VK_TAB", {shiftKey: true}, "color", -1, 0], michael@0: ["VK_BACK_SPACE", {}, "", -1, 0], michael@0: ["d", {}, "direction", 0, 3], michael@0: ["i", {}, "direction", 0, 2], michael@0: ["s", {}, "display", -1, 0], michael@0: ["VK_TAB", {}, "blue", -1, 0], michael@0: ["n", {}, "none", -1, 0], michael@0: ["VK_RETURN", {}, null, -1, 0] michael@0: ]; michael@0: michael@0: let TEST_URL = "data:text/html,

Filename: " + michael@0: "browser_bug894376_css_value_completion_existing_property_value_pair.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 value"); michael@0: let value = view.doc.querySelectorAll(".ruleview-propertyvalue")[0]; michael@0: let editor = yield focusEditableField(value); michael@0: michael@0: info("Starting to test for css property completion"); michael@0: for (let i = 0; i < testData.length; i ++) { michael@0: // Re-define the editor at each iteration, because the focus may have moved michael@0: // from property to value and back michael@0: editor = inplaceEditor(view.doc.activeElement); michael@0: yield testCompletion(testData[i], editor, view); michael@0: } michael@0: }); michael@0: michael@0: function* testCompletion([key, modifiers, completion, index, total], editor, view) { michael@0: info("Pressing key " + key); michael@0: info("Expecting " + completion + ", " + index + ", " + total); michael@0: michael@0: let onKeyPress; michael@0: michael@0: if (/tab/ig.test(key)) { michael@0: info("Waiting for the new property or value editor to get focused"); michael@0: let brace = view.doc.querySelector(".ruleview-ruleclose"); michael@0: onKeyPress = once(brace.parentNode, "focus", true); michael@0: } else if (/(right|return|back_space)/ig.test(key)) { michael@0: info("Adding event listener for right|return|back_space keys"); michael@0: onKeyPress = once(editor.input, "keypress"); michael@0: } else { michael@0: info("Waiting for after-suggest event on the editor"); michael@0: onKeyPress = editor.once("after-suggest"); michael@0: } michael@0: michael@0: info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers)); michael@0: EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView); michael@0: michael@0: yield onKeyPress; michael@0: yield wait(1); // Equivalent of executeSoon michael@0: michael@0: // The key might have been a TAB or shift-TAB, in which case the editor will michael@0: // be a new one michael@0: editor = inplaceEditor(view.doc.activeElement); 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: }