summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_colorpicker-and-image-tooltip_02.js
blob: 743ad5180149e4675dd7d30ee195e222df618138 (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
/* 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 after a color change, opening another tooltip, like the image
// preview doesn't revert the color change in the rule view.
// This used to happen when the activeSwatch wasn't reset when the colorpicker
// would hide.
// See bug 979292

const TEST_URI = `
  <style type="text/css">
    body {
      background: red url("chrome://global/skin/icons/warning-64.png")
        no-repeat center center;
    }
  </style>
  Testing the color picker tooltip!
`;

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

function* testColorChangeIsntRevertedWhenOtherTooltipIsShown(ruleView) {
  let swatch = getRuleViewProperty(ruleView, "body", "background").valueSpan
    .querySelector(".ruleview-colorswatch");

  info("Open the color picker tooltip and change the color");
  let picker = ruleView.tooltips.colorPicker;
  let onColorPickerReady = picker.once("ready");
  swatch.click();
  yield onColorPickerReady;

  yield simulateColorPickerChange(ruleView, picker, [0, 0, 0, 1], {
    selector: "body",
    name: "background-color",
    value: "rgb(0, 0, 0)"
  });

  let spectrum = picker.spectrum;

  let onModifications = waitForNEvents(ruleView, "ruleview-changed", 2);
  let onHidden = picker.tooltip.once("hidden");
  focusAndSendKey(spectrum.element.ownerDocument.defaultView, "RETURN");
  yield onHidden;
  yield onModifications;

  info("Open the image preview tooltip");
  let value = getRuleViewProperty(ruleView, "body", "background").valueSpan;
  let url = value.querySelector(".theme-link");
  let onShown = ruleView.tooltips.previewTooltip.once("shown");
  let anchor = yield isHoverTooltipTarget(ruleView.tooltips.previewTooltip, url);
  ruleView.tooltips.previewTooltip.show(anchor);
  yield onShown;

  info("Image tooltip is shown, verify that the swatch is still correct");
  swatch = value.querySelector(".ruleview-colorswatch");
  is(swatch.style.backgroundColor, "black",
    "The swatch's color is correct");
  is(swatch.nextSibling.textContent, "black", "The color name is correct");
}