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.

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

mercurial