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

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

Issue 23338005: Mac InfoBar: Use cross platform infobar classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 5 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.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"
11 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" 13 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
12 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" 14 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
15 #import "content/public/browser/web_contents.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
15 18
16 namespace { 19 namespace {
17 20
18 class InfoBarContainerControllerTest : public CocoaTest { 21 class InfoBarContainerControllerTest : public CocoaProfileTest {
19 virtual void SetUp() { 22 virtual void SetUp() {
20 CocoaTest::SetUp(); 23 CocoaProfileTest::SetUp();
24 web_contents_.reset(content::WebContents::Create(
25 content::WebContents::CreateParams(profile())));
26 InfoBarService::CreateForWebContents(web_contents_.get());
27
21 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 28 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
22 ViewResizerPong *viewResizer = resizeDelegate_.get(); 29 ViewResizerPong *viewResizer = resizeDelegate_.get();
23 controller_ = 30 controller_ =
24 [[InfoBarContainerController alloc] initWithResizeDelegate:viewResizer]; 31 [[InfoBarContainerController alloc] initWithResizeDelegate:viewResizer];
25 NSView* view = [controller_ view]; 32 NSView* view = [controller_ view];
26 [[test_window() contentView] addSubview:view]; 33 [[test_window() contentView] addSubview:view];
27 } 34 }
28 35
29 virtual void TearDown() { 36 virtual void TearDown() {
30 [[controller_ view] removeFromSuperviewWithoutNeedingDisplay]; 37 [[controller_ view] removeFromSuperviewWithoutNeedingDisplay];
31 [controller_ release]; 38 [controller_ release];
32 CocoaTest::TearDown(); 39 CocoaProfileTest::TearDown();
33 } 40 }
34 41
35 public: 42 public:
36 base::scoped_nsobject<ViewResizerPong> resizeDelegate_; 43 base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
37 InfoBarContainerController* controller_; 44 InfoBarContainerController* controller_;
45 scoped_ptr<content::WebContents> web_contents_;
38 }; 46 };
39 47
40 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view]) 48 TEST_VIEW(InfoBarContainerControllerTest, [controller_ view])
41 49
42 TEST_F(InfoBarContainerControllerTest, BWCPong) { 50 TEST_F(InfoBarContainerControllerTest, BWCPong) {
43 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a 51 // Call positionInfoBarsAndResize and check that |resizeDelegate_| got a
44 // resize message. 52 // resize message.
45 [resizeDelegate_ setHeight:-1]; 53 [resizeDelegate_ setHeight:-1];
46 [controller_ positionInfoBarsAndRedraw]; 54 [controller_ positionInfoBarsAndRedraw:NO];
47 EXPECT_NE(-1, [resizeDelegate_ height]); 55 EXPECT_NE(-1, [resizeDelegate_ height]);
48 } 56 }
49 57
50 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { 58 TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
51 NSView* view = [controller_ view]; 59 NSView* view = [controller_ view];
52 60
53 // Add three infobars and then remove them.
54 // After each step check to make sure we have the correct number of
55 // infobar subviews.
56
57 // This delegate deletes itself when they're told their infobars have closed. 61 // This delegate deletes itself when they're told their infobars have closed.
58 InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); 62 InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL);
59 63
60 [controller_ addInfoBar:confirmDelegate->CreateInfoBar(NULL) animate:NO]; 64 InfoBarService* infobar_service =
65 InfoBarService::FromWebContents(web_contents_.get());
66 scoped_ptr<InfoBarCocoa> infobar(static_cast<InfoBarCocoa*>(
67 confirmDelegate->CreateInfoBar(infobar_service)));
68 [controller_ addInfoBar:infobar.get() position:0];
61 EXPECT_EQ(1U, [[view subviews] count]); 69 EXPECT_EQ(1U, [[view subviews] count]);
62 70
63 // Just to mix things up, remove them in a different order. 71 [controller_ removeInfoBar:infobar.release()];
64 [controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO];
65 EXPECT_EQ(0U, [[view subviews] count]); 72 EXPECT_EQ(0U, [[view subviews] count]);
66 } 73 }
67 74
68 TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) {
69 NSView* view = [controller_ view];
70
71 // Add three infobars and then remove them all.
72
73 // removeAllInfobars does not close these, so we stack-allocate them so
74 // they'll get cleaned up.
75 MockConfirmInfoBarDelegate confirmDelegate(NULL);
76 MockConfirmInfoBarDelegate confirmDelegate2(NULL);
77 InfoBarDelegate* confirmDelegatePtr = &confirmDelegate;
78 InfoBarDelegate* confirmDelegate2Ptr = &confirmDelegate2;
79
80 [controller_ addInfoBar:confirmDelegatePtr->CreateInfoBar(NULL) animate:NO];
81 [controller_ addInfoBar:confirmDelegate2Ptr->CreateInfoBar(NULL) animate:NO];
82 EXPECT_EQ(2U, [[view subviews] count]);
83
84 [controller_ removeAllInfoBars];
85 EXPECT_EQ(0U, [[view subviews] count]);
86 }
87
88 } // namespace 75 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698