Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / test / base / interactive_test_utils_win.cc
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 "ui/base/test/ui_controls.h"
13 #include "ui/base/win/foreground_helper.h"
14 #include "ui/views/focus/focus_manager.h"
15
16 #if defined(USE_AURA)
17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/test/base/interactive_test_utils_aura.h"
19 #include "ui/aura/window_tree_host.h"
20 #endif
21
22 namespace ui_test_utils {
23
24 void HideNativeWindow(gfx::NativeWindow window) {
25 #if defined(USE_AURA)
26   if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
27       chrome::HOST_DESKTOP_TYPE_ASH) {
28     HideNativeWindowAura(window);
29     return;
30   }
31   HWND hwnd = window->GetHost()->GetAcceleratedWidget();
32 #else
33   HWND hwnd = window;
34 #endif
35   ::ShowWindow(hwnd, SW_HIDE);
36 }
37
38 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
39 #if defined(USE_AURA)
40   if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
41       chrome::HOST_DESKTOP_TYPE_ASH)
42     ShowAndFocusNativeWindowAura(window);
43   window->Show();
44   // Always make sure the window hosting ash is visible and focused.
45   HWND hwnd = window->GetHost()->GetAcceleratedWidget();
46 #else
47   HWND hwnd = window;
48 #endif
49
50   ::ShowWindow(hwnd, SW_SHOW);
51
52   if (GetForegroundWindow() != hwnd) {
53     VLOG(1) << "Forcefully refocusing front window";
54     ui::ForegroundHelper::SetForeground(hwnd);
55   }
56
57   // ShowWindow does not necessarily activate the window. In particular if a
58   // window from another app is the foreground window then the request to
59   // activate the window fails. See SetForegroundWindow for details.
60   return GetForegroundWindow() == hwnd;
61 }
62
63 }  // namespace ui_test_utils