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.
5 #include "chrome/test/base/interactive_test_utils.h"
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/window_snapshot/window_snapshot.h"
13 #include "ui/base/test/ui_controls.h"
14 #include "ui/base/win/foreground_helper.h"
15 #include "ui/views/focus/focus_manager.h"
18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/test/base/interactive_test_utils_aura.h"
20 #include "ui/aura/root_window.h"
23 namespace ui_test_utils {
25 void HideNativeWindow(gfx::NativeWindow window) {
27 if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
28 chrome::HOST_DESKTOP_TYPE_ASH) {
29 HideNativeWindowAura(window);
32 HWND hwnd = window->GetDispatcher()->GetAcceleratedWidget();
36 ::ShowWindow(hwnd, SW_HIDE);
39 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
41 if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
42 chrome::HOST_DESKTOP_TYPE_ASH)
43 ShowAndFocusNativeWindowAura(window);
45 // Always make sure the window hosting ash is visible and focused.
46 HWND hwnd = window->GetDispatcher()->GetAcceleratedWidget();
51 ::ShowWindow(hwnd, SW_SHOW);
53 if (GetForegroundWindow() != hwnd) {
54 VLOG(1) << "Forcefully refocusing front window";
55 ui::ForegroundHelper::SetForeground(hwnd);
58 // ShowWindow does not necessarily activate the window. In particular if a
59 // window from another app is the foreground window then the request to
60 // activate the window fails. See SetForegroundWindow for details.
61 return GetForegroundWindow() == hwnd;
64 } // namespace ui_test_utils