summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_colorpicker-release-outside-frame.js
blob: ef6ca02b1ca5ae970d9b2fb0ef9c9c2d646fd448 (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
/* 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 color pickers stops following the pointer if the pointer is
// released outside the tooltip frame (bug 1160720).

const TEST_URI = "<body style='color: red'>Test page for bug 1160720";

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

  let cSwatch = getRuleViewProperty(view, "element", "color").valueSpan
    .querySelector(".ruleview-colorswatch");

  let picker = yield openColorPickerForSwatch(cSwatch, view);
  let spectrum = picker.spectrum;
  let change = spectrum.once("changed");

  info("Pressing mouse down over color picker.");
  let onRuleViewChanged = view.once("ruleview-changed");
  EventUtils.synthesizeMouseAtCenter(spectrum.dragger, {
    type: "mousedown",
  }, spectrum.dragger.ownerDocument.defaultView);
  yield onRuleViewChanged;

  let value = yield change;
  info(`Color changed to ${value} on mousedown.`);

  // If the mousemove below fails to detect that the button is no longer pressed
  // the spectrum will update and emit changed event synchronously after calling
  // synthesizeMouse so this handler is executed before the test ends.
  spectrum.once("changed", (event, newValue) => {
    is(newValue, value, "Value changed on mousemove without a button pressed.");
  });

  // Releasing the button pressed by mousedown above on top of a different frame
  // does not make sense in this test as EventUtils doesn't preserve the context
  // i.e. the buttons that were pressed down between events.

  info("Moving mouse over color picker without any buttons pressed.");

  EventUtils.synthesizeMouse(spectrum.dragger, 10, 10, {
    // -1 = no buttons are pressed down
    button: -1,
    type: "mousemove",
  }, spectrum.dragger.ownerDocument.defaultView);
});

function* openColorPickerForSwatch(swatch, view) {
  let cPicker = view.tooltips.colorPicker;
  ok(cPicker, "The rule-view has the expected colorPicker property");

  let cPickerPanel = cPicker.tooltip.panel;
  ok(cPickerPanel, "The XUL panel for the color picker exists");

  let onColorPickerReady = cPicker.once("ready");
  swatch.click();
  yield onColorPickerReady;

  ok(true, "The color picker was shown on click of the color swatch");

  return cPicker;
}