1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_completion-existing-property_02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 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 existing 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 + ["b", {}, "beige", 0, 8], 1.23 + ["l", {}, "black", 0, 4], 1.24 + ["VK_DOWN", {}, "blanchedalmond", 1, 4], 1.25 + ["VK_DOWN", {}, "blue", 2, 4], 1.26 + ["VK_RIGHT", {}, "blue", -1, 0], 1.27 + [" ", {}, "blue !important", 0, 10], 1.28 + ["!", {}, "blue !important", 0, 0], 1.29 + ["VK_BACK_SPACE", {}, "blue !", -1, 0], 1.30 + ["VK_BACK_SPACE", {}, "blue ", -1, 0], 1.31 + ["VK_BACK_SPACE", {}, "blue", -1, 0], 1.32 + ["VK_TAB", {shiftKey: true}, "color", -1, 0], 1.33 + ["VK_BACK_SPACE", {}, "", -1, 0], 1.34 + ["d", {}, "direction", 0, 3], 1.35 + ["i", {}, "direction", 0, 2], 1.36 + ["s", {}, "display", -1, 0], 1.37 + ["VK_TAB", {}, "blue", -1, 0], 1.38 + ["n", {}, "none", -1, 0], 1.39 + ["VK_RETURN", {}, null, -1, 0] 1.40 +]; 1.41 + 1.42 +let TEST_URL = "data:text/html,<h1 style='color: red'>Filename: " + 1.43 + "browser_bug894376_css_value_completion_existing_property_value_pair.js</h1>"; 1.44 + 1.45 +let test = asyncTest(function*() { 1.46 + yield addTab(TEST_URL); 1.47 + let {toolbox, inspector, view} = yield openRuleView(); 1.48 + 1.49 + info("Selecting the test node"); 1.50 + yield selectNode("h1", inspector); 1.51 + 1.52 + info("Focusing the css property editable value"); 1.53 + let value = view.doc.querySelectorAll(".ruleview-propertyvalue")[0]; 1.54 + let editor = yield focusEditableField(value); 1.55 + 1.56 + info("Starting to test for css property completion"); 1.57 + for (let i = 0; i < testData.length; i ++) { 1.58 + // Re-define the editor at each iteration, because the focus may have moved 1.59 + // from property to value and back 1.60 + editor = inplaceEditor(view.doc.activeElement); 1.61 + yield testCompletion(testData[i], editor, view); 1.62 + } 1.63 +}); 1.64 + 1.65 +function* testCompletion([key, modifiers, completion, index, total], editor, view) { 1.66 + info("Pressing key " + key); 1.67 + info("Expecting " + completion + ", " + index + ", " + total); 1.68 + 1.69 + let onKeyPress; 1.70 + 1.71 + if (/tab/ig.test(key)) { 1.72 + info("Waiting for the new property or value editor to get focused"); 1.73 + let brace = view.doc.querySelector(".ruleview-ruleclose"); 1.74 + onKeyPress = once(brace.parentNode, "focus", true); 1.75 + } else if (/(right|return|back_space)/ig.test(key)) { 1.76 + info("Adding event listener for right|return|back_space keys"); 1.77 + onKeyPress = once(editor.input, "keypress"); 1.78 + } else { 1.79 + info("Waiting for after-suggest event on the editor"); 1.80 + onKeyPress = editor.once("after-suggest"); 1.81 + } 1.82 + 1.83 + info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers)); 1.84 + EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView); 1.85 + 1.86 + yield onKeyPress; 1.87 + yield wait(1); // Equivalent of executeSoon 1.88 + 1.89 + // The key might have been a TAB or shift-TAB, in which case the editor will 1.90 + // be a new one 1.91 + editor = inplaceEditor(view.doc.activeElement); 1.92 + 1.93 + info("Checking the state"); 1.94 + if (completion != null) { 1.95 + is(editor.input.value, completion, "Correct value is autocompleted"); 1.96 + } 1.97 + if (total == 0) { 1.98 + ok(!(editor.popup && editor.popup.isOpen), "Popup is closed"); 1.99 + } else { 1.100 + ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open"); 1.101 + is(editor.popup.getItems().length, total, "Number of suggestions match"); 1.102 + is(editor.popup.selectedIndex, index, "Correct item is selected"); 1.103 + } 1.104 +}