summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/flexbox/test/browser_flexbox_highlighter_color_picker_on_ESC.js
blob: 59b24ba5121099c6607fe64af32ff24283bcff1f (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const asyncStorage = require("resource://devtools/shared/async-storage.js");

// Test that the flexbox highlighter color change in the color picker is reverted when
// ESCAPE is pressed.

const TEST_URI = URL_ROOT + "doc_flexbox_specific_cases.html";

add_task(async function () {
  // Make sure there are no custom highlighter colors stored before starting.
  await asyncStorage.removeItem("flexboxInspectorHostColors");

  await addTab(TEST_URI);
  const { inspector, flexboxInspector, layoutView } = await openLayoutView();
  const { document: doc } = flexboxInspector;
  const { store } = inspector;
  const cPicker = layoutView.swatchColorPickerTooltip;
  const spectrum = cPicker.spectrum;

  const onColorSwatchRendered = waitForDOM(
    doc,
    ".layout-flexbox-wrapper .layout-color-swatch"
  );
  await selectNode("#container", inspector);
  const [swatch] = await onColorSwatchRendered;

  info("Checking the initial state of the Flexbox Inspector color picker.");
  is(
    swatch.style.backgroundColor,
    "rgb(148, 0, 255)",
    "The color swatch's background is correct."
  );
  is(
    store.getState().flexbox.color,
    "#9400FF",
    "The flexbox color state is correct."
  );

  info("Opening the color picker by clicking on the color swatch.");
  const onColorPickerReady = cPicker.once("ready");
  swatch.click();
  await onColorPickerReady;

  await simulateColorPickerChange(cPicker, [0, 255, 0, 0.5]);

  is(
    swatch.style.backgroundColor,
    "rgba(0, 255, 0, 0.5)",
    "The color swatch's background was updated."
  );

  info("Pressing ESCAPE to close the tooltip.");
  const onColorUpdate = waitUntilState(
    store,
    state => state.flexbox.color === "#9400FF"
  );
  const onColorPickerHidden = cPicker.tooltip.once("hidden");
  focusAndSendKey(spectrum.element.ownerDocument.defaultView, "ESCAPE");
  await onColorPickerHidden;
  await onColorUpdate;

  is(
    swatch.style.backgroundColor,
    "rgb(148, 0, 255)",
    "The color swatch's background was reverted after ESCAPE."
  );
});