-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
phone_hub_recent_apps_view_unittest.cc
111 lines (86 loc) · 3.42 KB
/
phone_hub_recent_apps_view_unittest.cc
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
// Copyright 2021 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 "ash/system/phonehub/phone_hub_recent_apps_view.h"
#include "ash/system/phonehub/phone_hub_recent_app_button.h"
#include "ash/test/ash_test_base.h"
#include "chromeos/components/phonehub/fake_recent_apps_interaction_handler.h"
#include "chromeos/components/phonehub/notification.h"
#include "ui/gfx/image/image.h"
#include "ui/views/test/button_test_api.h"
namespace ash {
const char16_t kAppName[] = u"Test App";
const char kPackageName[] = "com.google.testapp";
namespace {
class FakeEvent : public ui::Event {
public:
FakeEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {}
};
} // namespace
class RecentAppButtonsViewTest : public AshTestBase {
public:
RecentAppButtonsViewTest() = default;
~RecentAppButtonsViewTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
phone_hub_recent_apps_view_ = std::make_unique<PhoneHubRecentAppsView>(
&fake_recent_apps_interaction_handler_);
}
void TearDown() override {
phone_hub_recent_apps_view_.reset();
AshTestBase::TearDown();
}
protected:
PhoneHubRecentAppsView* recent_apps_view() {
return phone_hub_recent_apps_view_.get();
}
void NotifyRecentAppAddedOrUpdated() {
fake_recent_apps_interaction_handler_.NotifyRecentAppAddedOrUpdated(
chromeos::phonehub::Notification::AppMetadata(kAppName, kPackageName,
/*icon=*/gfx::Image()),
base::Time::Now());
}
size_t PackageNameToClickCount(const std::string& package_name) {
return fake_recent_apps_interaction_handler_.HandledRecentAppsCount(
package_name);
}
private:
std::unique_ptr<PhoneHubRecentAppsView> phone_hub_recent_apps_view_;
chromeos::phonehub::FakeRecentAppsInteractionHandler
fake_recent_apps_interaction_handler_;
};
TEST_F(RecentAppButtonsViewTest, TaskViewVisibility) {
// The recent app view is not visible if the NotifyRecentAppAddedOrUpdated
// function never be called, e.g. device boot.
EXPECT_FALSE(recent_apps_view()->GetVisible());
NotifyRecentAppAddedOrUpdated();
recent_apps_view()->Update();
EXPECT_TRUE(recent_apps_view()->GetVisible());
}
TEST_F(RecentAppButtonsViewTest, SingleRecentAppButtonsView) {
NotifyRecentAppAddedOrUpdated();
recent_apps_view()->Update();
size_t expected_recent_app_button = 1;
EXPECT_EQ(expected_recent_app_button,
recent_apps_view()->recent_app_buttons_view_->children().size());
}
TEST_F(RecentAppButtonsViewTest, MultipleRecentAppButtonsView) {
NotifyRecentAppAddedOrUpdated();
NotifyRecentAppAddedOrUpdated();
NotifyRecentAppAddedOrUpdated();
recent_apps_view()->Update();
size_t expected_recent_app_button = 3;
EXPECT_EQ(expected_recent_app_button,
recent_apps_view()->recent_app_buttons_view_->children().size());
for (auto* child : recent_apps_view()->recent_app_buttons_view_->children()) {
PhoneHubRecentAppButton* recent_app =
static_cast<PhoneHubRecentAppButton*>(child);
// Simulate clicking button using placeholder event.
views::test::ButtonTestApi(recent_app).NotifyClick(FakeEvent());
}
size_t expected_number_of_button_be_clicked = 3;
EXPECT_EQ(expected_number_of_button_be_clicked,
PackageNameToClickCount(kPackageName));
}
} // namespace ash