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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests methods from the LinearEasingWidget module
const {
LinearEasingFunctionWidget,
parseTimingFunction,
} = require("resource://devtools/client/shared/widgets/LinearEasingFunctionWidget.js");
add_task(function testParseTimingFunction() {
info("test parseTimingFunction");
for (const test of ["ease", "linear", "ease-in", "ease-out", "ease-in-out"]) {
ok(!parseTimingFunction(test), `"${test}" is not valid`);
}
ok(!parseTimingFunction("something"), "non-function token");
ok(!parseTimingFunction("something()"), "non-linear function");
ok(
!parseTimingFunction(
"linear(something)",
"linear with non-numeric argument"
)
);
ok(!parseTimingFunction("linear(0)", "linear with only 1 point"));
deepEqual(
parseTimingFunction("linear(0, 0.5, 1)"),
[
{ input: 0, output: 0 },
{ input: 0.5, output: 0.5 },
{ input: 1, output: 1 },
],
"correct invocation"
);
deepEqual(
parseTimingFunction("linear(0, 0.5 /* mid */, 1)"),
[
{ input: 0, output: 0 },
{ input: 0.5, output: 0.5 },
{ input: 1, output: 1 },
],
"correct with comments and whitespace"
);
deepEqual(
parseTimingFunction("linear(0 10%, 0.5 20%, 1 90%)"),
[
{ input: 0.1, output: 0 },
{ input: 0.2, output: 0.5 },
{ input: 0.9, output: 1 },
],
"correct invocation with single stop"
);
deepEqual(
parseTimingFunction(
"linear(0, 0.1, 0.2, 0.3, 0.4, 0.5 50%, 0.6, 0.7, 0.8, 0.9 70%, 1)"
),
[
{ input: 0, output: 0 },
{ input: 0.1, output: 0.1 },
{ input: 0.2, output: 0.2 },
{ input: 0.3, output: 0.3 },
{ input: 0.4, output: 0.4 },
{ input: 0.5, output: 0.5 },
{ input: 0.55, output: 0.6 },
{ input: 0.6, output: 0.7 },
{
// This should be 0.65, but JS doesn't play well with floating points, which makes
// the test fail. So re-do the computation here
input: 0.5 * 0.25 + 0.7 * 0.75,
output: 0.8,
},
{ input: 0.7, output: 0.9 },
{ input: 1, output: 1 },
],
"correct invocation with single stop and run of non-stop values"
);
deepEqual(
parseTimingFunction("linear(0, 0.5 80%, 0.75 40%, 1)"),
[
{ input: 0, output: 0 },
{ input: 0.8, output: 0.5 },
{ input: 0.8, output: 0.75 },
{ input: 1, output: 1 },
],
"correct invocation with out of order single stop"
);
deepEqual(
parseTimingFunction("linear(0.5 10% 40%, 0, 0.2 60% 70%, 0.75 80% 100%)"),
[
{ input: 0.1, output: 0.5 },
{ input: 0.4, output: 0.5 },
{ input: 0.5, output: 0 },
{ input: 0.6, output: 0.2 },
{ input: 0.7, output: 0.2 },
{ input: 0.8, output: 0.75 },
{ input: 1, output: 0.75 },
],
"correct invocation with multiple stops"
);
deepEqual(
parseTimingFunction("linear(0, 0.2 60% 10%, 1)"),
[
{ input: 0, output: 0 },
{ input: 0.6, output: 0.2 },
{ input: 0.6, output: 0.2 },
{ input: 1, output: 1 },
],
"correct invocation with multiple out of order stops"
);
deepEqual(
parseTimingFunction("linear(0, 1.5, 1)"),
[
{ input: 0, output: 0 },
{ input: 0.5, output: 1.5 },
{ input: 1, output: 1 },
],
"linear function easing with output greater than 1"
);
deepEqual(
parseTimingFunction("linear(1, -0.5, 0)"),
[
{ input: 0, output: 1 },
{ input: 0.5, output: -0.5 },
{ input: 1, output: 0 },
],
"linear function easing with output less than 1"
);
deepEqual(
parseTimingFunction("linear(0, 0.1 -10%, 1)"),
[
{ input: 0, output: 0 },
{ input: 0, output: 0.1 },
{ input: 1, output: 1 },
],
"correct invocation, input value being unspecified in the first entry implies zero"
);
deepEqual(
parseTimingFunction("linear(0, 0.9 110%, 1)"),
[
{ input: 0, output: 0 },
{ input: 1.1, output: 0.9 },
{ input: 1.1, output: 1 },
],
"correct invocation, input value being unspecified in the last entry implies max input value"
);
});
add_task(function testGetSetCssLinearValue() {
const doc = Services.appShell.createWindowlessBrowser().document;
const widget = new LinearEasingFunctionWidget(doc.body);
widget.setCssLinearValue("linear(0)");
ok(!widget.getCssLinearValue(), "no value returned for invalid value");
widget.setCssLinearValue("linear(0, 0.5, 1)");
deepEqual(
widget.getCssLinearValue(),
"linear(0 0%, 0.5 50%, 1 100%)",
"no stops"
);
widget.setCssLinearValue("linear(0 10%, 0.5 20%, 1 90%)");
deepEqual(
widget.getCssLinearValue(),
"linear(0 10%, 0.5 20%, 1 90%)",
"with single stops"
);
widget.setCssLinearValue("linear(0, 0.5 80%, 0.75 40%, 1)");
deepEqual(
widget.getCssLinearValue(),
"linear(0 0%, 0.5 80%, 0.75 80%, 1 100%)",
"correcting out of order single stops"
);
widget.setCssLinearValue(
"linear(0.5 10% 40%, 0, 0.2 60% 70%, 0.75 80% 100%)"
);
deepEqual(
widget.getCssLinearValue(),
"linear(0.5 10%, 0.5 40%, 0 50%, 0.2 60%, 0.2 70%, 0.75 80%, 0.75 100%)",
"multiple stops"
);
widget.setCssLinearValue("linear(0, 0.2 60% 10%, 1)");
deepEqual(
widget.getCssLinearValue(),
"linear(0 0%, 0.2 60%, 0.2 60%, 1 100%)",
"correcting multiple out-of-order stops"
);
widget.setCssLinearValue("linear(1, -0.5, 1.5)");
deepEqual(
widget.getCssLinearValue(),
"linear(1 0%, -0.5 50%, 1.5 100%)",
"output outside of [0,1] range"
);
widget.setCssLinearValue("linear(0 -10%, 0.5, 1 130%)");
deepEqual(
widget.getCssLinearValue(),
"linear(0 -10%, 0.5 60%, 1 130%)",
"input outside of [0%,100%] range"
);
});
|