1 // Copyright (c) 2012 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/test/base/interactive_test_utils.h" 6 7 #include "base/files/file_path.h" 8 #include "base/logging.h" 9 #include "base/path_service.h" 10 #include "base/strings/stringprintf.h" 11 #include "base/time/time.h" 12 #include "chrome/browser/ui/host_desktop.h" 13 #include "chrome/test/base/interactive_test_utils_aura.h" 14 #include "ui/aura/window_tree_host.h" 15 #include "ui/base/test/ui_controls.h" 16 #include "ui/base/win/foreground_helper.h" 17 #include "ui/views/focus/focus_manager.h" 18 19 namespace ui_test_utils { 20 HideNativeWindow(gfx::NativeWindow window)21void HideNativeWindow(gfx::NativeWindow window) { 22 if (chrome::GetHostDesktopTypeForNativeWindow(window) == 23 chrome::HOST_DESKTOP_TYPE_ASH) { 24 HideNativeWindowAura(window); 25 return; 26 } 27 HWND hwnd = window->GetHost()->GetAcceleratedWidget(); 28 ::ShowWindow(hwnd, SW_HIDE); 29 } 30 ShowAndFocusNativeWindow(gfx::NativeWindow window)31bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 32 if (chrome::GetHostDesktopTypeForNativeWindow(window) == 33 chrome::HOST_DESKTOP_TYPE_ASH) 34 ShowAndFocusNativeWindowAura(window); 35 window->Show(); 36 // Always make sure the window hosting ash is visible and focused. 37 HWND hwnd = window->GetHost()->GetAcceleratedWidget(); 38 39 ::ShowWindow(hwnd, SW_SHOW); 40 41 if (GetForegroundWindow() != hwnd) { 42 VLOG(1) << "Forcefully refocusing front window"; 43 ui::ForegroundHelper::SetForeground(hwnd); 44 } 45 46 // ShowWindow does not necessarily activate the window. In particular if a 47 // window from another app is the foreground window then the request to 48 // activate the window fails. See SetForegroundWindow for details. 49 return GetForegroundWindow() == hwnd; 50 } 51 52 } // namespace ui_test_utils 53