1 // Copyright 2019 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 "chrome/browser/apps/platform_apps/app_window_interactive_uitest_base.h" 6 7 #include "chrome/browser/lifetime/application_lifetime.h" 8 #include "chrome/test/base/interactive_test_utils.h" 9 #include "components/keep_alive_registry/keep_alive_registry.h" 10 #include "components/keep_alive_registry/keep_alive_types.h" 11 #include "content/public/test/test_utils.h" 12 #include "extensions/browser/app_window/native_app_window.h" 13 #include "extensions/test/extension_test_message_listener.h" 14 #include "extensions/test/result_catcher.h" 15 FullscreenChangeWaiter(extensions::NativeAppWindow * window)16FullscreenChangeWaiter::FullscreenChangeWaiter( 17 extensions::NativeAppWindow* window) 18 : window_(window), initial_fullscreen_state_(window_->IsFullscreen()) {} 19 Wait()20void FullscreenChangeWaiter::Wait() { 21 while (initial_fullscreen_state_ == window_->IsFullscreen()) 22 content::RunAllPendingInMessageLoop(); 23 } 24 RunAppWindowInteractiveTest(const char * testName)25bool AppWindowInteractiveTest::RunAppWindowInteractiveTest( 26 const char* testName) { 27 ExtensionTestMessageListener launched_listener("Launched", true); 28 LoadAndLaunchPlatformApp("window_api_interactive", &launched_listener); 29 30 extensions::ResultCatcher catcher; 31 launched_listener.Reply(testName); 32 33 if (!catcher.GetNextResult()) { 34 message_ = catcher.message(); 35 return false; 36 } 37 38 return true; 39 } 40 SimulateKeyPress(ui::KeyboardCode key)41bool AppWindowInteractiveTest::SimulateKeyPress(ui::KeyboardCode key) { 42 return ui_test_utils::SendKeyPressToWindowSync( 43 GetFirstAppWindow()->GetNativeWindow(), key, false, false, false, false); 44 } 45 WaitUntilKeyFocus()46void AppWindowInteractiveTest::WaitUntilKeyFocus() { 47 ExtensionTestMessageListener key_listener("KeyReceived", false); 48 49 while (!key_listener.was_satisfied()) { 50 ASSERT_TRUE(SimulateKeyPress(ui::VKEY_Z)); 51 content::RunAllPendingInMessageLoop(); 52 } 53 } 54