Chromium Code Reviews| 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 FullscreenChangeHelper { | |
| 15 public: | |
| 16 explicit FullscreenChangeHelper(NativeAppWindow* window) | |
| 17 : window_(window), | |
| 18 initial_fullscreen_state_(window_->IsFullscreen()), | |
| 19 already_changed_(false) {} | |
| 20 | |
| 21 bool DidFullscreenChanged() { | |
| 22 if (already_changed_) | |
| 23 return true; | |
| 24 | |
| 25 if (initial_fullscreen_state_ != window_->IsFullscreen()) { | |
| 26 already_changed_ = true; | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 return false; | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 NativeAppWindow* window_; | |
| 35 bool initial_fullscreen_state_; | |
| 36 bool already_changed_; | |
|
koz (OOO until 15th September)
2013/11/21 23:12:41
DISALLOW_COPY_AND_ASSIGN(FullscreenChangeHelper);
| |
| 37 }; | |
| 38 | |
| 39 class AppInteractiveTest : public extensions::PlatformAppBrowserTest {}; | |
| 40 | |
| 41 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenWindow) { | |
| 42 ExtensionTestMessageListener launched_listener("Launched", true); | |
| 43 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
| 44 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 45 | |
| 46 launched_listener.Reply("window"); | |
| 47 | |
| 48 // When receiving the reply, the application will try to go fullscreen using | |
| 49 // the Window API but there is no synchronous way to know if that actually | |
| 50 // succeeded. Also, failure will not be notified. A failure case will only be | |
| 51 // known with a timeout. | |
| 52 { | |
| 53 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
|
koz (OOO until 15th September)
2013/11/21 23:12:41
I'd say rename this to FullscreenChangeWatcher, an
| |
| 54 | |
| 55 while (!fs_changed.DidFullscreenChanged()) | |
| 56 content::RunAllPendingInMessageLoop(); | |
| 57 } | |
| 58 | |
| 59 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 60 GetFirstShellWindow()->GetNativeWindow(), | |
| 61 ui::VKEY_ESCAPE, | |
| 62 false, | |
| 63 false, | |
| 64 false, | |
| 65 false)); | |
| 66 | |
| 67 // Same idea as above but for leaving fullscreen. | |
| 68 { | |
| 69 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
| 70 | |
| 71 while (!fs_changed.DidFullscreenChanged()) | |
| 72 content::RunAllPendingInMessageLoop(); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenDOM) { | |
| 77 ExtensionTestMessageListener launched_listener("Launched", true); | |
| 78 LoadAndLaunchPlatformApp("leave_fullscreen"); | |
| 79 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 80 | |
| 81 launched_listener.Reply("dom"); | |
| 82 | |
| 83 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
| 84 // key event to get the window entering in fullscreen mode. The reply will | |
| 85 // make the window listen for the key event. The reply will be sent to the | |
| 86 // renderer process before the keypress and should be received in that order. | |
| 87 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 88 GetFirstShellWindow()->GetNativeWindow(), | |
| 89 ui::VKEY_A, | |
| 90 false, | |
| 91 false, | |
| 92 false, | |
| 93 false)); | |
| 94 | |
| 95 // When receiving the key event, the application will try to go fullscreen | |
| 96 // using the Window API but there is no synchronous way to know if that | |
| 97 // actually succeeded. Also, failure will not be notified. A failure case will | |
| 98 // only be known with a timeout. | |
| 99 { | |
| 100 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
| 101 | |
| 102 while (!fs_changed.DidFullscreenChanged()) | |
| 103 content::RunAllPendingInMessageLoop(); | |
| 104 } | |
| 105 | |
| 106 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 107 GetFirstShellWindow()->GetNativeWindow(), | |
| 108 ui::VKEY_ESCAPE, | |
| 109 false, | |
| 110 false, | |
| 111 false, | |
| 112 false)); | |
| 113 | |
| 114 // Same idea as above but for leaving fullscreen. | |
| 115 { | |
| 116 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
| 117 | |
| 118 while (!fs_changed.DidFullscreenChanged()) | |
| 119 content::RunAllPendingInMessageLoop(); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenWindow) { | |
| 124 ExtensionTestMessageListener launched_listener("Launched", true); | |
| 125 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
| 126 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 127 | |
| 128 launched_listener.Reply("window"); | |
| 129 | |
| 130 // When receiving the reply, the application will try to go fullscreen using | |
| 131 // the Window API but there is no synchronous way to know if that actually | |
| 132 // succeeded. Also, failure will not be notified. A failure case will only be | |
| 133 // known with a timeout. | |
| 134 { | |
| 135 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
| 136 | |
| 137 while (!fs_changed.DidFullscreenChanged()) | |
| 138 content::RunAllPendingInMessageLoop(); | |
| 139 } | |
| 140 | |
| 141 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 142 GetFirstShellWindow()->GetNativeWindow(), | |
| 143 ui::VKEY_ESCAPE, | |
| 144 false, | |
| 145 false, | |
| 146 false, | |
| 147 false)); | |
| 148 | |
| 149 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
| 150 | |
| 151 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 152 GetFirstShellWindow()->GetNativeWindow(), | |
| 153 ui::VKEY_B, | |
| 154 false, | |
| 155 false, | |
| 156 false, | |
| 157 false)); | |
| 158 | |
| 159 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
| 160 | |
| 161 // We assume that at that point, if we had to leave fullscreen, we should be. | |
| 162 // However, by nature, we can not guarantee that and given that we do test | |
| 163 // that nothing happens, we might end up with random-success when the feature | |
| 164 // is broken. | |
| 165 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
|
koz (OOO until 15th September)
2013/11/21 23:12:41
Seeing as we expect fullscreen to occur asynchrono
| |
| 166 } | |
| 167 | |
| 168 IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenDOM) { | |
|
koz (OOO until 15th September)
2013/11/21 23:12:41
Again, I think this is impossible to test unless m
| |
| 169 ExtensionTestMessageListener launched_listener("Launched", true); | |
| 170 LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); | |
| 171 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 172 | |
| 173 launched_listener.Reply("dom"); | |
| 174 | |
| 175 // Because the DOM way to go fullscreen requires user gesture, we simulate a | |
| 176 // key event to get the window entering in fullscreen mode. The reply will | |
| 177 // make the window listen for the key event. The reply will be sent to the | |
| 178 // renderer process before the keypress and should be received in that order. | |
| 179 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 180 GetFirstShellWindow()->GetNativeWindow(), | |
| 181 ui::VKEY_A, | |
| 182 false, | |
| 183 false, | |
| 184 false, | |
| 185 false)); | |
| 186 | |
| 187 // When receiving the key event, the application will try to go fullscreen | |
| 188 // using the Window API but there is no synchronous way to know if that | |
| 189 // actually succeeded. Also, failure will not be notified. A failure case will | |
| 190 // only be known with a timeout. | |
| 191 { | |
| 192 FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); | |
| 193 | |
| 194 while (!fs_changed.DidFullscreenChanged()) | |
| 195 content::RunAllPendingInMessageLoop(); | |
| 196 } | |
| 197 | |
| 198 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 199 GetFirstShellWindow()->GetNativeWindow(), | |
| 200 ui::VKEY_ESCAPE, | |
| 201 false, | |
| 202 false, | |
| 203 false, | |
| 204 false)); | |
| 205 | |
| 206 ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); | |
| 207 | |
| 208 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | |
| 209 GetFirstShellWindow()->GetNativeWindow(), | |
| 210 ui::VKEY_B, | |
| 211 false, | |
| 212 false, | |
| 213 false, | |
| 214 false)); | |
| 215 | |
| 216 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | |
| 217 | |
| 218 // We assume that at that point, if we had to leave fullscreen, we should be. | |
| 219 // However, by nature, we can not guarantee that and given that we do test | |
| 220 // that nothing happens, we might end up with random-success when the feature | |
| 221 // is broken. | |
| 222 EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); | |
| 223 } | |
| OLD | NEW |