summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_colorpicker-revert-on-ESC.js
blob: e244d429c97b487a8731ee9adf790ec81f547592 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* 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";

// Tests that a color change in the color picker is reverted when ESC is
// pressed.

const TEST_URI = `
  <style type="text/css">
    body {
      background-color: #EDEDED;
    }
  </style>
`;

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

function* testPressingEscapeRevertsChanges(view) {
  let {swatch, propEditor, cPicker} = yield openColorPickerAndSelectColor(view,
    1, 0, [0, 0, 0, 1], {
      selector: "body",
      name: "background-color",
      value: "rgb(0, 0, 0)"
    });

  is(swatch.style.backgroundColor, "rgb(0, 0, 0)",
    "The color swatch's background was updated");
  is(propEditor.valueSpan.textContent, "#000",
    "The text of the background-color css property was updated");

  let spectrum = cPicker.spectrum;

  info("Pressing ESCAPE to close the tooltip");
  let onHidden = cPicker.tooltip.once("hidden");
  let onModifications = view.once("ruleview-changed");
  EventUtils.sendKey("ESCAPE", spectrum.element.ownerDocument.defaultView);
  yield onHidden;
  yield onModifications;

  yield waitForComputedStyleProperty("body", null, "background-color",
    "rgb(237, 237, 237)");
  is(propEditor.valueSpan.textContent, "#EDEDED",
    "Got expected property value.");
}

function* testPressingEscapeRevertsChangesAndDisables(view) {
  let ruleEditor = getRuleViewRuleEditor(view, 1);

  info("Disabling background-color property");
  let textProp = ruleEditor.rule.textProps[0];
  yield togglePropStatus(view, textProp);

  ok(textProp.editor.element.classList.contains("ruleview-overridden"),
    "property is overridden.");
  is(textProp.editor.enable.style.visibility, "visible",
    "property enable checkbox is visible.");
  ok(!textProp.editor.enable.getAttribute("checked"),
    "property enable checkbox is not checked.");
  ok(!textProp.editor.prop.enabled,
    "background-color property is disabled.");
  let newValue = yield getRulePropertyValue("background-color");
  is(newValue, "", "background-color should have been unset.");

  let {cPicker} = yield openColorPickerAndSelectColor(view,
    1, 0, [0, 0, 0, 1]);

  ok(!textProp.editor.element.classList.contains("ruleview-overridden"),
    "property overridden is not displayed.");
  is(textProp.editor.enable.style.visibility, "hidden",
    "property enable checkbox is hidden.");

  let spectrum = cPicker.spectrum;

  info("Pressing ESCAPE to close the tooltip");
  let onHidden = cPicker.tooltip.once("hidden");
  let onModifications = view.once("ruleview-changed");
  EventUtils.sendKey("ESCAPE", spectrum.element.ownerDocument.defaultView);
  yield onHidden;
  yield onModifications;

  ok(textProp.editor.element.classList.contains("ruleview-overridden"),
    "property is overridden.");
  is(textProp.editor.enable.style.visibility, "visible",
    "property enable checkbox is visible.");
  ok(!textProp.editor.enable.getAttribute("checked"),
    "property enable checkbox is not checked.");
  ok(!textProp.editor.prop.enabled,
    "background-color property is disabled.");
  newValue = yield getRulePropertyValue("background-color");
  is(newValue, "", "background-color should have been unset.");
  is(textProp.editor.valueSpan.textContent, "#EDEDED",
    "Got expected property value.");
}

function* getRulePropertyValue(name) {
  let propValue = yield executeInContent("Test:GetRulePropertyValue", {
    styleSheetIndex: 0,
    ruleIndex: 0,
    name: name
  });
  return propValue;
}