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

Unified Diff: ui/base/cocoa/three_part_image_unittest.mm

Issue 918533005: Mac: Optimize TabView drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split ThreePartImage Created 5 years, 10 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
Index: ui/base/cocoa/three_part_image_unittest.mm
diff --git a/ui/base/cocoa/three_part_image_unittest.mm b/ui/base/cocoa/three_part_image_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1294f5d963560da87da03bc53de6de7dfad2cf64
--- /dev/null
+++ b/ui/base/cocoa/three_part_image_unittest.mm
@@ -0,0 +1,56 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "ui/base/cocoa/three_part_image.h"
Robert Sesek 2015/02/12 21:56:37 This should be the first #include and then separat
Andre 2015/02/12 22:10:37 Done.
+#include "testing/gtest_mac.h"
+#import "ui/gfx/test/ui_cocoa_test_helper.h"
+#include "ui/resources/grit/ui_resources.h"
+
+#define EXPECT_EQ_RECT(a, b) \
Robert Sesek 2015/02/12 21:56:37 There's EXPECT_NSRECT_EQ.
Andre 2015/02/12 22:10:38 Done.
+ EXPECT_NSEQ(NSStringFromRect(a), NSStringFromRect(b))
+
+namespace ui {
+namespace test {
+
+TEST(ThreePartImageTest, GetRects) {
+ ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
+ IDR_BROWSER_ACTION_BADGE_CENTER,
+ IDR_BROWSER_ACTION_BADGE_RIGHT);
+ NSRect bounds = NSMakeRect(0, 0, 20, 11);
+ EXPECT_EQ_RECT(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
+ EXPECT_EQ_RECT(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
+ EXPECT_EQ_RECT(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
+}
+
+TEST(ThreePartImageTest, GetRectsWithoutMiddle) {
+ ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
+ 0,
+ IDR_BROWSER_ACTION_BADGE_RIGHT);
+ NSRect bounds = NSMakeRect(0, 0, 20, 11);
+ EXPECT_EQ_RECT(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
+ EXPECT_EQ_RECT(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
+ EXPECT_EQ_RECT(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
+}
+
+TEST(ThreePartImageTest, HitTest) {
+ ThreePartImage image(IDR_BACK_ARROW, 0, IDR_FORWARD_ARROW);
+ NSRect bounds = NSMakeRect(0, 0, 512, 128);
+
+ // The middle of the arrows are hits.
+ EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds));
+ EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds));
+
+ // No middle image means the middle rect is a hit.
+ EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds));
+
+ // The corners are transparent.
+ EXPECT_FALSE(image.HitTest(NSMakePoint(0, 0), bounds));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(0, 127), bounds));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(511, 0), bounds));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(511, 127), bounds));
+}
+
+} // namespace test
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698