browser/devtools/styleinspector/test/browser_ruleview_completion-new-property_02.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.

     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 new 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   ["a", {accelKey: true, ctrlKey: true}, "", -1, 0],
    20   ["d", {}, "direction", 0, 3],
    21   ["VK_DOWN", {}, "display", 1, 3],
    22   ["VK_TAB", {}, "", -1, 10],
    23   ["VK_DOWN", {}, "-moz-box", 0, 10],
    24   ["n", {}, "none", -1, 0],
    25   ["VK_TAB", {shiftKey: true}, "display", -1, 0],
    26   ["VK_BACK_SPACE", {}, "", -1, 0],
    27   ["c", {}, "caption-side", 0, 10],
    28   ["o", {}, "color", 0, 6],
    29   ["VK_TAB", {}, "none", -1, 0],
    30   ["r", {}, "red", 0, 5],
    31   ["VK_DOWN", {}, "rgb", 1, 5],
    32   ["VK_DOWN", {}, "rgba", 2, 5],
    33   ["VK_DOWN", {}, "rosybrown", 3, 5],
    34   ["VK_DOWN", {}, "royalblue", 4, 5],
    35   ["VK_RIGHT", {}, "royalblue", -1, 0],
    36   [" ", {}, "royalblue !important", 0, 10],
    37   ["!", {}, "royalblue !important", 0, 0],
    38   ["VK_ESCAPE", {}, null, -1, 0]
    39 ];
    41 let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename:"+
    42                " browser_bug894376_css_value_completion_new_property_value_pair.js</h1>";
    44 let test = asyncTest(function*() {
    45   yield addTab(TEST_URL);
    46   let {toolbox, inspector, view} = yield openRuleView();
    48   info("Selecting the test node");
    49   yield selectNode("h1", inspector);
    51   info("Focusing a new css property editable property");
    52   let brace = view.doc.querySelectorAll(".ruleview-ruleclose")[0];
    53   let editor = yield focusEditableField(brace);
    55   info("Starting to test for css property completion");
    56   for (let i = 0; i < testData.length; i ++) {
    57     // Re-define the editor at each iteration, because the focus may have moved
    58     // from property to value and back
    59     editor = inplaceEditor(view.doc.activeElement);
    60     yield testCompletion(testData[i], editor, view);
    61   }
    62 });
    64 function* testCompletion([key, modifiers, completion, index, total], editor, view) {
    65   info("Pressing key " + key);
    66   info("Expecting " + completion + ", " + index + ", " + total);
    68   let onKeyPress;
    70   if (/tab/ig.test(key)) {
    71     info("Waiting for the new property or value editor to get focused");
    72     let brace = view.doc.querySelector(".ruleview-ruleclose");
    73     onKeyPress = once(brace.parentNode, "focus", true);
    74   } else if (/(right|back_space|escape|return)/ig.test(key) ||
    75              (modifiers.accelKey || modifiers.ctrlKey)) {
    76     info("Adding event listener for right|escape|back_space|return keys");
    77     onKeyPress = once(editor.input, "keypress");
    78   } else {
    79     info("Waiting for after-suggest event on the editor");
    80     onKeyPress = editor.once("after-suggest");
    81   }
    83   info("Synthesizing key " + key + ", modifiers: " + Object.keys(modifiers));
    84   EventUtils.synthesizeKey(key, modifiers, view.doc.defaultView);
    86   yield onKeyPress;
    87   yield wait(1); // Equivalent of executeSoon
    89   info("Checking the state");
    90   if (completion != null) {
    91     // The key might have been a TAB or shift-TAB, in which case the editor will
    92     // be a new one
    93     editor = inplaceEditor(view.doc.activeElement);
    94     is(editor.input.value, completion, "Correct value is autocompleted");
    95   }
    96   if (total == 0) {
    97     ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
    98   } else {
    99     ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
   100     is(editor.popup.getItems().length, total, "Number of suggestions match");
   101     is(editor.popup.selectedIndex, index, "Correct item is selected");
   102   }
   103 }

mercurial