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
ash / system / tray / tray_detailed_view_unittest.cc [blame]
// Copyright 2024 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/system/tray/tray_detailed_view.h"
#include <memory>
#include <utility>
#include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/fake_detailed_view_delegate.h"
#include "ash/test/ash_test_base.h"
#include "ui/views/controls/scroll_view.h"
namespace ash {
class TrayDetailedViewTest : public AshTestBase {
public:
TrayDetailedViewTest() {
delegate_ = std::make_unique<FakeDetailedViewDelegate>();
detailed_view_ = std::make_unique<TrayDetailedView>(delegate_.get());
detailed_view_->CreateScrollableList();
}
void CreateZeroStateView(std::unique_ptr<ZeroStateView> view) {
detailed_view_->CreateZeroStateView(std::move(view));
}
void SetZeroStateViewVisibility(bool visibility) {
detailed_view_->SetZeroStateViewVisibility(visibility);
}
TrayDetailedViewTest(const TrayDetailedViewTest&) = delete;
TrayDetailedViewTest& operator=(const TrayDetailedViewTest&) = delete;
protected:
std::unique_ptr<TrayDetailedView> detailed_view_;
std::unique_ptr<FakeDetailedViewDelegate> delegate_;
};
TEST_F(TrayDetailedViewTest, CreateZeroStateView) {
auto zero_state_view = std::make_unique<ZeroStateView>(
IDR_MAHI_GENERAL_ERROR_STATUS_IMAGE,
IDS_ASH_STATUS_TRAY_CAST_ZERO_STATE_TITLE,
IDS_ASH_STATUS_TRAY_CAST_ZERO_STATE_SUBTITLE);
auto zero_state_view_ptr = zero_state_view.get();
const int scroller_index = detailed_view_
->GetIndexOf(static_cast<views::View*>(
detailed_view_->scroll_view_for_testing()))
.value();
CreateZeroStateView((std::move(zero_state_view)));
EXPECT_EQ(detailed_view_->zero_state_view_for_testing(), zero_state_view_ptr);
const int zero_state_view_index =
detailed_view_->GetIndexOf(detailed_view_->zero_state_view_for_testing())
.value();
EXPECT_EQ(zero_state_view_index, scroller_index);
EXPECT_FALSE(zero_state_view_ptr->GetVisible());
}
TEST_F(TrayDetailedViewTest, SetZeroStateViewVisibility) {
auto zero_state_view = std::make_unique<ZeroStateView>(
IDR_MAHI_GENERAL_ERROR_STATUS_IMAGE,
IDS_ASH_STATUS_TRAY_CAST_ZERO_STATE_TITLE,
IDS_ASH_STATUS_TRAY_CAST_ZERO_STATE_SUBTITLE);
auto zero_state_view_ptr = zero_state_view.get();
CreateZeroStateView(std::move(zero_state_view));
SetZeroStateViewVisibility(true);
EXPECT_TRUE(zero_state_view_ptr->GetVisible());
EXPECT_FALSE(detailed_view_->scroll_view_for_testing()->GetVisible());
SetZeroStateViewVisibility(false);
EXPECT_FALSE(zero_state_view_ptr->GetVisible());
EXPECT_TRUE(detailed_view_->scroll_view_for_testing()->GetVisible());
SetZeroStateViewVisibility(true);
EXPECT_TRUE(zero_state_view_ptr->GetVisible());
EXPECT_FALSE(detailed_view_->scroll_view_for_testing()->GetVisible());
}
} // namespace ash