Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / vibration / vibration-durations.html
blob39e2b6a783e2842ba9120e14e1448cfa5a7609a4
1 <html>
2 <head>
3 <script src="../resources/js-test.js"></script>
4 <script src="vibration-utils.js"></script>
5 </head>
6 <body>
7 <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)");
14 stopVibration();
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)");
20 stopVibration();
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)");
26 stopVibration();
28 // The maximum vibration duration.
29 shouldBeTrue("navigator.vibrate(10000)");
30 shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(document), [10000])");
31 shouldBeTrue("internals.isVibrating(document)");
32 stopVibration();
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)");
38 stopVibration();
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)");
44 stopVibration();
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)");
50 stopVibration();
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)");
60 stopVibration();
62 </script>
63 </body>
64 </html>