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> | |
6 | |
7 #include "base/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
8 #include "chrome/browser/cocoa/browser_test_helper.h" | 6 #include "chrome/browser/cocoa/browser_test_helper.h" |
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
10 #import "chrome/browser/cocoa/extension_shelf_controller.h" | 8 #import "chrome/browser/cocoa/extension_shelf_controller.h" |
11 #import "chrome/browser/cocoa/view_resizer_pong.h" | 9 #import "chrome/browser/cocoa/view_resizer_pong.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "testing/platform_test.h" | |
14 | 10 |
15 namespace { | 11 namespace { |
16 | 12 |
17 class ExtensionShelfControllerTest : public PlatformTest { | 13 class ExtensionShelfControllerTest : public CocoaTest { |
18 public: | 14 public: |
19 ExtensionShelfControllerTest() { | 15 ExtensionShelfControllerTest() { |
20 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 16 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
21 | 17 |
22 NSRect frame = NSMakeRect(0, 0, 100, 30); | 18 NSRect frame = NSMakeRect(0, 0, 100, 30); |
23 controller_.reset([[ExtensionShelfController alloc] | 19 controller_.reset([[ExtensionShelfController alloc] |
24 initWithBrowser:helper_.browser() | 20 initWithBrowser:helper_.browser() |
25 resizeDelegate:resizeDelegate_.get()]); | 21 resizeDelegate:resizeDelegate_.get()]); |
| 22 NSView* view = [controller_ view]; |
| 23 EXPECT_TRUE(view); |
| 24 [[test_window() contentView] addSubview:view]; |
26 } | 25 } |
27 | 26 |
28 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | |
29 BrowserTestHelper helper_; | 27 BrowserTestHelper helper_; |
30 scoped_nsobject<ExtensionShelfController> controller_; | 28 scoped_nsobject<ExtensionShelfController> controller_; |
31 scoped_nsobject<ViewResizerPong> resizeDelegate_; | 29 scoped_nsobject<ViewResizerPong> resizeDelegate_; |
32 }; | 30 }; |
33 | 31 |
| 32 TEST_VIEW(ExtensionShelfControllerTest, [controller_ view]) |
| 33 |
34 // Check that |hide:| tells the delegate to set the shelf's height to zero. | 34 // Check that |hide:| tells the delegate to set the shelf's height to zero. |
35 TEST_F(ExtensionShelfControllerTest, HideSetsHeightToZero) { | 35 TEST_F(ExtensionShelfControllerTest, HideSetsHeightToZero) { |
36 [resizeDelegate_ setHeight:10]; | 36 [resizeDelegate_ setHeight:10]; |
37 [controller_ hide:nil]; | 37 [controller_ hide:nil]; |
38 EXPECT_EQ(0, [resizeDelegate_ height]); | 38 EXPECT_EQ(0, [resizeDelegate_ height]); |
39 } | 39 } |
40 | 40 |
41 // Check that |show:| tells the delegate to set the shelf's height to the | 41 // Check that |show:| tells the delegate to set the shelf's height to the |
42 // shelf's desired height. | 42 // shelf's desired height. |
43 TEST_F(ExtensionShelfControllerTest, ShowSetsHeightToHeight) { | 43 TEST_F(ExtensionShelfControllerTest, ShowSetsHeightToHeight) { |
44 [resizeDelegate_ setHeight:0]; | 44 [resizeDelegate_ setHeight:0]; |
45 [controller_ show:nil]; | 45 [controller_ show:nil]; |
46 EXPECT_GT([controller_ height], 0); | 46 EXPECT_GT([controller_ height], 0); |
47 EXPECT_EQ([controller_ height], [resizeDelegate_ height]); | 47 EXPECT_EQ([controller_ height], [resizeDelegate_ height]); |
48 } | 48 } |
49 | 49 |
50 // Test adding to the view hierarchy, mostly to ensure nothing leaks or crashes. | |
51 TEST_F(ExtensionShelfControllerTest, Add) { | |
52 [cocoa_helper_.contentView() addSubview:[controller_ view]]; | |
53 [controller_ wasInsertedIntoWindow]; | |
54 } | |
55 | |
56 } // namespace | 50 } // namespace |
OLD | NEW |