Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: chrome/browser/ui/views/harmony/layout_provider_unittest.cc

Issue 2810403002: Views: Don't add insets for views::Link focus rings under MD. (Closed)
Patch Set: Add missing // namespace comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/label.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/utf_string_conversions.h"
5 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" 6 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
6 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 7 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/default_style.h" 9 #include "ui/base/default_style.h"
9 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/base/test/material_design_controller_test_api.h" 11 #include "ui/base/test/material_design_controller_test_api.h"
11 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/controls/styled_label.h"
12 #include "ui/views/style/typography.h" 15 #include "ui/views/style/typography.h"
13 #include "ui/views/style/typography_provider.h" 16 #include "ui/views/style/typography_provider.h"
14 17
15 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
16 #include "base/mac/mac_util.h" 19 #include "base/mac/mac_util.h"
17 #endif 20 #endif
18 21
22 namespace {
23
24 // Constant from the Harmony spec.
25 constexpr int kHarmonyTitleSize = 15;
26 } // namespace
27
19 // Check legacy font sizes. No new code should be using these constants, but if 28 // 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 29 // these tests ever fail it probably means something in the old UI will have
21 // changed by mistake. 30 // changed by mistake.
22 // Disabled since this relies on machine configuration. http://crbug.com/701241. 31 // Disabled since this relies on machine configuration. http://crbug.com/701241.
23 TEST(LayoutProviderTest, DISABLED_LegacyFontSizeConstants) { 32 TEST(LayoutProviderTest, DISABLED_LegacyFontSizeConstants) {
24 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 33 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
25 gfx::FontList label_font = rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); 34 gfx::FontList label_font = rb.GetFontListWithDelta(ui::kLabelFontSizeDelta);
26 35
27 EXPECT_EQ(12, label_font.GetFontSize()); 36 EXPECT_EQ(12, label_font.GetFontSize());
28 EXPECT_EQ(15, label_font.GetHeight()); 37 EXPECT_EQ(15, label_font.GetHeight());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // correctly to _non-standard_ system font configurations on user machines. 118 // correctly to _non-standard_ system font configurations on user machines.
110 // Disabled since this relies on machine configuration. http://crbug.com/701241. 119 // Disabled since this relies on machine configuration. http://crbug.com/701241.
111 TEST(LayoutProviderTest, DISABLED_RequestFontBySize) { 120 TEST(LayoutProviderTest, DISABLED_RequestFontBySize) {
112 #if defined(OS_MACOSX) 121 #if defined(OS_MACOSX)
113 constexpr int kBase = 13; 122 constexpr int kBase = 13;
114 #else 123 #else
115 constexpr int kBase = 12; 124 constexpr int kBase = 12;
116 #endif 125 #endif
117 // Harmony spec. 126 // Harmony spec.
118 constexpr int kHeadline = 20; 127 constexpr int kHeadline = 20;
119 constexpr int kTitle = 15; // Leading 22. 128 constexpr int kTitle = kHarmonyTitleSize; // Leading 22.
120 constexpr int kBody1 = 13; // Leading 20. 129 constexpr int kBody1 = 13; // Leading 20.
121 constexpr int kBody2 = 12; // Leading 20. 130 constexpr int kBody2 = 12; // Leading 20.
122 constexpr int kButton = 12; 131 constexpr int kButton = 12;
123 132
124 #if defined(OS_WIN) 133 #if defined(OS_WIN)
125 constexpr gfx::Font::Weight kButtonWeight = gfx::Font::Weight::BOLD; 134 constexpr gfx::Font::Weight kButtonWeight = gfx::Font::Weight::BOLD;
126 #else 135 #else
127 constexpr gfx::Font::Weight kButtonWeight = gfx::Font::Weight::MEDIUM; 136 constexpr gfx::Font::Weight kButtonWeight = gfx::Font::Weight::MEDIUM;
128 #endif 137 #endif
129 138
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 int line_spacing = views::style::GetLineHeight(increase.context, kStyle); 273 int line_spacing = views::style::GetLineHeight(increase.context, kStyle);
265 EXPECT_GE(increase.max, line_spacing - font.GetHeight()); 274 EXPECT_GE(increase.max, line_spacing - font.GetHeight());
266 EXPECT_LE(increase.min, line_spacing - font.GetHeight()); 275 EXPECT_LE(increase.min, line_spacing - font.GetHeight());
267 } 276 }
268 277
269 // Buttons should specify zero line height (i.e. use the font's height) so 278 // Buttons should specify zero line height (i.e. use the font's height) so
270 // buttons have flexibility to configure their own spacing. 279 // buttons have flexibility to configure their own spacing.
271 EXPECT_EQ(0, 280 EXPECT_EQ(0,
272 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle)); 281 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle));
273 } 282 }
283
284 // Ensure that line heights reported in a default bot configuration match the
285 // Harmony spec. This test will only run if it detects that the current machine
286 // has the default OS configuration.
287 TEST(LayoutProviderTest, ExplicitTypographyLineHeight) {
288 ui::test::MaterialDesignControllerTestAPI md_test_api(
289 ui::MaterialDesignController::MATERIAL_NORMAL);
290 md_test_api.SetSecondaryUiMaterial(true);
291
292 std::unique_ptr<views::LayoutProvider> layout_provider =
293 ChromeLayoutProvider::CreateLayoutProvider();
294
295 constexpr int kStyle = views::style::STYLE_PRIMARY;
296 if (views::style::GetFont(views::style::CONTEXT_DIALOG_TITLE, kStyle)
297 .GetFontSize() != kHarmonyTitleSize) {
298 LOG(WARNING) << "Skipping: Test machine not in default configuration.";
299 return;
300 }
301
302 // Line heights from the Harmony spec.
303 constexpr int kBodyLineHeight = 20;
304 constexpr struct {
305 int context;
306 int line_height;
307 } kHarmonyHeights[] = {{CONTEXT_HEADLINE, 32},
308 {views::style::CONTEXT_DIALOG_TITLE, 22},
309 {CONTEXT_BODY_TEXT_LARGE, kBodyLineHeight},
310 {CONTEXT_BODY_TEXT_SMALL, kBodyLineHeight}};
311
312 for (size_t i = 0; i < arraysize(kHarmonyHeights); ++i) {
313 SCOPED_TRACE(testing::Message() << "Testing index: " << i);
314 EXPECT_EQ(kHarmonyHeights[i].line_height,
315 views::style::GetLineHeight(kHarmonyHeights[i].context, kStyle));
316
317 views::Label label(base::ASCIIToUTF16("test"), kHarmonyHeights[i].context);
318 label.SizeToPreferredSize();
319 EXPECT_EQ(kHarmonyHeights[i].line_height, label.height());
320 }
321
322 // TODO(tapted): Pass in contexts to StyledLabel instead. Currently they are
323 // stuck on style::CONTEXT_LABEL. That only matches the default line height in
324 // HarmonyTypographyProvider::GetLineHeight(), which is body text.
325 EXPECT_EQ(kBodyLineHeight,
326 views::style::GetLineHeight(views::style::CONTEXT_LABEL, kStyle));
327 views::StyledLabel styled_label(base::ASCIIToUTF16("test"), nullptr);
328 constexpr int kStyledLabelWidth = 200; // Enough to avoid wrapping.
329 styled_label.SizeToFit(kStyledLabelWidth);
330 EXPECT_EQ(kBodyLineHeight, styled_label.height());
331
332 // Adding a link should not change the size.
333 styled_label.AddStyleRange(
334 gfx::Range(0, 2), views::StyledLabel::RangeStyleInfo::CreateForLink());
335 styled_label.SizeToFit(kStyledLabelWidth);
336 EXPECT_EQ(kBodyLineHeight, styled_label.height());
337 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698