Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/ */
5 "use strict";
7 // Test that CSS property names and values are autocompleted and cycled correctly
8 // when editing existing properties in the rule view
10 // format :
11 // [
12 // what key to press,
13 // modifers,
14 // expected input box value after keypress,
15 // selectedIndex of the popup,
16 // total items in the popup
17 // ]
18 let testData = [
19 ["b", {}, "beige", 0, 8],
20 ["l", {}, "black", 0, 4],
21 ["VK_DOWN", {}, "blanchedalmond", 1, 4],
22 ["VK_DOWN", {}, "blue", 2, 4],
23 ["VK_RIGHT", {}, "blue", -1, 0],
24 [" ", {}, "blue !important", 0, 10],
25 ["!", {}, "blue !important", 0, 0],
26 ["VK_BACK_SPACE", {}, "blue !", -1, 0],
27 ["VK_BACK_SPACE", {}, "blue ", -1, 0],
28 ["VK_BACK_SPACE", {}, "blue", -1, 0],
29 ["VK_TAB", {shiftKey: true}, "color", -1, 0],
30 ["VK_BACK_SPACE", {}, "", -1, 0],
31 ["d", {}, "direction", 0, 3],
32 ["i", {}, "direction", 0, 2],
33 ["s", {}, "display", -1, 0],
34 ["VK_TAB", {}, "blue", -1, 0],
35 ["n", {}, "none", -1, 0],
36 ["VK_RETURN", {}, null, -1, 0]
37 ];
39 let TEST_URL = "data:text/html,<h1 style='color: red'>Filename: " +
40 "browser_bug894376_css_value_completion_existing_property_value_pair.js</h1>";
42 let test = asyncTest(function*() {
43 yield addTab(TEST_URL);
44 let {toolbox, inspector, view} = yield openRuleView();
46 info("Selecting the test node");
47 yield selectNode("h1", inspector);
49 info("Focusing the css property editable value");
50 let value = view.doc.querySelectorAll(".ruleview-propertyvalue")[0];
51 let editor = yield focusEditableField(value);
53 info("Starting to test for css property completion");
54 for (let i = 0; i < testData.length; i ++) {
55 // Re-define the editor at each iteration, because the focus may have moved
56 // from property to value and back
57 editor = inplaceEditor(view.doc.activeElement);
58 yield testCompletion(testData[i], editor, view);
59 }
60 });
62 function* testCompletion([key, modifiers, completion, index, total], editor, view) {
63 info("Pressing key " + key);
64 info("Expecting " + completion + ", " + index + ", " + total);
66 let onKeyPress;
68 if (/tab/ig.test(key)) {
69 info("Waiting for the new property or value editor to get focused");
70 let brace = view.doc.querySelector(".ruleview-ruleclose");
71 onKeyPress = once(brace.parentNode, "focus", true);
72 } else if (/(right|return|back_space)/ig.test(key)) {
73 info("Adding event listener for right|return|back_space keys");
74 onKeyPress = once(editor.input, "keypress");
75 } else {
76 info("Waiting for after-suggest event on the editor");
77 onKeyPress = editor.once("after-suggest");
78 }
80 info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers));
81 EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView);
83 yield onKeyPress;
84 yield wait(1); // Equivalent of executeSoon
86 // The key might have been a TAB or shift-TAB, in which case the editor will
87 // be a new one
88 editor = inplaceEditor(view.doc.activeElement);
90 info("Checking the state");
91 if (completion != null) {
92 is(editor.input.value, completion, "Correct value is autocompleted");
93 }
94 if (total == 0) {
95 ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
96 } else {
97 ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
98 is(editor.popup.getItems().length, total, "Number of suggestions match");
99 is(editor.popup.selectedIndex, index, "Correct item is selected");
100 }
101 }