File: test_browser_window_aura.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (144 lines) | stat: -rw-r--r-- 4,132 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

#include <memory>
#include <utility>

#include "base/memory/ptr_util.h"
#include "chrome/browser/ui/browser.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/activation_client.h"

namespace chrome {

std::unique_ptr<Browser> CreateBrowserWithAuraTestWindowForParams(
    std::unique_ptr<aura::Window> window,
    Browser::CreateParams* params) {
  if (!window) {
    window = std::make_unique<aura::Window>(nullptr);
    window->SetId(0);
    window->SetType(aura::client::WINDOW_TYPE_NORMAL);
    window->Init(ui::LAYER_TEXTURED);
    window->Show();
  }
  auto browser_window =
      std::make_unique<TestBrowserWindowAura>(std::move(window));
  auto browser = browser_window->CreateBrowser(params);
  // Self deleting.
  new TestBrowserWindowOwner(std::move(browser_window));
  return browser;
}

std::unique_ptr<Browser> CreateBrowserWithViewsTestWindowForParams(
    const Browser::CreateParams& params,
    aura::Window* parent) {
  auto browser_window = std::make_unique<TestBrowserWindowViews>(parent);
  auto browser = browser_window->CreateBrowser(params);
  // Self deleting.
  new TestBrowserWindowOwner(std::move(browser_window));
  return browser;
}

}  // namespace chrome

TestBrowserWindowAura::TestBrowserWindowAura(
    std::unique_ptr<aura::Window> native_window)
    : native_window_(std::move(native_window)) {}

TestBrowserWindowAura::~TestBrowserWindowAura() = default;

gfx::NativeWindow TestBrowserWindowAura::GetNativeWindow() const {
  return native_window_.get();
}

void TestBrowserWindowAura::Show() {
  native_window_->Show();
}

void TestBrowserWindowAura::Hide() {
  native_window_->Hide();
}

bool TestBrowserWindowAura::IsVisible() const {
  return native_window_->IsVisible();
}

void TestBrowserWindowAura::Activate() {
  CHECK(native_window_->GetRootWindow())
      << "A TestBrowserWindowAura must have a root window to be activated.";
  ::wm::GetActivationClient(native_window_->GetRootWindow())
      ->ActivateWindow(native_window_.get());
}

bool TestBrowserWindowAura::IsActive() const {
  // A test window might not be parented.
  if (!native_window_->GetRootWindow())
    return false;
  return ::wm::GetActivationClient(native_window_->GetRootWindow())
             ->GetActiveWindow() == native_window_.get();
}

gfx::Rect TestBrowserWindowAura::GetBounds() const {
  return native_window_->bounds();
}

std::unique_ptr<Browser> TestBrowserWindowAura::CreateBrowser(
    Browser::CreateParams* params) {
  params->window = this;
  auto browser = Browser::DeprecatedCreateOwnedForTesting(*params);
  browser_ = browser.get();
  return browser;
}

TestBrowserWindowViews::TestBrowserWindowViews(aura::Window* parent)
    : widget_(std::make_unique<views::Widget>()) {
  views::Widget::InitParams params(
      views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET,
      views::Widget::InitParams::TYPE_WINDOW);
  params.bounds = gfx::Rect(5, 5, 20, 20);
  params.parent = parent;
  widget_->Init(std::move(params));
}

TestBrowserWindowViews::~TestBrowserWindowViews() = default;

gfx::NativeWindow TestBrowserWindowViews::GetNativeWindow() const {
  return widget_->GetNativeWindow();
}

void TestBrowserWindowViews::Show() {
  widget_->Show();
}

void TestBrowserWindowViews::Hide() {
  widget_->Hide();
}

bool TestBrowserWindowViews::IsVisible() const {
  return widget_->IsVisible();
}

void TestBrowserWindowViews::Activate() {
  widget_->Activate();
}

bool TestBrowserWindowViews::IsActive() const {
  return widget_->IsActive();
}

gfx::Rect TestBrowserWindowViews::GetBounds() const {
  return widget_->GetWindowBoundsInScreen();
}

std::unique_ptr<Browser> TestBrowserWindowViews::CreateBrowser(
    const Browser::CreateParams& params) {
  Browser::CreateParams params_copy = params;
  params_copy.window = this;
  auto browser = Browser::DeprecatedCreateOwnedForTesting(params_copy);
  browser_ = browser.get();
  return browser;
}