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

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

Issue 2765883004: Implement Harmony typography spec. (Closed)
Patch Set: test, nit comment 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
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 "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
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 is overridden under Harmony for the standard set of
Peter Kasting 2017/04/04 00:47:58 Nit: If there's a way to word comments/test names
tapted 2017/04/04 06:23:00 Done.
235 // styles. This varies by platform and test machine configuration. Generally,
236 // for a particular platform configuration, there should be a consistent
237 // increase in line height when compared to the height of a given font.
238 TEST(LayoutDelegateTest, HarmonyLineHeight) {
239 constexpr int kStyle = views::style::STYLE_PRIMARY;
240
241 // Only Harmony overrides the default line spacing.
242 ui::test::MaterialDesignControllerTestAPI md_test_api(
243 ui::MaterialDesignController::MATERIAL_NORMAL);
244 md_test_api.SetSecondaryUiMaterial(true);
245
246 ChromeViewsDelegate views_delegate;
247
248 const struct {
Peter Kasting 2017/04/04 00:47:58 Nit: Can this be constexpr?
tapted 2017/04/04 06:23:00 Done.
249 int context;
250 int min;
251 int max;
252 } kExpectedIncreases[] = {{CONTEXT_HEADLINE, 4, 8},
253 {views::style::CONTEXT_DIALOG_TITLE, 2, 4},
254 {CONTEXT_BODY_TEXT_LARGE, 3, 4},
255 {CONTEXT_BODY_TEXT_SMALL, 5, 5}};
256
257 int i = 0;
258 for (const auto& increase : kExpectedIncreases) {
259 SCOPED_TRACE(testing::Message() << "Testing index: " << i++);
Peter Kasting 2017/04/04 00:47:58 Nit: If we're going to have a counting index anywa
tapted 2017/04/04 06:23:00 Done.
260 const gfx::FontList& font = views::style::GetFont(increase.context, kStyle);
261 int line_spacing = views::style::GetLineHeight(increase.context, kStyle);
262 EXPECT_GE(increase.max, line_spacing - font.GetHeight());
263 EXPECT_LE(increase.min, line_spacing - font.GetHeight());
264 }
265
266 // Buttons should specify zero line height (i.e. use the font's height) so
267 // buttons have flexibility to configure their own spacing.
268 EXPECT_EQ(0,
269 views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle));
270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698