OLD | NEW |
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/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 if ([self infobar]) | 78 if ([self infobar]) |
79 [self infobar]->CloseSoon(); | 79 [self infobar]->CloseSoon(); |
80 } | 80 } |
81 @end | 81 @end |
82 | 82 |
83 namespace { | 83 namespace { |
84 | 84 |
85 class ConfirmInfoBarControllerTest : public CocoaProfileTest, | 85 class ConfirmInfoBarControllerTest : public CocoaProfileTest, |
86 public MockConfirmInfoBarDelegate::Owner { | 86 public MockConfirmInfoBarDelegate::Owner { |
87 public: | 87 public: |
88 virtual void SetUp() OVERRIDE { | 88 virtual void SetUp() override { |
89 CocoaProfileTest::SetUp(); | 89 CocoaProfileTest::SetUp(); |
90 web_contents_.reset( | 90 web_contents_.reset( |
91 WebContents::Create(WebContents::CreateParams(profile()))); | 91 WebContents::Create(WebContents::CreateParams(profile()))); |
92 InfoBarService::CreateForWebContents(web_contents_.get()); | 92 InfoBarService::CreateForWebContents(web_contents_.get()); |
93 | 93 |
94 scoped_ptr<infobars::InfoBarDelegate> delegate( | 94 scoped_ptr<infobars::InfoBarDelegate> delegate( |
95 new MockConfirmInfoBarDelegate(this)); | 95 new MockConfirmInfoBarDelegate(this)); |
96 infobar_ = new InfoBarCocoa(delegate.Pass()); | 96 infobar_ = new InfoBarCocoa(delegate.Pass()); |
97 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); | 97 infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); |
98 | 98 |
99 controller_.reset([[TestConfirmInfoBarController alloc] | 99 controller_.reset([[TestConfirmInfoBarController alloc] |
100 initWithInfoBar:infobar_]); | 100 initWithInfoBar:infobar_]); |
101 infobar_->set_controller(controller_); | 101 infobar_->set_controller(controller_); |
102 | 102 |
103 container_.reset( | 103 container_.reset( |
104 [[InfoBarContainerTest alloc] initWithController:controller_]); | 104 [[InfoBarContainerTest alloc] initWithController:controller_]); |
105 [controller_ setContainerController:container_]; | 105 [controller_ setContainerController:container_]; |
106 [[test_window() contentView] addSubview:[controller_ view]]; | 106 [[test_window() contentView] addSubview:[controller_ view]]; |
107 closed_delegate_ok_clicked_ = false; | 107 closed_delegate_ok_clicked_ = false; |
108 closed_delegate_cancel_clicked_ = false; | 108 closed_delegate_cancel_clicked_ = false; |
109 closed_delegate_link_clicked_ = false; | 109 closed_delegate_link_clicked_ = false; |
110 delegate_closed_ = false; | 110 delegate_closed_ = false; |
111 } | 111 } |
112 | 112 |
113 virtual void TearDown() OVERRIDE { | 113 virtual void TearDown() override { |
114 [controller_ removeSelf]; | 114 [controller_ removeSelf]; |
115 CocoaProfileTest::TearDown(); | 115 CocoaProfileTest::TearDown(); |
116 } | 116 } |
117 | 117 |
118 protected: | 118 protected: |
119 // True if delegate is closed. | 119 // True if delegate is closed. |
120 bool delegate_closed() const { return delegate_closed_; } | 120 bool delegate_closed() const { return delegate_closed_; } |
121 | 121 |
122 MockConfirmInfoBarDelegate* delegate() const { | 122 MockConfirmInfoBarDelegate* delegate() const { |
123 return static_cast<MockConfirmInfoBarDelegate*>(infobar_->delegate()); | 123 return static_cast<MockConfirmInfoBarDelegate*>(infobar_->delegate()); |
124 } | 124 } |
125 | 125 |
126 base::scoped_nsobject<id> container_; | 126 base::scoped_nsobject<id> container_; |
127 base::scoped_nsobject<ConfirmInfoBarController> controller_; | 127 base::scoped_nsobject<ConfirmInfoBarController> controller_; |
128 bool closed_delegate_ok_clicked_; | 128 bool closed_delegate_ok_clicked_; |
129 bool closed_delegate_cancel_clicked_; | 129 bool closed_delegate_cancel_clicked_; |
130 bool closed_delegate_link_clicked_; | 130 bool closed_delegate_link_clicked_; |
131 | 131 |
132 private: | 132 private: |
133 virtual void OnInfoBarDelegateClosed() OVERRIDE { | 133 virtual void OnInfoBarDelegateClosed() override { |
134 closed_delegate_ok_clicked_ = delegate()->ok_clicked(); | 134 closed_delegate_ok_clicked_ = delegate()->ok_clicked(); |
135 closed_delegate_cancel_clicked_ = delegate()->cancel_clicked(); | 135 closed_delegate_cancel_clicked_ = delegate()->cancel_clicked(); |
136 closed_delegate_link_clicked_ = delegate()->link_clicked(); | 136 closed_delegate_link_clicked_ = delegate()->link_clicked(); |
137 delegate_closed_ = true; | 137 delegate_closed_ = true; |
138 controller_.reset(); | 138 controller_.reset(); |
139 } | 139 } |
140 | 140 |
141 scoped_ptr<WebContents> web_contents_; | 141 scoped_ptr<WebContents> web_contents_; |
142 InfoBarCocoa* infobar_; // Weak, will delete itself. | 142 InfoBarCocoa* infobar_; // Weak, will delete itself. |
143 bool delegate_closed_; | 143 bool delegate_closed_; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 const CGFloat width = 20; | 238 const CGFloat width = 20; |
239 NSRect newViewFrame = [[controller_ view] frame]; | 239 NSRect newViewFrame = [[controller_ view] frame]; |
240 newViewFrame.size.width += width; | 240 newViewFrame.size.width += width; |
241 [[controller_ view] setFrame:newViewFrame]; | 241 [[controller_ view] setFrame:newViewFrame]; |
242 | 242 |
243 NSRect newLabelFrame = [controller_ labelFrame]; | 243 NSRect newLabelFrame = [controller_ labelFrame]; |
244 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); | 244 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); |
245 } | 245 } |
246 | 246 |
247 } // namespace | 247 } // namespace |
OLD | NEW |