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 using namespace apps; | 10 using apps::NativeAppWindow; |
11 | 11 |
12 // Helper class that has to be created in the stack to check if the fullscreen | 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. | 13 // setting of a NativeWindow has changed since the creation of the object. |
14 class FullscreenChangeWaiter { | 14 class FullscreenChangeWaiter { |
15 public: | 15 public: |
16 explicit FullscreenChangeWaiter(NativeAppWindow* window) | 16 explicit FullscreenChangeWaiter(NativeAppWindow* window) |
17 : window_(window), | 17 : window_(window), |
18 initial_fullscreen_state_(window_->IsFullscreen()) {} | 18 initial_fullscreen_state_(window_->IsFullscreen()) {} |
19 | 19 |
20 void Wait() { | 20 void Wait() { |
21 while (initial_fullscreen_state_ != window_->IsFullscreen()) | 21 while (initial_fullscreen_state_ == window_->IsFullscreen()) |
22 content::RunAllPendingInMessageLoop(); | 22 content::RunAllPendingInMessageLoop(); |
23 } | 23 } |
24 | 24 |
25 private: | 25 private: |
26 NativeAppWindow* window_; | 26 NativeAppWindow* window_; |
27 bool initial_fullscreen_state_; | 27 bool initial_fullscreen_state_; |
28 | 28 |
29 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); | 29 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); |
30 }; | 30 }; |
31 | 31 |
(...skipping 20 matching lines...) Expand all Loading... | |
52 | 52 |
53 bool SimulateKeyPress(ui::KeyboardCode key) { | 53 bool SimulateKeyPress(ui::KeyboardCode key) { |
54 return ui_test_utils::SendKeyPressToWindowSync( | 54 return ui_test_utils::SendKeyPressToWindowSync( |
55 GetFirstShellWindow()->GetNativeWindow(), | 55 GetFirstShellWindow()->GetNativeWindow(), |
56 key, | 56 key, |
57 false, | 57 false, |
58 false, | 58 false, |
59 false, | 59 false, |
60 false); | 60 false); |
61 } | 61 } |
62 | |
63 // This method will wait until the application is able to ack a key event. | |
64 void WaitUntilKeyFocus() { | |
65 ExtensionTestMessageListener key_listener("KEY_RECEIVED", false); | |
66 | |
67 while (!key_listener.was_satisfied()) { | |
68 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); | |
69 content::RunAllPendingInMessageLoop(); | |
70 } | |
71 } | |
62 }; | 72 }; |
63 | 73 |
64 #if defined(OS_LINUX) && defined(USE_AURA) | 74 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) { |
65 // These tests do not work on Linux Aura because when the window is raised, the | |
66 // content is not focused thus do not get the key events. | |
67 // See http://crbug.com/324346 | |
68 #define MAYBE_ESCDoesNotLeaveFullscreenWindow \ | |
69 DISABLED_ESCDoesNotLeaveFullscreenWindow | |
70 #define MAYBE_ESCDoesNotLeaveFullscreenDOM DISABLED_ESCDoesNotLeaveFullscreenDOM | |
71 // These tests are failing on Linux Aura for unknown reasons. | |
72 #define MAYBE_ESCLeavesFullscreenWindow DISABLED_ESCLeavesFullscreenWindow | |
73 #define MAYBE_ESCLeavesFullscreenDOM DISABLED_ESCLeavesFullscreenDOM | |
74 #elif defined(OS_MACOSX) | |
75 // These tests are highly flaky on MacOS. | |
76 #define MAYBE_ESCLeavesFullscreenWindow DISABLED_ESCLeavesFullscreenWindow | |
77 #define MAYBE_ESCLeavesFullscreenDOM DISABLED_ESCLeavesFullscreenDOM | |
78 #define MAYBE_ESCDoesNotLeaveFullscreenWindow \ | |
79 DISABLED_ESCDoesNotLeaveFullscreenWindow | |
80 #define MAYBE_ESCDoesNotLeaveFullscreenDOM DISABLED_ESCDoesNotLeaveFullscreenDOM | |
81 #else | |
82 #define MAYBE_ESCLeavesFullscreenWindow ESCLeavesFullscreenWindow | |
83 #define MAYBE_ESCLeavesFullscreenDOM ESCLeavesFullscreenDOM | |
84 #define MAYBE_ESCDoesNotLeaveFullscreenWindow ESCDoesNotLeaveFullscreenWindow | |
85 #define MAYBE_ESCDoesNotLeaveFullscreenDOM ESCDoesNotLeaveFullscreenDOM | |
86 #endif | |
87 | |
88 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | |
89 MAYBE_ESCLeavesFullscreenWindow) { | |
90 ExtensionTestMessageListener launched_listener("Launched", true); | 75 ExtensionTestMessageListener launched_listener("Launched", true); |
91 LoadAndLaunchPlatformApp("leave_fullscreen"); | 76 LoadAndLaunchPlatformApp("leave_fullscreen"); |
92 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 77 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
93 | 78 |
79 // We start by making sure the window is actually focused. | |
80 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | |
81 GetFirstShellWindow()->GetNativeWindow())); | |
koz (OOO until 15th September)
2014/01/08 23:29:25
nit: I think the second line should be indented 4
mlamouri (slow - plz ping)
2014/01/09 17:08:46
Done.
| |
82 | |
94 // When receiving the reply, the application will try to go fullscreen using | 83 // When receiving the reply, the application will try to go fullscreen using |
95 // the Window API but there is no synchronous way to know if that actually | 84 // the Window API but there is no synchronous way to know if that actually |
96 // succeeded. Also, failure will not be notified. A failure case will only be | 85 // succeeded. Also, failure will not be notified. A failure case will only be |
97 // known with a timeout. | 86 // known with a timeout. |
98 { | 87 { |
99 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 88 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
100 | 89 |
101 launched_listener.Reply("window"); | 90 launched_listener.Reply("window"); |
102 | 91 |
103 fs_changed.Wait(); | 92 fs_changed.Wait(); |
104 } | 93 } |
105 | 94 |
95 // Depending on the platform, going fullscreen might create an animation. | |
96 // We want to make sure that the ESC key we will send next is actually going | |
97 // to be received and the application might not receive key events during the | |
98 // animation so we should wait for the key focus to be back. | |
99 WaitUntilKeyFocus(); | |
100 | |
106 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | 101 // Same idea as above but for leaving fullscreen. Fullscreen mode should be |
107 // left when ESC is received. | 102 // left when ESC is received. |
108 { | 103 { |
109 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 104 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
110 | 105 |
111 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 106 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
112 | 107 |
113 fs_changed.Wait(); | 108 fs_changed.Wait(); |
114 } | 109 } |
115 } | 110 } |
116 | 111 |
117 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_ESCLeavesFullscreenDOM) { | 112 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) { |
118 ExtensionTestMessageListener launched_listener("Launched", true); | 113 ExtensionTestMessageListener launched_listener("Launched", true); |
119 LoadAndLaunchPlatformApp("leave_fullscreen"); | 114 LoadAndLaunchPlatformApp("leave_fullscreen"); |
120 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 115 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
121 | 116 |
117 // We start by making sure the window is actually focused. | |
118 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | |
119 GetFirstShellWindow()->GetNativeWindow())); | |
120 | |
122 launched_listener.Reply("dom"); | 121 launched_listener.Reply("dom"); |
123 | 122 |
124 // Because the DOM way to go fullscreen requires user gesture, we simulate a | 123 // Because the DOM way to go fullscreen requires user gesture, we simulate a |
125 // key event to get the window entering in fullscreen mode. The reply will | 124 // key event to get the window entering in fullscreen mode. The reply will |
126 // make the window listen for the key event. The reply will be sent to the | 125 // make the window listen for the key event. The reply will be sent to the |
127 // renderer process before the keypress and should be received in that order. | 126 // renderer process before the keypress and should be received in that order. |
128 // When receiving the key event, the application will try to go fullscreen | 127 // When receiving the key event, the application will try to go fullscreen |
129 // using the Window API but there is no synchronous way to know if that | 128 // using the Window API but there is no synchronous way to know if that |
130 // actually succeeded. Also, failure will not be notified. A failure case will | 129 // actually succeeded. Also, failure will not be notified. A failure case will |
131 // only be known with a timeout. | 130 // only be known with a timeout. |
132 { | 131 { |
133 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 132 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
134 | 133 |
135 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 134 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
136 | 135 |
137 fs_changed.Wait(); | 136 fs_changed.Wait(); |
138 } | 137 } |
139 | 138 |
139 // Depending on the platform, going fullscreen might create an animation. | |
140 // We want to make sure that the ESC key we will send next is actually going | |
141 // to be received and the application might not receive key events during the | |
142 // animation so we should wait for the key focus to be back. | |
143 WaitUntilKeyFocus(); | |
144 | |
140 // Same idea as above but for leaving fullscreen. Fullscreen mode should be | 145 // Same idea as above but for leaving fullscreen. Fullscreen mode should be |
141 // left when ESC is received. | 146 // left when ESC is received. |
142 { | 147 { |
143 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 148 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
144 | 149 |
145 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 150 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
146 | 151 |
147 fs_changed.Wait(); | 152 fs_changed.Wait(); |
148 } | 153 } |
149 } | 154 } |
150 | 155 |
151 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 156 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
152 MAYBE_ESCDoesNotLeaveFullscreenWindow) { | 157 ESCDoesNotLeaveFullscreenWindow) { |
153 ExtensionTestMessageListener launched_listener("Launched", true); | 158 ExtensionTestMessageListener launched_listener("Launched", true); |
154 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 159 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
155 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 160 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
156 | 161 |
162 // We start by making sure the window is actually focused. | |
163 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | |
164 GetFirstShellWindow()->GetNativeWindow())); | |
165 | |
157 // When receiving the reply, the application will try to go fullscreen using | 166 // When receiving the reply, the application will try to go fullscreen using |
158 // the Window API but there is no synchronous way to know if that actually | 167 // the Window API but there is no synchronous way to know if that actually |
159 // succeeded. Also, failure will not be notified. A failure case will only be | 168 // succeeded. Also, failure will not be notified. A failure case will only be |
160 // known with a timeout. | 169 // known with a timeout. |
161 { | 170 { |
162 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 171 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
163 | 172 |
164 launched_listener.Reply("window"); | 173 launched_listener.Reply("window"); |
165 | 174 |
166 fs_changed.Wait(); | 175 fs_changed.Wait(); |
167 } | 176 } |
168 | 177 |
178 // Depending on the platform, going fullscreen might create an animation. | |
179 // We want to make sure that the ESC key we will send next is actually going | |
180 // to be received and the application might not receive key events during the | |
181 // animation so we should wait for the key focus to be back. | |
182 WaitUntilKeyFocus(); | |
183 | |
169 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 184 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
170 | 185 |
171 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 186 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
172 | 187 |
173 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 188 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
174 | 189 |
175 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 190 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
176 | 191 |
177 // We assume that at that point, if we had to leave fullscreen, we should be. | 192 // We assume that at that point, if we had to leave fullscreen, we should be. |
178 // However, by nature, we can not guarantee that and given that we do test | 193 // However, by nature, we can not guarantee that and given that we do test |
179 // that nothing happens, we might end up with random-success when the feature | 194 // that nothing happens, we might end up with random-success when the feature |
180 // is broken. | 195 // is broken. |
181 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | 196 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); |
182 } | 197 } |
183 | 198 |
184 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 199 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
185 MAYBE_ESCDoesNotLeaveFullscreenDOM) { | 200 ESCDoesNotLeaveFullscreenDOM) { |
186 ExtensionTestMessageListener launched_listener("Launched", true); | 201 ExtensionTestMessageListener launched_listener("Launched", true); |
187 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 202 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
188 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 203 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
189 | 204 |
205 // We start by making sure the window is actually focused. | |
206 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( | |
207 GetFirstShellWindow()->GetNativeWindow())); | |
208 | |
190 launched_listener.Reply("dom"); | 209 launched_listener.Reply("dom"); |
191 | 210 |
192 // Because the DOM way to go fullscreen requires user gesture, we simulate a | 211 // Because the DOM way to go fullscreen requires user gesture, we simulate a |
193 // key event to get the window entering in fullscreen mode. The reply will | 212 // key event to get the window entering in fullscreen mode. The reply will |
194 // make the window listen for the key event. The reply will be sent to the | 213 // make the window listen for the key event. The reply will be sent to the |
195 // renderer process before the keypress and should be received in that order. | 214 // renderer process before the keypress and should be received in that order. |
196 // When receiving the key event, the application will try to go fullscreen | 215 // When receiving the key event, the application will try to go fullscreen |
197 // using the Window API but there is no synchronous way to know if that | 216 // using the Window API but there is no synchronous way to know if that |
198 // actually succeeded. Also, failure will not be notified. A failure case will | 217 // actually succeeded. Also, failure will not be notified. A failure case will |
199 // only be known with a timeout. | 218 // only be known with a timeout. |
200 { | 219 { |
201 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 220 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
202 | 221 |
203 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 222 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
204 | 223 |
205 fs_changed.Wait(); | 224 fs_changed.Wait(); |
206 } | 225 } |
207 | 226 |
227 // Depending on the platform, going fullscreen might create an animation. | |
228 // We want to make sure that the ESC key we will send next is actually going | |
229 // to be received and the application might not receive key events during the | |
230 // animation so we should wait for the key focus to be back. | |
231 WaitUntilKeyFocus(); | |
koz (OOO until 15th September)
2014/01/08 23:29:25
It might make sense to name this WaitForFullscreen
mlamouri (slow - plz ping)
2014/01/09 17:08:46
But we might want to re-use that logic for other t
| |
232 | |
208 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 233 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
209 | 234 |
210 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 235 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
211 | 236 |
212 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 237 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
213 | 238 |
214 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 239 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
215 | 240 |
216 // We assume that at that point, if we had to leave fullscreen, we should be. | 241 // We assume that at that point, if we had to leave fullscreen, we should be. |
217 // However, by nature, we can not guarantee that and given that we do test | 242 // However, by nature, we can not guarantee that and given that we do test |
(...skipping 11 matching lines...) Expand all Loading... | |
229 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ | 254 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ |
230 defined(OS_WIN) || defined(OS_MACOSX) | 255 defined(OS_WIN) || defined(OS_MACOSX) |
231 #define MAYBE_TestCreate DISABLED_TestCreate | 256 #define MAYBE_TestCreate DISABLED_TestCreate |
232 #else | 257 #else |
233 #define MAYBE_TestCreate TestCreate | 258 #define MAYBE_TestCreate TestCreate |
234 #endif | 259 #endif |
235 | 260 |
236 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { | 261 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { |
237 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; | 262 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; |
238 } | 263 } |
OLD | NEW |