3 <script src=
"../resources/js-test.js"></script>
4 <script src=
"vibration-utils.js"></script>
8 description('Tests for how durations are handled in the Vibration API.');
10 // Empty pattern is empty. Does not start a vibration.
11 shouldBeTrue("navigator.vibrate([])");
12 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [])");
13 shouldBeFalse("internals.isVibrating(document)");
16 // An empty pattern is stored internally for a single 0.
17 shouldBeTrue("navigator.vibrate(0)");
18 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [])");
19 shouldBeFalse("internals.isVibrating(document)");
22 // An empty pattern is stored internally for a single 0.
23 shouldBeTrue("navigator.vibrate([0])");
24 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [])");
25 shouldBeFalse("internals.isVibrating(document)");
28 // The maximum vibration duration.
29 shouldBeTrue("navigator.vibrate(10000)");
30 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [10000])");
31 shouldBeTrue("internals.isVibrating(document)");
34 // Overly long vibrations are truncated to the maximum duration.
35 shouldBeTrue("navigator.vibrate(10001)");
36 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [10000])");
37 shouldBeTrue("internals.isVibrating(document)");
40 // All values in the sequence are truncated.
41 shouldBeTrue("navigator.vibrate([10001, 10001, 10001])");
42 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [10000, 10000, 10000])");
43 shouldBeTrue("internals.isVibrating(document)");
46 // A negative integer is clamped to 0. This becomes an empty pattern.
47 shouldBeTrue("navigator.vibrate(-1)");
48 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [])");
49 shouldBeFalse("internals.isVibrating(document)");
52 // WebIDL cannot clamp values in sequences yet, so -1 first overflows to a huge
53 // number, then it is truncated to the maximum duration.
54 // All values in the sequence overflow and truncate in the same way.
55 // This is a bug, and this test exposes the incorrect behavior.
56 // FIXME: http://crbug.com/309700
57 shouldBeTrue("navigator.vibrate([-1, -1, -1])");
58 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [10000, 10000, 10000])");
59 shouldBeTrue("internals.isVibrating(document)");