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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
ash / components / arc / metrics / arc_wm_metrics_unittest.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/components/arc/metrics/arc_wm_metrics.h"
#include <memory>
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "base/test/metrics/histogram_tester.h"
#include "chromeos/ui/base/app_types.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/mojom/window_show_state.mojom.h"
#include "ui/views/widget/widget.h"
namespace arc {
class ArcWmMetricsTest : public ash::AshTestBase {
public:
ArcWmMetricsTest() = default;
ArcWmMetricsTest(const ArcWmMetricsTest&) = delete;
ArcWmMetricsTest& operator=(const ArcWmMetricsTest&) = delete;
~ArcWmMetricsTest() override = default;
void SetUp() override {
ash::AshTestBase::SetUp();
arc_wm_metrics_ = std::make_unique<ArcWmMetrics>();
}
void TearDown() override {
arc_wm_metrics_.reset();
ash::AshTestBase::TearDown();
}
void OnWindowCloseRequested(aura::Window* window) {
arc_wm_metrics_->OnWindowCloseRequested(window);
}
void OnDisplayRotated() {
arc_wm_metrics_->OnScreenCopiedBeforeRotation();
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
ash::Shell::Get()->display_manager()->SetDisplayRotation(
display.id(), display::Display::ROTATE_90,
display::Display::RotationSource::USER);
}
private:
std::unique_ptr<ArcWmMetrics> arc_wm_metrics_;
};
TEST_F(ArcWmMetricsTest, TestWindowMaximizeDelayMetrics) {
chromeos::AppType app_type = chromeos::AppType::ARC_APP;
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100), app_type);
window->SetProperty(aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorCanMaximize);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetWindowMaximizedTimeHistogramName(app_type);
histogram_tester.ExpectTotalCount(histogram_name, 0);
auto* widget = views::Widget::GetWidgetForNativeWindow(window.get());
widget->Maximize();
histogram_tester.ExpectTotalCount(histogram_name, 1);
// If the old window state type is not `kNormal`, the data should not be
// recorded in histogram.
widget->Minimize();
widget->Maximize();
histogram_tester.ExpectTotalCount(histogram_name, 1);
// The histogram should not record data when maximizing in tablet mode.
ash::TabletModeControllerTestApi().EnterTabletMode();
window->SetProperty(aura::client::kShowStateKey,
ui::mojom::WindowShowState::kNormal);
widget->Maximize();
histogram_tester.ExpectTotalCount(histogram_name, 1);
}
TEST_F(ArcWmMetricsTest, TestWindowMinimizeDelayMetrics) {
chromeos::AppType app_type = chromeos::AppType::ARC_APP;
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100), app_type);
window->SetProperty(aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorCanMinimize);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetWindowMinimizedTimeHistogramName(app_type);
histogram_tester.ExpectTotalCount(histogram_name, 0);
auto* widget = views::Widget::GetWidgetForNativeWindow(window.get());
widget->Minimize();
histogram_tester.ExpectTotalCount(histogram_name, 1);
// The histogram should not record data when minimizing in tablet mode.
ash::TabletModeControllerTestApi().EnterTabletMode();
widget->Maximize();
widget->Minimize();
histogram_tester.ExpectTotalCount(histogram_name, 1);
}
TEST_F(ArcWmMetricsTest, TestWindowCloseDelayMetrics) {
auto window =
CreateAppWindow(gfx::Rect(0, 0, 100, 100), chromeos::AppType::ARC_APP);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetArcWindowClosedTimeHistogramName();
histogram_tester.ExpectTotalCount(histogram_name, 0);
OnWindowCloseRequested(window.get());
histogram_tester.ExpectTotalCount(histogram_name, 0);
window.reset();
histogram_tester.ExpectTotalCount(histogram_name, 1);
}
TEST_F(ArcWmMetricsTest, TestWindowEnterTabletModeDelayMetrics) {
chromeos::AppType app_type = chromeos::AppType::ARC_APP;
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100), app_type);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetWindowEnterTabletModeTimeHistogramName(app_type);
histogram_tester.ExpectTotalCount(histogram_name, 0);
ash::TabletModeControllerTestApi().EnterTabletMode();
histogram_tester.ExpectTotalCount(histogram_name, 1);
// Window maximizing histogram should not record data.
histogram_tester.ExpectTotalCount(
ArcWmMetrics::GetWindowMaximizedTimeHistogramName(app_type), 0);
}
TEST_F(ArcWmMetricsTest, TestMultipleWindowsEnterTabletModeDelayMetrics) {
auto lower_window =
CreateAppWindow(gfx::Rect(0, 0, 100, 100), chromeos::AppType::BROWSER);
lower_window->Show();
auto upper_window =
CreateAppWindow(gfx::Rect(0, 0, 100, 100), chromeos::AppType::ARC_APP);
upper_window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name_lower_window =
ArcWmMetrics::GetWindowEnterTabletModeTimeHistogramName(
chromeos::AppType::BROWSER);
const auto histogram_name_upper_window =
ArcWmMetrics::GetWindowEnterTabletModeTimeHistogramName(
chromeos::AppType::ARC_APP);
histogram_tester.ExpectTotalCount(histogram_name_lower_window, 0);
histogram_tester.ExpectTotalCount(histogram_name_upper_window, 0);
// Only the data of upper window should be recorded.
ash::TabletModeControllerTestApi().EnterTabletMode();
histogram_tester.ExpectTotalCount(histogram_name_lower_window, 0);
histogram_tester.ExpectTotalCount(histogram_name_upper_window, 1);
}
TEST_F(ArcWmMetricsTest, TestWindowLeaveTabletModeDelayMetrics) {
chromeos::AppType app_type = chromeos::AppType::ARC_APP;
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100), app_type);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetWindowExitTabletModeTimeHistogramName(app_type);
histogram_tester.ExpectTotalCount(histogram_name, 0);
ash::TabletModeControllerTestApi().EnterTabletMode();
histogram_tester.ExpectTotalCount(histogram_name, 0);
ash::TabletModeControllerTestApi().LeaveTabletMode();
histogram_tester.ExpectTotalCount(histogram_name, 1);
// If the window state of a window is maximized before entering into tablet
// mode, its window state should remains maximized after exiting tablet mode.
// In this case, histogram should not records data.
views::Widget::GetWidgetForNativeWindow(window.get())->Maximize();
ash::TabletModeControllerTestApi().EnterTabletMode();
histogram_tester.ExpectTotalCount(histogram_name, 1);
ash::TabletModeControllerTestApi().LeaveTabletMode();
histogram_tester.ExpectTotalCount(histogram_name, 1);
}
TEST_F(ArcWmMetricsTest, TestWindowRotateDelayOnDisplayRotationMetrics) {
chromeos::AppType app_type = chromeos::AppType::ARC_APP;
auto window = CreateAppWindow(gfx::Rect(0, 0, 100, 100), app_type);
window->Show();
base::HistogramTester histogram_tester;
const auto histogram_name =
ArcWmMetrics::GetWindowRotateTimeHistogramName(app_type);
histogram_tester.ExpectTotalCount(histogram_name, 0);
// UMA only records data when display rotates in tablet mode.
ash::TabletModeControllerTestApi().EnterTabletMode();
OnDisplayRotated();
histogram_tester.ExpectTotalCount(histogram_name, 1);
}
} // namespace arc