- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / infobars / infobar_container_controller_unittest.mm
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.
4
5 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
6
7 #import <Cocoa/Cocoa.h>
8
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 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h"
13 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
14 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
15 #include "chrome/test/base/testing_profile.h"
16 #import "content/public/browser/web_contents.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/platform_test.h"
19
20 namespace {
21
22 class InfoBarContainerControllerTest : public CocoaProfileTest {
23   virtual void SetUp() OVERRIDE {
24     CocoaProfileTest::SetUp();
25     web_contents_.reset(content::WebContents::Create(
26         content::WebContents::CreateParams(profile())));
27     InfoBarService::CreateForWebContents(web_contents_.get());
28
29     resizeDelegate_.reset([[ViewResizerPong alloc] init]);
30     ViewResizerPong *viewResizer = resizeDelegate_.get();
31     controller_.reset([[InfoBarContainerController alloc]
32         initWithResizeDelegate:viewResizer]);
33     NSView* view = [controller_ view];
34     [[test_window() contentView] addSubview:view];
35   }
36
37   virtual void TearDown() OVERRIDE {
38     [[controller_ view] removeFromSuperviewWithoutNeedingDisplay];
39     controller_.reset();
40     CocoaProfileTest::TearDown();
41   }
42
43  public:
44   base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
45   base::scoped_nsobject<InfoBarContainerController> controller_;
46   scoped_ptr<content::WebContents> web_contents_;
47 };
48
49 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view])
50
51 TEST_F(InfoBarContainerControllerTest, BWCPong) {
52   // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a
53   // resize message.
54   [resizeDelegate_ resizeView:[controller_ view] newHeight:-1];
55   [controller_ positionInfoBarsAndRedraw:NO];
56   EXPECT_NE(-1, [resizeDelegate_ height]);
57 }
58
59 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
60   NSView* view = [controller_ view];
61
62   // This delegate deletes itself when they're told their infobars have closed.
63   InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL);
64
65   InfoBarService* infobar_service =
66       InfoBarService::FromWebContents(web_contents_.get());
67   scoped_ptr<InfoBarCocoa> infobar(static_cast<InfoBarCocoa*>(
68       confirmDelegate->CreateInfoBar(infobar_service)));
69   [controller_ addInfoBar:infobar.get() position:0];
70   EXPECT_EQ(1U, [[view subviews] count]);
71
72   [controller_ removeInfoBar:infobar.release()];
73   EXPECT_EQ(0U, [[view subviews] count]);
74 }
75
76 }  // namespace