Index: chrome/browser/apps/app_interactive_uitest.cc |
diff --git a/chrome/browser/apps/app_interactive_uitest.cc b/chrome/browser/apps/app_interactive_uitest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26f58e0b638abef6c1d3384a8b0d2ce1dd297f68 |
--- /dev/null |
+++ b/chrome/browser/apps/app_interactive_uitest.cc |
@@ -0,0 +1,223 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "apps/ui/native_app_window.h" |
+#include "chrome/browser/apps/app_browsertest_util.h" |
+#include "chrome/browser/extensions/extension_test_message_listener.h" |
+#include "chrome/test/base/interactive_test_utils.h" |
+ |
+using namespace apps; |
+ |
+// Helper class that has to be created in the stack to check if the fullscreen |
+// setting of a NativeWindow has changed since the creation of the object. |
+class FullscreenChangeHelper { |
+ public: |
+ explicit FullscreenChangeHelper(NativeAppWindow* window) |
+ : window_(window), |
+ initial_fullscreen_state_(window_->IsFullscreen()), |
+ already_changed_(false) {} |
+ |
+ bool DidFullscreenChanged() { |
+ if (already_changed_) |
+ return true; |
+ |
+ if (initial_fullscreen_state_ != window_->IsFullscreen()) { |
+ already_changed_ = true; |
+ return true; |
+ } |
+ |
+ return false; |
+ } |
+ |
+ private: |
+ NativeAppWindow* window_; |
+ bool initial_fullscreen_state_; |
+ bool already_changed_; |
koz (OOO until 15th September)
2013/11/21 23:12:41
DISALLOW_COPY_AND_ASSIGN(FullscreenChangeHelper);
|
+}; |
+ |
+class AppInteractiveTest : public extensions::PlatformAppBrowserTest {}; |
+ |
+IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenWindow) { |
+ ExtensionTestMessageListener launched_listener("Launched", true); |
+ LoadAndLaunchPlatformApp("leave_fullscreen"); |
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ |
+ launched_listener.Reply("window"); |
+ |
+ // When receiving the reply, the application will try to go fullscreen using |
+ // the Window API but there is no synchronous way to know if that actually |
+ // succeeded. Also, failure will not be notified. A failure case will only be |
+ // known with a timeout. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
koz (OOO until 15th September)
2013/11/21 23:12:41
I'd say rename this to FullscreenChangeWatcher, an
|
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_ESCAPE, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ // Same idea as above but for leaving fullscreen. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCLeavesFullscreenDOM) { |
+ ExtensionTestMessageListener launched_listener("Launched", true); |
+ LoadAndLaunchPlatformApp("leave_fullscreen"); |
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ |
+ launched_listener.Reply("dom"); |
+ |
+ // Because the DOM way to go fullscreen requires user gesture, we simulate a |
+ // key event to get the window entering in fullscreen mode. The reply will |
+ // make the window listen for the key event. The reply will be sent to the |
+ // renderer process before the keypress and should be received in that order. |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_A, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ // When receiving the key event, the application will try to go fullscreen |
+ // using the Window API but there is no synchronous way to know if that |
+ // actually succeeded. Also, failure will not be notified. A failure case will |
+ // only be known with a timeout. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_ESCAPE, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ // Same idea as above but for leaving fullscreen. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(AppInteractiveTest, ESCDoesNotLeaveFullscreenWindow) { |
+ ExtensionTestMessageListener launched_listener("Launched", true); |
+ LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ |
+ launched_listener.Reply("window"); |
+ |
+ // When receiving the reply, the application will try to go fullscreen using |
+ // the Window API but there is no synchronous way to know if that actually |
+ // succeeded. Also, failure will not be notified. A failure case will only be |
+ // known with a timeout. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_ESCAPE, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_B, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
+ |
+ // We assume that at that point, if we had to leave fullscreen, we should be. |
+ // However, by nature, we can not guarantee that and given that we do test |
+ // that nothing happens, we might end up with random-success when the feature |
+ // is broken. |
+ EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); |
koz (OOO until 15th September)
2013/11/21 23:12:41
Seeing as we expect fullscreen to occur asynchrono
|
+} |
+ |
+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
|
+ ExtensionTestMessageListener launched_listener("Launched", true); |
+ LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); |
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
+ |
+ launched_listener.Reply("dom"); |
+ |
+ // Because the DOM way to go fullscreen requires user gesture, we simulate a |
+ // key event to get the window entering in fullscreen mode. The reply will |
+ // make the window listen for the key event. The reply will be sent to the |
+ // renderer process before the keypress and should be received in that order. |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_A, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ // When receiving the key event, the application will try to go fullscreen |
+ // using the Window API but there is no synchronous way to know if that |
+ // actually succeeded. Also, failure will not be notified. A failure case will |
+ // only be known with a timeout. |
+ { |
+ FullscreenChangeHelper fs_changed(GetFirstShellWindow()->GetBaseWindow()); |
+ |
+ while (!fs_changed.DidFullscreenChanged()) |
+ content::RunAllPendingInMessageLoop(); |
+ } |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_ESCAPE, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); |
+ |
+ ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
+ GetFirstShellWindow()->GetNativeWindow(), |
+ ui::VKEY_B, |
+ false, |
+ false, |
+ false, |
+ false)); |
+ |
+ ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
+ |
+ // We assume that at that point, if we had to leave fullscreen, we should be. |
+ // However, by nature, we can not guarantee that and given that we do test |
+ // that nothing happens, we might end up with random-success when the feature |
+ // is broken. |
+ EXPECT_TRUE(GetFirstShellWindow()->GetBaseWindow()->IsFullscreen()); |
+} |