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

Side by Side Diff: chrome/browser/cocoa/infobar_container_controller_unittest.mm

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_nsautorelease_pool.h" 7 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/scoped_nsobject.h" 8 #include "base/scoped_nsobject.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #import "chrome/browser/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/cocoa/infobar_container_controller.h" 11 #import "chrome/browser/cocoa/infobar_container_controller.h"
12 #include "chrome/browser/cocoa/infobar_test_helper.h" 12 #include "chrome/browser/cocoa/infobar_test_helper.h"
13 #import "chrome/browser/cocoa/view_resizer_pong.h" 13 #import "chrome/browser/cocoa/view_resizer_pong.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
16 16
17 namespace { 17 namespace {
18 18
19 class InfoBarContainerControllerTest : public PlatformTest { 19 class InfoBarContainerControllerTest : public CocoaTest {
20 virtual void SetUp() { 20 virtual void SetUp() {
21 CocoaTest::SetUp();
21 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 22 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
22 TabStripModel* model = browser_helper_.browser()->tabstrip_model(); 23 TabStripModel* model = browser_helper_.browser()->tabstrip_model();
23 controller_.reset([[InfoBarContainerController alloc] 24 ViewResizerPong *viewResizer = resizeDelegate_.get();
24 initWithTabStripModel:model 25 controller_ =
25 resizeDelegate:resizeDelegate_.get()]); 26 [[InfoBarContainerController alloc] initWithTabStripModel:model
27 resizeDelegate:viewResizer];
28 NSView* view = [controller_ view];
29 [[test_window() contentView] addSubview:view];
30 }
31
32 virtual void TearDown() {
33 [[controller_ view] removeFromSuperviewWithoutNeedingDisplay];
34 [controller_ release];
35 CocoaTest::TearDown();
26 } 36 }
27 37
28 public: 38 public:
29 // Order is very important here. We want the controller deleted
30 // before the pool, and want the pool deleted before
31 // BrowserTestHelper.
32 CocoaTestHelper cocoa_helper_;
33 BrowserTestHelper browser_helper_; 39 BrowserTestHelper browser_helper_;
34 base::ScopedNSAutoreleasePool pool_;
35 scoped_nsobject<ViewResizerPong> resizeDelegate_; 40 scoped_nsobject<ViewResizerPong> resizeDelegate_;
36 scoped_nsobject<InfoBarContainerController> controller_; 41 InfoBarContainerController* controller_;
37 }; 42 };
38 43
39 TEST_F(InfoBarContainerControllerTest, Show) { 44 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view])
40 // Make sure the container's view is non-nil and draws without crashing.
41 NSView* view = [controller_ view];
42 EXPECT_TRUE(view != nil);
43
44 [cocoa_helper_.contentView() addSubview:view];
45 }
46 45
47 TEST_F(InfoBarContainerControllerTest, BWCPong) { 46 TEST_F(InfoBarContainerControllerTest, BWCPong) {
48 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a 47 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a
49 // resize message. 48 // resize message.
50 [resizeDelegate_ setHeight:-1]; 49 [resizeDelegate_ setHeight:-1];
51 [controller_ positionInfoBarsAndRedraw]; 50 [controller_ positionInfoBarsAndRedraw];
52 EXPECT_NE(-1, [resizeDelegate_ height]); 51 EXPECT_NE(-1, [resizeDelegate_ height]);
53 } 52 }
54 53
55 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { 54 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
56 NSView* view = [controller_ view]; 55 NSView* view = [controller_ view];
57 [cocoa_helper_.contentView() addSubview:view];
58 56
59 // Add three infobars, one of each type, and then remove them. 57 // Add three infobars, one of each type, and then remove them.
60 // After each step check to make sure we have the correct number of 58 // After each step check to make sure we have the correct number of
61 // infobar subviews. 59 // infobar subviews.
62 MockAlertInfoBarDelegate alertDelegate; 60 MockAlertInfoBarDelegate alertDelegate;
63 MockLinkInfoBarDelegate linkDelegate; 61 MockLinkInfoBarDelegate linkDelegate;
64 MockConfirmInfoBarDelegate confirmDelegate; 62 MockConfirmInfoBarDelegate confirmDelegate;
65 63
66 [controller_ addInfoBar:&alertDelegate animate:NO]; 64 [controller_ addInfoBar:&alertDelegate animate:NO];
67 EXPECT_EQ(1U, [[view subviews] count]); 65 EXPECT_EQ(1U, [[view subviews] count]);
(...skipping 10 matching lines...) Expand all
78 76
79 [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO]; 77 [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO];
80 EXPECT_EQ(1U, [[view subviews] count]); 78 EXPECT_EQ(1U, [[view subviews] count]);
81 79
82 [controller_ closeInfoBarsForDelegate:&alertDelegate animate:NO]; 80 [controller_ closeInfoBarsForDelegate:&alertDelegate animate:NO];
83 EXPECT_EQ(0U, [[view subviews] count]); 81 EXPECT_EQ(0U, [[view subviews] count]);
84 } 82 }
85 83
86 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { 84 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) {
87 NSView* view = [controller_ view]; 85 NSView* view = [controller_ view];
88 [cocoa_helper_.contentView() addSubview:view];
89 86
90 // Add three infobars and then remove them all. 87 // Add three infobars and then remove them all.
91 MockAlertInfoBarDelegate alertDelegate; 88 MockAlertInfoBarDelegate alertDelegate;
92 MockLinkInfoBarDelegate linkDelegate; 89 MockLinkInfoBarDelegate linkDelegate;
93 MockConfirmInfoBarDelegate confirmDelegate; 90 MockConfirmInfoBarDelegate confirmDelegate;
94 91
95 [controller_ addInfoBar:&alertDelegate animate:NO]; 92 [controller_ addInfoBar:&alertDelegate animate:NO];
96 [controller_ addInfoBar:&linkDelegate animate:NO]; 93 [controller_ addInfoBar:&linkDelegate animate:NO];
97 [controller_ addInfoBar:&confirmDelegate animate:NO]; 94 [controller_ addInfoBar:&confirmDelegate animate:NO];
98 EXPECT_EQ(3U, [[view subviews] count]); 95 EXPECT_EQ(3U, [[view subviews] count]);
99 96
100 [controller_ removeAllInfoBars]; 97 [controller_ removeAllInfoBars];
101 EXPECT_EQ(0U, [[view subviews] count]); 98 EXPECT_EQ(0U, [[view subviews] count]);
102 } 99 }
103 } // namespace 100 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/hyperlink_button_cell_unittest.mm ('k') | chrome/browser/cocoa/infobar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698