OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "apps/ui/native_app_window.h" | |
6 #include "chrome/browser/apps/app_browsertest_util.h" | |
7 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
8 #include "chrome/test/base/interactive_test_utils.h" | |
9 | |
10 using namespace apps; | |
11 | |
12 // Helper class that has to be created in the stack to check if the fullscreen | |
13 // setting of a NativeWindow has changed since the creation of the object. | |
14 class FullscreenChangeWaiter { | |
15 public: | |
16 explicit FullscreenChangeWaiter(NativeAppWindow* window) | |
17 : window_(window), | |
18 initial_fullscreen_state_(window_->IsFullscreen()) {} | |
19 | |
20 void Wait() { | |
21 while (initial_fullscreen_state_ != window_->IsFullscreen()) | |
22 content::RunAllPendingInMessageLoop(); | |
23 } | |
24 | |
25 private: | |
26 NativeAppWindow* window_; | |
27 bool initial_fullscreen_state_; | |
28 | |
29 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); | |
30 }; | |
31 | |
32 class AppInteractiveTest : public extensions::PlatformAppBrowserTest {}; | |
33 | |
34 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenWindow) { | |
35 ExtensionTestMessageListener launched_listener("Launched", true); | |
36 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
37 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
38 | |
39 // When receiving the reply, the application will try to go fullscreen using | |
40 // the Window API but there is no synchronous way to know if that actually | |
41 // succeeded. Also, failure will not be notified. A failure case will only be | |
42 // known with a timeout. | |
43 { | |
44 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
45 | |
46 launched_listener.Reply("window"); | |
47 | |
48 fs_changed.Wait(); | |
49 } | |
50 | |
51 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | |
52 // left when ESC is received. | |
53 { | |
54 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
55 | |
56 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
57 GetFirstShellWindow()->GetNativeWindow(), | |
58 ui::VKEY_ESCAPE, | |
59 false, | |
60 false, | |
61 false, | |
62 false)); | |
63 | |
64 fs_changed.Wait(); | |
65 } | |
66 } | |
67 | |
68 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenDOM) { | |
69 ExtensionTestMessageListener launched_listener("Launched", true); | |
70 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
71 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
72 | |
73 launched_listener.Reply("dom"); | |
74 | |
75 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
76 // key event to get the window entering in fullscreen mode. The reply will | |
77 // make the window listen for the key event. The reply will be sent to the | |
78 // renderer process before the keypress and should be received in that order. | |
79 // When receiving the key event, the application will try to go fullscreen | |
80 // using the Window API but there is no synchronous way to know if that | |
81 // actually succeeded. Also, failure will not be notified. A failure case will | |
82 // only be known with a timeout. | |
83 { | |
84 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
85 | |
86 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
87 GetFirstShellWindow()->GetNativeWindow(), | |
88 ui::VKEY_A, | |
89 false, | |
90 false, | |
91 false, | |
92 false)); | |
93 | |
94 fs_changed.Wait(); | |
95 } | |
96 | |
97 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | |
98 // left when ESC is received. | |
99 { | |
100 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
101 | |
102 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
103 GetFirstShellWindow()->GetNativeWindow(), | |
104 ui::VKEY_ESCAPE, | |
105 false, | |
106 false, | |
107 false, | |
108 false)); | |
109 | |
110 fs_changed.Wait(); | |
111 } | |
112 } | |
113 | |
114 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenWindow) { | |
115 ExtensionTestMessageListener launched_listener("Launched", true); | |
116 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
117 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
118 | |
119 // When receiving the reply, the application will try to go fullscreen using | |
120 // the Window API but there is no synchronous way to know if that actually | |
121 // succeeded. Also, failure will not be notified. A failure case will only be | |
122 // known with a timeout. | |
123 { | |
124 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
125 | |
126 launched_listener.Reply("window"); | |
127 | |
128 fs_changed.Wait(); | |
129 } | |
130 | |
131 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
132 GetFirstShellWindow()->GetNativeWindow(), | |
133 ui::VKEY_ESCAPE, | |
134 false, | |
135 false, | |
136 false, | |
137 false)); | |
138 | |
139 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
140 | |
141 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
142 GetFirstShellWindow()->GetNativeWindow(), | |
143 ui::VKEY_B, | |
144 false, | |
145 false, | |
146 false, | |
147 false)); | |
148 | |
149 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
150 | |
151 // We assume that at that point, if we had to leave fullscreen, we should be. | |
152 // However, by nature, we can not guarantee that and given that we do test | |
153 // that nothing happens, we might end up with random-success when the feature | |
154 // is broken. | |
155 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
156 } | |
157 | |
158 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenDOM) { | |
159 ExtensionTestMessageListener launched_listener("Launched", true); | |
160 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
161 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
162 | |
163 launched_listener.Reply("dom"); | |
164 | |
165 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
166 // key event to get the window entering in fullscreen mode. The reply will | |
167 // make the window listen for the key event. The reply will be sent to the | |
168 // renderer process before the keypress and should be received in that order. | |
169 // When receiving the key event, the application will try to go fullscreen | |
170 // using the Window API but there is no synchronous way to know if that | |
171 // actually succeeded. Also, failure will not be notified. A failure case will | |
172 // only be known with a timeout. | |
173 { | |
174 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
175 | |
176 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
koz (OOO until 15th September)
2013/11/22 00:33:11
nit: consider encapsulating this as well
Simulate
| |
177 GetFirstShellWindow()->GetNativeWindow(), | |
178 ui::VKEY_A, | |
179 false, | |
180 false, | |
181 false, | |
182 false)); | |
183 | |
184 fs_changed.Wait(); | |
185 } | |
186 | |
187 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
188 GetFirstShellWindow()->GetNativeWindow(), | |
189 ui::VKEY_ESCAPE, | |
190 false, | |
191 false, | |
192 false, | |
193 false)); | |
194 | |
195 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
196 | |
197 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
198 GetFirstShellWindow()->GetNativeWindow(), | |
199 ui::VKEY_B, | |
200 false, | |
201 false, | |
202 false, | |
203 false)); | |
204 | |
205 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
206 | |
207 // We assume that at that point, if we had to leave fullscreen, we should be. | |
208 // However, by nature, we can not guarantee that and given that we do test | |
209 // that nothing happens, we might end up with random-success when the feature | |
210 // is broken. | |
211 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
212 } | |
OLD | NEW |