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

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

Issue 155494: First cut at infobars on Mac. These are not expected to be... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 months 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
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/scoped_nsobject.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #import "chrome/browser/cocoa/browser_window_controller.h"
11 #import "chrome/browser/cocoa/cocoa_test_helper.h"
12 #import "chrome/browser/cocoa/infobar_container_controller.h"
13 #include "chrome/browser/cocoa/infobar_test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 // Objective-C classes must be defined outside the namespace.
17 @interface BrowserWindowControllerPong : BrowserWindowController {
18 BOOL pong_;
19 }
20 @property(readonly) BOOL pong;
21 @end
22
23 @implementation BrowserWindowControllerPong
24 @synthesize pong = pong_;
25
26 - (id)initWithBrowser:(Browser*)browser {
27 if ((self = [super initWithBrowser:browser takeOwnership:NO])) {
28 pong_ = NO;
29 }
30 return self;
31 }
32
33 - (void)infoBarResized:(float)newHeight {
34 pong_ = TRUE;
35 }
36 @end
37
38 namespace {
39
40 class InfoBarContainerControllerTest : public testing::Test {
41 virtual void SetUp() {
42 browserController_.reset([[BrowserWindowControllerPong alloc]
43 initWithBrowser:browser_helper_.browser()]);
44 TabStripModel* model = browser_helper_.browser()->tabstrip_model();
45 controller_.reset([[InfoBarContainerController alloc]
46 initWithTabStripModel:model
47 browserWindowController:browserController_]);
48 }
49
50 public:
51 // Order is very important here. We want the controller deleted
52 // before the pool, and want the pool deleted before
53 // BrowserTestHelper.
54 CocoaTestHelper cocoa_helper_;
55 BrowserTestHelper browser_helper_;
56 base::ScopedNSAutoreleasePool pool_;
57 scoped_nsobject<BrowserWindowControllerPong> browserController_;
58 scoped_nsobject<InfoBarContainerController> controller_;
59 };
60
61 TEST_F(InfoBarContainerControllerTest, Show) {
62 // Make sure the container's view is non-nil and draws without crashing.
63 NSView* view = [controller_ view];
64 EXPECT_TRUE(view != nil);
65
66 [cocoa_helper_.contentView() addSubview:view];
67 }
68
69 TEST_F(InfoBarContainerControllerTest, BWCPong) {
70 // Call positionInfoBarsAndResize and check that the BWC got a resize message.
71 [controller_ positionInfoBarsAndRedraw];
72 EXPECT_TRUE([browserController_ pong]);
73 }
74
75 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
76 NSView* view = [controller_ view];
77 [cocoa_helper_.contentView() addSubview:view];
78
79 // Add three infobars, one of each type, and then remove them.
80 // After each step check to make sure we have the correct number of
81 // infobar subviews.
82 MockAlertInfoBarDelegate alertDelegate;
83 MockLinkInfoBarDelegate linkDelegate;
84 MockConfirmInfoBarDelegate confirmDelegate;
85
86 [controller_ addInfoBar:&alertDelegate];
87 EXPECT_EQ(1U, [[view subviews] count]);
88
89 [controller_ addInfoBar:&linkDelegate];
90 EXPECT_EQ(2U, [[view subviews] count]);
91
92 [controller_ addInfoBar:&confirmDelegate];
93 EXPECT_EQ(3U, [[view subviews] count]);
94
95 // Just to mix things up, remove them in a different order.
96 [controller_ removeInfoBarsForDelegate:&linkDelegate];
97 EXPECT_EQ(2U, [[view subviews] count]);
98
99 [controller_ removeInfoBarsForDelegate:&confirmDelegate];
100 EXPECT_EQ(1U, [[view subviews] count]);
101
102 [controller_ removeInfoBarsForDelegate:&alertDelegate];
103 EXPECT_EQ(0U, [[view subviews] count]);
104 }
105
106 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) {
107 NSView* view = [controller_ view];
108 [cocoa_helper_.contentView() addSubview:view];
109
110 // Add three infobars and then remove them all.
111 MockAlertInfoBarDelegate alertDelegate;
112 MockLinkInfoBarDelegate linkDelegate;
113 MockConfirmInfoBarDelegate confirmDelegate;
114
115 [controller_ addInfoBar:&alertDelegate];
116 [controller_ addInfoBar:&linkDelegate];
117 [controller_ addInfoBar:&confirmDelegate];
118 EXPECT_EQ(3U, [[view subviews] count]);
119
120 [controller_ removeAllInfoBars];
121 EXPECT_EQ(0U, [[view subviews] count]);
122 }
123 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/infobar_container_controller.mm ('k') | chrome/browser/cocoa/infobar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698