1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_completion-new-property_02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +// Test that CSS property names and values are autocompleted and cycled correctly 1.11 +// when editing new properties in the rule view 1.12 + 1.13 +// format : 1.14 +// [ 1.15 +// what key to press, 1.16 +// modifers, 1.17 +// expected input box value after keypress, 1.18 +// selectedIndex of the popup, 1.19 +// total items in the popup 1.20 +// ] 1.21 +let testData = [ 1.22 + ["a", {accelKey: true, ctrlKey: true}, "", -1, 0], 1.23 + ["d", {}, "direction", 0, 3], 1.24 + ["VK_DOWN", {}, "display", 1, 3], 1.25 + ["VK_TAB", {}, "", -1, 10], 1.26 + ["VK_DOWN", {}, "-moz-box", 0, 10], 1.27 + ["n", {}, "none", -1, 0], 1.28 + ["VK_TAB", {shiftKey: true}, "display", -1, 0], 1.29 + ["VK_BACK_SPACE", {}, "", -1, 0], 1.30 + ["c", {}, "caption-side", 0, 10], 1.31 + ["o", {}, "color", 0, 6], 1.32 + ["VK_TAB", {}, "none", -1, 0], 1.33 + ["r", {}, "red", 0, 5], 1.34 + ["VK_DOWN", {}, "rgb", 1, 5], 1.35 + ["VK_DOWN", {}, "rgba", 2, 5], 1.36 + ["VK_DOWN", {}, "rosybrown", 3, 5], 1.37 + ["VK_DOWN", {}, "royalblue", 4, 5], 1.38 + ["VK_RIGHT", {}, "royalblue", -1, 0], 1.39 + [" ", {}, "royalblue !important", 0, 10], 1.40 + ["!", {}, "royalblue !important", 0, 0], 1.41 + ["VK_ESCAPE", {}, null, -1, 0] 1.42 +]; 1.43 + 1.44 +let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename:"+ 1.45 + " browser_bug894376_css_value_completion_new_property_value_pair.js</h1>"; 1.46 + 1.47 +let test = asyncTest(function*() { 1.48 + yield addTab(TEST_URL); 1.49 + let {toolbox, inspector, view} = yield openRuleView(); 1.50 + 1.51 + info("Selecting the test node"); 1.52 + yield selectNode("h1", inspector); 1.53 + 1.54 + info("Focusing a new css property editable property"); 1.55 + let brace = view.doc.querySelectorAll(".ruleview-ruleclose")[0]; 1.56 + let editor = yield focusEditableField(brace); 1.57 + 1.58 + info("Starting to test for css property completion"); 1.59 + for (let i = 0; i < testData.length; i ++) { 1.60 + // Re-define the editor at each iteration, because the focus may have moved 1.61 + // from property to value and back 1.62 + editor = inplaceEditor(view.doc.activeElement); 1.63 + yield testCompletion(testData[i], editor, view); 1.64 + } 1.65 +}); 1.66 + 1.67 +function* testCompletion([key, modifiers, completion, index, total], editor, view) { 1.68 + info("Pressing key " + key); 1.69 + info("Expecting " + completion + ", " + index + ", " + total); 1.70 + 1.71 + let onKeyPress; 1.72 + 1.73 + if (/tab/ig.test(key)) { 1.74 + info("Waiting for the new property or value editor to get focused"); 1.75 + let brace = view.doc.querySelector(".ruleview-ruleclose"); 1.76 + onKeyPress = once(brace.parentNode, "focus", true); 1.77 + } else if (/(right|back_space|escape|return)/ig.test(key) || 1.78 + (modifiers.accelKey || modifiers.ctrlKey)) { 1.79 + info("Adding event listener for right|escape|back_space|return keys"); 1.80 + onKeyPress = once(editor.input, "keypress"); 1.81 + } else { 1.82 + info("Waiting for after-suggest event on the editor"); 1.83 + onKeyPress = editor.once("after-suggest"); 1.84 + } 1.85 + 1.86 + info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers)); 1.87 + EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView); 1.88 + 1.89 + yield onKeyPress; 1.90 + yield wait(1); // Equivalent of executeSoon 1.91 + 1.92 + info("Checking the state"); 1.93 + if (completion != null) { 1.94 + // The key might have been a TAB or shift-TAB, in which case the editor will 1.95 + // be a new one 1.96 + editor = inplaceEditor(view.doc.activeElement); 1.97 + is(editor.input.value, completion, "Correct value is autocompleted"); 1.98 + } 1.99 + if (total == 0) { 1.100 + ok(!(editor.popup && editor.popup.isOpen), "Popup is closed"); 1.101 + } else { 1.102 + ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open"); 1.103 + is(editor.popup.getItems().length, total, "Number of suggestions match"); 1.104 + is(editor.popup.selectedIndex, index, "Correct item is selected"); 1.105 + } 1.106 +}