OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 5 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
6 #include "chrome/browser/ui/views/harmony/chrome_typography.h" | 6 #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/default_style.h" | 8 #include "ui/base/default_style.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/base/test/material_design_controller_test_api.h" |
10 #include "ui/gfx/font_list.h" | 11 #include "ui/gfx/font_list.h" |
11 #include "ui/views/style/typography.h" | 12 #include "ui/views/style/typography.h" |
12 #include "ui/views/style/typography_provider.h" | 13 #include "ui/views/style/typography_provider.h" |
13 | 14 |
14 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
15 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
16 #endif | 17 #endif |
17 | 18 |
18 // Check legacy font sizes. No new code should be using these constants, but if | 19 // Check legacy font sizes. No new code should be using these constants, but if |
19 // these tests ever fail it probably means something in the old UI will have | 20 // these tests ever fail it probably means something in the old UI will have |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // E.g. Headline should give a 20pt font. | 223 // E.g. Headline should give a 20pt font. |
223 EXPECT_EQ(twelve + 8, GetFont(CONTEXT_HEADLINE, kStyle).GetFontSize()); | 224 EXPECT_EQ(twelve + 8, GetFont(CONTEXT_HEADLINE, kStyle).GetFontSize()); |
224 // Titles should be 15pt. Etc. | 225 // Titles should be 15pt. Etc. |
225 EXPECT_EQ(twelve + 3, | 226 EXPECT_EQ(twelve + 3, |
226 GetFont(views::style::CONTEXT_DIALOG_TITLE, kStyle).GetFontSize()); | 227 GetFont(views::style::CONTEXT_DIALOG_TITLE, kStyle).GetFontSize()); |
227 EXPECT_EQ(twelve + 1, GetFont(CONTEXT_BODY_TEXT_LARGE, kStyle).GetFontSize()); | 228 EXPECT_EQ(twelve + 1, GetFont(CONTEXT_BODY_TEXT_LARGE, kStyle).GetFontSize()); |
228 EXPECT_EQ(twelve - 1, | 229 EXPECT_EQ(twelve - 1, |
229 GetFont(CONTEXT_DEPRECATED_SMALL, kStyle).GetFontSize()); | 230 GetFont(CONTEXT_DEPRECATED_SMALL, kStyle).GetFontSize()); |
230 #endif | 231 #endif |
231 } | 232 } |
| 233 |
| 234 // Ensure that line height can be overridden by Chrome's TypographyProvider for |
| 235 // for the standard set of styles. This varies by platform and test machine |
| 236 // configuration. Generally, for a particular platform configuration, there |
| 237 // should be a consistent increase in line height when compared to the height of |
| 238 // a given font. |
| 239 TEST(LayoutDelegateTest, TypographyLineHeight) { |
| 240 constexpr int kStyle = views::style::STYLE_PRIMARY; |
| 241 |
| 242 // Only MD overrides the default line spacing. |
| 243 ui::test::MaterialDesignControllerTestAPI md_test_api( |
| 244 ui::MaterialDesignController::MATERIAL_NORMAL); |
| 245 md_test_api.SetSecondaryUiMaterial(true); |
| 246 |
| 247 ChromeViewsDelegate views_delegate; |
| 248 |
| 249 constexpr struct { |
| 250 int context; |
| 251 int min; |
| 252 int max; |
| 253 } kExpectedIncreases[] = {{CONTEXT_HEADLINE, 4, 8}, |
| 254 {views::style::CONTEXT_DIALOG_TITLE, 2, 4}, |
| 255 {CONTEXT_BODY_TEXT_LARGE, 3, 4}, |
| 256 {CONTEXT_BODY_TEXT_SMALL, 5, 5}}; |
| 257 |
| 258 for (size_t i = 0; i < arraysize(kExpectedIncreases); ++i) { |
| 259 SCOPED_TRACE(testing::Message() << "Testing index: " << i); |
| 260 const auto& increase = kExpectedIncreases[i]; |
| 261 const gfx::FontList& font = views::style::GetFont(increase.context, kStyle); |
| 262 int line_spacing = views::style::GetLineHeight(increase.context, kStyle); |
| 263 EXPECT_GE(increase.max, line_spacing - font.GetHeight()); |
| 264 EXPECT_LE(increase.min, line_spacing - font.GetHeight()); |
| 265 } |
| 266 |
| 267 // Buttons should specify zero line height (i.e. use the font's height) so |
| 268 // buttons have flexibility to configure their own spacing. |
| 269 EXPECT_EQ(0, |
| 270 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle)); |
| 271 } |
OLD | NEW |