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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 are autocompleted and cycled correctly when
michael@0 8 // editing an existing property in the rule view
michael@0 9
michael@0 10 const MAX_ENTRIES = 10;
michael@0 11
michael@0 12 // format :
michael@0 13 // [
michael@0 14 // what key to press,
michael@0 15 // expected input box value after keypress,
michael@0 16 // selectedIndex of the popup,
michael@0 17 // total items in the popup
michael@0 18 // ]
michael@0 19 let testData = [
michael@0 20 ["VK_RIGHT", "border", -1, 0],
michael@0 21 ["-","border-bottom", 0, 10],
michael@0 22 ["b","border-bottom", 0, 6],
michael@0 23 ["VK_BACK_SPACE", "border-b", -1, 0],
michael@0 24 ["VK_BACK_SPACE", "border-", -1, 0],
michael@0 25 ["VK_BACK_SPACE", "border", -1, 0],
michael@0 26 ["VK_BACK_SPACE", "borde", -1, 0],
michael@0 27 ["VK_BACK_SPACE", "bord", -1, 0],
michael@0 28 ["VK_BACK_SPACE", "bor", -1, 0],
michael@0 29 ["VK_BACK_SPACE", "bo", -1, 0],
michael@0 30 ["VK_BACK_SPACE", "b", -1, 0],
michael@0 31 ["VK_BACK_SPACE", "", -1, 0],
michael@0 32 ["d", "direction", 0, 3],
michael@0 33 ["VK_DOWN", "display", 1, 3],
michael@0 34 ["VK_DOWN", "dominant-baseline", 2, 3],
michael@0 35 ["VK_DOWN", "direction", 0, 3],
michael@0 36 ["VK_DOWN", "display", 1, 3],
michael@0 37 ["VK_UP", "direction", 0, 3],
michael@0 38 ["VK_UP", "dominant-baseline", 2, 3],
michael@0 39 ["VK_UP", "display", 1, 3],
michael@0 40 ["VK_BACK_SPACE", "d", -1, 0],
michael@0 41 ["i", "direction", 0, 2],
michael@0 42 ["s", "display", -1, 0],
michael@0 43 ["VK_BACK_SPACE", "dis", -1, 0],
michael@0 44 ["VK_BACK_SPACE", "di", -1, 0],
michael@0 45 ["VK_BACK_SPACE", "d", -1, 0],
michael@0 46 ["VK_BACK_SPACE", "", -1, 0],
michael@0 47 ["f", "fill", 0, MAX_ENTRIES],
michael@0 48 ["i", "fill", 0, 4],
michael@0 49 ["VK_LEFT", "fill", -1, 0],
michael@0 50 ["VK_LEFT", "fill", -1, 0],
michael@0 51 ["i", "fiill", -1, 0],
michael@0 52 ["VK_ESCAPE", null, -1, 0],
michael@0 53 ];
michael@0 54
michael@0 55 let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename" +
michael@0 56 ": browser_bug893965_css_property_completion_existing_property.js</h1>";
michael@0 57
michael@0 58 let test = asyncTest(function*() {
michael@0 59 yield addTab(TEST_URL);
michael@0 60 let {toolbox, inspector, view} = yield openRuleView();
michael@0 61
michael@0 62 info("Selecting the test node");
michael@0 63 yield selectNode("h1", inspector);
michael@0 64
michael@0 65 info("Focusing the css property editable field");
michael@0 66 let propertyName = view.doc.querySelectorAll(".ruleview-propertyname")[0];
michael@0 67 let editor = yield focusEditableField(propertyName);
michael@0 68
michael@0 69 info("Starting to test for css property completion");
michael@0 70 for (let i = 0; i < testData.length; i ++) {
michael@0 71 yield testCompletion(testData[i], editor, view);
michael@0 72 }
michael@0 73 });
michael@0 74
michael@0 75 function* testCompletion([key, completion, index, total], editor, view) {
michael@0 76 info("Pressing key " + key);
michael@0 77 info("Expecting " + completion + ", " + index + ", " + total);
michael@0 78
michael@0 79 let onSuggest;
michael@0 80
michael@0 81 if (/(left|right|back_space|escape)/ig.test(key)) {
michael@0 82 info("Adding event listener for left|right|back_space|escape keys");
michael@0 83 onSuggest = once(editor.input, "keypress");
michael@0 84 } else {
michael@0 85 info("Waiting for after-suggest event on the editor");
michael@0 86 onSuggest = editor.once("after-suggest");
michael@0 87 }
michael@0 88
michael@0 89 info("Synthesizing key " + key);
michael@0 90 EventUtils.synthesizeKey(key, {}, view.doc.defaultView);
michael@0 91
michael@0 92 yield onSuggest;
michael@0 93 yield wait(1); // Equivalent of executeSoon
michael@0 94
michael@0 95 info("Checking the state");
michael@0 96 if (completion != null) {
michael@0 97 is(editor.input.value, completion, "Correct value is autocompleted");
michael@0 98 }
michael@0 99 if (total == 0) {
michael@0 100 ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
michael@0 101 } else {
michael@0 102 ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
michael@0 103 is(editor.popup.getItems().length, total, "Number of suggestions match");
michael@0 104 is(editor.popup.selectedIndex, index, "Correct item is selected");
michael@0 105 }
michael@0 106 }

mercurial