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

Side by Side Diff: LayoutTests/screen_orientation/orientationchange-event.html

Issue 241203003: Screen Orientation: fire event on Window instead of Screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@ScreenOrientationUndefined
Patch Set: fix tests Created 6 years, 8 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 orientations = [
9 'portrait-primary',
10 'portrait-secondary',
11 'landscape-primary',
12 'landscape-secondary'
13 ];
14
15 var currentIndex = orientations.indexOf(window.screen.orientation);
16 // Count the number of calls received from the EventHandler set on window.onorie ntationchange.
17 var orientationChangeEventHandlerCalls = 0;
18 // Count the number of calls received from the listener set with window.addEvent Listene().
19 var orientationChangeEventListenerCalls = 0;
20
21 // TODO: window.onorientationchange is enabled on Android only. We will enable
22 // it with ScreenOrientation later, at which point this test will fail. We will
23 // then have to fix it.
24 function todo_equals(actual, expected) {
25 assert_not_equals(actual, expected, "TODO: if this fails, it means that someth ing got fixed.");
26 }
27
28 function getNextIndex() {
29 return (currentIndex + 1) % orientations.length;
30 }
31
32 window.onorientationchange = function() {
33 orientationChangeEventHandlerCalls++;
34 };
35
36 window.addEventListener('orientationchange', function() {
37 orientationChangeEventListenerCalls++;
38 });
39
40 for (var i = 0; i < 4; ++i) {
41 test(function() {
42 window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]);
43
44 currentIndex = getNextIndex();
45 assert_equals(screen.orientation, orientations[currentIndex]);
46
47 todo_equals(orientationChangeEventHandlerCalls, i + 1);
48 assert_equals(orientationChangeEventListenerCalls, i + 1);
49 }, "Test that orientationchange event is fired when the orientation changes");
50 }
51
52 test(function() {
53 window.testRunner.setMockScreenOrientation(orientations[currentIndex]);
54 assert_equals(screen.orientation, orientations[currentIndex]);
55
56 todo_equals(orientationChangeEventHandlerCalls, 4);
57 assert_equals(orientationChangeEventListenerCalls, 4);
58 }, "Test that orientationchange event is not fired when the orientation does not change");
59
60 </script>
61 </body>
62 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698