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

Side by Side Diff: chrome/browser/ui/cocoa/infobars/confirm_infobar_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, 3 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/confirm_infobar_controller.h" 5 #import "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h"
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 10 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
13 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h"
13 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 14 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
14 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" 15 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h"
15 #include "chrome/browser/ui/cocoa/run_loop_testing.h" 16 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
16 #import "content/public/browser/web_contents.h" 17 #import "content/public/browser/web_contents.h"
17 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 20 #include "testing/platform_test.h"
20 21
21 using content::WebContents; 22 using content::WebContents;
22 23
23 @interface InfoBarController (ExposedForTesting) 24 @interface InfoBarController (ExposedForTesting)
24 - (NSString*)labelString; 25 - (NSString*)labelString;
25 - (NSRect)labelFrame; 26 - (NSRect)labelFrame;
26 @end 27 @end
27 28
28 @implementation InfoBarController (ExposedForTesting) 29 @implementation InfoBarController (ExposedForTesting)
29 - (NSString*)labelString { 30 - (NSString*)labelString {
30 return [label_.get() string]; 31 return [label_.get() string];
31 } 32 }
32 - (NSRect)labelFrame { 33 - (NSRect)labelFrame {
33 return [label_.get() frame]; 34 return [label_.get() frame];
34 } 35 }
35 @end 36 @end
36 37
37 38
38 @interface InfoBarContainerTest : NSObject<InfoBarContainer> { 39 @interface InfoBarContainerTest : NSObject<InfoBarContainerControllerBase> {
39 InfoBarController* controller_; 40 InfoBarController* controller_;
40 } 41 }
42
41 - (id)initWithController:(InfoBarController*)controller; 43 - (id)initWithController:(InfoBarController*)controller;
42 - (void)willRemoveController:(InfoBarController*)controller; 44
43 - (void)removeController:(InfoBarController*)controller;
44 @end 45 @end
45 46
46 @implementation InfoBarContainerTest 47 @implementation InfoBarContainerTest
48
47 - (id)initWithController:(InfoBarController*)controller { 49 - (id)initWithController:(InfoBarController*)controller {
48 if ((self = [super init])) { 50 if ((self = [super init])) {
49 controller_ = controller; 51 controller_ = controller;
50 } 52 }
51 return self; 53 return self;
52 } 54 }
53 55
54 - (void)willRemoveController:(InfoBarController*)controller {
55 }
56
57 - (void)removeController:(InfoBarController*)controller {
58 DCHECK(controller_ == controller);
59 controller_ = nil;
60 }
61
62 - (BrowserWindowController*)browserWindowController { 56 - (BrowserWindowController*)browserWindowController {
63 return nil; 57 return nil;
64 } 58 }
59
60 - (BOOL)shouldSuppressTopInfoBarTip {
61 return NO;
62 }
63
64 - (CGFloat)infobarArrowX {
65 return 0;
66 }
67
65 @end 68 @end
66 69
67 @interface TestConfirmInfoBarController : ConfirmInfoBarController 70 @interface TestConfirmInfoBarController : ConfirmInfoBarController
68 - (void)removeSelf; 71 - (void)removeSelf;
69 @end 72 @end
70 73
71 @implementation TestConfirmInfoBarController 74 @implementation TestConfirmInfoBarController
72 - (void)removeSelf { 75 - (void)removeSelf {
73 [self close]; 76 [self infobarWillClose];
77 if ([self infobar])
78 [self infobar]->CloseSoon();
74 } 79 }
75 @end 80 @end
76 81
77 namespace { 82 namespace {
78 83
79 class ConfirmInfoBarControllerTest : public CocoaProfileTest, 84 class ConfirmInfoBarControllerTest : public CocoaProfileTest,
80 public MockConfirmInfoBarDelegate::Owner { 85 public MockConfirmInfoBarDelegate::Owner {
81 public: 86 public:
82 virtual void SetUp() { 87 virtual void SetUp() OVERRIDE {
83 CocoaProfileTest::SetUp(); 88 CocoaProfileTest::SetUp();
84 web_contents_.reset( 89 web_contents_.reset(
85 WebContents::Create(WebContents::CreateParams(profile()))); 90 WebContents::Create(WebContents::CreateParams(profile())));
86 InfoBarService::CreateForWebContents(web_contents_.get()); 91 InfoBarService::CreateForWebContents(web_contents_.get());
87 92
88 InfoBarService* infobar_service = 93 InfoBarService* infobar_service =
89 InfoBarService::FromWebContents(web_contents_.get()); 94 InfoBarService::FromWebContents(web_contents_.get());
90 delegate_ = new MockConfirmInfoBarDelegate(this); 95 delegate_ = new MockConfirmInfoBarDelegate(this);
96 infobar_.reset(new InfoBarCocoa(infobar_service, delegate_));
97
91 controller_.reset([[TestConfirmInfoBarController alloc] 98 controller_.reset([[TestConfirmInfoBarController alloc]
92 initWithDelegate:delegate_ owner:infobar_service]); 99 initWithInfoBar:infobar_.get()]);
100 infobar_->set_controller(controller_);
101
93 container_.reset( 102 container_.reset(
94 [[InfoBarContainerTest alloc] initWithController:controller_]); 103 [[InfoBarContainerTest alloc] initWithController:controller_]);
95 [controller_ setContainerController:container_]; 104 [controller_ setContainerController:container_];
96 [[test_window() contentView] addSubview:[controller_ view]]; 105 [[test_window() contentView] addSubview:[controller_ view]];
97 closed_delegate_ok_clicked_ = false; 106 closed_delegate_ok_clicked_ = false;
98 closed_delegate_cancel_clicked_ = false; 107 closed_delegate_cancel_clicked_ = false;
99 closed_delegate_link_clicked_ = false; 108 closed_delegate_link_clicked_ = false;
100 } 109 }
101 110
102 virtual void TearDown() { 111 virtual void TearDown() OVERRIDE {
112 [controller_ removeSelf];
103 if (delegate_) 113 if (delegate_)
104 delete delegate_; 114 delete delegate_;
105 CocoaProfileTest::TearDown(); 115 CocoaProfileTest::TearDown();
106 } 116 }
107 117
108 protected: 118 protected:
109 // Hopefully-obvious: If this returns true, you must not deref |delegate_|! 119 // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
110 bool delegate_closed() const { return delegate_ == NULL; } 120 bool delegate_closed() const { return delegate_ == NULL; }
111 121
112 MockConfirmInfoBarDelegate* delegate_; // Owns itself. 122 MockConfirmInfoBarDelegate* delegate_; // Owns itself.
113 base::scoped_nsobject<id> container_; 123 base::scoped_nsobject<id> container_;
114 base::scoped_nsobject<ConfirmInfoBarController> controller_; 124 base::scoped_nsobject<ConfirmInfoBarController> controller_;
115 bool closed_delegate_ok_clicked_; 125 bool closed_delegate_ok_clicked_;
116 bool closed_delegate_cancel_clicked_; 126 bool closed_delegate_cancel_clicked_;
117 bool closed_delegate_link_clicked_; 127 bool closed_delegate_link_clicked_;
118 128
119 private: 129 private:
120 virtual void OnInfoBarDelegateClosed() OVERRIDE { 130 virtual void OnInfoBarDelegateClosed() OVERRIDE {
121 closed_delegate_ok_clicked_ = delegate_->ok_clicked(); 131 closed_delegate_ok_clicked_ = delegate_->ok_clicked();
122 closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); 132 closed_delegate_cancel_clicked_ = delegate_->cancel_clicked();
123 closed_delegate_link_clicked_ = delegate_->link_clicked(); 133 closed_delegate_link_clicked_ = delegate_->link_clicked();
124 delegate_ = NULL; 134 delegate_ = NULL;
125 } 135 }
126 136
127 scoped_ptr<WebContents> web_contents_; 137 scoped_ptr<WebContents> web_contents_;
138 scoped_ptr<InfoBarCocoa> infobar_;
128 }; 139 };
129 140
130 141
131 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); 142 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]);
132 143
133 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { 144 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) {
134 // Make sure someone looked at the message, link, and icon. 145 // Make sure someone looked at the message, link, and icon.
135 EXPECT_TRUE(delegate_->message_text_accessed()); 146 EXPECT_TRUE(delegate_->message_text_accessed());
136 EXPECT_TRUE(delegate_->link_text_accessed()); 147 EXPECT_TRUE(delegate_->link_text_accessed());
137 EXPECT_TRUE(delegate_->icon_accessed()); 148 EXPECT_TRUE(delegate_->icon_accessed());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 const CGFloat width = 20; 233 const CGFloat width = 20;
223 NSRect newViewFrame = [[controller_ view] frame]; 234 NSRect newViewFrame = [[controller_ view] frame];
224 newViewFrame.size.width += width; 235 newViewFrame.size.width += width;
225 [[controller_ view] setFrame:newViewFrame]; 236 [[controller_ view] setFrame:newViewFrame];
226 237
227 NSRect newLabelFrame = [controller_ labelFrame]; 238 NSRect newLabelFrame = [controller_ labelFrame];
228 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); 239 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width);
229 } 240 }
230 241
231 } // namespace 242 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698