4 <script src=
"../resources/testharness.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
7 <iframe id=
"testIframe" sandbox=
"allow-scripts allow-same-origin" style=
"display:none">
11 var test
= async_test("Test subframes receive window orientationchange events (includes window.onorientationchange and an event listener for orientationchange)");
13 if (window
.internals
&& internals
.runtimeFlags
.orientationEventEnabled
) {
21 var orientationAngles
= [
29 var eventsReceived
= 0;
30 var numOrientationChanges
= 0;
32 function getNextIndex() {
33 return (currentIndex
+ 1) % orientations
.length
;
36 function changeOrientation() {
37 window
.testRunner
.setMockScreenOrientation(orientations
[getNextIndex()]);
38 currentIndex
= getNextIndex();
39 ++numOrientationChanges
;
42 window
.onmessage
= test
.step_func(function (ev
) {
43 assert_equals(ev
.data
, orientationAngles
[currentIndex
], "subframe received orientationchange event (window.screen.orientation.type=" + window
.screen
.orientation
.type
+ ")");
46 // Once *both* of the event handlers/listeners have seen this event,
47 // change the orientation or end the test.
48 if ((eventsReceived
% 2) == 0) {
49 assert_equals(eventsReceived
, numOrientationChanges
*2);
51 if (numOrientationChanges
< 4) {
53 } else if (numOrientationChanges
== 4) {
59 var testIframe
= document
.getElementById("testIframe");
60 testIframe
.src
= "resources/iframe-listen-window-orientationchange.html";
61 testIframe
.onload
= changeOrientation
;
63 console
.error("This test requires window.internals and the orientationchange event to be enabled.");