This source file includes following definitions.
- initial_fullscreen_state_
- Wait
- RunAppWindowInteractiveTest
- SimulateKeyPress
- WaitUntilKeyFocus
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#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"
#if defined(OS_MACOSX) && !defined(OS_IOS)
#include "base/mac/mac_util.h"
#endif
using apps::NativeAppWindow;
class FullscreenChangeWaiter {
public:
explicit FullscreenChangeWaiter(NativeAppWindow* window)
: window_(window),
initial_fullscreen_state_(window_->IsFullscreen()) {}
void Wait() {
while (initial_fullscreen_state_ == window_->IsFullscreen())
content::RunAllPendingInMessageLoop();
}
private:
NativeAppWindow* window_;
bool initial_fullscreen_state_;
DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter);
};
class AppWindowInteractiveTest : public extensions::PlatformAppBrowserTest {
public:
bool RunAppWindowInteractiveTest(const char* testName) {
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("window_api_interactive");
if (!launched_listener.WaitUntilSatisfied()) {
message_ = "Did not get the 'Launched' message.";
return false;
}
ResultCatcher catcher;
launched_listener.Reply(testName);
if (!catcher.GetNextResult()) {
message_ = catcher.message();
return false;
}
return true;
}
bool SimulateKeyPress(ui::KeyboardCode key) {
return ui_test_utils::SendKeyPressToWindowSync(
GetFirstAppWindow()->GetNativeWindow(),
key,
false,
false,
false,
false);
}
void WaitUntilKeyFocus() {
ExtensionTestMessageListener key_listener("KeyReceived", false);
while (!key_listener.was_satisfied()) {
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z));
content::RunAllPendingInMessageLoop();
}
}
};
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::IsOSSnowLeopard())
return;
#endif
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("leave_fullscreen");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
WaitUntilKeyFocus();
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
fs_changed.Wait();
}
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::IsOSSnowLeopard())
return;
#endif
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("leave_fullscreen");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
launched_listener.Reply("dom");
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
fs_changed.Wait();
}
WaitUntilKeyFocus();
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
fs_changed.Wait();
}
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
ESCDoesNotLeaveFullscreenWindow) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::IsOSSnowLeopard())
return;
#endif
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
ESCDoesNotLeaveFullscreenDOM) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::IsOSSnowLeopard())
return;
#endif
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
launched_listener.Reply("dom");
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A));
fs_changed.Wait();
}
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest,
ESCDoesNotLeaveFullscreenOldPermission) {
#if defined(OS_MACOSX) && !defined(OS_IOS)
if (base::mac::IsOSSnowLeopard())
return;
#endif
ExtensionTestMessageListener launched_listener("Launched", true);
LoadAndLaunchPlatformApp("prevent_leave_fullscreen_old");
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
GetFirstAppWindow()->GetNativeWindow()));
{
FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow());
launched_listener.Reply("window");
fs_changed.Wait();
}
WaitUntilKeyFocus();
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE));
ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false);
ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B));
ASSERT_TRUE(second_key_listener.WaitUntilSatisfied());
EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen());
}
#if (defined(OS_LINUX) && defined(USE_AURA)) || \
defined(OS_WIN) || defined(OS_MACOSX)
#define MAYBE_TestCreate DISABLED_TestCreate
#define MAYBE_TestShow DISABLED_TestShow
#else
#define MAYBE_TestCreate TestCreate
#define MAYBE_TestShow TestShow
#endif
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) {
ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_;
}