4 <script src=
"../resources/testharness.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
8 var changeTest
= async_test("Test that window's orientationchange event is fired when the orientation changes.");
9 var noChangeTest
= async_test("Test that window's orientationchange event is not fired when the orientation does not change.");
11 if (window
.internals
&& internals
.runtimeFlags
.orientationEventEnabled
) {
19 var orientationAngles
= [
27 // Count the number of calls received from the EventHandler set on window.onorientationchange
28 var orientationChangeEventHandlerCalls
= 0;
29 // Count the number of calls received from the listener set with window.addEventListener("orientationchange",...)
30 var orientationChangeEventListenerCalls
= 0;
32 function getNextIndex() {
33 return (currentIndex
+ 1) % orientationAngles
.length
;
36 window
.onorientationchange = function(event
) {
37 orientationChangeEventHandlerCalls
++;
40 window
.addEventListener('orientationchange', function() {
41 orientationChangeEventListenerCalls
++;
44 function runNoChangeTest() {
45 window
.testRunner
.setMockScreenOrientation(orientations
[currentIndex
]);
47 setTimeout(function() {
48 noChangeTest
.step(function() {
49 assert_equals(window
.orientation
, orientationAngles
[currentIndex
]);
50 assert_equals(orientationChangeEventHandlerCalls
, 4);
51 assert_equals(orientationChangeEventListenerCalls
, 4);
59 function runChangeTest() {
60 window
.testRunner
.setMockScreenOrientation(orientations
[getNextIndex()]);
61 currentIndex
= getNextIndex();
63 setTimeout(function() {
64 changeTest
.step(function() {
65 assert_equals(window
.orientation
, orientationAngles
[currentIndex
]);
66 assert_equals(orientationChangeEventHandlerCalls
, i
+ 1);
67 assert_equals(orientationChangeEventListenerCalls
, i
+ 1);
82 console
.error("This test requires window.internals and the orientationchange event to be enabled.");