diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 03:16:58 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 03:16:58 +0000 |
commit | 91cea0e774541297a46197d87e486cf8a4199775 (patch) | |
tree | be5058bd3eec65a923abbaef68342249574b7ce2 /chrome/browser/cocoa/infobar_container_controller_unittest.mm | |
parent | 8a1d601fcd2f8bf457ea4e9592e918acc9835f87 (diff) | |
download | chromium_src-91cea0e774541297a46197d87e486cf8a4199775.zip chromium_src-91cea0e774541297a46197d87e486cf8a4199775.tar.gz chromium_src-91cea0e774541297a46197d87e486cf8a4199775.tar.bz2 |
First cut at infobars on Mac. These are not expected to be
pretty. Animations and aesthetic appeal will come in a
future CL.
BUG=http://crbug.com/14462
BUG=http://crbug.com/14937
BUG=http://crbug.com/15839
BUG=http://crbug.com/16487
TEST=Infobars should show up when expected.
Review URL: http://codereview.chromium.org/155494
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20930 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/infobar_container_controller_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/infobar_container_controller_unittest.mm | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/infobar_container_controller_unittest.mm b/chrome/browser/cocoa/infobar_container_controller_unittest.mm new file mode 100644 index 0000000..77e8e82 --- /dev/null +++ b/chrome/browser/cocoa/infobar_container_controller_unittest.mm @@ -0,0 +1,123 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsautorelease_pool.h" +#include "base/scoped_nsobject.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#import "chrome/browser/cocoa/infobar_container_controller.h" +#include "chrome/browser/cocoa/infobar_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" + +// Objective-C classes must be defined outside the namespace. +@interface BrowserWindowControllerPong : BrowserWindowController { + BOOL pong_; +} +@property(readonly) BOOL pong; +@end + +@implementation BrowserWindowControllerPong +@synthesize pong = pong_; + +- (id)initWithBrowser:(Browser*)browser { + if ((self = [super initWithBrowser:browser takeOwnership:NO])) { + pong_ = NO; + } + return self; +} + +- (void)infoBarResized:(float)newHeight { + pong_ = TRUE; +} +@end + +namespace { + +class InfoBarContainerControllerTest : public testing::Test { + virtual void SetUp() { + browserController_.reset([[BrowserWindowControllerPong alloc] + initWithBrowser:browser_helper_.browser()]); + TabStripModel* model = browser_helper_.browser()->tabstrip_model(); + controller_.reset([[InfoBarContainerController alloc] + initWithTabStripModel:model + browserWindowController:browserController_]); + } + + public: + // Order is very important here. We want the controller deleted + // before the pool, and want the pool deleted before + // BrowserTestHelper. + CocoaTestHelper cocoa_helper_; + BrowserTestHelper browser_helper_; + base::ScopedNSAutoreleasePool pool_; + scoped_nsobject<BrowserWindowControllerPong> browserController_; + scoped_nsobject<InfoBarContainerController> controller_; +}; + +TEST_F(InfoBarContainerControllerTest, Show) { + // Make sure the container's view is non-nil and draws without crashing. + NSView* view = [controller_ view]; + EXPECT_TRUE(view != nil); + + [cocoa_helper_.contentView() addSubview:view]; +} + +TEST_F(InfoBarContainerControllerTest, BWCPong) { + // Call positionInfoBarsAndResize and check that the BWC got a resize message. + [controller_ positionInfoBarsAndRedraw]; + EXPECT_TRUE([browserController_ pong]); +} + +TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { + NSView* view = [controller_ view]; + [cocoa_helper_.contentView() addSubview:view]; + + // Add three infobars, one of each type, and then remove them. + // After each step check to make sure we have the correct number of + // infobar subviews. + MockAlertInfoBarDelegate alertDelegate; + MockLinkInfoBarDelegate linkDelegate; + MockConfirmInfoBarDelegate confirmDelegate; + + [controller_ addInfoBar:&alertDelegate]; + EXPECT_EQ(1U, [[view subviews] count]); + + [controller_ addInfoBar:&linkDelegate]; + EXPECT_EQ(2U, [[view subviews] count]); + + [controller_ addInfoBar:&confirmDelegate]; + EXPECT_EQ(3U, [[view subviews] count]); + + // Just to mix things up, remove them in a different order. + [controller_ removeInfoBarsForDelegate:&linkDelegate]; + EXPECT_EQ(2U, [[view subviews] count]); + + [controller_ removeInfoBarsForDelegate:&confirmDelegate]; + EXPECT_EQ(1U, [[view subviews] count]); + + [controller_ removeInfoBarsForDelegate:&alertDelegate]; + EXPECT_EQ(0U, [[view subviews] count]); +} + +TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { + NSView* view = [controller_ view]; + [cocoa_helper_.contentView() addSubview:view]; + + // Add three infobars and then remove them all. + MockAlertInfoBarDelegate alertDelegate; + MockLinkInfoBarDelegate linkDelegate; + MockConfirmInfoBarDelegate confirmDelegate; + + [controller_ addInfoBar:&alertDelegate]; + [controller_ addInfoBar:&linkDelegate]; + [controller_ addInfoBar:&confirmDelegate]; + EXPECT_EQ(3U, [[view subviews] count]); + + [controller_ removeAllInfoBars]; + EXPECT_EQ(0U, [[view subviews] count]); +} +} // namespace |