diff --git a/browser/farbling/BUILD.gn b/browser/farbling/BUILD.gn index 077e80e3b42..7a715e6ecce 100644 --- a/browser/farbling/BUILD.gn +++ b/browser/farbling/BUILD.gn @@ -45,6 +45,7 @@ if (!is_android) { "//components/prefs", "//content/public/browser", "//content/test:test_support", + "//ui/color:test_support", "//ui/native_theme:test_support", ] } diff --git a/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc b/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc index b0dacb3743a..f8001b7ca6c 100644 --- a/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc +++ b/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc @@ -24,6 +24,9 @@ #include "content/public/test/browser_test.h" #include "content/public/test/browser_test_utils.h" #include "net/dns/mock_host_resolver.h" +#include "ui/color/color_provider.h" +#include "ui/color/color_provider_manager.h" +#include "ui/color/color_provider_source.h" #include "ui/native_theme/test_native_theme.h" using brave_shields::ControlType; @@ -48,6 +51,30 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { const raw_ptr theme_; }; + class MockColorProviderSource : public ui::ColorProviderSource { + public: + explicit MockColorProviderSource(bool is_dark) { + key_.color_mode = is_dark ? ui::ColorProviderManager::ColorMode::kDark + : ui::ColorProviderManager::ColorMode::kLight; + provider_.GenerateColorMap(); + } + MockColorProviderSource(const MockColorProviderSource&) = delete; + MockColorProviderSource& operator=(const MockColorProviderSource&) = delete; + ~MockColorProviderSource() override = default; + + // ui::ColorProviderSource: + const ui::ColorProvider* GetColorProvider() const override { + return &provider_; + } + ui::ColorProviderManager::Key GetColorProviderKey() const override { + return key_; + } + + private: + ui::ColorProvider provider_; + ui::ColorProviderManager::Key key_; + }; + void SetUpOnMainThread() override { InProcessBrowserTest::SetUpOnMainThread(); @@ -93,6 +120,11 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { void SetDarkMode(bool dark_mode) { test_theme_.SetDarkMode(dark_mode); + browser() + ->tab_strip_model() + ->GetActiveWebContents() + ->SetColorProviderSource(dark_mode ? &dark_color_provider_source_ + : &light_color_provider_source_); browser() ->tab_strip_model() ->GetActiveWebContents() @@ -126,6 +158,8 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { protected: ui::TestNativeTheme test_theme_; + MockColorProviderSource dark_color_provider_source_{true}; + MockColorProviderSource light_color_provider_source_{false}; private: GURL top_level_page_url_;