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