browser/devtools/styleinspector/test/browser_ruleview_completion-new-property_02.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 // Test that CSS property names and values are autocompleted and cycled correctly
michael@0 8 // when editing new properties in the rule view
michael@0 9
michael@0 10 // format :
michael@0 11 // [
michael@0 12 // what key to press,
michael@0 13 // modifers,
michael@0 14 // expected input box value after keypress,
michael@0 15 // selectedIndex of the popup,
michael@0 16 // total items in the popup
michael@0 17 // ]
michael@0 18 let testData = [
michael@0 19 ["a", {accelKey: true, ctrlKey: true}, "", -1, 0],
michael@0 20 ["d", {}, "direction", 0, 3],
michael@0 21 ["VK_DOWN", {}, "display", 1, 3],
michael@0 22 ["VK_TAB", {}, "", -1, 10],
michael@0 23 ["VK_DOWN", {}, "-moz-box", 0, 10],
michael@0 24 ["n", {}, "none", -1, 0],
michael@0 25 ["VK_TAB", {shiftKey: true}, "display", -1, 0],
michael@0 26 ["VK_BACK_SPACE", {}, "", -1, 0],
michael@0 27 ["c", {}, "caption-side", 0, 10],
michael@0 28 ["o", {}, "color", 0, 6],
michael@0 29 ["VK_TAB", {}, "none", -1, 0],
michael@0 30 ["r", {}, "red", 0, 5],
michael@0 31 ["VK_DOWN", {}, "rgb", 1, 5],
michael@0 32 ["VK_DOWN", {}, "rgba", 2, 5],
michael@0 33 ["VK_DOWN", {}, "rosybrown", 3, 5],
michael@0 34 ["VK_DOWN", {}, "royalblue", 4, 5],
michael@0 35 ["VK_RIGHT", {}, "royalblue", -1, 0],
michael@0 36 [" ", {}, "royalblue !important", 0, 10],
michael@0 37 ["!", {}, "royalblue !important", 0, 0],
michael@0 38 ["VK_ESCAPE", {}, null, -1, 0]
michael@0 39 ];
michael@0 40
michael@0 41 let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename:"+
michael@0 42 " browser_bug894376_css_value_completion_new_property_value_pair.js</h1>";
michael@0 43
michael@0 44 let test = asyncTest(function*() {
michael@0 45 yield addTab(TEST_URL);
michael@0 46 let {toolbox, inspector, view} = yield openRuleView();
michael@0 47
michael@0 48 info("Selecting the test node");
michael@0 49 yield selectNode("h1", inspector);
michael@0 50
michael@0 51 info("Focusing a new css property editable property");
michael@0 52 let brace = view.doc.querySelectorAll(".ruleview-ruleclose")[0];
michael@0 53 let editor = yield focusEditableField(brace);
michael@0 54
michael@0 55 info("Starting to test for css property completion");
michael@0 56 for (let i = 0; i < testData.length; i ++) {
michael@0 57 // Re-define the editor at each iteration, because the focus may have moved
michael@0 58 // from property to value and back
michael@0 59 editor = inplaceEditor(view.doc.activeElement);
michael@0 60 yield testCompletion(testData[i], editor, view);
michael@0 61 }
michael@0 62 });
michael@0 63
michael@0 64 function* testCompletion([key, modifiers, completion, index, total], editor, view) {
michael@0 65 info("Pressing key " + key);
michael@0 66 info("Expecting " + completion + ", " + index + ", " + total);
michael@0 67
michael@0 68 let onKeyPress;
michael@0 69
michael@0 70 if (/tab/ig.test(key)) {
michael@0 71 info("Waiting for the new property or value editor to get focused");
michael@0 72 let brace = view.doc.querySelector(".ruleview-ruleclose");
michael@0 73 onKeyPress = once(brace.parentNode, "focus", true);
michael@0 74 } else if (/(right|back_space|escape|return)/ig.test(key) ||
michael@0 75 (modifiers.accelKey || modifiers.ctrlKey)) {
michael@0 76 info("Adding event listener for right|escape|back_space|return keys");
michael@0 77 onKeyPress = once(editor.input, "keypress");
michael@0 78 } else {
michael@0 79 info("Waiting for after-suggest event on the editor");
michael@0 80 onKeyPress = editor.once("after-suggest");
michael@0 81 }
michael@0 82
michael@0 83 info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers));
michael@0 84 EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView);
michael@0 85
michael@0 86 yield onKeyPress;
michael@0 87 yield wait(1); // Equivalent of executeSoon
michael@0 88
michael@0 89 info("Checking the state");
michael@0 90 if (completion != null) {
michael@0 91 // The key might have been a TAB or shift-TAB, in which case the editor will
michael@0 92 // be a new one
michael@0 93 editor = inplaceEditor(view.doc.activeElement);
michael@0 94 is(editor.input.value, completion, "Correct value is autocompleted");
michael@0 95 }
michael@0 96 if (total == 0) {
michael@0 97 ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
michael@0 98 } else {
michael@0 99 ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
michael@0 100 is(editor.popup.getItems().length, total, "Number of suggestions match");
michael@0 101 is(editor.popup.selectedIndex, index, "Correct item is selected");
michael@0 102 }
michael@0 103 }

mercurial