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

Unified Diff: ui/native_theme/native_theme_aura_unittest.cc

Issue 2009733002: Draw nicer arrows when the scrollbar buttons are not square. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no floats allowed Created 4 years, 6 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 | « ui/native_theme/BUILD.gn ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/native_theme/native_theme_aura_unittest.cc
diff --git a/ui/native_theme/native_theme_aura_unittest.cc b/ui/native_theme/native_theme_aura_unittest.cc
index b5ded9d46cca2066b4ebb74a2be52e670c51ced9..db3c5c19f410a19d6febbc7c154fab8390b230f8 100644
--- a/ui/native_theme/native_theme_aura_unittest.cc
+++ b/ui/native_theme/native_theme_aura_unittest.cc
@@ -24,50 +24,120 @@ void VerifyTriangle(SkPath actualPath, SkPoint p0, SkPoint p1, SkPoint p2) {
}
}
-TEST(NativeThemeAuraTest, VerticalArrows) {
- NativeThemeAura* theme = NativeThemeAura::instance();
+class NativeThemeAuraTest : public testing::Test {
+ protected:
+ NativeThemeAuraTest() : theme_(NativeThemeAura::instance()) {}
+
+ SkPath PathForArrow(const gfx::Rect& rect,
+ NativeTheme::Part direction) const {
+ return theme_->PathForArrow(rect, direction);
+ }
+
+ gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const {
+ return theme_->BoundingRectForArrow(rect);
+ }
+
+ private:
+ NativeThemeAura* theme_;
+};
+
+TEST_F(NativeThemeAuraTest, VerticalArrows) {
SkPath path;
// Up arrow, sized for 1x.
- path = theme->PathForArrow(gfx::Rect(100, 200, 17, 17),
- NativeTheme::kScrollbarUpArrow);
+ path =
+ PathForArrow(gfx::Rect(100, 200, 17, 17), NativeTheme::kScrollbarUpArrow);
VerifyTriangle(path, SkPoint::Make(105, 211), SkPoint::Make(112, 211),
SkPoint::Make(108.5, 207));
// 1.25x, should be larger.
- path = theme->PathForArrow(gfx::Rect(50, 70, 21, 21),
- NativeTheme::kScrollbarUpArrow);
+ path =
+ PathForArrow(gfx::Rect(50, 70, 21, 21), NativeTheme::kScrollbarUpArrow);
VerifyTriangle(path, SkPoint::Make(56, 84), SkPoint::Make(65, 84),
SkPoint::Make(60.5, 79));
// Down arrow is just a flipped up arrow.
- path = theme->PathForArrow(gfx::Rect(20, 80, 17, 17),
- NativeTheme::kScrollbarDownArrow);
+ path =
+ PathForArrow(gfx::Rect(20, 80, 17, 17), NativeTheme::kScrollbarDownArrow);
VerifyTriangle(path, SkPoint::Make(25, 86), SkPoint::Make(32, 86),
SkPoint::Make(28.5, 90));
}
-TEST(NativeThemeAuraTest, HorizontalArrows) {
- NativeThemeAura* theme = NativeThemeAura::instance();
+TEST_F(NativeThemeAuraTest, HorizontalArrows) {
SkPath path;
// Right arrow, sized for 1x.
- path = theme->PathForArrow(gfx::Rect(100, 200, 17, 17),
- NativeTheme::kScrollbarRightArrow);
+ path = PathForArrow(gfx::Rect(100, 200, 17, 17),
+ NativeTheme::kScrollbarRightArrow);
VerifyTriangle(path, SkPoint::Make(107, 205), SkPoint::Make(107, 212),
SkPoint::Make(111, 208.5));
// Button size for 1.25x, should be larger.
- path = theme->PathForArrow(gfx::Rect(50, 70, 21, 21),
- NativeTheme::kScrollbarRightArrow);
+ path = PathForArrow(gfx::Rect(50, 70, 21, 21),
+ NativeTheme::kScrollbarRightArrow);
VerifyTriangle(path, SkPoint::Make(58, 76), SkPoint::Make(58, 85),
SkPoint::Make(63, 80.5));
// Left arrow is just a flipped right arrow.
- path = theme->PathForArrow(gfx::Rect(20, 80, 17, 17),
- NativeTheme::kScrollbarLeftArrow);
+ path =
+ PathForArrow(gfx::Rect(20, 80, 17, 17), NativeTheme::kScrollbarLeftArrow);
VerifyTriangle(path, SkPoint::Make(30, 85), SkPoint::Make(30, 92),
SkPoint::Make(26, 88.5));
}
+TEST_F(NativeThemeAuraTest, ArrowForNonSquareButton) {
+ SkPath path =
+ PathForArrow(gfx::Rect(90, 80, 42, 37), NativeTheme::kScrollbarLeftArrow);
+ VerifyTriangle(path, SkPoint::Make(116, 89), SkPoint::Make(116, 109),
+ SkPoint::Make(105, 99));
+}
+
+TEST_F(NativeThemeAuraTest, BoundingRectSquare) {
+ gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 21, 21));
+ EXPECT_EQ(48.f, bounding_rect.x());
+ EXPECT_EQ(67.f, bounding_rect.y());
+ EXPECT_EQ(9.f, bounding_rect.width());
+ EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
+}
+
+TEST_F(NativeThemeAuraTest, BoundingRectSlightlyRectangular) {
+ // Stretched horzontally.
+ gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 25, 20));
+ EXPECT_EQ(49.f, bounding_rect.x());
+ EXPECT_EQ(66.f, bounding_rect.y());
+ EXPECT_EQ(11.f, bounding_rect.width());
+ EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
+
+ // Stretched vertically.
+ bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 14, 10));
+ EXPECT_EQ(46.f, bounding_rect.x());
+ EXPECT_EQ(63.f, bounding_rect.y());
+ EXPECT_EQ(6.f, bounding_rect.width());
+ EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
+}
+
+TEST_F(NativeThemeAuraTest, BoundingRectVeryRectangular) {
+ // Stretched horzontally.
+ gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 30, 8));
+ EXPECT_EQ(53.f, bounding_rect.x());
+ EXPECT_EQ(61.f, bounding_rect.y());
+ EXPECT_EQ(8.f, bounding_rect.width());
+ EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
+
+ // Stretched vertically.
+ bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 6, 44));
+ EXPECT_EQ(42.f, bounding_rect.x());
+ EXPECT_EQ(80.f, bounding_rect.y());
+ EXPECT_EQ(6.f, bounding_rect.width());
+ EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
+}
+
+TEST_F(NativeThemeAuraTest, BoundingRectSnappedToWholePixels) {
+ gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(0, 0, 9, 10));
+ EXPECT_EQ(3.f, bounding_rect.x());
+
+ bounding_rect = BoundingRectForArrow(gfx::Rect(0, 0, 10, 9));
+ EXPECT_EQ(3.f, bounding_rect.y());
+}
+
} // namespace ui
« no previous file with comments | « ui/native_theme/BUILD.gn ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698