#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/chrome_typography_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/default_style.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/font_util.h"
#include "ui/strings/grit/app_locale_settings.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/system_fonts_win.h"
#endif
namespace {
#if BUILDFLAG(IS_WIN)
const char kDefaultFontName[] = "Segoe UI";
#endif
constexpr int kHarmonyTitleSize = …;
}
class LayoutProviderTest : public testing::Test { … };
TEST_F(LayoutProviderTest, EnsuresDefaultSystemSettings) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_LegacyFontSizeConstants …
#else
#define MAYBE_LegacyFontSizeConstants …
#endif
TEST_F(LayoutProviderTest, MAYBE_LegacyFontSizeConstants) { … }
TEST_F(LayoutProviderTest, RequestFontBySize) { … }
TEST_F(LayoutProviderTest, FontSizeRelativeToBase) { … }
TEST_F(LayoutProviderTest, TypographyLineHeight) { … }
TEST_F(LayoutProviderTest, ExplicitTypographyLineHeight) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(LayoutProviderTest, OmniboxFontAlways14) {
constexpr int kOmniboxHeight = 24;
constexpr int kDecorationHeight = 14;
constexpr int kOmniboxDesiredSize = 14;
constexpr int kDecorationRequestedSize = 11;
auto& bundle = ui::ResourceBundle::GetSharedInstance();
auto set_system_font = [&bundle](const char* font) {
bundle.OverrideLocaleStringResource(IDS_UI_FONT_FAMILY_CROS,
base::ASCIIToUTF16(font));
bundle.ReloadFonts();
return gfx::FontList().GetFontSize();
};
int base_font_size = set_system_font("Roboto, 12px");
EXPECT_EQ(12, base_font_size);
EXPECT_EQ(base_font_size, bundle.GetFontListWithDelta(0).GetFontSize());
EXPECT_EQ(14 - base_font_size, GetFontSizeDeltaBoundedByAvailableHeight(
kOmniboxHeight, kOmniboxDesiredSize));
EXPECT_EQ(11 - base_font_size,
GetFontSizeDeltaBoundedByAvailableHeight(kDecorationHeight,
kDecorationRequestedSize));
int latin_height_threshold = kOmniboxHeight;
for (; latin_height_threshold > 0; --latin_height_threshold) {
if (kOmniboxDesiredSize - base_font_size !=
GetFontSizeDeltaBoundedByAvailableHeight(latin_height_threshold,
kOmniboxDesiredSize))
break;
}
EXPECT_EQ(16, latin_height_threshold);
base_font_size = set_system_font("Roboto, Noto Sans Hebrew, 13px");
EXPECT_EQ(13, gfx::FontList().GetFontSize());
EXPECT_EQ(base_font_size, bundle.GetFontListWithDelta(0).GetFontSize());
EXPECT_EQ(14 - base_font_size, GetFontSizeDeltaBoundedByAvailableHeight(
kOmniboxHeight, kOmniboxDesiredSize));
EXPECT_EQ(11 - base_font_size,
GetFontSizeDeltaBoundedByAvailableHeight(kDecorationHeight,
kDecorationRequestedSize));
}
#endif