Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/web-platform-tests/screen-orientation/onchange-event.html

Issue 1666363003: Import web-platform-tests@27e3d93f88a71a249d1df872a5d613b3243b9588 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed win failiure in TestExpectations Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../../resources/testharness.js"></script>
5 <script src="../../../resources/testharnessreport.js"></script>
6 <script>
7
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 wh en the orientation does not change.");
10
11 var orientations = [
12 'portrait-primary',
13 'portrait-secondary',
14 'landscape-primary',
15 'landscape-secondary'
16 ];
17
18 var currentIndex = orientations.indexOf(window.screen.orientation.type);
19 // Count the number of calls received from the EventHandler set on screen.orient ation.onchange.
20 var orientationChangeEventHandlerCalls = 0;
21 // Count the number of calls received from the listener set with screen.orientat ion.addEventListene().
22 var orientationChangeEventListenerCalls = 0;
23
24 var orientationChangeContinuation = null;
25
26 function getNextIndex() {
27 return (currentIndex + 1) % orientations.length;
28 }
29
30 window.screen.orientation.onchange = function() {
31 orientationChangeEventHandlerCalls++;
32 if (orientationChangeEventContinuation) {
33 setTimeout(orientationChangeEventContinuation);
34 orientationChangeEventContinuation = null;
35 }
36 };
37
38 window.screen.orientation.addEventListener('change', function() {
39 orientationChangeEventListenerCalls++;
40 });
41
42 function runNoChangeTest() {
43 screen.orientation.lock(orientations[currentIndex]).then(function() {}, functi on() {});
44
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 });
50
51 noChangeTest.done();
52 }
53
54 var i = 0;
55 function runChangeTest() {
56 screen.orientation.lock(orientations[getNextIndex()]).then(function() {}, func tion() {});
57 currentIndex = getNextIndex();
58
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 });
65
66 ++i;
67 if (i == orientations.length) {
68 changeTest.done();
69 runNoChangeTest();
70 } else {
71 runChangeTest();
72 }
73 };
74 }
75
76 runChangeTest();
77
78 </script>
79 </body>
80 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698