| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
| 10 #include "ui/base/cocoa/base_view.h" | 10 #include "ui/base/cocoa/base_view.h" |
| 11 #import "ui/base/test/ui_cocoa_test_helper.h" | 11 #import "ui/base/test/ui_cocoa_test_helper.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class BaseViewTest : public ui::CocoaTest { | 15 class BaseViewTest : public ui::CocoaTest { |
| 16 public: | 16 public: |
| 17 BaseViewTest() { | 17 BaseViewTest() { |
| 18 NSRect frame = NSMakeRect(0, 0, 100, 100); | 18 NSRect frame = NSMakeRect(0, 0, 100, 100); |
| 19 scoped_nsobject<BaseView> view([[BaseView alloc] initWithFrame:frame]); | 19 base::scoped_nsobject<BaseView> view( |
| 20 [[BaseView alloc] initWithFrame:frame]); |
| 20 view_ = view.get(); | 21 view_ = view.get(); |
| 21 [[test_window() contentView] addSubview:view_]; | 22 [[test_window() contentView] addSubview:view_]; |
| 22 } | 23 } |
| 23 | 24 |
| 24 BaseView* view_; // weak | 25 BaseView* view_; // weak |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 TEST_VIEW(BaseViewTest, view_) | 28 TEST_VIEW(BaseViewTest, view_) |
| 28 | 29 |
| 29 // Convert a rect in |view_|'s Cocoa coordinate system to gfx::Rect's top-left | 30 // Convert a rect in |view_|'s Cocoa coordinate system to gfx::Rect's top-left |
| 30 // coordinate system. Repeat the process in reverse and make sure we come out | 31 // coordinate system. Repeat the process in reverse and make sure we come out |
| 31 // with the original rect. | 32 // with the original rect. |
| 32 TEST_F(BaseViewTest, flipNSRectToRect) { | 33 TEST_F(BaseViewTest, flipNSRectToRect) { |
| 33 NSRect convert = NSMakeRect(10, 10, 50, 50); | 34 NSRect convert = NSMakeRect(10, 10, 50, 50); |
| 34 gfx::Rect converted = [view_ flipNSRectToRect:convert]; | 35 gfx::Rect converted = [view_ flipNSRectToRect:convert]; |
| 35 EXPECT_EQ(converted.x(), 10); | 36 EXPECT_EQ(converted.x(), 10); |
| 36 EXPECT_EQ(converted.y(), 40); // Due to view being 100px tall. | 37 EXPECT_EQ(converted.y(), 40); // Due to view being 100px tall. |
| 37 EXPECT_EQ(converted.width(), NSWidth(convert)); | 38 EXPECT_EQ(converted.width(), NSWidth(convert)); |
| 38 EXPECT_EQ(converted.height(), NSHeight(convert)); | 39 EXPECT_EQ(converted.height(), NSHeight(convert)); |
| 39 | 40 |
| 40 // Go back the other way. | 41 // Go back the other way. |
| 41 NSRect back_again = [view_ flipRectToNSRect:converted]; | 42 NSRect back_again = [view_ flipRectToNSRect:converted]; |
| 42 EXPECT_EQ(NSMinX(back_again), NSMinX(convert)); | 43 EXPECT_EQ(NSMinX(back_again), NSMinX(convert)); |
| 43 EXPECT_EQ(NSMinY(back_again), NSMinY(convert)); | 44 EXPECT_EQ(NSMinY(back_again), NSMinY(convert)); |
| 44 EXPECT_EQ(NSWidth(back_again), NSWidth(convert)); | 45 EXPECT_EQ(NSWidth(back_again), NSWidth(convert)); |
| 45 EXPECT_EQ(NSHeight(back_again), NSHeight(convert)); | 46 EXPECT_EQ(NSHeight(back_again), NSHeight(convert)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| OLD | NEW |