| 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 changeTest = async_test("Test that orientationchange event is fired when the
orientation changes."); | 8 var changeTest = async_test("Test that orientationchange event is fired when the
orientation changes."); |
| 9 var noChangeTest = async_test("Test that orientationchange event is not fired wh
en the orientation does not change."); | 9 var noChangeTest = async_test("Test that orientationchange event is not fired wh
en the orientation does not change."); |
| 10 | 10 |
| 11 var orientations = [ | 11 var orientations = [ |
| 12 'portrait-primary', | 12 'portrait-primary', |
| 13 'portrait-secondary', | 13 'portrait-secondary', |
| 14 'landscape-primary', | 14 'landscape-primary', |
| 15 'landscape-secondary' | 15 'landscape-secondary' |
| 16 ]; | 16 ]; |
| 17 | 17 |
| 18 var currentIndex = orientations.indexOf(window.screen.orientation.type); | 18 var currentIndex = orientations.indexOf(window.screen.orientation.type); |
| 19 // Count the number of calls received from the EventHandler set on screen.orient
ation.onchange. | 19 // Count the number of calls received from the EventHandler set on screen.orient
ation.onchange. |
| 20 var orientationChangeEventHandlerCalls = 0; | 20 var orientationChangeEventHandlerCalls = 0; |
| 21 // Count the number of calls received from the listener set with screen.orientat
ion.addEventListene(). | 21 // Count the number of calls received from the listener set with screen.orientat
ion.addEventListene(). |
| 22 var orientationChangeEventListenerCalls = 0; | 22 var orientationChangeEventListenerCalls = 0; |
| 23 | 23 |
| 24 var orientationChangeContinuation = null; |
| 25 |
| 24 function getNextIndex() { | 26 function getNextIndex() { |
| 25 return (currentIndex + 1) % orientations.length; | 27 return (currentIndex + 1) % orientations.length; |
| 26 } | 28 } |
| 27 | 29 |
| 28 window.screen.orientation.onchange = function() { | 30 window.screen.orientation.onchange = function() { |
| 29 orientationChangeEventHandlerCalls++; | 31 orientationChangeEventHandlerCalls++; |
| 32 if (orientationChangeEventContinuation) { |
| 33 setTimeout(orientationChangeEventContinuation); |
| 34 orientationChangeEventContinuation = null; |
| 35 } |
| 30 }; | 36 }; |
| 31 | 37 |
| 32 window.screen.orientation.addEventListener('change', function() { | 38 window.screen.orientation.addEventListener('change', function() { |
| 33 orientationChangeEventListenerCalls++; | 39 orientationChangeEventListenerCalls++; |
| 34 }); | 40 }); |
| 35 | 41 |
| 36 function runNoChangeTest() { | 42 function runNoChangeTest() { |
| 37 window.testRunner.setMockScreenOrientation(orientations[currentIndex]); | 43 window.testRunner.setMockScreenOrientation(orientations[currentIndex]); |
| 38 | 44 |
| 39 setTimeout(function() { | 45 noChangeTest.step(function() { |
| 40 noChangeTest.step(function() { | 46 assert_equals(screen.orientation.type, orientations[currentIndex]); |
| 41 assert_equals(screen.orientation.type, orientations[currentIndex]); | 47 assert_equals(orientationChangeEventHandlerCalls, 4); |
| 42 assert_equals(orientationChangeEventHandlerCalls, 4); | 48 assert_equals(orientationChangeEventListenerCalls, 4); |
| 43 assert_equals(orientationChangeEventListenerCalls, 4); | 49 }); |
| 44 }); | |
| 45 | 50 |
| 46 noChangeTest.done(); | 51 noChangeTest.done(); |
| 47 }); | |
| 48 } | 52 } |
| 49 | 53 |
| 50 var i = 0; | 54 var i = 0; |
| 51 function runChangeTest() { | 55 function runChangeTest() { |
| 52 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]); | 56 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]); |
| 53 currentIndex = getNextIndex(); | 57 currentIndex = getNextIndex(); |
| 54 | 58 |
| 55 setTimeout(function() { | 59 orientationChangeEventContinuation = function() { |
| 56 changeTest.step(function() { | 60 changeTest.step(function() { |
| 57 assert_equals(screen.orientation.type, orientations[currentIndex]); | 61 assert_equals(screen.orientation.type, orientations[currentIndex]); |
| 58 assert_equals(orientationChangeEventHandlerCalls, i + 1); | 62 assert_equals(orientationChangeEventHandlerCalls, i + 1); |
| 59 assert_equals(orientationChangeEventListenerCalls, i + 1); | 63 assert_equals(orientationChangeEventListenerCalls, i + 1); |
| 60 }); | 64 }); |
| 61 | 65 |
| 62 ++i; | 66 ++i; |
| 63 if (i == 4) { | 67 if (i == 4) { |
| 64 changeTest.done(); | 68 changeTest.done(); |
| 65 runNoChangeTest(); | 69 runNoChangeTest(); |
| 66 } else { | 70 } else { |
| 67 runChangeTest(); | 71 runChangeTest(); |
| 68 } | 72 } |
| 69 }); | 73 }; |
| 70 } | 74 } |
| 71 | 75 |
| 72 runChangeTest(); | 76 runChangeTest(); |
| 73 | 77 |
| 74 </script> | 78 </script> |
| 75 </body> | 79 </body> |
| 76 </html> | 80 </html> |
| OLD | NEW |