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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/label.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/harmony/layout_provider_unittest.cc
diff --git a/chrome/browser/ui/views/harmony/layout_provider_unittest.cc b/chrome/browser/ui/views/harmony/layout_provider_unittest.cc
index aaa4ab26cd58c8d01cc7c4c4611dda320be33471..2e9136af69ea8ba4c7ca8a6ff3b2587f4e230d41 100644
--- a/chrome/browser/ui/views/harmony/layout_provider_unittest.cc
+++ b/chrome/browser/ui/views/harmony/layout_provider_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
#include "chrome/browser/ui/views/harmony/chrome_typography.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -9,6 +10,8 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/gfx/font_list.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"
@@ -16,6 +19,12 @@
#include "base/mac/mac_util.h"
#endif
+namespace {
+
+// Constant from the Harmony spec.
+constexpr int kHarmonyTitleSize = 15;
+} // namespace
+
// Check legacy font sizes. No new code should be using these constants, but if
// these tests ever fail it probably means something in the old UI will have
// changed by mistake.
@@ -116,7 +125,7 @@ TEST(LayoutProviderTest, DISABLED_RequestFontBySize) {
#endif
// Harmony spec.
constexpr int kHeadline = 20;
- constexpr int kTitle = 15; // Leading 22.
+ constexpr int kTitle = kHarmonyTitleSize; // Leading 22.
constexpr int kBody1 = 13; // Leading 20.
constexpr int kBody2 = 12; // Leading 20.
constexpr int kButton = 12;
@@ -271,3 +280,58 @@ TEST(LayoutProviderTest, TypographyLineHeight) {
EXPECT_EQ(0,
views::style::GetLineHeight(views::style::CONTEXT_BUTTON, kStyle));
}
+
+// Ensure that line heights reported in a default bot configuration match the
+// Harmony spec. This test will only run if it detects that the current machine
+// has the default OS configuration.
+TEST(LayoutProviderTest, ExplicitTypographyLineHeight) {
+ ui::test::MaterialDesignControllerTestAPI md_test_api(
+ ui::MaterialDesignController::MATERIAL_NORMAL);
+ md_test_api.SetSecondaryUiMaterial(true);
+
+ std::unique_ptr<views::LayoutProvider> layout_provider =
+ ChromeLayoutProvider::CreateLayoutProvider();
+
+ constexpr int kStyle = views::style::STYLE_PRIMARY;
+ if (views::style::GetFont(views::style::CONTEXT_DIALOG_TITLE, kStyle)
+ .GetFontSize() != kHarmonyTitleSize) {
+ LOG(WARNING) << "Skipping: Test machine not in default configuration.";
+ return;
+ }
+
+ // Line heights from the Harmony spec.
+ constexpr int kBodyLineHeight = 20;
+ constexpr struct {
+ int context;
+ int line_height;
+ } kHarmonyHeights[] = {{CONTEXT_HEADLINE, 32},
+ {views::style::CONTEXT_DIALOG_TITLE, 22},
+ {CONTEXT_BODY_TEXT_LARGE, kBodyLineHeight},
+ {CONTEXT_BODY_TEXT_SMALL, kBodyLineHeight}};
+
+ for (size_t i = 0; i < arraysize(kHarmonyHeights); ++i) {
+ SCOPED_TRACE(testing::Message() << "Testing index: " << i);
+ EXPECT_EQ(kHarmonyHeights[i].line_height,
+ views::style::GetLineHeight(kHarmonyHeights[i].context, kStyle));
+
+ views::Label label(base::ASCIIToUTF16("test"), kHarmonyHeights[i].context);
+ label.SizeToPreferredSize();
+ EXPECT_EQ(kHarmonyHeights[i].line_height, label.height());
+ }
+
+ // TODO(tapted): Pass in contexts to StyledLabel instead. Currently they are
+ // stuck on style::CONTEXT_LABEL. That only matches the default line height in
+ // HarmonyTypographyProvider::GetLineHeight(), which is body text.
+ EXPECT_EQ(kBodyLineHeight,
+ views::style::GetLineHeight(views::style::CONTEXT_LABEL, kStyle));
+ views::StyledLabel styled_label(base::ASCIIToUTF16("test"), nullptr);
+ constexpr int kStyledLabelWidth = 200; // Enough to avoid wrapping.
+ styled_label.SizeToFit(kStyledLabelWidth);
+ EXPECT_EQ(kBodyLineHeight, styled_label.height());
+
+ // Adding a link should not change the size.
+ styled_label.AddStyleRange(
+ gfx::Range(0, 2), views::StyledLabel::RangeStyleInfo::CreateForLink());
+ styled_label.SizeToFit(kStyledLabelWidth);
+ EXPECT_EQ(kBodyLineHeight, styled_label.height());
+}
« 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