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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_completion-new-property_01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     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 are autocompleted and cycled correctly when
    1.11 +// creating a new property in the ruleview
    1.12 +
    1.13 +const MAX_ENTRIES = 10;
    1.14 +
    1.15 +// format :
    1.16 +//  [
    1.17 +//    what key to press,
    1.18 +//    expected input box value after keypress,
    1.19 +//    selectedIndex of the popup,
    1.20 +//    total items in the popup
    1.21 +//  ]
    1.22 +let testData = [
    1.23 +  ["d", "direction", 0, 3],
    1.24 +  ["VK_DOWN", "display", 1, 3],
    1.25 +  ["VK_DOWN", "dominant-baseline", 2, 3],
    1.26 +  ["VK_DOWN", "direction", 0, 3],
    1.27 +  ["VK_DOWN", "display", 1, 3],
    1.28 +  ["VK_UP", "direction", 0, 3],
    1.29 +  ["VK_UP", "dominant-baseline", 2, 3],
    1.30 +  ["VK_UP", "display", 1, 3],
    1.31 +  ["VK_BACK_SPACE", "d", -1, 0],
    1.32 +  ["i", "direction", 0, 2],
    1.33 +  ["s", "display", -1, 0],
    1.34 +  ["VK_BACK_SPACE", "dis", -1, 0],
    1.35 +  ["VK_BACK_SPACE", "di", -1, 0],
    1.36 +  ["VK_BACK_SPACE", "d", -1, 0],
    1.37 +  ["VK_BACK_SPACE", "", -1, 0],
    1.38 +  ["f", "fill", 0, MAX_ENTRIES],
    1.39 +  ["i", "fill", 0, 4],
    1.40 +  ["VK_ESCAPE", null, -1, 0],
    1.41 +];
    1.42 +
    1.43 +let TEST_URL = "data:text/html,<h1 style='border: 1px solid red'>Filename:" +
    1.44 +               "browser_bug893965_css_property_completion_new_property.js</h1>";
    1.45 +
    1.46 +let test = asyncTest(function*() {
    1.47 +  yield addTab(TEST_URL);
    1.48 +  let {toolbox, inspector, view} = yield openRuleView();
    1.49 +
    1.50 +  info("Selecting the test node");
    1.51 +  yield selectNode("h1", inspector);
    1.52 +
    1.53 +  info("Focusing the css property editable field");
    1.54 +  let brace = view.doc.querySelector(".ruleview-ruleclose");
    1.55 +  let editor = yield focusEditableField(brace);
    1.56 +
    1.57 +  info("Starting to test for css property completion");
    1.58 +  for (let i = 0; i < testData.length; i ++) {
    1.59 +    yield testCompletion(testData[i], editor, view);
    1.60 +  }
    1.61 +});
    1.62 +
    1.63 +function* testCompletion([key, completion, index, total], editor, view) {
    1.64 +  info("Pressing key " + key);
    1.65 +  info("Expecting " + completion + ", " + index + ", " + total);
    1.66 +
    1.67 +  let onSuggest;
    1.68 +
    1.69 +  if (/(right|back_space|escape)/ig.test(key)) {
    1.70 +    info("Adding event listener for right|back_space|escape keys");
    1.71 +    onSuggest = once(editor.input, "keypress");
    1.72 +  } else {
    1.73 +    info("Waiting for after-suggest event on the editor");
    1.74 +    onSuggest = editor.once("after-suggest");
    1.75 +  }
    1.76 +
    1.77 +  info("Synthesizing key " + key);
    1.78 +  EventUtils.synthesizeKey(key, {}, view.doc.defaultView);
    1.79 +
    1.80 +  yield onSuggest;
    1.81 +  yield wait(1); // Equivalent of executeSoon
    1.82 +
    1.83 +  info("Checking the state");
    1.84 +  if (completion != null) {
    1.85 +    is(editor.input.value, completion, "Correct value is autocompleted");
    1.86 +  }
    1.87 +  if (total == 0) {
    1.88 +    ok(!(editor.popup && editor.popup.isOpen), "Popup is closed");
    1.89 +  } else {
    1.90 +    ok(editor.popup._panel.state == "open" || editor.popup._panel.state == "showing", "Popup is open");
    1.91 +    is(editor.popup.getItems().length, total, "Number of suggestions match");
    1.92 +    is(editor.popup.selectedIndex, index, "Correct item is selected");
    1.93 +  }
    1.94 +}

mercurial