Commit 7fc92bec authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Dark Mode: split out TestNativeTheme as a separate class/target

There was a handy dandy testing version of NativeTheme in
view_unittest.cc that I'd like to reuse in upcoming unit tests for WebUI
Dark Mode support (https://crrev.com/c/1354685).

BUG=883049
R=sky@chromium.org

Change-Id: Ie39f6c42f5069450ec9933b1b83d4cb615ab713d
Reviewed-on: https://chromium-review.googlesource.com/c/1357607
Commit-Queue: Dan Beam <dbeam@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613233}
parent daf8790a
...@@ -37,11 +37,14 @@ jumbo_component("native_theme") { ...@@ -37,11 +37,14 @@ jumbo_component("native_theme") {
defines = [ "NATIVE_THEME_IMPLEMENTATION" ] defines = [ "NATIVE_THEME_IMPLEMENTATION" ]
public_deps = [
"//skia",
]
deps = [ deps = [
"//base", "//base",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//cc/paint", "//cc/paint",
"//skia",
"//ui/base", "//ui/base",
"//ui/display", "//ui/display",
"//ui/gfx", "//ui/gfx",
...@@ -81,6 +84,20 @@ if (is_win) { ...@@ -81,6 +84,20 @@ if (is_win) {
} }
} }
jumbo_source_set("test_support") {
testonly = true
deps = [
":native_theme",
"//base",
]
sources = [
"test_native_theme.cc",
"test_native_theme.h",
]
}
test("native_theme_unittests") { test("native_theme_unittests") {
sources = [] sources = []
......
// Copyright 2018 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 "ui/native_theme/test_native_theme.h"
namespace ui {
TestNativeTheme::TestNativeTheme() {}
TestNativeTheme::~TestNativeTheme() {}
SkColor TestNativeTheme::GetSystemColor(ColorId color_id) const {
return SK_ColorRED;
}
gfx::Size TestNativeTheme::GetPartSize(Part part,
State state,
const ExtraParams& extra) const {
return gfx::Size();
}
void TestNativeTheme::Paint(cc::PaintCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const {}
bool TestNativeTheme::SupportsNinePatch(Part part) const {
return false;
}
gfx::Size TestNativeTheme::GetNinePatchCanvasSize(Part part) const {
return gfx::Size();
}
gfx::Rect TestNativeTheme::GetNinePatchAperture(Part part) const {
return gfx::Rect();
}
bool TestNativeTheme::UsesHighContrastColors() const {
return false;
}
bool TestNativeTheme::SystemDarkModeEnabled() const {
return dark_mode_;
}
} // namespace ui
// Copyright 2018 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 UI_NATIVE_THEME_TEST_NATIVE_THEME_H_
#define UI_NATIVE_THEME_TEST_NATIVE_THEME_H_
#include "base/macros.h"
#include "ui/native_theme/native_theme.h"
namespace ui {
class TestNativeTheme : public NativeTheme {
public:
TestNativeTheme();
~TestNativeTheme() override;
// NativeTheme:
SkColor GetSystemColor(ColorId color_id) const override;
gfx::Size GetPartSize(Part part,
State state,
const ExtraParams& extra) const override;
void Paint(cc::PaintCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const override;
bool SupportsNinePatch(Part part) const override;
gfx::Size GetNinePatchCanvasSize(Part part) const override;
gfx::Rect GetNinePatchAperture(Part part) const override;
bool UsesHighContrastColors() const override;
bool SystemDarkModeEnabled() const override;
void SetDarkMode(bool dark_mode) { dark_mode_ = dark_mode; }
private:
bool dark_mode_ = false;
DISALLOW_COPY_AND_ASSIGN(TestNativeTheme);
};
} // namespace ui
#endif // UI_NATIVE_THEME_TEST_NATIVE_THEME_H_
...@@ -1073,6 +1073,7 @@ source_set("views_unittests_sources") { ...@@ -1073,6 +1073,7 @@ source_set("views_unittests_sources") {
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//ui/gl:test_support", "//ui/gl:test_support",
"//ui/native_theme", "//ui/native_theme",
"//ui/native_theme:test_support",
"//ui/resources", "//ui/resources",
"//ui/resources:ui_test_pak", "//ui/resources:ui_test_pak",
"//ui/strings", "//ui/strings",
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/native_theme/test_native_theme.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
...@@ -4787,41 +4788,6 @@ class ViewThatAddsViewInOnNativeThemeChanged : public View { ...@@ -4787,41 +4788,6 @@ class ViewThatAddsViewInOnNativeThemeChanged : public View {
DISALLOW_COPY_AND_ASSIGN(ViewThatAddsViewInOnNativeThemeChanged); DISALLOW_COPY_AND_ASSIGN(ViewThatAddsViewInOnNativeThemeChanged);
}; };
// See comment above test for details.
class TestNativeTheme : public ui::NativeTheme {
public:
TestNativeTheme() {}
~TestNativeTheme() override {}
// ui::NativeTheme:
SkColor GetSystemColor(ColorId color_id) const override {
return SK_ColorRED;
}
gfx::Size GetPartSize(Part part,
State state,
const ExtraParams& extra) const override {
return gfx::Size();
}
void Paint(cc::PaintCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const override {}
bool SupportsNinePatch(Part part) const override { return false; }
gfx::Size GetNinePatchCanvasSize(Part part) const override {
return gfx::Size();
}
gfx::Rect GetNinePatchAperture(Part part) const override {
return gfx::Rect();
}
bool UsesHighContrastColors() const override { return false; }
bool SystemDarkModeEnabled() const override { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(TestNativeTheme);
};
// Creates and adds a new child view to |parent| that has a layer. // Creates and adds a new child view to |parent| that has a layer.
void AddViewWithChildLayer(View* parent) { void AddViewWithChildLayer(View* parent) {
View* child = new View; View* child = new View;
...@@ -4838,7 +4804,7 @@ void AddViewWithChildLayer(View* parent) { ...@@ -4838,7 +4804,7 @@ void AddViewWithChildLayer(View* parent) {
// before the layer hierarchy was updated. OnNativeThemeChanged() should be // before the layer hierarchy was updated. OnNativeThemeChanged() should be
// called after the layer hierarchy matches the view hierarchy. // called after the layer hierarchy matches the view hierarchy.
TEST_F(ViewTest, CrashOnAddFromFromOnNativeThemeChanged) { TEST_F(ViewTest, CrashOnAddFromFromOnNativeThemeChanged) {
TestNativeTheme theme; ui::TestNativeTheme theme;
WidgetWithCustomTheme widget(&theme); WidgetWithCustomTheme widget(&theme);
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
......
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