summaryrefslogtreecommitdiffstats
path: root/chrome/test/base/interactive_test_utils_win.cc
blob: 970fd1dacc0bab1e41dd3e8489766f10a3b17111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/base/interactive_test_utils.h"

#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/stringprintf.h"
#include "base/time.h"
#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
#include "chrome/test/base/ui_controls.h"
#include "ui/base/win/foreground_helper.h"
#include "ui/views/focus/focus_manager.h"

#if defined(USE_AURA)
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/test/base/interactive_test_utils_aura.h"
#include "ui/aura/root_window.h"
#endif

namespace ui_test_utils {

void HideNativeWindow(gfx::NativeWindow window) {
#if defined(USE_AURA)
  if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
      chrome::HOST_DESKTOP_TYPE_ASH) {
    HideNativeWindowAura(window);
    return;
  }
  HWND hwnd = window->GetRootWindow()->GetAcceleratedWidget();
#else
  HWND hwnd = window;
#endif
  ::ShowWindow(hwnd, SW_HIDE);
}

bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
#if defined(USE_AURA)
  if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
      chrome::HOST_DESKTOP_TYPE_ASH)
    ShowAndFocusNativeWindowAura(window);
  // Always make sure the window hosting ash is visible and focused.
  HWND hwnd = window->GetRootWindow()->GetAcceleratedWidget();
#else
  HWND hwnd = window;
#endif

  ::ShowWindow(hwnd, SW_SHOW);

  if (GetForegroundWindow() != hwnd) {
    VLOG(1) << "Forcefully refocusing front window";
    ui::ForegroundHelper::SetForeground(hwnd);
  }

  // ShowWindow does not necessarily activate the window. In particular if a
  // window from another app is the foreground window then the request to
  // activate the window fails. See SetForegroundWindow for details.
  return GetForegroundWindow() == hwnd;
}

}  // namespace ui_test_utils