Fixes dark mode fingerprinting browser tests.
Chromium change: https://chromium.googlesource.com/chromium/src/+/c6b1f22dbe7db commit c6b1f22dbe7db922f5064272de4447bf4d5b777f Author: Thomas Lukaszewicz <tluk@chromium.org> Date: Tue Jun 13 18:24:50 2023 +0000 [color] Set PreferredColorScheme to track the Browser for WebUI Current UX guidance is to have WebUI follow the color scheme of the browser, and to have web content continue to follow the color scheme of the global NativeTheme instance. This CL updates Chrome WebUI's preferred-color-scheme to track the ColorMode of its associated ColorProvider. This addresses the current gap between Views and WebUI where Views UI tracks the ColorMode of its associated ColorProvider (which can be unique per UI tree), while WebUI tracks the ColorMode of the global NativeTheme provider instance. Bug: 1431202
This commit is contained in:
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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<const ui::NativeTheme> 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_;
|
||||
|
||||
Reference in New Issue
Block a user