OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/testharness.js"></script> |
| 5 <script src="../resources/testharnessreport.js"></script> |
5 <script> | 6 <script> |
6 description("Validates that screen.lockOrientation() returns false on bad input"
); | 7 |
7 window.jsTestIsAsync = true; | 8 var test = async_test("Test that screen.orientation.lock() throws when the input
isn't valid."); |
8 | 9 |
9 function onOrientationChangeEvent(ev) { | 10 function onOrientationChangeEvent(ev) { |
10 testFailed("Unexpected 'orientationchange' event"); | 11 assert_unreached('Unexpected orientation change'); |
11 } | 12 } |
12 | 13 |
13 function completeTest() { | 14 window.screen.orientation.addEventListener('change', test.step_func(onOrientatio
nChangeEvent)); |
14 shouldBeEqualToString("screen.orientation", "portrait-primary"); | |
15 screen.unlockOrientation(); | |
16 finishJSTest(); | |
17 } | |
18 | 15 |
19 window.addEventListener("orientationchange", onOrientationChangeEvent); | 16 test.step(function() { |
| 17 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 18 assert_throws({ name: 'TypeError' }, function() { |
| 19 screen.lock('invalid-orientation'); |
| 20 }); |
20 | 21 |
21 function typeErrorEnum(argStr) { | 22 assert_equals(screen.orientation.type, 'portrait-primary'); |
22 return "TypeError: Failed to execute 'lockOrientation' on 'Screen': parameter
1 ('" + argStr + "') is not a valid enum value."; | 23 assert_throws({ name: 'TypeError' }, function() { |
23 } | 24 screen.lock(null); |
| 25 }); |
24 | 26 |
25 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 27 assert_equals(screen.orientation.type, 'portrait-primary'); |
26 shouldThrow("screen.lockOrientation('invalid-orientation')", "typeErrorEnum('inv
alid-orientation')"); | 28 assert_throws({ name: 'TypeError' }, function() { |
27 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 29 screen.lock(undefined); |
28 shouldThrow("screen.lockOrientation(null)", "typeErrorEnum('null')"); | 30 }); |
29 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 31 |
30 shouldThrow("screen.lockOrientation(undefined)", "typeErrorEnum('undefined')"); | 32 assert_equals(screen.orientation.type, 'portrait-primary'); |
31 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 33 assert_throws({ name: 'TypeError' }, function() { |
32 shouldThrow("screen.lockOrientation(123)", "typeErrorEnum('123')"); | 34 screen.lock(undefined); |
33 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 35 }); |
34 shouldThrow("screen.lockOrientation(window)", "typeErrorEnum('[object Window]')"
); | 36 |
35 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 37 assert_equals(screen.orientation.type, 'portrait-primary'); |
36 shouldThrow("screen.lockOrientation(['portrait-primary', 'landscape-primary'])",
"typeErrorEnum('portrait-primary,landscape-primary')"); | 38 assert_throws({ name: 'TypeError' }, function() { |
37 shouldBeEqualToString("screen.orientation", "portrait-primary"); | 39 screen.lock(123); |
38 shouldThrow("screen.lockOrientation()", '"TypeError: Failed to execute \'lockOri
entation\' on \'Screen\': 1 argument required, but only 0 present."'); | 40 }); |
| 41 |
| 42 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 43 assert_throws({ name: 'TypeError' }, function() { |
| 44 screen.lock(window); |
| 45 }); |
| 46 |
| 47 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 48 assert_throws({ name: 'TypeError' }, function() { |
| 49 screen.lock(['portrait-primary']); |
| 50 }); |
| 51 |
| 52 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 53 assert_throws({ name: 'TypeError' }, function() { |
| 54 screen.lock(['portrait-primary', 'landscape-primary']); |
| 55 }); |
| 56 |
| 57 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 58 assert_throws({ name: 'TypeError' }, function() { |
| 59 screen.lock(); |
| 60 }); |
| 61 }); |
39 | 62 |
40 // Finish asynchronously to give events a chance to fire. | 63 // Finish asynchronously to give events a chance to fire. |
41 setTimeout(completeTest, 0); | 64 setTimeout(test.step_func(function() { |
| 65 assert_equals(screen.orientation.type, 'portrait-primary'); |
| 66 screen.orientation.unlock(); |
| 67 test.done(); |
| 68 })); |
| 69 |
42 </script> | 70 </script> |
43 </body> | 71 </body> |
44 </html> | 72 </html> |
45 | 73 |
OLD | NEW |