| 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 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 11 #include "base/mac/mac_util.h" |
| 12 #endif |
| 13 |
| 14 using apps::NativeAppWindow; |
| 11 | 15 |
| 12 // Helper class that has to be created in the stack to check if the fullscreen | 16 // 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. | 17 // setting of a NativeWindow has changed since the creation of the object. |
| 14 class FullscreenChangeWaiter { | 18 class FullscreenChangeWaiter { |
| 15 public: | 19 public: |
| 16 explicit FullscreenChangeWaiter(NativeAppWindow* window) | 20 explicit FullscreenChangeWaiter(NativeAppWindow* window) |
| 17 : window_(window), | 21 : window_(window), |
| 18 initial_fullscreen_state_(window_->IsFullscreen()) {} | 22 initial_fullscreen_state_(window_->IsFullscreen()) {} |
| 19 | 23 |
| 20 void Wait() { | 24 void Wait() { |
| 21 while (initial_fullscreen_state_ != window_->IsFullscreen()) | 25 while (initial_fullscreen_state_ == window_->IsFullscreen()) |
| 22 content::RunAllPendingInMessageLoop(); | 26 content::RunAllPendingInMessageLoop(); |
| 23 } | 27 } |
| 24 | 28 |
| 25 private: | 29 private: |
| 26 NativeAppWindow* window_; | 30 NativeAppWindow* window_; |
| 27 bool initial_fullscreen_state_; | 31 bool initial_fullscreen_state_; |
| 28 | 32 |
| 29 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); | 33 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); |
| 30 }; | 34 }; |
| 31 | 35 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 | 56 |
| 53 bool SimulateKeyPress(ui::KeyboardCode key) { | 57 bool SimulateKeyPress(ui::KeyboardCode key) { |
| 54 return ui_test_utils::SendKeyPressToWindowSync( | 58 return ui_test_utils::SendKeyPressToWindowSync( |
| 55 GetFirstShellWindow()->GetNativeWindow(), | 59 GetFirstShellWindow()->GetNativeWindow(), |
| 56 key, | 60 key, |
| 57 false, | 61 false, |
| 58 false, | 62 false, |
| 59 false, | 63 false, |
| 60 false); | 64 false); |
| 61 } | 65 } |
| 66 |
| 67 // This method will wait until the application is able to ack a key event. |
| 68 void WaitUntilKeyFocus() { |
| 69 ExtensionTestMessageListener key_listener("KeyReceived", false); |
| 70 |
| 71 while (!key_listener.was_satisfied()) { |
| 72 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); |
| 73 content::RunAllPendingInMessageLoop(); |
| 74 } |
| 75 } |
| 62 }; | 76 }; |
| 63 | 77 |
| 64 #if defined(OS_LINUX) && defined(USE_AURA) | 78 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) { |
| 65 // These tests do not work on Linux Aura because when the window is raised, the | 79 // This test is flaky on MacOS 10.6. |
| 66 // content is not focused thus do not get the key events. | 80 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 67 // See http://crbug.com/324346 | 81 if (base::mac::IsOSSnowLeopard()) |
| 68 #define MAYBE_ESCDoesNotLeaveFullscreenWindow \ | 82 return; |
| 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 | 83 #endif |
| 87 | 84 |
| 88 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | |
| 89 MAYBE_ESCLeavesFullscreenWindow) { | |
| 90 ExtensionTestMessageListener launched_listener("Launched", true); | 85 ExtensionTestMessageListener launched_listener("Launched", true); |
| 91 LoadAndLaunchPlatformApp("leave_fullscreen"); | 86 LoadAndLaunchPlatformApp("leave_fullscreen"); |
| 92 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 87 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 93 | 88 |
| 89 // We start by making sure the window is actually focused. |
| 90 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 91 GetFirstShellWindow()->GetNativeWindow())); |
| 92 |
| 94 // 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 |
| 95 // 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 |
| 96 // 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 |
| 97 // known with a timeout. | 96 // known with a timeout. |
| 98 { | 97 { |
| 99 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 98 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 100 | 99 |
| 101 launched_listener.Reply("window"); | 100 launched_listener.Reply("window"); |
| 102 | 101 |
| 103 fs_changed.Wait(); | 102 fs_changed.Wait(); |
| 104 } | 103 } |
| 105 | 104 |
| 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 |
| 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. |
| 109 WaitUntilKeyFocus(); |
| 110 |
| 106 // 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 |
| 107 // left when ESC is received. | 112 // left when ESC is received. |
| 108 { | 113 { |
| 109 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 114 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 110 | 115 |
| 111 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 116 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
| 112 | 117 |
| 113 fs_changed.Wait(); | 118 fs_changed.Wait(); |
| 114 } | 119 } |
| 115 } | 120 } |
| 116 | 121 |
| 117 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_ESCLeavesFullscreenDOM) { | 122 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) { |
| 123 // This test is flaky on MacOS 10.6. |
| 124 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 125 if (base::mac::IsOSSnowLeopard()) |
| 126 return; |
| 127 #endif |
| 128 |
| 118 ExtensionTestMessageListener launched_listener("Launched", true); | 129 ExtensionTestMessageListener launched_listener("Launched", true); |
| 119 LoadAndLaunchPlatformApp("leave_fullscreen"); | 130 LoadAndLaunchPlatformApp("leave_fullscreen"); |
| 120 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 121 | 132 |
| 133 // We start by making sure the window is actually focused. |
| 134 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 135 GetFirstShellWindow()->GetNativeWindow())); |
| 136 |
| 122 launched_listener.Reply("dom"); | 137 launched_listener.Reply("dom"); |
| 123 | 138 |
| 124 // 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 |
| 125 // 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 |
| 126 // 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 |
| 127 // 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. |
| 128 // 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 |
| 129 // 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 |
| 130 // 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 |
| 131 // only be known with a timeout. | 146 // only be known with a timeout. |
| 132 { | 147 { |
| 133 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 148 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 134 | 149 |
| 150 WaitUntilKeyFocus(); |
| 135 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 151 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
| 136 | 152 |
| 137 fs_changed.Wait(); | 153 fs_changed.Wait(); |
| 138 } | 154 } |
| 139 | 155 |
| 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 |
| 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. |
| 160 WaitUntilKeyFocus(); |
| 161 |
| 140 // 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 |
| 141 // left when ESC is received. | 163 // left when ESC is received. |
| 142 { | 164 { |
| 143 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 165 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 144 | 166 |
| 145 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 167 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
| 146 | 168 |
| 147 fs_changed.Wait(); | 169 fs_changed.Wait(); |
| 148 } | 170 } |
| 149 } | 171 } |
| 150 | 172 |
| 151 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 173 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
| 152 MAYBE_ESCDoesNotLeaveFullscreenWindow) { | 174 ESCDoesNotLeaveFullscreenWindow) { |
| 175 // This test is flaky on MacOS 10.6. |
| 176 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 177 if (base::mac::IsOSSnowLeopard()) |
| 178 return; |
| 179 #endif |
| 180 |
| 153 ExtensionTestMessageListener launched_listener("Launched", true); | 181 ExtensionTestMessageListener launched_listener("Launched", true); |
| 154 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 182 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
| 155 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 183 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 156 | 184 |
| 185 // We start by making sure the window is actually focused. |
| 186 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 187 GetFirstShellWindow()->GetNativeWindow())); |
| 188 |
| 157 // 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 |
| 158 // 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 |
| 159 // 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 |
| 160 // known with a timeout. | 192 // known with a timeout. |
| 161 { | 193 { |
| 162 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 194 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 163 | 195 |
| 164 launched_listener.Reply("window"); | 196 launched_listener.Reply("window"); |
| 165 | 197 |
| 166 fs_changed.Wait(); | 198 fs_changed.Wait(); |
| 167 } | 199 } |
| 168 | 200 |
| 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 |
| 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. |
| 205 WaitUntilKeyFocus(); |
| 206 |
| 169 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 207 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
| 170 | 208 |
| 171 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 209 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
| 172 | 210 |
| 173 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 211 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
| 174 | 212 |
| 175 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 213 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
| 176 | 214 |
| 177 // 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. |
| 178 // 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 |
| 179 // 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 |
| 180 // is broken. | 218 // is broken. |
| 181 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | 219 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); |
| 182 } | 220 } |
| 183 | 221 |
| 184 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, | 222 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, |
| 185 MAYBE_ESCDoesNotLeaveFullscreenDOM) { | 223 ESCDoesNotLeaveFullscreenDOM) { |
| 224 // This test is flaky on MacOS 10.6. |
| 225 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 226 if (base::mac::IsOSSnowLeopard()) |
| 227 return; |
| 228 #endif |
| 229 |
| 186 ExtensionTestMessageListener launched_listener("Launched", true); | 230 ExtensionTestMessageListener launched_listener("Launched", true); |
| 187 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | 231 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
| 188 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 232 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 189 | 233 |
| 234 // We start by making sure the window is actually focused. |
| 235 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 236 GetFirstShellWindow()->GetNativeWindow())); |
| 237 |
| 190 launched_listener.Reply("dom"); | 238 launched_listener.Reply("dom"); |
| 191 | 239 |
| 192 // 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 |
| 193 // 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 |
| 194 // 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 |
| 195 // 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. |
| 196 // 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 |
| 197 // 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 |
| 198 // 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 |
| 199 // only be known with a timeout. | 247 // only be known with a timeout. |
| 200 { | 248 { |
| 201 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); | 249 FullscreenChangeWaiter fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
| 202 | 250 |
| 251 WaitUntilKeyFocus(); |
| 203 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); | 252 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); |
| 204 | 253 |
| 205 fs_changed.Wait(); | 254 fs_changed.Wait(); |
| 206 } | 255 } |
| 207 | 256 |
| 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 |
| 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. |
| 261 WaitUntilKeyFocus(); |
| 262 |
| 208 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); | 263 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); |
| 209 | 264 |
| 210 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | 265 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
| 211 | 266 |
| 212 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); | 267 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); |
| 213 | 268 |
| 214 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 269 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
| 215 | 270 |
| 216 // 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. |
| 217 // 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 237 #define MAYBE_TestShow TestShow | 292 #define MAYBE_TestShow TestShow |
| 238 #endif | 293 #endif |
| 239 | 294 |
| 240 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { | 295 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { |
| 241 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; | 296 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; |
| 242 } | 297 } |
| 243 | 298 |
| 244 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { | 299 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { |
| 245 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; | 300 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; |
| 246 } | 301 } |
| OLD | NEW |