Chromium Code Reviews| 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/harmony/chrome_layout_provider.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/base/test/material_design_controller_test_api.h" |
| 11 #include "ui/gfx/font_list.h" | 11 #include "ui/gfx/font_list.h" |
| 12 #include "ui/views/style/typography.h" | 12 #include "ui/views/style/typography.h" |
| 13 #include "ui/views/style/typography_provider.h" | 13 #include "ui/views/style/typography_provider.h" |
| 14 | 14 |
| 15 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
| 16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 // 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 |
| 20 // 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 |
| 21 // changed by mistake. | 21 // changed by mistake. |
| 22 // Disabled since this relies on machine configuration. http://crbug.com/701241. | 22 // Disabled since this relies on machine configuration. http://crbug.com/701241. |
| 23 TEST(LayoutDelegateTest, DISABLED_LegacyFontSizeConstants) { | 23 TEST(LayoutProviderTest, DISABLED_LegacyFontSizeConstants) { |
| 24 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 24 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 25 gfx::FontList label_font = rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); | 25 gfx::FontList label_font = rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); |
| 26 | 26 |
| 27 EXPECT_EQ(12, label_font.GetFontSize()); | 27 EXPECT_EQ(12, label_font.GetFontSize()); |
| 28 EXPECT_EQ(15, label_font.GetHeight()); | 28 EXPECT_EQ(15, label_font.GetHeight()); |
| 29 EXPECT_EQ(12, label_font.GetBaseline()); | 29 EXPECT_EQ(12, label_font.GetBaseline()); |
| 30 EXPECT_EQ(9, label_font.GetCapHeight()); | 30 EXPECT_EQ(9, label_font.GetCapHeight()); |
| 31 // Note some Windows bots report 11,13,11,9 for the above. | 31 // Note some Windows bots report 11,13,11,9 for the above. |
| 32 // TODO(tapted): Smoke them out and figure out why. | 32 // TODO(tapted): Smoke them out and figure out why. |
| 33 | 33 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Check that asking for fonts of a given size match the Harmony spec. If these | 103 // Check that asking for fonts of a given size match the Harmony spec. If these |
| 104 // tests fail, the Harmony TypographyProvider needs to be updated to handle the | 104 // tests fail, the Harmony TypographyProvider needs to be updated to handle the |
| 105 // new font properties. For example, when title_font.GetHeight() returns 19, the | 105 // new font properties. For example, when title_font.GetHeight() returns 19, the |
| 106 // Harmony TypographyProvider adds 3 to obtain its target height of 22. If a | 106 // Harmony TypographyProvider adds 3 to obtain its target height of 22. If a |
| 107 // platform starts returning 18 in a standard configuration then the | 107 // platform starts returning 18 in a standard configuration then the |
| 108 // TypographyProvider must add 4 instead. We do this so that Chrome adapts | 108 // TypographyProvider must add 4 instead. We do this so that Chrome adapts |
| 109 // correctly to _non-standard_ system font configurations on user machines. | 109 // correctly to _non-standard_ system font configurations on user machines. |
| 110 // Disabled since this relies on machine configuration. http://crbug.com/701241. | 110 // Disabled since this relies on machine configuration. http://crbug.com/701241. |
| 111 TEST(LayoutDelegateTest, DISABLED_RequestFontBySize) { | 111 TEST(LayoutProviderTest, DISABLED_RequestFontBySize) { |
| 112 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
| 113 constexpr int kBase = 13; | 113 constexpr int kBase = 13; |
| 114 #else | 114 #else |
| 115 constexpr int kBase = 12; | 115 constexpr int kBase = 12; |
| 116 #endif | 116 #endif |
| 117 // Harmony spec. | 117 // Harmony spec. |
| 118 constexpr int kHeadline = 20; | 118 constexpr int kHeadline = 20; |
| 119 constexpr int kTitle = 15; // Leading 22. | 119 constexpr int kTitle = 15; // Leading 22. |
| 120 constexpr int kBody1 = 13; // Leading 20. | 120 constexpr int kBody1 = 13; // Leading 20. |
| 121 constexpr int kBody2 = 12; // Leading 20. | 121 constexpr int kBody2 = 12; // Leading 20. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 EXPECT_EQ(kButton, button_font.GetFontSize()); | 181 EXPECT_EQ(kButton, button_font.GetFontSize()); |
| 182 | 182 |
| 183 // Button leading not specified (shouldn't be needed: no multiline buttons). | 183 // Button leading not specified (shouldn't be needed: no multiline buttons). |
| 184 EXPECT_EQ(15, button_font.GetHeight()); | 184 EXPECT_EQ(15, button_font.GetHeight()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Test that the default TypographyProvider correctly maps TextContexts relative | 187 // Test that the default TypographyProvider correctly maps TextContexts relative |
| 188 // to the "base" font in the manner that legacy toolkit-views code expects. This | 188 // to the "base" font in the manner that legacy toolkit-views code expects. This |
| 189 // reads the base font configuration at runtime, and only tests font sizes, so | 189 // reads the base font configuration at runtime, and only tests font sizes, so |
| 190 // should be robust against platform changes. | 190 // should be robust against platform changes. |
| 191 TEST(LayoutDelegateTest, FontSizeRelativeToBase) { | 191 TEST(LayoutProviderTest, FontSizeRelativeToBase) { |
| 192 using views::style::GetFont; | 192 using views::style::GetFont; |
| 193 | 193 |
| 194 constexpr int kStyle = views::style::STYLE_PRIMARY; | 194 constexpr int kStyle = views::style::STYLE_PRIMARY; |
| 195 | 195 |
| 196 // Typography described in chrome_typography.h requires a ChromeViewsDelegate. | 196 // Typography described in chrome_typography.h requires a |
| 197 ChromeViewsDelegate views_delegate; | 197 // ChromeLayoutProvider. |
| 198 ChromeLayoutProvider layout_delegate; | |
|
Peter Kasting
2017/04/12 21:37:44
Nit: |layout_provider|
kylix_rd
2017/04/13 16:45:42
Done.
| |
| 198 | 199 |
| 199 // Legacy code measures everything relative to a default-constructed FontList. | 200 // Legacy code measures everything relative to a default-constructed FontList. |
| 200 // On Mac, subtract one since that is 13pt instead of 12pt. | 201 // On Mac, subtract one since that is 13pt instead of 12pt. |
| 201 #if defined(OS_MACOSX) | 202 #if defined(OS_MACOSX) |
| 202 const int twelve = gfx::FontList().GetFontSize() - 1; | 203 const int twelve = gfx::FontList().GetFontSize() - 1; |
| 203 #else | 204 #else |
| 204 const int twelve = gfx::FontList().GetFontSize(); | 205 const int twelve = gfx::FontList().GetFontSize(); |
| 205 #endif | 206 #endif |
| 206 | 207 |
| 207 EXPECT_EQ(twelve, GetFont(CONTEXT_BODY_TEXT_SMALL, kStyle).GetFontSize()); | 208 EXPECT_EQ(twelve, GetFont(CONTEXT_BODY_TEXT_SMALL, kStyle).GetFontSize()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 229 EXPECT_EQ(twelve - 1, | 230 EXPECT_EQ(twelve - 1, |
| 230 GetFont(CONTEXT_DEPRECATED_SMALL, kStyle).GetFontSize()); | 231 GetFont(CONTEXT_DEPRECATED_SMALL, kStyle).GetFontSize()); |
| 231 #endif | 232 #endif |
| 232 } | 233 } |
| 233 | 234 |
| 234 // Ensure that line height can be overridden by Chrome's TypographyProvider for | 235 // 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 // for the standard set of styles. This varies by platform and test machine |
| 236 // configuration. Generally, for a particular platform configuration, there | 237 // configuration. Generally, for a particular platform configuration, there |
| 237 // should be a consistent increase in line height when compared to the height of | 238 // should be a consistent increase in line height when compared to the height of |
| 238 // a given font. | 239 // a given font. |
| 239 TEST(LayoutDelegateTest, TypographyLineHeight) { | 240 TEST(LayoutProviderTest, TypographyLineHeight) { |
| 240 constexpr int kStyle = views::style::STYLE_PRIMARY; | 241 constexpr int kStyle = views::style::STYLE_PRIMARY; |
| 241 | 242 |
| 242 // Only MD overrides the default line spacing. | 243 // Only MD overrides the default line spacing. |
| 243 ui::test::MaterialDesignControllerTestAPI md_test_api( | 244 ui::test::MaterialDesignControllerTestAPI md_test_api( |
| 244 ui::MaterialDesignController::MATERIAL_NORMAL); | 245 ui::MaterialDesignController::MATERIAL_NORMAL); |
| 245 md_test_api.SetSecondaryUiMaterial(true); | 246 md_test_api.SetSecondaryUiMaterial(true); |
| 246 | 247 |
| 247 ChromeViewsDelegate views_delegate; | 248 std::unique_ptr<views::LayoutProvider> layout_delegate = |
|
Peter Kasting
2017/04/12 21:37:44
Nit: |layout_provider|; can just be created on the
kylix_rd
2017/04/13 16:45:42
Not really. It needs to create the HarmonyLayoutPr
| |
| 249 ChromeLayoutProvider::CreateLayoutProvider(); | |
| 248 | 250 |
| 249 constexpr struct { | 251 constexpr struct { |
| 250 int context; | 252 int context; |
| 251 int min; | 253 int min; |
| 252 int max; | 254 int max; |
| 253 } kExpectedIncreases[] = {{CONTEXT_HEADLINE, 4, 8}, | 255 } kExpectedIncreases[] = {{CONTEXT_HEADLINE, 4, 8}, |
| 254 {views::style::CONTEXT_DIALOG_TITLE, 2, 4}, | 256 {views::style::CONTEXT_DIALOG_TITLE, 2, 4}, |
| 255 {CONTEXT_BODY_TEXT_LARGE, 3, 4}, | 257 {CONTEXT_BODY_TEXT_LARGE, 3, 4}, |
| 256 {CONTEXT_BODY_TEXT_SMALL, 5, 5}}; | 258 {CONTEXT_BODY_TEXT_SMALL, 5, 5}}; |
| 257 | 259 |
| 258 for (size_t i = 0; i < arraysize(kExpectedIncreases); ++i) { | 260 for (size_t i = 0; i < arraysize(kExpectedIncreases); ++i) { |
| 259 SCOPED_TRACE(testing::Message() << "Testing index: " << i); | 261 SCOPED_TRACE(testing::Message() << "Testing index: " << i); |
| 260 const auto& increase = kExpectedIncreases[i]; | 262 const auto& increase = kExpectedIncreases[i]; |
| 261 const gfx::FontList& font = views::style::GetFont(increase.context, kStyle); | 263 const gfx::FontList& font = views::style::GetFont(increase.context, kStyle); |
| 262 int line_spacing = views::style::GetLineHeight(increase.context, kStyle); | 264 int line_spacing = views::style::GetLineHeight(increase.context, kStyle); |
| 263 EXPECT_GE(increase.max, line_spacing - font.GetHeight()); | 265 EXPECT_GE(increase.max, line_spacing - font.GetHeight()); |
| 264 EXPECT_LE(increase.min, line_spacing - font.GetHeight()); | 266 EXPECT_LE(increase.min, line_spacing - font.GetHeight()); |
| 265 } | 267 } |
| 266 | 268 |
| 267 // Buttons should specify zero line height (i.e. use the font's height) so | 269 // Buttons should specify zero line height (i.e. use the font's height) so |
| 268 // buttons have flexibility to configure their own spacing. | 270 // buttons have flexibility to configure their own spacing. |
| 269 EXPECT_EQ(0, | 271 EXPECT_EQ(0, |
| 270 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle)); | 272 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle)); |
| 271 } | 273 } |
| OLD | NEW |