-
-
Notifications
You must be signed in to change notification settings - Fork 423
Restore custom fonts after theme changes #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,15 @@ | |
| #include "Bookmarks/UI/Views/BookmarksToolbarView.h" | ||
| #include "BrowserTestBase.h" | ||
| #include "BrowserWindowFake.h" | ||
| #include "CustomFont.h" | ||
| #include "FontHelper.h" | ||
| #include "IconFetcherFake.h" | ||
| #include "PidlTestHelper.h" | ||
| #include "ShellBrowser/ShellBrowser.h" | ||
| #include "ShellBrowser/ShellNavigationController.h" | ||
| #include <boost/range/combine.hpp> | ||
| #include <gtest/gtest.h> | ||
| #include <uxtheme.h> | ||
|
|
||
| class BookmarksToolbarTest : public BrowserTestBase | ||
| { | ||
|
|
@@ -138,3 +141,54 @@ TEST_F(BookmarksToolbarTest, OpenBookmarkOnClick) | |
| EXPECT_EQ(currentEntry->GetPidl(), CreateSimplePidlForTest(bookmark->GetLocation())); | ||
| } | ||
| } | ||
|
|
||
| class BookmarksToolbarFontTest : public BrowserTestBase | ||
| { | ||
| protected: | ||
| BookmarksToolbarFontTest() : | ||
| m_browser(AddBrowser()), | ||
| m_bookmarksToolbarView(CreateBookmarksToolbarView(m_browser->GetHWND(), &m_config)) | ||
| { | ||
| m_bookmarkTree.AddBookmarkItem(m_bookmarkTree.GetBookmarksToolbarFolder(), | ||
| std::make_unique<BookmarkItem>(std::nullopt, L"Bookmark", L"c:\\path")); | ||
|
|
||
| m_bookmarksToolbar = | ||
| BookmarksToolbar::Create(m_bookmarksToolbarView, m_browser, &m_acceleratorManager, | ||
| &m_resourceLoader, &m_iconFetcher, &m_bookmarkTree, &m_platformContext); | ||
| } | ||
|
|
||
| static BookmarksToolbarView *CreateBookmarksToolbarView(HWND parent, Config *config) | ||
| { | ||
| config->mainFont = CustomFont(L"Segoe UI", 15); | ||
| return BookmarksToolbarView::Create(parent, config); | ||
| } | ||
|
|
||
| IconFetcherFake m_iconFetcher; | ||
| BrowserWindowFake *const m_browser; | ||
| BookmarksToolbarView *const m_bookmarksToolbarView; | ||
| BookmarksToolbar *m_bookmarksToolbar = nullptr; | ||
| }; | ||
|
|
||
| TEST_F(BookmarksToolbarFontTest, UsesConfiguredFontOnStartup) | ||
| { | ||
| // The theme is applied after the main window and all its child controls have been created. | ||
| ASSERT_TRUE(SUCCEEDED(SetWindowTheme(m_bookmarksToolbarView->GetHWND(), L"", nullptr))); | ||
|
|
||
| auto toolbarFont = reinterpret_cast<HFONT>( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please format your changes using ClangFormat? A Lines like this are formatted differently when using ClangFormat. |
||
| SendMessage(m_bookmarksToolbarView->GetHWND(), WM_GETFONT, 0, 0)); | ||
| ASSERT_NE(toolbarFont, nullptr); | ||
|
|
||
| LOGFONT toolbarLogFont; | ||
| ASSERT_EQ(GetObject(toolbarFont, sizeof(toolbarLogFont), &toolbarLogFont), | ||
| static_cast<int>(sizeof(toolbarLogFont))); | ||
|
|
||
| auto expectedFont = CreateFontFromNameAndSize(L"Segoe UI", 15, | ||
| m_bookmarksToolbarView->GetHWND()); | ||
| ASSERT_NE(expectedFont, nullptr); | ||
|
|
||
| LOGFONT expectedLogFont; | ||
| ASSERT_EQ(GetObject(expectedFont.get(), sizeof(expectedLogFont), &expectedLogFont), | ||
| static_cast<int>(sizeof(expectedLogFont))); | ||
|
|
||
| EXPECT_EQ(toolbarLogFont, expectedLogFont); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this test needs its own test fixture. It's testing that the main font is kept after the window theme is changed. So, you can use the existing
BookmarksToolbarTestfixture and simply set the main font at the start of the test (before changing the theme).I'd also change the name of the test to
UsesConfiguredFontAfterThemeChanged, since this is testing specifically what happens when the theme changes, not what happens when the font is set on startup.