| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
| 8 #import "chrome/browser/cocoa/base_view.h" | 8 #import "chrome/browser/cocoa/base_view.h" |
| 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class BaseViewTest : public PlatformTest { | 15 class BaseViewTest : public 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 view_.reset([[BaseView alloc] initWithFrame:frame]); | 19 scoped_nsobject<BaseView> view([[BaseView alloc] initWithFrame:frame]); |
| 20 [cocoa_helper_.contentView() addSubview:view_.get()]; | 20 view_ = view.get(); |
| 21 [[test_window() contentView] addSubview:view_]; |
| 21 } | 22 } |
| 22 | 23 |
| 23 scoped_nsobject<BaseView> view_; | 24 BaseView* view_; // weak |
| 24 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // Test adding/removing from the view hierarchy, mostly to ensure nothing | 27 TEST_VIEW(BaseViewTest, view_) |
| 28 // leaks or crashes. | |
| 29 TEST_F(BaseViewTest, AddRemove) { | |
| 30 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); | |
| 31 [view_.get() removeFromSuperview]; | |
| 32 EXPECT_FALSE([view_ superview]); | |
| 33 } | |
| 34 | |
| 35 // Test drawing, mostly to ensure nothing leaks or crashes. | |
| 36 TEST_F(BaseViewTest, Display) { | |
| 37 [view_ display]; | |
| 38 } | |
| 39 | 28 |
| 40 // Convert a rect in |view_|'s Cocoa coordinate system to gfx::Rect's top-left | 29 // Convert a rect in |view_|'s Cocoa coordinate system to gfx::Rect's top-left |
| 41 // coordinate system. Repeat the process in reverse and make sure we come out | 30 // coordinate system. Repeat the process in reverse and make sure we come out |
| 42 // with the original rect. | 31 // with the original rect. |
| 43 TEST_F(BaseViewTest, NSRectToRect) { | 32 TEST_F(BaseViewTest, NSRectToRect) { |
| 44 NSRect convert = NSMakeRect(10, 10, 50, 50); | 33 NSRect convert = NSMakeRect(10, 10, 50, 50); |
| 45 gfx::Rect converted = [view_ NSRectToRect:convert]; | 34 gfx::Rect converted = [view_ NSRectToRect:convert]; |
| 46 EXPECT_EQ(converted.x(), 10); | 35 EXPECT_EQ(converted.x(), 10); |
| 47 EXPECT_EQ(converted.y(), 40); // Due to view being 100px tall. | 36 EXPECT_EQ(converted.y(), 40); // Due to view being 100px tall. |
| 48 EXPECT_EQ(converted.width(), convert.size.width); | 37 EXPECT_EQ(converted.width(), convert.size.width); |
| 49 EXPECT_EQ(converted.height(), convert.size.height); | 38 EXPECT_EQ(converted.height(), convert.size.height); |
| 50 | 39 |
| 51 // Go back the other way. | 40 // Go back the other way. |
| 52 NSRect back_again = [view_ RectToNSRect:converted]; | 41 NSRect back_again = [view_ RectToNSRect:converted]; |
| 53 EXPECT_EQ(back_again.origin.x, convert.origin.x); | 42 EXPECT_EQ(back_again.origin.x, convert.origin.x); |
| 54 EXPECT_EQ(back_again.origin.y, convert.origin.y); | 43 EXPECT_EQ(back_again.origin.y, convert.origin.y); |
| 55 EXPECT_EQ(back_again.size.width, convert.size.width); | 44 EXPECT_EQ(back_again.size.width, convert.size.width); |
| 56 EXPECT_EQ(back_again.size.height, convert.size.height); | 45 EXPECT_EQ(back_again.size.height, convert.size.height); |
| 57 } | 46 } |
| 58 | 47 |
| 59 } // namespace | 48 } // namespace |
| OLD | NEW |