4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
15 var currentIndex = orientations.indexOf(window.screen.orientation);
16 // Count the number of calls received from the EventHandler set on window.onorientationchange.
17 var orientationChangeEventHandlerCalls = 0;
18 // Count the number of calls received from the listener set with window.addEventListene().
19 var orientationChangeEventListenerCalls = 0;
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 something got fixed.");
28 function getNextIndex() {
29 return (currentIndex + 1) % orientations.length;
32 window.onorientationchange = function() {
33 orientationChangeEventHandlerCalls++;
36 window.addEventListener('orientationchange', function() {
37 orientationChangeEventListenerCalls++;
40 for (var i = 0; i < 4; ++i) {
42 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]);
44 currentIndex = getNextIndex();
45 assert_equals(screen.orientation, orientations[currentIndex]);
47 todo_equals(orientationChangeEventHandlerCalls, i + 1);
48 assert_equals(orientationChangeEventListenerCalls, i + 1);
49 }, "Test that orientationchange event is fired when the orientation changes");
53 window.testRunner.setMockScreenOrientation(orientations[currentIndex]);
54 assert_equals(screen.orientation, orientations[currentIndex]);
56 todo_equals(orientationChangeEventHandlerCalls, 4);
57 assert_equals(orientationChangeEventListenerCalls, 4);
58 }, "Test that orientationchange event is not fired when the orientation does not change");