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

Side by Side Diff: LayoutTests/screen_orientation/page-visibility.html

Issue 1089523002: ScreenOrientationController: task-based dispatching of change events. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <body> 3 <body>
4 <script src="../resources/testharness.js"></script> 4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script> 5 <script src="../resources/testharnessreport.js"></script>
6 <iframe src='about:blank'></iframe> 6 <iframe src='about:blank'></iframe>
7 <script> 7 <script>
8 8
9 var eventVisibleTest = async_test("Test that a change event is fired when the pa ge is visible."); 9 var eventVisibleTest = async_test("Test that a change event is fired when the pa ge is visible.");
10 var noEventHiddenTest = async_test("Test that change event is not fired when the page is not visible."); 10 var noEventHiddenTest = async_test("Test that change event is not fired when the page is not visible.");
11 var orientationUnchangeHiddenTest = async_test("Test that screen.orientation kee ps returning the same orientation when the page is not visible."); 11 var orientationUnchangeHiddenTest = async_test("Test that screen.orientation kee ps returning the same orientation when the page is not visible.");
12 var orientationUpdateVisibleTest = async_test("Test that screen.orientation is u pdated once the page is visible again."); 12 var orientationUpdateVisibleTest = async_test("Test that screen.orientation is u pdated once the page is visible again.");
13 var frameEventsTest = async_test("Test that the iframe got as many events as the main frame."); 13 var frameEventsTest = async_test("Test that the iframe got as many events as the main frame.");
14 14
15 var orientationChangeContinuation = null;
15 var orientationChangeEventListenerCalls = 0; 16 var orientationChangeEventListenerCalls = 0;
16 var orientationChangeEventListenerCallsForFrame = 0; 17 var orientationChangeEventListenerCallsForFrame = 0;
17 18
18 screen.orientation.addEventListener('change', function() { 19 screen.orientation.addEventListener('change', function() {
19 orientationChangeEventListenerCalls++; 20 orientationChangeEventListenerCalls++;
21 if (orientationChangeEventContinuation) {
22 setTimeout(orientationChangeEventContinuation);
23 orientationChangeEventContinuation = null;
24 }
20 }); 25 });
21 26
22 window.frames[0].screen.orientation.addEventListener('change', function() { 27 window.frames[0].screen.orientation.addEventListener('change', function() {
23 orientationChangeEventListenerCallsForFrame++; 28 orientationChangeEventListenerCallsForFrame++;
24 }); 29 });
25 30
26 function runEventVisibleTest() { 31 function runEventVisibleTest() {
27 eventVisibleTest.step(function() { 32 eventVisibleTest.step(function() {
28 assert_false(document.hidden); 33 assert_false(document.hidden);
29 }); 34 });
30 35
31 if (window.testRunner) 36 if (window.testRunner)
32 window.testRunner.setMockScreenOrientation("landscape-primary"); 37 window.testRunner.setMockScreenOrientation("landscape-primary");
33 38
34 setTimeout(function() { 39 orientationChangeEventContinuation = function() {
35 eventVisibleTest.step(function() { 40 eventVisibleTest.step(function() {
36 assert_equals(orientationChangeEventListenerCalls, 1); 41 assert_equals(orientationChangeEventListenerCalls, 1);
37 assert_equals(screen.orientation.type, "landscape-primary"); 42 assert_equals(screen.orientation.type, "landscape-primary");
38 }); 43 });
39 eventVisibleTest.done(); 44 eventVisibleTest.done();
40 45
41 runNoEventHiddenTest(); 46 runNoEventHiddenTest();
42 }); 47 };
43 } 48 }
44 49
45 function runNoEventHiddenTest() { 50 function runNoEventHiddenTest() {
46 if (window.testRunner) 51 if (window.testRunner)
47 testRunner.setPageVisibility("hidden"); 52 testRunner.setPageVisibility("hidden");
48 53
49 noEventHiddenTest.step(function() { 54 noEventHiddenTest.step(function() {
50 assert_true(document.hidden); 55 assert_true(document.hidden);
51 }); 56 });
52 57
53 if (window.testRunner) 58 if (window.testRunner)
54 window.testRunner.setMockScreenOrientation("portrait-primary"); 59 window.testRunner.setMockScreenOrientation("portrait-primary");
55 60
56 setTimeout(function() { 61 noEventHiddenTest.step(function() {
57 noEventHiddenTest.step(function() { 62 assert_equals(orientationChangeEventListenerCalls, 1);
58 assert_equals(orientationChangeEventListenerCalls, 1); 63 });
59 }); 64 noEventHiddenTest.done();
60 noEventHiddenTest.done();
61 65
62 runOrientationUnchangeHiddenTest(); 66 runOrientationUnchangeHiddenTest();
63 });
64 } 67 }
65 68
66 function runOrientationUnchangeHiddenTest() { 69 function runOrientationUnchangeHiddenTest() {
67 orientationUnchangeHiddenTest.step(function() { 70 orientationUnchangeHiddenTest.step(function() {
68 assert_equals(screen.orientation.type, "landscape-primary"); 71 assert_equals(screen.orientation.type, "landscape-primary");
69 }); 72 });
70 orientationUnchangeHiddenTest.done(); 73 orientationUnchangeHiddenTest.done();
71 74
72 runOrientationUpdateVisibleTest(); 75 runOrientationUpdateVisibleTest();
73 } 76 }
74 77
75 function runOrientationUpdateVisibleTest() { 78 function runOrientationUpdateVisibleTest() {
76 if (window.testRunner) 79 if (window.testRunner)
77 testRunner.setPageVisibility("visible"); 80 testRunner.setPageVisibility("visible");
78 81
79 setTimeout(function() { 82 orientationChangeEventContinuation = function() {
80 orientationUpdateVisibleTest.step(function() { 83 orientationUpdateVisibleTest.step(function() {
81 assert_false(document.hidden); 84 assert_false(document.hidden);
82 // A change event should have been fired. 85 // A change event should have been fired.
83 assert_equals(orientationChangeEventListenerCalls, 2); 86 assert_equals(orientationChangeEventListenerCalls, 2);
84 // Should keep returning the start returning the orientation value. 87 // Should keep returning the start returning the orientation value.
85 assert_equals(screen.orientation.type, "portrait-primary"); 88 assert_equals(screen.orientation.type, "portrait-primary");
86 }); 89 });
87 90
88 orientationUpdateVisibleTest.done(); 91 orientationUpdateVisibleTest.done();
89 92
90 runFrameEventsTest(); 93 runFrameEventsTest();
91 }); 94 };
92 } 95 }
93 96
94 function runFrameEventsTest() { 97 function runFrameEventsTest() {
95 frameEventsTest.step(function() { 98 frameEventsTest.step(function() {
96 assert_equals(orientationChangeEventListenerCallsForFrame, orientationCh angeEventListenerCalls); 99 assert_equals(orientationChangeEventListenerCallsForFrame, orientationCh angeEventListenerCalls);
97 }); 100 });
98 frameEventsTest.done(); 101 frameEventsTest.done();
99 } 102 }
100 103
101 runEventVisibleTest(); 104 runEventVisibleTest();
102 105
103 </script> 106 </script>
104 </body> 107 </body>
105 </html> 108 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698