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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f3b31bfccc88
1 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
4
5 "use strict";
6
7 // Test that CSS property names are autocompleted and cycled correctly when
8 // creating a new property in the ruleview
9
10 const MAX_ENTRIES = 10;
11
12 // format :
13 // [
14 // what key to press,
15 // expected input box value after keypress,
16 // selectedIndex of the popup,
17 // total items in the popup
18 // ]
19 let testData = [
20 ["d", "direction", 0, 3],
21 ["VK_DOWN", "display", 1, 3],
22 ["VK_DOWN", "dominant-baseline", 2, 3],
23 ["VK_DOWN", "direction", 0, 3],
24 ["VK_DOWN", "display", 1, 3],
25 ["VK_UP", "direction", 0, 3],
26 ["VK_UP", "dominant-baseline", 2, 3],
27 ["VK_UP", "display", 1, 3],
28 ["VK_BACK_SPACE", "d", -1, 0],
29 ["i", "direction", 0, 2],
30 ["s", "display", -1, 0],
31 ["VK_BACK_SPACE", "dis", -1, 0],
32 ["VK_BACK_SPACE", "di", -1, 0],
33 ["VK_BACK_SPACE", "d", -1, 0],
34 ["VK_BACK_SPACE", "", -1, 0],
35 ["f", "fill", 0, MAX_ENTRIES],
36 ["i", "fill", 0, 4],
37 ["VK_ESCAPE", null, -1, 0],
38 ];
39
40 let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename:" +
41 "browser_bug893965_css_property_completion_new_property.js</h1>";
42
43 let test = asyncTest(function*() {
44 yield addTab(TEST_URL);
45 let {toolbox, inspector, view} = yield openRuleView();
46
47 info("Selecting the test node");
48 yield selectNode("h1", inspector);
49
50 info("Focusing the css property editable field");
51 let brace = view.doc.querySelector(".ruleview-ruleclose");
52 let editor = yield focusEditableField(brace);
53
54 info("Starting to test for css property completion");
55 for (let i = 0; i < testData.length; i ++) {
56 yield testCompletion(testData[i], editor, view);
57 }
58 });
59
60 function* testCompletion([key, completion, index, total], editor, view) {
61 info("Pressing key " + key);
62 info("Expecting " + completion + ", " + index + ", " + total);
63
64 let onSuggest;
65
66 if (/(right|back_space|escape)/ig.test(key)) {
67 info("Adding event listener for right|back_space|escape keys");
68 onSuggest = once(editor.input, "keypress");
69 } else {
70 info("Waiting for after-suggest event on the editor");
71 onSuggest = editor.once("after-suggest");
72 }
73
74 info("Synthesizing key " + key);
75 EventUtils.synthesizeKey(key, {}, view.doc.defaultView);
76
77 yield onSuggest;
78 yield wait(1); // Equivalent of executeSoon
79
80 info("Checking the state");
81 if (completion != null) {
82 is(editor.input.value, completion, "Correct value is autocompleted");
83 }
84 if (total == 0) {
85 ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
86 } else {
87 ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
88 is(editor.popup.getItems().length, total, "Number of suggestions match");
89 is(editor.popup.selectedIndex, index, "Correct item is selected");
90 }
91 }

mercurial