summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_edit-property-commit.js
blob: 8e16601c732b18b2bbbff8ccbe05793c9a493d16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test original value is correctly displayed when ESCaping out of the
// inplace editor in the style inspector.

const TEST_URI = `
  <style type='text/css'>
  #testid {
    color: #00F;
  }
  </style>
  <div id='testid'>Styled Node</div>
`;

// Test data format
// {
//  value: what char sequence to type,
//  commitKey: what key to type to "commit" the change,
//  modifiers: commitKey modifiers,
//  expected: what value is expected as a result
// }
const testData = [
  {
    value: "red",
    commitKey: "VK_ESCAPE",
    modifiers: {},
    expected: "#00F"
  },
  {
    value: "red",
    commitKey: "VK_RETURN",
    modifiers: {},
    expected: "red"
  },
  {
    value: "invalid",
    commitKey: "VK_RETURN",
    modifiers: {},
    expected: "invalid"
  },
  {
    value: "blue",
    commitKey: "VK_TAB", modifiers: {shiftKey: true},
    expected: "blue"
  }
];

add_task(function* () {
  yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  let {inspector, view} = yield openRuleView();
  yield selectNode("#testid", inspector);

  for (let data of testData) {
    yield runTestData(view, data);
  }
});

function* runTestData(view, {value, commitKey, modifiers, expected}) {
  let idRuleEditor = getRuleViewRuleEditor(view, 1);
  let propEditor = idRuleEditor.rule.textProps[0].editor;

  info("Focusing the inplace editor field");

  let editor = yield focusEditableField(view, propEditor.valueSpan);
  is(inplaceEditor(propEditor.valueSpan), editor,
    "Focused editor should be the value span.");

  info("Entering test data " + value);
  let onRuleViewChanged = view.once("ruleview-changed");
  EventUtils.sendString(value, view.styleWindow);
  view.throttle.flush();
  yield onRuleViewChanged;

  info("Entering the commit key " + commitKey + " " + modifiers);
  onRuleViewChanged = view.once("ruleview-changed");
  let onBlur = once(editor.input, "blur");
  EventUtils.synthesizeKey(commitKey, modifiers);
  yield onBlur;
  yield onRuleViewChanged;

  if (commitKey === "VK_ESCAPE") {
    is(propEditor.valueSpan.textContent, expected,
      "Value is as expected: " + expected);
  } else {
    is(propEditor.valueSpan.textContent, expected,
      "Value is as expected: " + expected);
  }
}