1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/download/download_shelf_view.h"
6
7 #include <memory>
8
9 #include "chrome/browser/themes/theme_properties.h"
10 #include "chrome/test/base/browser_with_test_window_test.h"
11 #include "chrome/test/base/test_theme_provider.h"
12 #include "chrome/test/views/chrome_test_widget.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/button/md_text_button.h"
16
17 using DownloadShelfViewTest = BrowserWithTestWindowTest;
18
TEST_F(DownloadShelfViewTest,ShowAllViewColors)19 TEST_F(DownloadShelfViewTest, ShowAllViewColors) {
20 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
21 params.context = GetContext();
22 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
23 ChromeTestWidget widget;
24 widget.Init(std::move(params));
25 DownloadShelfView* view = widget.SetContentsView(
26 std::make_unique<DownloadShelfView>(browser(), nullptr));
27 views::MdTextButton* button = view->show_all_view_;
28
29 // With default theme, button should have GoogleBlue600 text and no bg.
30 EXPECT_FALSE(button->GetBgColorOverride().has_value());
31 SkColor default_text_color = button->GetCurrentTextColor();
32
33 // Custom theme will update text and bg.
34 auto custom_theme = std::make_unique<TestThemeProvider>();
35 custom_theme->SetColor(ThemeProperties::COLOR_DOWNLOAD_SHELF, SK_ColorGREEN);
36 custom_theme->SetColor(ThemeProperties::COLOR_BOOKMARK_TEXT, SK_ColorYELLOW);
37 widget.SetThemeProvider(std::move(custom_theme));
38 // The button bg color is derived from the shelf color by applying a tint.
39 // We will verify that a color has been set, and that it is different to the
40 // shelf color.
41 EXPECT_TRUE(button->GetBgColorOverride().has_value());
42 EXPECT_NE(button->GetBgColorOverride(), SK_ColorGREEN);
43 EXPECT_EQ(button->GetCurrentTextColor(), SK_ColorYELLOW);
44
45 // Setting back to a default theme will revert.
46 widget.SetThemeProvider(std::make_unique<TestThemeProvider>());
47 EXPECT_FALSE(button->GetBgColorOverride().has_value());
48 EXPECT_EQ(button->GetCurrentTextColor(), default_text_color);
49 }
50