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

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

Issue 2656463002: Implement MD simple gesture nav (Closed)
Patch Set: Simplified ThreePartImage test Created 3 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
index 963249023e729e03849eb8be1680623b00de632e..a517ae33d905d2a7ba471b9fb7d55f755883e7da 100644
--- a/ui/base/cocoa/three_part_image_unittest.mm
+++ b/ui/base/cocoa/three_part_image_unittest.mm
@@ -7,9 +7,13 @@
#include <memory>
#include "testing/gtest_mac.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/skia/include/core/SkRect.h"
#include "ui/base/resource/resource_bundle.h"
-#import "ui/gfx/test/ui_cocoa_test_helper.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_unittest_util.h"
+#import "ui/gfx/test/ui_cocoa_test_helper.h"
#include "ui/resources/grit/ui_resources.h"
namespace ui {
@@ -48,26 +52,33 @@ TEST(ThreePartImageTest, GetRects) {
}
TEST(ThreePartImageTest, HitTest) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- base::scoped_nsobject<NSImage> leftImage(
- rb.GetNativeImageNamed(IDR_BACK_ARROW).CopyNSImage());
- base::scoped_nsobject<NSImage> rightImage(
- rb.GetNativeImageNamed(IDR_FORWARD_ARROW).CopyNSImage());
- ThreePartImage image(leftImage, nullptr, rightImage);
- NSRect bounds = NSMakeRect(0, 0, 512, 128);
+ // Create a bitmap with transparent top and bottom.
+ const int size = 128;
+ const int corner_size = 8;
+ SkBitmap bitmap = gfx::test::CreateBitmap(size, size);
+ // Clear top and bottom.
+ bitmap.erase(SK_ColorTRANSPARENT, SkIRect::MakeXYWH(0, 0, size, corner_size));
+ bitmap.erase(SK_ColorTRANSPARENT,
+ SkIRect::MakeXYWH(0, size - corner_size, size, corner_size));
+ gfx::Image part_image = gfx::Image::CreateFrom1xBitmap(bitmap);
+
+ // Create a three-part image.
+ base::scoped_nsobject<NSImage> ns_image(part_image.CopyNSImage());
+ ThreePartImage image(ns_image, nullptr, ns_image);
+ NSRect bounds = NSMakeRect(0, 0, 4 * size, size);
- // The middle of the arrows are hits.
- EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds));
- EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds));
+ // The middle of the left and right parts are hits.
+ EXPECT_TRUE(image.HitTest(NSMakePoint(size / 2, size / 2), bounds));
+ EXPECT_TRUE(image.HitTest(NSMakePoint(7 * size / 2, size / 2), bounds));
// No middle image means the middle rect is a hit.
- EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds));
+ EXPECT_TRUE(image.HitTest(NSMakePoint(2 * size, size / 2), 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));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(0, size - 1), bounds));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(4 * size - 1, 0), bounds));
+ EXPECT_FALSE(image.HitTest(NSMakePoint(4 * size - 1, size - 1), bounds));
}
} // namespace test
« no previous file with comments | « content/browser/web_contents/aura/gesture_nav_simple.cc ('k') | ui/resources/default_100_percent/common/back_arrow.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698