Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / imported / web-platform-tests / screen-orientation / onchange-event.html
blob0843d552848718dcf36fa280f12b53e7af14ed3b
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../../resources/testharness.js"></script>
5 <script src="../../../resources/testharnessreport.js"></script>
6 <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.");
11 var orientations = [
12 'portrait-primary',
13 'portrait-secondary',
14 'landscape-primary',
15 'landscape-secondary'
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++;
40 });
42 function runNoChangeTest() {
43 screen.orientation.lock(orientations[currentIndex]).then(function() {}, function() {});
45 noChangeTest.step(function() {
46 assert_equals(screen.orientation.type, orientations[currentIndex]);
47 assert_equals(orientationChangeEventHandlerCalls, orientations.length);
48 assert_equals(orientationChangeEventListenerCalls, orientations.length);
49 });
51 noChangeTest.done();
54 var i = 0;
55 function runChangeTest() {
56 screen.orientation.lock(orientations[getNextIndex()]).then(function() {}, function() {});
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);
64 });
66 ++i;
67 if (i == orientations.length) {
68 changeTest.done();
69 runNoChangeTest();
70 } else {
71 runChangeTest();
76 runChangeTest();
78 </script>
79 </body>
80 </html>