Bug 1249212 part 1 - Simplify various keyframe-effect tests; r=boris

This patch just simplifies the keyframe-effect tests so that we don't have to
repeat default values. This makes the tests shorter, easier to scan, and
easier to understand what is being tested.

In some cases we still repeat the default values in order to indicate that
we're testing that we get a particular default value.
This commit is contained in:
Brian Birtles 2016-02-19 08:37:31 +09:00
Родитель dcd04d21d2
Коммит dbaa0a27a0
2 изменённых файлов: 70 добавлений и 193 удалений

Просмотреть файл

@ -474,12 +474,8 @@ test(function(t) {
var gKeyframeEffectOptionTests = [
{ desc: "an empty KeyframeEffectOptions object",
input: {},
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: "auto",
direction: "normal" } },
input: { },
expected: { } },
{ desc: "a normal KeyframeEffectOptions object",
input: { delay: 1000,
fill: "auto",
@ -493,123 +489,55 @@ var gKeyframeEffectOptionTests = [
direction: "alternate" } },
{ desc: "a double value",
input: 3000,
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: 3000,
direction: "normal" } },
expected: { duration: 3000 } },
{ desc: "+Infinity",
input: Infinity,
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: Infinity,
direction: "normal" } },
expected: { duration: Infinity } },
{ desc: "-Infinity",
input: -Infinity,
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: -Infinity,
direction: "normal" } },
expected: { duration: -Infinity } },
{ desc: "NaN",
input: NaN,
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: NaN,
direction: "normal" } },
expected: { duration: NaN } },
{ desc: "a negative value",
input: -1,
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: -1,
direction: "normal" } },
expected: { duration: -1 } },
{ desc: "an Infinity duration",
input: { duration: Infinity },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: Infinity,
direction: "normal" } },
expected: { duration: Infinity } },
{ desc: "a negative Infinity duration",
input: { duration: -Infinity },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: -Infinity,
direction: "normal" } },
expected: { duration: -Infinity } },
{ desc: "a NaN duration",
input: { duration: NaN },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: NaN,
direction: "normal" } },
expected: { duration: NaN } },
{ desc: "a negative duration",
input: { duration: -1 },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: -1,
direction: "normal" } },
expected: { duration: -1 } },
{ desc: "a string duration",
input: { duration: "merrychristmas" },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: "merrychristmas",
direction: "normal" } },
expected: { duration: "merrychristmas" } },
{ desc: "an auto duration",
input: { duration: "auto" },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: "auto",
direction: "normal" } },
expected: { duration: "auto" } },
{ desc: "an Infinity iterations",
input: { iterations: Infinity },
expected: { delay: 0,
fill: "auto",
iterations: Infinity,
duration: "auto",
direction: "normal" } },
expected: { iterations: Infinity } },
{ desc: "a negative Infinity iterations",
input: { iterations: -Infinity },
expected: { delay: 0,
fill: "auto",
iterations: -Infinity,
duration: "auto",
direction: "normal" } },
expected: { iterations: -Infinity } },
{ desc: "a NaN iterations",
input: { iterations: NaN },
expected: { delay: 0,
fill: "auto",
iterations: NaN,
duration: "auto",
direction: "normal" } },
expected: { iterations: NaN } },
{ desc: "a negative iterations",
input: { iterations: -1 },
expected: { delay: 0,
fill: "auto",
iterations: -1,
duration: "auto",
direction: "normal" } },
expected: { iterations: -1 } },
{ desc: "an auto fill",
input: { fill: "auto" },
expected: { delay: 0,
fill: "auto",
iterations: 1,
duration: "auto",
direction: "normal" } },
expected: { fill: "auto" } },
{ desc: "a forwards fill",
input: { fill: "forwards" },
expected: { delay: 0,
fill: "forwards",
iterations: 1,
duration: "auto",
direction: "normal" } }
expected: { fill: "forwards" } }
];
gKeyframeEffectOptionTests.forEach(function(stest) {
@ -618,14 +546,24 @@ gKeyframeEffectOptionTests.forEach(function(stest) {
{left: ["10px", "20px"]},
stest.input);
// Helper function to provide default expected values when the test does
// not supply them.
var expected = function(field, defaultValue) {
return field in stest.expected ? stest.expected[field] : defaultValue;
};
var timing = effect.timing;
assert_equals(timing.delay, stest.expected.delay, "timing delay");
assert_equals(timing.fill, stest.expected.fill, "timing fill");
assert_equals(timing.iterations, stest.expected.iterations,
assert_equals(timing.delay, expected("delay", 0),
"timing delay");
assert_equals(timing.fill, expected("fill", "auto"),
"timing fill");
assert_equals(timing.iterations, expected("iterations", 1),
"timing iterations");
assert_equals(timing.duration, stest.expected.duration, "timing duration");
assert_equals(timing.direction, stest.expected.direction,
assert_equals(timing.duration, expected("duration", "auto"),
"timing duration");
assert_equals(timing.direction, expected("direction", "normal"),
"timing direction");
}, "a KeyframeEffectReadOnly constructed by " + stest.desc);
});

Просмотреть файл

@ -30,12 +30,8 @@ test(function(t) {
var gGetComputedTimingTests = [
{ desc: "an empty KeyframeEffectOptions object",
input: {},
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
input: { },
expected: { } },
{ desc: "a normal KeyframeEffectOptions object",
input: { delay: 1000,
fill: "auto",
@ -47,13 +43,9 @@ var gGetComputedTimingTests = [
iterations: 5.5,
duration: 0,
direction: "alternate" } },
{ desc: " a double value",
{ desc: "a double value",
input: 3000,
timing: { delay: 0,
fill: "auto",
iterations: 1,
duration: 3000,
direction: "normal" },
timing: { duration: 3000 },
expected: { delay: 0,
fill: "none",
iterations: 1,
@ -61,116 +53,52 @@ var gGetComputedTimingTests = [
direction: "normal" } },
{ desc: "+Infinity",
input: Infinity,
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: Infinity,
direction: "normal" } },
expected: { duration: Infinity } },
{ desc: "-Infinity",
input: -Infinity,
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "NaN",
input: NaN,
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "a negative value",
input: -1,
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "an Infinity duration",
input: { duration: Infinity },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: Infinity,
direction: "normal" } },
expected: { duration: Infinity } },
{ desc: "a negative Infinity duration",
input: { duration: -Infinity },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "a NaN duration",
input: { duration: NaN },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "a negative duration",
input: { duration: -1},
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "a string duration",
input: { duration: "merrychristmas"},
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "an auto duration",
input: { duration: "auto" },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { duration: 0 } },
{ desc: "an Infinity iterations",
input: { iterations: Infinity },
expected: { delay: 0,
fill: "none",
iterations: Infinity,
duration: 0,
direction: "normal" } },
expected: { iterations: Infinity } },
{ desc: "a negative Infinity iterations",
input: { iterations: -Infinity},
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { iterations: 1 } },
{ desc: "a NaN iterations",
input: { iterations: NaN },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { iterations: 1 } },
{ desc: "a negative iterations",
input: { iterations: -1 },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { iterations: 1 } },
{ desc: "an auto fill",
input: { fill: "auto" },
expected: { delay: 0,
fill: "none",
iterations: 1,
duration: 0,
direction: "normal" } },
expected: { fill: "none" } },
{ desc: "a forwards fill",
input: { fill: "forwards" },
expected: { delay: 0,
fill: "forwards",
iterations: 1,
duration: 0,
direction: "normal" } }
expected: { fill: "forwards" } }
];
gGetComputedTimingTests.forEach(function(stest) {
@ -179,13 +107,24 @@ gGetComputedTimingTests.forEach(function(stest) {
{ left: ["10px", "20px"] },
stest.input);
// Helper function to provide default expected values when the test does
// not supply them.
var expected = function(field, defaultValue) {
return field in stest.expected ? stest.expected[field] : defaultValue;
};
var ct = effect.getComputedTiming();
assert_equals(ct.delay, stest.expected.delay, "computed delay");
assert_equals(ct.fill, stest.expected.fill, "computed fill");
assert_equals(ct.iterations, stest.expected.iterations,
assert_equals(ct.delay, expected("delay", 0),
"computed delay");
assert_equals(ct.fill, expected("fill", "none"),
"computed fill");
assert_equals(ct.iterations, expected("iterations", 1),
"computed iterations");
assert_equals(ct.duration, stest.expected.duration, "computed duration");
assert_equals(ct.direction, stest.expected.direction, "computed direction");
assert_equals(ct.duration, expected("duration", 0),
"computed duration");
assert_equals(ct.direction, expected("direction", "normal"),
"computed direction");
}, "values of getComputedTiming() when a KeyframeEffectReadOnly is " +
"constructed by " + stest.desc);
});