4 <script src=
"../resources/testharness.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
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 when the orientation does not change.");
18 var currentIndex
= orientations
.indexOf(window
.screen
.orientation
.type
);
19 // Count the number of calls received from the EventHandler set on screen.orientation.onchange.
20 var orientationChangeEventHandlerCalls
= 0;
21 // Count the number of calls received from the listener set with screen.orientation.addEventListene().
22 var orientationChangeEventListenerCalls
= 0;
24 var orientationChangeContinuation
= null;
26 function getNextIndex() {
27 return (currentIndex
+ 1) % orientations
.length
;
30 window
.screen
.orientation
.onchange = function() {
31 orientationChangeEventHandlerCalls
++;
32 if (orientationChangeEventContinuation
) {
33 setTimeout(orientationChangeEventContinuation
);
34 orientationChangeEventContinuation
= null;
38 window
.screen
.orientation
.addEventListener('change', function() {
39 orientationChangeEventListenerCalls
++;
42 function runNoChangeTest() {
43 window
.testRunner
.setMockScreenOrientation(orientations
[currentIndex
]);
45 noChangeTest
.step(function() {
46 assert_equals(screen
.orientation
.type
, orientations
[currentIndex
]);
47 assert_equals(orientationChangeEventHandlerCalls
, 4);
48 assert_equals(orientationChangeEventListenerCalls
, 4);
55 function runChangeTest() {
56 window
.testRunner
.setMockScreenOrientation(orientations
[getNextIndex()]);
57 currentIndex
= getNextIndex();
59 orientationChangeEventContinuation = function() {
60 changeTest
.step(function() {
61 assert_equals(screen
.orientation
.type
, orientations
[currentIndex
]);
62 assert_equals(orientationChangeEventHandlerCalls
, i
+ 1);
63 assert_equals(orientationChangeEventListenerCalls
, i
+ 1);