OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/ui/native_app_window.h" | 5 #include "apps/ui/native_app_window.h" |
6 #include "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
7 #include "chrome/browser/extensions/extension_test_message_listener.h" | 7 #include "chrome/browser/extensions/extension_test_message_listener.h" |
8 #include "chrome/test/base/interactive_test_utils.h" | 8 #include "chrome/test/base/interactive_test_utils.h" |
9 | 9 |
10 #if defined(OS_MACOSX) && !defined(OS_IOS) | 10 #if defined(OS_MACOSX) && !defined(OS_IOS) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 if (!catcher.GetNextResult()) { | 49 if (!catcher.GetNextResult()) { |
50 message_ = catcher.message(); | 50 message_ = catcher.message(); |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 bool SimulateKeyPress(ui::KeyboardCode key) { | 57 bool SimulateKeyPress(ui::KeyboardCode key) { |
58 return ui_test_utils::SendKeyPressToWindowSync( | 58 return ui_test_utils::SendKeyPressToWindowSync( |
59 GetFirstShellWindow()->GetNativeWindow(), | 59 GetFirstAppWindow()->GetNativeWindow(), |
60 key, | 60 key, |
61 false, | 61 false, |
62 false, | 62 false, |
63 false, | 63 false, |
64 false); | 64 false); |
65 } | 65 } |
66 | 66 |
67 // This method will wait until the application is able to ack a key event. | 67 // This method will wait until the application is able to ack a key event. |
68 void WaitUntilKeyFocus() { | 68 void WaitUntilKeyFocus() { |
69 ExtensionTestMessageListener key_listener("KeyReceived", false); | 69 ExtensionTestMessageListener key_listener("KeyReceived", false); |
70 | 70 |
71 while (!key_listener.was_satisfied()) { | 71 while (!key_listener.was_satisfied()) { |
72 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); | 72 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); |
73 content::RunAllPendingInMessageLoop(); | 73 content::RunAllPendingInMessageLoop(); |
74 } | 74 } |
75 } | 75 } |
76 }; | 76 }; |
77 | 77 |
78 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) { | 78 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) { |
79 // This test is flaky on MacOS 10.6. | 79 // This test is flaky on MacOS 10.6. |
80 #if defined(OS_MACOSX) && !defined(OS_IOS) | 80 #if defined(OS_MACOSX) && !defined(OS_IOS) |
81 if (base::mac::IsOSSnowLeopard()) | 81 if (base::mac::IsOSSnowLeopard()) |
82 return; | 82 return; |
83 #endif | 83 #endif |
84 | 84 |
85 ExtensionTestMessageListener launched_listener("Launched", true); | 85 ExtensionTestMessageListener launched_listener("Launched", true); |
86 LoadAndLaunchPlatformApp("leave_fullscreen"); | 86 LoadAndLaunchPlatformApp("leave_fullscreen"); |
87 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 87 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
88 | 88 |
89 // We start by making sure the window is actually focused. | 89 // We start by making sure the window is actually focused. |
90 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 90 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
91 GetFirstShellWindow()->GetNativeWindow())); | 91 GetFirstAppWindow()->GetNativeWindow())); |
92 | 92 |
93 // When receiving the reply, the application will try to go fullscreen using | 93 // When receiving the reply, the application will try to go fullscreen using |
94 // the Window API but there is no synchronous way to know if that actually | 94 // the Window API but there is no synchronous way to know if that actually |
95 // succeeded. Also, failure will not be notified. A failure case will only be | 95 // succeeded. Also, failure will not be notified. A failure case will only be |
96 // known with a timeout. | 96 // known with a timeout. |
97 { | 97 { |
98 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 98 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
99 | 99 |
100 launched_listener.Reply("window"); | 100 launched_listener.Reply("window"); |
101 | 101 |
102 fs_changed.Wait(); | 102 fs_changed.Wait(); |
103 } | 103 } |
104 | 104 |
105 // Depending on the platform, going fullscreen might create an animation. | 105 // Depending on the platform, going fullscreen might create an animation. |
106 // We want to make sure that the ESC key we will send next is actually going | 106 // We want to make sure that the ESC key we will send next is actually going |
107 // to be received and the application might not receive key events during the | 107 // to be received and the application might not receive key events during the |
108 // animation so we should wait for the key focus to be back. | 108 // animation so we should wait for the key focus to be back. |
109 WaitUntilKeyFocus(); | 109 WaitUntilKeyFocus(); |
110 | 110 |
111 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | 111 // Same idea as above but for leaving fullscreen. Fullscreen mode should be |
112 // left when ESC is received. | 112 // left when ESC is received. |
113 { | 113 { |
114 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 114 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
115 | 115 |
116 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 116 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
117 | 117 |
118 fs_changed.Wait(); | 118 fs_changed.Wait(); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) { | 122 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) { |
123 // This test is flaky on MacOS 10.6. | 123 // This test is flaky on MacOS 10.6. |
124 #if defined(OS_MACOSX) && !defined(OS_IOS) | 124 #if defined(OS_MACOSX) && !defined(OS_IOS) |
125 if (base::mac::IsOSSnowLeopard()) | 125 if (base::mac::IsOSSnowLeopard()) |
126 return; | 126 return; |
127 #endif | 127 #endif |
128 | 128 |
129 ExtensionTestMessageListener launched_listener("Launched", true); | 129 ExtensionTestMessageListener launched_listener("Launched", true); |
130 LoadAndLaunchPlatformApp("leave_fullscreen"); | 130 LoadAndLaunchPlatformApp("leave_fullscreen"); |
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
132 | 132 |
133 // We start by making sure the window is actually focused. | 133 // We start by making sure the window is actually focused. |
134 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 134 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
135 GetFirstShellWindow()->GetNativeWindow())); | 135 GetFirstAppWindow()->GetNativeWindow())); |
136 | 136 |
137 launched_listener.Reply("dom"); | 137 launched_listener.Reply("dom"); |
138 | 138 |
139 // Because the DOM way to go fullscreen requires user gesture, we simulate a | 139 // Because the DOM way to go fullscreen requires user gesture, we simulate a |
140 // key event to get the window entering in fullscreen mode. The reply will | 140 // key event to get the window entering in fullscreen mode. The reply will |
141 // make the window listen for the key event. The reply will be sent to the | 141 // make the window listen for the key event. The reply will be sent to the |
142 // renderer process before the keypress and should be received in that order. | 142 // renderer process before the keypress and should be received in that order. |
143 // When receiving the key event, the application will try to go fullscreen | 143 // When receiving the key event, the application will try to go fullscreen |
144 // using the Window API but there is no synchronous way to know if that | 144 // using the Window API but there is no synchronous way to know if that |
145 // actually succeeded. Also, failure will not be notified. A failure case will | 145 // actually succeeded. Also, failure will not be notified. A failure case will |
146 // only be known with a timeout. | 146 // only be known with a timeout. |
147 { | 147 { |
148 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 148 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
149 | 149 |
150 WaitUntilKeyFocus(); | 150 WaitUntilKeyFocus(); |
151 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 151 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
152 | 152 |
153 fs_changed.Wait(); | 153 fs_changed.Wait(); |
154 } | 154 } |
155 | 155 |
156 // Depending on the platform, going fullscreen might create an animation. | 156 // Depending on the platform, going fullscreen might create an animation. |
157 // We want to make sure that the ESC key we will send next is actually going | 157 // We want to make sure that the ESC key we will send next is actually going |
158 // to be received and the application might not receive key events during the | 158 // to be received and the application might not receive key events during the |
159 // animation so we should wait for the key focus to be back. | 159 // animation so we should wait for the key focus to be back. |
160 WaitUntilKeyFocus(); | 160 WaitUntilKeyFocus(); |
161 | 161 |
162 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | 162 // Same idea as above but for leaving fullscreen. Fullscreen mode should be |
163 // left when ESC is received. | 163 // left when ESC is received. |
164 { | 164 { |
165 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 165 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
166 | 166 |
167 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 167 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
168 | 168 |
169 fs_changed.Wait(); | 169 fs_changed.Wait(); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 173 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
174 ESCDoesNotLeaveFullscreenWindow) { | 174 ESCDoesNotLeaveFullscreenWindow) { |
175 // This test is flaky on MacOS 10.6. | 175 // This test is flaky on MacOS 10.6. |
176 #if defined(OS_MACOSX) && !defined(OS_IOS) | 176 #if defined(OS_MACOSX) && !defined(OS_IOS) |
177 if (base::mac::IsOSSnowLeopard()) | 177 if (base::mac::IsOSSnowLeopard()) |
178 return; | 178 return; |
179 #endif | 179 #endif |
180 | 180 |
181 ExtensionTestMessageListener launched_listener("Launched", true); | 181 ExtensionTestMessageListener launched_listener("Launched", true); |
182 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 182 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
183 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 183 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
184 | 184 |
185 // We start by making sure the window is actually focused. | 185 // We start by making sure the window is actually focused. |
186 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 186 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
187 GetFirstShellWindow()->GetNativeWindow())); | 187 GetFirstAppWindow()->GetNativeWindow())); |
188 | 188 |
189 // When receiving the reply, the application will try to go fullscreen using | 189 // When receiving the reply, the application will try to go fullscreen using |
190 // the Window API but there is no synchronous way to know if that actually | 190 // the Window API but there is no synchronous way to know if that actually |
191 // succeeded. Also, failure will not be notified. A failure case will only be | 191 // succeeded. Also, failure will not be notified. A failure case will only be |
192 // known with a timeout. | 192 // known with a timeout. |
193 { | 193 { |
194 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 194 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
195 | 195 |
196 launched_listener.Reply("window"); | 196 launched_listener.Reply("window"); |
197 | 197 |
198 fs_changed.Wait(); | 198 fs_changed.Wait(); |
199 } | 199 } |
200 | 200 |
201 // Depending on the platform, going fullscreen might create an animation. | 201 // Depending on the platform, going fullscreen might create an animation. |
202 // We want to make sure that the ESC key we will send next is actually going | 202 // We want to make sure that the ESC key we will send next is actually going |
203 // to be received and the application might not receive key events during the | 203 // to be received and the application might not receive key events during the |
204 // animation so we should wait for the key focus to be back. | 204 // animation so we should wait for the key focus to be back. |
205 WaitUntilKeyFocus(); | 205 WaitUntilKeyFocus(); |
206 | 206 |
207 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 207 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
208 | 208 |
209 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 209 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
210 | 210 |
211 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 211 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
212 | 212 |
213 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 213 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
214 | 214 |
215 // We assume that at that point, if we had to leave fullscreen, we should be. | 215 // We assume that at that point, if we had to leave fullscreen, we should be. |
216 // However, by nature, we can not guarantee that and given that we do test | 216 // However, by nature, we can not guarantee that and given that we do test |
217 // that nothing happens, we might end up with random-success when the feature | 217 // that nothing happens, we might end up with random-success when the feature |
218 // is broken. | 218 // is broken. |
219 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | 219 EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); |
220 } | 220 } |
221 | 221 |
222 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 222 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
223 ESCDoesNotLeaveFullscreenDOM) { | 223 ESCDoesNotLeaveFullscreenDOM) { |
224 // This test is flaky on MacOS 10.6. | 224 // This test is flaky on MacOS 10.6. |
225 #if defined(OS_MACOSX) && !defined(OS_IOS) | 225 #if defined(OS_MACOSX) && !defined(OS_IOS) |
226 if (base::mac::IsOSSnowLeopard()) | 226 if (base::mac::IsOSSnowLeopard()) |
227 return; | 227 return; |
228 #endif | 228 #endif |
229 | 229 |
230 ExtensionTestMessageListener launched_listener("Launched", true); | 230 ExtensionTestMessageListener launched_listener("Launched", true); |
231 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 231 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
232 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 232 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
233 | 233 |
234 // We start by making sure the window is actually focused. | 234 // We start by making sure the window is actually focused. |
235 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | 235 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
236 GetFirstShellWindow()->GetNativeWindow())); | 236 GetFirstAppWindow()->GetNativeWindow())); |
237 | 237 |
238 launched_listener.Reply("dom"); | 238 launched_listener.Reply("dom"); |
239 | 239 |
240 // Because the DOM way to go fullscreen requires user gesture, we simulate a | 240 // Because the DOM way to go fullscreen requires user gesture, we simulate a |
241 // key event to get the window entering in fullscreen mode. The reply will | 241 // key event to get the window entering in fullscreen mode. The reply will |
242 // make the window listen for the key event. The reply will be sent to the | 242 // make the window listen for the key event. The reply will be sent to the |
243 // renderer process before the keypress and should be received in that order. | 243 // renderer process before the keypress and should be received in that order. |
244 // When receiving the key event, the application will try to go fullscreen | 244 // When receiving the key event, the application will try to go fullscreen |
245 // using the Window API but there is no synchronous way to know if that | 245 // using the Window API but there is no synchronous way to know if that |
246 // actually succeeded. Also, failure will not be notified. A failure case will | 246 // actually succeeded. Also, failure will not be notified. A failure case will |
247 // only be known with a timeout. | 247 // only be known with a timeout. |
248 { | 248 { |
249 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 249 FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); |
250 | 250 |
251 WaitUntilKeyFocus(); | 251 WaitUntilKeyFocus(); |
252 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 252 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
253 | 253 |
254 fs_changed.Wait(); | 254 fs_changed.Wait(); |
255 } | 255 } |
256 | 256 |
257 // Depending on the platform, going fullscreen might create an animation. | 257 // Depending on the platform, going fullscreen might create an animation. |
258 // We want to make sure that the ESC key we will send next is actually going | 258 // We want to make sure that the ESC key we will send next is actually going |
259 // to be received and the application might not receive key events during the | 259 // to be received and the application might not receive key events during the |
260 // animation so we should wait for the key focus to be back. | 260 // animation so we should wait for the key focus to be back. |
261 WaitUntilKeyFocus(); | 261 WaitUntilKeyFocus(); |
262 | 262 |
263 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 263 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
264 | 264 |
265 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 265 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
266 | 266 |
267 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 267 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
268 | 268 |
269 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 269 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
270 | 270 |
271 // We assume that at that point, if we had to leave fullscreen, we should be. | 271 // We assume that at that point, if we had to leave fullscreen, we should be. |
272 // However, by nature, we can not guarantee that and given that we do test | 272 // However, by nature, we can not guarantee that and given that we do test |
273 // that nothing happens, we might end up with random-success when the feature | 273 // that nothing happens, we might end up with random-success when the feature |
274 // is broken. | 274 // is broken. |
275 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | 275 EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); |
276 } | 276 } |
277 | 277 |
278 // This test does not work on Linux Aura because ShowInactive() is not | 278 // This test does not work on Linux Aura because ShowInactive() is not |
279 // implemented. See http://crbug.com/325142 | 279 // implemented. See http://crbug.com/325142 |
280 // It also does not work on Windows because of the document being focused even | 280 // It also does not work on Windows because of the document being focused even |
281 // though the window is not activated. See http://crbug.com/326986 | 281 // though the window is not activated. See http://crbug.com/326986 |
282 // It also does not work on MacOS because ::ShowInactive() ends up behaving like | 282 // It also does not work on MacOS because ::ShowInactive() ends up behaving like |
283 // ::Show() because of Cocoa conventions. See http://crbug.com/326987 | 283 // ::Show() because of Cocoa conventions. See http://crbug.com/326987 |
284 // Those tests should be disabled on Linux GTK when they are enabled on the | 284 // Those tests should be disabled on Linux GTK when they are enabled on the |
285 // other platforms, see http://crbug.com/328829 | 285 // other platforms, see http://crbug.com/328829 |
286 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ | 286 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ |
287 defined(OS_WIN) || defined(OS_MACOSX) | 287 defined(OS_WIN) || defined(OS_MACOSX) |
288 #define MAYBE_TestCreate DISABLED_TestCreate | 288 #define MAYBE_TestCreate DISABLED_TestCreate |
289 #define MAYBE_TestShow DISABLED_TestShow | 289 #define MAYBE_TestShow DISABLED_TestShow |
290 #else | 290 #else |
291 #define MAYBE_TestCreate TestCreate | 291 #define MAYBE_TestCreate TestCreate |
292 #define MAYBE_TestShow TestShow | 292 #define MAYBE_TestShow TestShow |
293 #endif | 293 #endif |
294 | 294 |
295 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { | 295 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { |
296 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; | 296 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; |
297 } | 297 } |
298 | 298 |
299 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { | 299 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { |
300 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; | 300 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; |
301 } | 301 } |
OLD | NEW |