1 // Copyright (c) 2011 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.
5 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/mac/scoped_nsobject.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
12 #import "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h"
13 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h"
14 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
15 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
16 #include "chrome/test/base/testing_profile.h"
17 #import "content/public/browser/web_contents.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h"
23 class InfoBarContainerControllerTest : public CocoaProfileTest {
24 void SetUp() override {
25 CocoaProfileTest::SetUp();
26 web_contents_.reset(content::WebContents::Create(
27 content::WebContents::CreateParams(profile())));
28 InfoBarService::CreateForWebContents(web_contents_.get());
30 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
31 ViewResizerPong *viewResizer = resizeDelegate_.get();
32 controller_.reset([[InfoBarContainerController alloc]
33 initWithResizeDelegate:viewResizer]);
34 NSView* view = [controller_ view];
35 [[test_window() contentView] addSubview:view];
38 void TearDown() override {
39 [[controller_ view] removeFromSuperviewWithoutNeedingDisplay];
41 CocoaProfileTest::TearDown();
45 base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
46 base::scoped_nsobject<InfoBarContainerController> controller_;
47 scoped_ptr<content::WebContents> web_contents_;
50 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view])
52 TEST_F(InfoBarContainerControllerTest, BWCPong) {
53 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a
55 [resizeDelegate_ resizeView:[controller_ view] newHeight:-1];
56 [controller_ positionInfoBarsAndRedraw:NO];
57 EXPECT_NE(-1, [resizeDelegate_ height]);
60 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
61 NSView* view = [controller_ view];
63 scoped_ptr<infobars::InfoBarDelegate> confirm_delegate(
64 new MockConfirmInfoBarDelegate(NULL));
65 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(confirm_delegate.Pass()));
66 base::scoped_nsobject<ConfirmInfoBarController> controller(
67 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]);
68 infobar->set_controller(controller);
69 [controller_ addInfoBar:infobar.get() position:0];
70 EXPECT_EQ(1U, [[view subviews] count]);
72 [controller_ removeInfoBar:infobar.get()];
73 EXPECT_EQ(0U, [[view subviews] count]);