|
22 | 22 | #include "chrome/browser/search/instant_service.h"
|
23 | 23 | #include "chrome/browser/search/instant_service_factory.h"
|
24 | 24 | #include "chrome/browser/search/search.h"
|
| 25 | +#include "chrome/browser/themes/theme_service.h" |
| 26 | +#include "chrome/browser/themes/theme_service_factory.h" |
25 | 27 | #include "chrome/browser/ui/browser.h"
|
26 | 28 | #include "chrome/browser/ui/search/instant_test_base.h"
|
27 | 29 | #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
|
65 | 67 | #include "net/test/embedded_test_server/embedded_test_server.h"
|
66 | 68 | #include "net/test/embedded_test_server/http_request.h"
|
67 | 69 | #include "net/test/embedded_test_server/http_response.h"
|
| 70 | +#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h" |
68 | 71 | #include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
|
69 | 72 | #include "ui/color/color_provider.h"
|
70 | 73 | #include "ui/color/color_provider_key.h"
|
@@ -691,6 +694,80 @@ INSTANTIATE_TEST_SUITE_P(All,
|
691 | 694 | PrefersColorSchemeTest,
|
692 | 695 | testing::Combine(testing::Bool(), testing::Bool()));
|
693 | 696 |
|
| 697 | +class PreferredRootScrollbarColorSchemeChromeClientTest |
| 698 | + : public testing::WithParamInterface<std::tuple<bool, bool>>, |
| 699 | + public InProcessBrowserTest { |
| 700 | + protected: |
| 701 | + PreferredRootScrollbarColorSchemeChromeClientTest() |
| 702 | + : dark_mode_(std::get<0>(GetParam())), |
| 703 | + uses_custom_theme_(std::get<1>(GetParam())), |
| 704 | + theme_client_(&test_theme_) { |
| 705 | + test_theme_.SetDarkMode(dark_mode_); |
| 706 | + } |
| 707 | + |
| 708 | + void SetUpOnMainThread() override { |
| 709 | + InProcessBrowserTest::SetUpOnMainThread(); |
| 710 | + original_client_ = SetBrowserClientForTesting(&theme_client_); |
| 711 | + test_theme_.SetDarkMode(dark_mode_); |
| 712 | + ui::NativeTheme::GetInstanceForNativeUi()->set_use_dark_colors(dark_mode_); |
| 713 | + ThemeService* theme_service = |
| 714 | + ThemeServiceFactory::GetForProfile(browser()->profile()); |
| 715 | + if (uses_custom_theme_) { |
| 716 | + theme_service->BuildAutogeneratedThemeFromColor(SK_ColorRED); |
| 717 | + } else { |
| 718 | + theme_service->UseDefaultTheme(); |
| 719 | + } |
| 720 | + } |
| 721 | + |
| 722 | + ~PreferredRootScrollbarColorSchemeChromeClientTest() override { |
| 723 | + CHECK_EQ(&theme_client_, SetBrowserClientForTesting(original_client_)); |
| 724 | + } |
| 725 | + |
| 726 | + blink::mojom::PreferredColorScheme ExpectedColorScheme() const { |
| 727 | + return dark_mode_ && !uses_custom_theme_ |
| 728 | + ? blink::mojom::PreferredColorScheme::kDark |
| 729 | + : blink::mojom::PreferredColorScheme::kLight; |
| 730 | + } |
| 731 | + |
| 732 | + private: |
| 733 | + class ChromeContentBrowserClientWithWebTheme |
| 734 | + : public ChromeContentBrowserClient { |
| 735 | + public: |
| 736 | + explicit ChromeContentBrowserClientWithWebTheme( |
| 737 | + const ui::NativeTheme* theme) |
| 738 | + : theme_(theme) {} |
| 739 | + |
| 740 | + protected: |
| 741 | + const ui::NativeTheme* GetWebTheme() const override { return theme_; } |
| 742 | + |
| 743 | + private: |
| 744 | + const raw_ptr<const ui::NativeTheme> theme_; |
| 745 | + }; |
| 746 | + |
| 747 | + const bool dark_mode_ = false; |
| 748 | + const bool uses_custom_theme_ = false; |
| 749 | + raw_ptr<content::ContentBrowserClient> original_client_ = nullptr; |
| 750 | + ui::TestNativeTheme test_theme_; |
| 751 | + ChromeContentBrowserClientWithWebTheme theme_client_; |
| 752 | +}; |
| 753 | + |
| 754 | +// This test verifies that the preferred color scheme for root scrollbars is set |
| 755 | +// appropriately following the web content's color scheme and the presence of |
| 756 | +// a custom theme. |
| 757 | +IN_PROC_BROWSER_TEST_P(PreferredRootScrollbarColorSchemeChromeClientTest, |
| 758 | + ScrollbarFollowsPreferredColorScheme) { |
| 759 | + EXPECT_EQ(browser() |
| 760 | + ->tab_strip_model() |
| 761 | + ->GetActiveWebContents() |
| 762 | + ->GetOrCreateWebPreferences() |
| 763 | + .preferred_root_scrollbar_color_scheme, |
| 764 | + ExpectedColorScheme()); |
| 765 | +} |
| 766 | + |
| 767 | +INSTANTIATE_TEST_SUITE_P(All, |
| 768 | + PreferredRootScrollbarColorSchemeChromeClientTest, |
| 769 | + testing::Combine(testing::Bool(), testing::Bool())); |
| 770 | + |
694 | 771 | class PrefersContrastTest
|
695 | 772 | : public testing::WithParamInterface<ui::NativeTheme::PreferredContrast>,
|
696 | 773 | public InProcessBrowserTest {
|
|
0 commit comments