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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests the Filter Editor Widget inputs increase/decrease value when cursor is
// on a number using arrow keys, applying multiplier using alt/shift on strings
const {CSSFilterEditorWidget} = require("devtools/client/shared/widgets/FilterWidget");
const {getClientCssProperties} = require("devtools/shared/fronts/css-properties");
const FAST_VALUE_MULTIPLIER = 10;
const SLOW_VALUE_MULTIPLIER = 0.1;
const DEFAULT_VALUE_MULTIPLIER = 1;
const TEST_URI = `data:text/html,<div id="filter-container" />`;
add_task(function* () {
let [,, doc] = yield createHost("bottom", TEST_URI);
const cssIsValid = getClientCssProperties().getValidityChecker(doc);
const container = doc.querySelector("#filter-container");
const initialValue = "drop-shadow(rgb(0, 0, 0) 1px 1px 0px)";
let widget = new CSSFilterEditorWidget(container, initialValue, cssIsValid);
widget.el.querySelector("#filters input").setSelectionRange(13, 13);
let value = 1;
triggerKey = triggerKey.bind(widget);
info("Test simple arrow keys");
triggerKey(40);
value -= DEFAULT_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease value using down arrow");
triggerKey(38);
value += DEFAULT_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease value using down arrow");
info("Test shift key multiplier");
triggerKey(38, "shiftKey");
value += FAST_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should increase value by fast multiplier using up arrow");
triggerKey(40, "shiftKey");
value -= FAST_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease value by fast multiplier using down arrow");
info("Test alt key multiplier");
triggerKey(38, "altKey");
value += SLOW_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should increase value by slow multiplier using up arrow");
triggerKey(40, "altKey");
value -= SLOW_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease value by slow multiplier using down arrow");
triggerKey(40, "shiftKey");
value -= FAST_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease to negative");
triggerKey(40);
value -= DEFAULT_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should decrease negative numbers correctly");
triggerKey(38);
value += DEFAULT_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should increase negative values correctly");
triggerKey(40, "altKey");
triggerKey(40, "altKey");
value -= SLOW_VALUE_MULTIPLIER * 2;
is(widget.getValueAt(0), val(value),
"Should decrease float numbers correctly");
triggerKey(38, "altKey");
value += SLOW_VALUE_MULTIPLIER;
is(widget.getValueAt(0), val(value),
"Should increase float numbers correctly");
triggerKey = null;
});
// Triggers the specified keyCode and modifier key on
// first filter's input
function triggerKey(key, modifier) {
const filter = this.el.querySelector("#filters").children[0];
const input = filter.querySelector("input");
this._keyDown({
target: input,
keyCode: key,
[modifier]: true,
preventDefault: function () {}
});
}
function val(value) {
let v = value.toFixed(1);
if (v.indexOf(".0") > -1) {
v = v.slice(0, -2);
}
return `rgb(0, 0, 0) ${v}px 1px 0px`;
}
|