| 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/background_gradient_view.h" | 8 #import "chrome/browser/cocoa/background_gradient_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 // Since BackgroundGradientView doesn't do any drawing by default, we |
| 14 // create a subclass to call its draw method for us. |
| 15 @interface BackgroundGradientSubClassTest : BackgroundGradientView |
| 16 @end |
| 17 |
| 18 @implementation BackgroundGradientSubClassTest |
| 19 - (void)drawRect:(NSRect)rect { |
| 20 [self drawBackground]; |
| 21 } |
| 22 @end |
| 23 |
| 13 namespace { | 24 namespace { |
| 14 | 25 |
| 15 class BackgroundGradientViewTest : public PlatformTest { | 26 class BackgroundGradientViewTest : public PlatformTest { |
| 16 public: | 27 public: |
| 17 BackgroundGradientViewTest() { | 28 BackgroundGradientViewTest() { |
| 18 NSRect frame = NSMakeRect(0, 0, 100, 30); | 29 NSRect frame = NSMakeRect(0, 0, 100, 30); |
| 19 view_.reset([[BackgroundGradientView alloc] initWithFrame:frame]); | 30 view_.reset([[BackgroundGradientSubClassTest alloc] initWithFrame:frame]); |
| 20 [cocoa_helper_.contentView() addSubview:view_.get()]; | 31 [cocoa_helper_.contentView() addSubview:view_.get()]; |
| 21 } | 32 } |
| 22 | 33 |
| 23 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 34 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
| 24 scoped_nsobject<BackgroundGradientView> view_; | 35 scoped_nsobject<BackgroundGradientSubClassTest> view_; |
| 25 }; | 36 }; |
| 26 | 37 |
| 27 // Test adding/removing from the view hierarchy, mostly to ensure nothing | 38 // Test adding/removing from the view hierarchy, mostly to ensure nothing |
| 28 // leaks or crashes. | 39 // leaks or crashes. |
| 29 TEST_F(BackgroundGradientViewTest, AddRemove) { | 40 TEST_F(BackgroundGradientViewTest, AddRemove) { |
| 30 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); | 41 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); |
| 31 [view_.get() removeFromSuperview]; | 42 [view_.get() removeFromSuperview]; |
| 32 EXPECT_FALSE([view_ superview]); | 43 EXPECT_FALSE([view_ superview]); |
| 33 } | 44 } |
| 34 | 45 |
| 35 // Test drawing, mostly to ensure nothing leaks or crashes. | 46 // Test drawing, mostly to ensure nothing leaks or crashes. |
| 36 TEST_F(BackgroundGradientViewTest, Display) { | 47 TEST_F(BackgroundGradientViewTest, Display) { |
| 37 [view_ display]; | 48 [view_ display]; |
| 38 [view_ setShowsDivider:YES]; | 49 [view_ setShowsDivider:YES]; |
| 39 [view_ display]; | 50 [view_ display]; |
| 40 } | 51 } |
| 41 | 52 |
| 42 } // namespace | 53 } // namespace |
| OLD | NEW |