app_window_interactive_uitest.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "apps/ui/native_app_window.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h" 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/extensions/extension_test_message_listener.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/test/base/interactive_test_utils.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/mac/mac_util.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using apps::NativeAppWindow; 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Helper class that has to be created in the stack to check if the fullscreen 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// setting of a NativeWindow has changed since the creation of the object. 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class FullscreenChangeWaiter { 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) explicit FullscreenChangeWaiter(NativeAppWindow* window) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : window_(window), 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) initial_fullscreen_state_(window_->IsFullscreen()) {} 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void Wait() { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) while (initial_fullscreen_state_ == window_->IsFullscreen()) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NativeAppWindow* window_; 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool initial_fullscreen_state_; 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(FullscreenChangeWaiter); 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class AppWindowInteractiveTest : public extensions::PlatformAppBrowserTest { 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool RunAppWindowInteractiveTest(const char* testName) { 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoadAndLaunchPlatformApp("window_api_interactive"); 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!launched_listener.WaitUntilSatisfied()) { 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) message_ = "Did not get the 'Launched' message."; 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ResultCatcher catcher; 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launched_listener.Reply(testName); 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!catcher.GetNextResult()) { 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) message_ = catcher.message(); 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool SimulateKeyPress(ui::KeyboardCode key) { 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ui_test_utils::SendKeyPressToWindowSync( 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow(), 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) key, 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This method will wait until the application is able to ack a key event. 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void WaitUntilKeyFocus() { 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener key_listener("KeyReceived", false); 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) while (!key_listener.was_satisfied()) { 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenWindow) { 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6. 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoadAndLaunchPlatformApp("leave_fullscreen"); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We start by making sure the window is actually focused. 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow())); 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // When receiving the reply, the application will try to go fullscreen using 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the Window API but there is no synchronous way to know if that actually 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // succeeded. Also, failure will not be notified. A failure case will only be 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // known with a timeout. 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launched_listener.Reply("window"); 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Depending on the platform, going fullscreen might create an animation. 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We want to make sure that the ESC key we will send next is actually going 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to be received and the application might not receive key events during the 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // animation so we should wait for the key focus to be back. 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same idea as above but for leaving fullscreen. Fullscreen mode should be 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // left when ESC is received. 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, ESCLeavesFullscreenDOM) { 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6. 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoadAndLaunchPlatformApp("leave_fullscreen"); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We start by making sure the window is actually focused. 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow())); 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launched_listener.Reply("dom"); 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Because the DOM way to go fullscreen requires user gesture, we simulate a 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // key event to get the window entering in fullscreen mode. The reply will 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // make the window listen for the key event. The reply will be sent to the 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // renderer process before the keypress and should be received in that order. 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // When receiving the key event, the application will try to go fullscreen 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // using the Window API but there is no synchronous way to know if that 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // actually succeeded. Also, failure will not be notified. A failure case will 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // only be known with a timeout. 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Depending on the platform, going fullscreen might create an animation. 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We want to make sure that the ESC key we will send next is actually going 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to be received and the application might not receive key events during the 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // animation so we should wait for the key focus to be back. 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same idea as above but for leaving fullscreen. Fullscreen mode should be 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // left when ESC is received. 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ESCDoesNotLeaveFullscreenWindow) { 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6. 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We start by making sure the window is actually focused. 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow())); 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // When receiving the reply, the application will try to go fullscreen using 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the Window API but there is no synchronous way to know if that actually 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // succeeded. Also, failure will not be notified. A failure case will only be 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // known with a timeout. 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launched_listener.Reply("window"); 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Depending on the platform, going fullscreen might create an animation. 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We want to make sure that the ESC key we will send next is actually going 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to be received and the application might not receive key events during the 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // animation so we should wait for the key focus to be back. 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We assume that at that point, if we had to leave fullscreen, we should be. 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // However, by nature, we can not guarantee that and given that we do test 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // that nothing happens, we might end up with random-success when the feature 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // is broken. 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ESCDoesNotLeaveFullscreenDOM) { 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test is flaky on MacOS 10.6. 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LoadAndLaunchPlatformApp("prevent_leave_fullscreen"); 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We start by making sure the window is actually focused. 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow())); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) launched_listener.Reply("dom"); 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Because the DOM way to go fullscreen requires user gesture, we simulate a 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // key event to get the window entering in fullscreen mode. The reply will 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // make the window listen for the key event. The reply will be sent to the 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // renderer process before the keypress and should be received in that order. 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // When receiving the key event, the application will try to go fullscreen 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // using the Window API but there is no synchronous way to know if that 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // actually succeeded. Also, failure will not be notified. A failure case will 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // only be known with a timeout. 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_A)); 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fs_changed.Wait(); 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Depending on the platform, going fullscreen might create an animation. 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We want to make sure that the ESC key we will send next is actually going 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to be received and the application might not receive key events during the 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // animation so we should wait for the key focus to be back. 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WaitUntilKeyFocus(); 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We assume that at that point, if we had to leave fullscreen, we should be. 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // However, by nature, we can not guarantee that and given that we do test 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // that nothing happens, we might end up with random-success when the feature 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // is broken. 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This test is duplicated from ESCDoesNotLeaveFullscreenWindow. 279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// It runs the same test, but uses the old permission names: 'fullscreen' 280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// and 'overrideEscFullscreen'. 281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, 282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ESCDoesNotLeaveFullscreenOldPermission) { 283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This test is flaky on MacOS 10.6. 284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 287a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif 288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExtensionTestMessageListener launched_listener("Launched", true); 290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LoadAndLaunchPlatformApp("prevent_leave_fullscreen_old"); 291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // We start by making sure the window is actually focused. 294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( 295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetFirstAppWindow()->GetNativeWindow())); 296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // When receiving the reply, the application will try to go fullscreen using 298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the Window API but there is no synchronous way to know if that actually 299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // succeeded. Also, failure will not be notified. A failure case will only be 300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // known with a timeout. 301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) { 302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); 303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) launched_listener.Reply("window"); 305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) fs_changed.Wait(); 307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Depending on the platform, going fullscreen might create an animation. 310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // We want to make sure that the ESC key we will send next is actually going 311a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // to be received and the application might not receive key events during the 312a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // animation so we should wait for the key focus to be back. 313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WaitUntilKeyFocus(); 314a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 315a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); 316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 317a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); 318a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 319a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); 320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 321a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); 322a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 323a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // We assume that at that point, if we had to leave fullscreen, we should be. 324a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // However, by nature, we can not guarantee that and given that we do test 325a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // that nothing happens, we might end up with random-success when the feature 326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // is broken. 327a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); 328a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 329a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This test does not work on Linux Aura because ShowInactive() is not 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// implemented. See http://crbug.com/325142 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It also does not work on Windows because of the document being focused even 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// though the window is not activated. See http://crbug.com/326986 3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It also does not work on MacOS because ::ShowInactive() ends up behaving like 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ::Show() because of Cocoa conventions. See http://crbug.com/326987 3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Those tests should be disabled on Linux GTK when they are enabled on the 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// other platforms, see http://crbug.com/328829 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if (defined(OS_LINUX) && defined(USE_AURA)) || \ 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) defined(OS_WIN) || defined(OS_MACOSX) 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestCreate DISABLED_TestCreate 3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestShow DISABLED_TestShow 3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#else 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestCreate TestCreate 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MAYBE_TestShow TestShow 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { 3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; 3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { 3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; 3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 354