| 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/testharness.js"></script> |
| 5 <script src="../resources/testharnessreport.js"></script> | 5 <script src="../resources/testharnessreport.js"></script> |
| 6 <script> | 6 <script> |
| 7 | 7 |
| 8 var orientations = [ | 8 var orientations = [ |
| 9 'portrait-primary', | 9 'portrait-primary', |
| 10 'portrait-secondary', | 10 'portrait-secondary', |
| 11 'landscape-primary', | 11 'landscape-primary', |
| 12 'landscape-secondary' | 12 'landscape-secondary' |
| 13 ]; | 13 ]; |
| 14 | 14 |
| 15 var currentIndex = orientations.indexOf(window.screen.orientation); | 15 var currentIndex = orientations.indexOf(window.screen.orientation.type); |
| 16 // Count the number of calls received from the EventHandler set on window.onorie
ntationchange. | 16 // Count the number of calls received from the EventHandler set on screen.orient
ation.onchange. |
| 17 var orientationChangeEventHandlerCalls = 0; | 17 var orientationChangeEventHandlerCalls = 0; |
| 18 // Count the number of calls received from the listener set with window.addEvent
Listene(). | 18 // Count the number of calls received from the listener set with screen.orientat
ion.addEventListene(). |
| 19 var orientationChangeEventListenerCalls = 0; | 19 var orientationChangeEventListenerCalls = 0; |
| 20 | 20 |
| 21 // TODO: window.onorientationchange is enabled on Android only. We will enable | |
| 22 // it with ScreenOrientation later, at which point this test will fail. We will | |
| 23 // then have to fix it. | |
| 24 function todo_equals(actual, expected) { | |
| 25 assert_not_equals(actual, expected, "TODO: if this fails, it means that someth
ing got fixed."); | |
| 26 } | |
| 27 | |
| 28 function getNextIndex() { | 21 function getNextIndex() { |
| 29 return (currentIndex + 1) % orientations.length; | 22 return (currentIndex + 1) % orientations.length; |
| 30 } | 23 } |
| 31 | 24 |
| 32 window.onorientationchange = function() { | 25 window.screen.orientation.onchange = function() { |
| 33 orientationChangeEventHandlerCalls++; | 26 orientationChangeEventHandlerCalls++; |
| 34 }; | 27 }; |
| 35 | 28 |
| 36 window.addEventListener('orientationchange', function() { | 29 window.screen.orientation.addEventListener('change', function() { |
| 37 orientationChangeEventListenerCalls++; | 30 orientationChangeEventListenerCalls++; |
| 38 }); | 31 }); |
| 39 | 32 |
| 40 for (var i = 0; i < 4; ++i) { | 33 for (var i = 0; i < 4; ++i) { |
| 41 test(function() { | 34 test(function() { |
| 42 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]); | 35 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]); |
| 43 | 36 |
| 44 currentIndex = getNextIndex(); | 37 currentIndex = getNextIndex(); |
| 45 assert_equals(screen.orientation, orientations[currentIndex]); | 38 assert_equals(screen.orientation.type, orientations[currentIndex]); |
| 46 | 39 |
| 47 todo_equals(orientationChangeEventHandlerCalls, i + 1); | 40 assert_equals(orientationChangeEventHandlerCalls, i + 1); |
| 48 assert_equals(orientationChangeEventListenerCalls, i + 1); | 41 assert_equals(orientationChangeEventListenerCalls, i + 1); |
| 49 }, "Test that orientationchange event is fired when the orientation changes"); | 42 }, "Test that orientationchange event is fired when the orientation changes"); |
| 50 } | 43 } |
| 51 | 44 |
| 52 test(function() { | 45 test(function() { |
| 53 window.testRunner.setMockScreenOrientation(orientations[currentIndex]); | 46 window.testRunner.setMockScreenOrientation(orientations[currentIndex]); |
| 54 assert_equals(screen.orientation, orientations[currentIndex]); | 47 assert_equals(screen.orientation.type, orientations[currentIndex]); |
| 55 | 48 |
| 56 todo_equals(orientationChangeEventHandlerCalls, 4); | 49 assert_equals(orientationChangeEventHandlerCalls, 4); |
| 57 assert_equals(orientationChangeEventListenerCalls, 4); | 50 assert_equals(orientationChangeEventListenerCalls, 4); |
| 58 }, "Test that orientationchange event is not fired when the orientation does not
change"); | 51 }, "Test that orientationchange event is not fired when the orientation does not
change"); |
| 59 | 52 |
| 60 </script> | 53 </script> |
| 61 </body> | 54 </body> |
| 62 </html> | 55 </html> |
| OLD | NEW |