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
ash / system / channel_indicator / channel_indicator_quick_settings_view_pixeltest.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/system/channel_indicator/channel_indicator_quick_settings_view.h"
#include "base/memory/raw_ptr.h"
#include "ash/public/cpp/test/test_system_tray_client.h"
#include "ash/system/unified/quick_settings_header.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_model.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test_shell_delegate.h"
#include "components/version_info/channel.h"
#include "ui/views/widget/widget.h"
namespace ash {
class ChannelIndicatorQuickSettingsViewPixelTest : public AshTestBase {
public:
ChannelIndicatorQuickSettingsViewPixelTest() = default;
ChannelIndicatorQuickSettingsViewPixelTest(
const ChannelIndicatorQuickSettingsViewPixelTest&) = delete;
ChannelIndicatorQuickSettingsViewPixelTest& operator=(
const ChannelIndicatorQuickSettingsViewPixelTest&) = delete;
~ChannelIndicatorQuickSettingsViewPixelTest() override = default;
// AshTestBase:
void SetUp() override {
// Install a test delegate to allow overriding channel version.
auto delegate = std::make_unique<TestShellDelegate>();
delegate->set_channel(version_info::Channel::BETA);
AshTestBase::SetUp(std::move(delegate));
system_tray_client_ = GetSystemTrayClient();
system_tray_client_->set_user_feedback_enabled(true);
// Place the view in a large views::Widget so the buttons are clickable.
widget_ = CreateFramelessTestWidget();
widget_->SetFullscreen(true);
// Implicitly instantiate the view by creating the quick settings header.
model_ = base::MakeRefCounted<UnifiedSystemTrayModel>(nullptr);
controller_ = std::make_unique<UnifiedSystemTrayController>(model_.get());
auto header = std::make_unique<QuickSettingsHeader>(controller_.get());
header_ = header.get();
widget_->SetContentsView(std::move(header));
}
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
void TearDown() override {
controller_.reset();
model_.reset();
widget_.reset();
AshTestBase::TearDown();
}
QuickSettingsHeader* header() { return header_; }
ChannelIndicatorQuickSettingsView* view() {
return header()->channel_view_for_test();
}
private:
raw_ptr<TestSystemTrayClient, DanglingUntriaged> system_tray_client_ =
nullptr;
scoped_refptr<UnifiedSystemTrayModel> model_;
std::unique_ptr<UnifiedSystemTrayController> controller_;
std::unique_ptr<views::Widget> widget_;
raw_ptr<QuickSettingsHeader, DanglingUntriaged> header_ = nullptr;
};
// Verifies the UI when the feedback button is visible.
TEST_F(ChannelIndicatorQuickSettingsViewPixelTest, FeedbackButtonVisible) {
// Basic verification that buttons are visible before taking screenshot.
ASSERT_TRUE(header()->GetVisible());
ASSERT_TRUE(view());
ASSERT_TRUE(view()->version_button_for_test());
ASSERT_TRUE(view()->version_button_for_test()->GetVisible());
ASSERT_TRUE(view()->feedback_button_for_test());
ASSERT_TRUE(view()->feedback_button_for_test()->GetVisible());
// Don't capture any part of the UI except for
// `ChannelIndicatorQuickSettingsView`.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"feedback_button_visible",
/*revision_number=*/8, view()));
}
} // namespace ash