Commit e1a5b21e authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Test for DownloadShelfView button colors

Follow up with test for crrev.com/c/2316182

Bug: 1108710
Change-Id: I1e13c07dc4afb2d3f762d9361166a5005509326b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316966
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Auto-Submit: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794336}
parent 0c4ebdd5
......@@ -81,6 +81,8 @@ class DownloadShelfView : public DownloadShelf,
views::View* GetDefaultFocusableChild() override;
private:
FRIEND_TEST_ALL_PREFIXES(DownloadShelfViewTest, ShowAllViewColors);
// The animation for adding new items to the shelf.
gfx::SlideAnimation new_item_animation_;
......
// Copyright 2020 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 "chrome/browser/ui/views/download/download_shelf_view.h"
#include <memory>
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/test_theme_provider.h"
#include "chrome/test/views/chrome_test_widget.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h"
using DownloadShelfViewTest = BrowserWithTestWindowTest;
TEST_F(DownloadShelfViewTest, ShowAllViewColors) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
params.context = GetContext();
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
ChromeTestWidget widget;
widget.Init(std::move(params));
DownloadShelfView view(browser(), nullptr);
widget.SetContentsView(&view);
views::MdTextButton* button = view.show_all_view_;
// With default theme, button should have GoogleBlue600 text and no bg.
EXPECT_FALSE(button->GetBgColorOverride().has_value());
SkColor default_text_color = button->GetCurrentTextColor();
// Custom theme will update text and bg.
auto custom_theme = std::make_unique<TestThemeProvider>();
custom_theme->SetColor(ThemeProperties::COLOR_DOWNLOAD_SHELF, SK_ColorGREEN);
custom_theme->SetColor(ThemeProperties::COLOR_BOOKMARK_TEXT, SK_ColorYELLOW);
widget.SetThemeProvider(std::move(custom_theme));
// The button bg color is derived from the shelf color by applying a tint.
// We will verify that a color has been set, and that it is different to the
// shelf color.
EXPECT_TRUE(button->GetBgColorOverride().has_value());
EXPECT_NE(button->GetBgColorOverride(), SK_ColorGREEN);
EXPECT_EQ(button->GetCurrentTextColor(), SK_ColorYELLOW);
// Setting back to a default theme will revert.
widget.SetThemeProvider(std::make_unique<TestThemeProvider>());
EXPECT_FALSE(button->GetBgColorOverride().has_value());
EXPECT_EQ(button->GetCurrentTextColor(), default_text_color);
}
......@@ -363,6 +363,8 @@ static_library("test_support") {
"../browser/ui/views/media_router/app_menu_test_api_views.cc",
"../browser/ui/views/web_apps/web_app_frame_toolbar_test_mixin.cc",
"../browser/ui/views/web_apps/web_app_frame_toolbar_test_mixin.h",
"base/test_theme_provider.cc",
"base/test_theme_provider.h",
"views/accessibility_checker.cc",
"views/accessibility_checker.h",
"views/chrome_test_views_delegate.h",
......@@ -5520,6 +5522,7 @@ test("unit_tests") {
"../browser/ui/views/desktop_capture/desktop_media_picker_views_unittest.cc",
"../browser/ui/views/device_chooser_content_view_unittest.cc",
"../browser/ui/views/download/download_in_progress_dialog_view_unittest.cc",
"../browser/ui/views/download/download_shelf_view_unittest.cc",
"../browser/ui/views/extensions/chooser_dialog_view_unittest.cc",
"../browser/ui/views/extensions/expandable_container_view_unittest.cc",
"../browser/ui/views/extensions/extensions_menu_item_unittest.cc",
......
// Copyright 2020 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 "chrome/test/base/test_theme_provider.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
TestThemeProvider::TestThemeProvider() = default;
TestThemeProvider::~TestThemeProvider() = default;
gfx::ImageSkia* TestThemeProvider::GetImageSkiaNamed(int id) const {
return nullptr;
}
SkColor TestThemeProvider::GetColor(int id) const {
auto it = colors_.find(id);
return it != colors_.end() ? it->second : gfx::kPlaceholderColor;
}
color_utils::HSL TestThemeProvider::GetTint(int id) const {
return color_utils::HSL();
}
int TestThemeProvider::GetDisplayProperty(int id) const {
return -1;
}
bool TestThemeProvider::ShouldUseNativeFrame() const {
return false;
}
bool TestThemeProvider::HasCustomImage(int id) const {
return false;
}
bool TestThemeProvider::HasCustomColor(int id) const {
return colors_.find(id) != colors_.end();
}
base::RefCountedMemory* TestThemeProvider::GetRawData(
int id,
ui::ScaleFactor scale_factor) const {
return nullptr;
}
void TestThemeProvider::SetColor(int id, SkColor color) {
colors_[id] = color;
}
// Copyright 2020 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.
#ifndef CHROME_TEST_BASE_TEST_THEME_PROVIDER_H_
#define CHROME_TEST_BASE_TEST_THEME_PROVIDER_H_
#include "base/containers/flat_map.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/theme_provider.h"
// Test ui::ThemeProvider implementation.
class TestThemeProvider : public ui::ThemeProvider {
public:
TestThemeProvider();
~TestThemeProvider() override;
// ui::ThemeProvider:
gfx::ImageSkia* GetImageSkiaNamed(int id) const override;
SkColor GetColor(int id) const override;
color_utils::HSL GetTint(int id) const override;
int GetDisplayProperty(int id) const override;
bool ShouldUseNativeFrame() const override;
bool HasCustomImage(int id) const override;
bool HasCustomColor(int id) const override;
base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
const override;
// Set a custom color.
void SetColor(int id, SkColor color);
private:
base::flat_map<int, SkColor> colors_;
};
#endif // CHROME_TEST_BASE_TEST_THEME_PROVIDER_H_
......@@ -6,42 +6,20 @@
#include <memory>
#include "chrome/test/base/test_theme_provider.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
namespace base {
class RefCountedMemory;
}
namespace gfx {
class ImageSkia;
}
class ChromeTestWidget::StubThemeProvider : public ui::ThemeProvider {
public:
StubThemeProvider() = default;
~StubThemeProvider() override = default;
// ui::ThemeProvider:
gfx::ImageSkia* GetImageSkiaNamed(int id) const override { return nullptr; }
SkColor GetColor(int id) const override { return gfx::kPlaceholderColor; }
color_utils::HSL GetTint(int id) const override { return color_utils::HSL(); }
int GetDisplayProperty(int id) const override { return -1; }
bool ShouldUseNativeFrame() const override { return false; }
bool HasCustomImage(int id) const override { return false; }
bool HasCustomColor(int id) const override { return false; }
base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
const override {
return nullptr;
}
};
ChromeTestWidget::ChromeTestWidget()
: theme_provider_(std::make_unique<StubThemeProvider>()) {}
: theme_provider_(std::make_unique<TestThemeProvider>()) {}
ChromeTestWidget::~ChromeTestWidget() = default;
const ui::ThemeProvider* ChromeTestWidget::GetThemeProvider() const {
return theme_provider_.get();
}
void ChromeTestWidget::SetThemeProvider(
std::unique_ptr<ui::ThemeProvider> theme_provider) {
theme_provider_.swap(theme_provider);
ThemeChanged();
}
......@@ -21,10 +21,11 @@ class ChromeTestWidget : public views::Widget {
// views::Widget:
const ui::ThemeProvider* GetThemeProvider() const override;
private:
class StubThemeProvider;
// Set new ThemeProvider. Calls ThemeChanged.
void SetThemeProvider(std::unique_ptr<ui::ThemeProvider> theme_provider);
std::unique_ptr<StubThemeProvider> theme_provider_;
private:
std::unique_ptr<ui::ThemeProvider> theme_provider_;
};
#endif // CHROME_TEST_VIEWS_CHROME_TEST_WIDGET_H_
......@@ -129,6 +129,10 @@ void LabelButton::SetEnabledTextColors(base::Optional<SkColor> color) {
ResetColorsFromNativeTheme();
}
SkColor LabelButton::GetCurrentTextColor() const {
return label_->GetEnabledColor();
}
void LabelButton::SetTextShadows(const gfx::ShadowValues& shadows) {
label_->SetShadows(shadows);
}
......
......@@ -67,6 +67,9 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// Sets the text colors shown for the non-disabled states to |color|.
virtual void SetEnabledTextColors(base::Optional<SkColor> color);
// Gets the current state text color.
SkColor GetCurrentTextColor() const;
// Sets drop shadows underneath the text.
void SetTextShadows(const gfx::ShadowValues& shadows);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment