| OLD | NEW |
| 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/tab_contents/infobar_delegate.h" | 10 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 | 125 |
| 126 //////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////// |
| 127 // Tests | 127 // Tests |
| 128 | 128 |
| 129 TEST_VIEW(AlertInfoBarControllerTest, [controller_ view]); | 129 TEST_VIEW(AlertInfoBarControllerTest, [controller_ view]); |
| 130 | 130 |
| 131 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) { | 131 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) { |
| 132 // Make sure someone looked at the message and icon. | 132 // Make sure someone looked at the message and icon. |
| 133 EXPECT_TRUE(delegate_.message_text_accessed); | 133 EXPECT_TRUE(delegate_.message_text_accessed()); |
| 134 EXPECT_TRUE(delegate_.icon_accessed); | 134 EXPECT_TRUE(delegate_.icon_accessed()); |
| 135 | 135 |
| 136 // Check to make sure the infobar message was set properly. | 136 // Check to make sure the infobar message was set properly. |
| 137 EXPECT_EQ(kMockAlertInfoBarMessage, | 137 EXPECT_EQ(MockAlertInfoBarDelegate::kMessage, |
| 138 base::SysNSStringToUTF8([controller_.get() labelString])); | 138 base::SysNSStringToUTF8([controller_.get() labelString])); |
| 139 | 139 |
| 140 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. | 140 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 141 [controller_ dismiss:nil]; | 141 [controller_ dismiss:nil]; |
| 142 EXPECT_TRUE(delegate_.closed); | 142 EXPECT_TRUE(delegate_.closed()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST_F(AlertInfoBarControllerTest, DeallocController) { | 145 TEST_F(AlertInfoBarControllerTest, DeallocController) { |
| 146 // Test that dealloc'ing the controller does not send an | 146 // Test that dealloc'ing the controller does not send an |
| 147 // InfoBarClosed() message to the delegate. | 147 // InfoBarClosed() message to the delegate. |
| 148 controller_.reset(nil); | 148 controller_.reset(nil); |
| 149 EXPECT_FALSE(delegate_.closed); | 149 EXPECT_FALSE(delegate_.closed()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(AlertInfoBarControllerTest, ResizeView) { | 152 TEST_F(AlertInfoBarControllerTest, ResizeView) { |
| 153 NSRect originalLabelFrame = [controller_ labelFrame]; | 153 NSRect originalLabelFrame = [controller_ labelFrame]; |
| 154 | 154 |
| 155 // Expand the view by 20 pixels and make sure the label frame changes | 155 // Expand the view by 20 pixels and make sure the label frame changes |
| 156 // accordingly. | 156 // accordingly. |
| 157 const CGFloat width = 20; | 157 const CGFloat width = 20; |
| 158 NSRect newViewFrame = [[controller_ view] frame]; | 158 NSRect newViewFrame = [[controller_ view] frame]; |
| 159 newViewFrame.size.width += width; | 159 newViewFrame.size.width += width; |
| 160 [[controller_ view] setFrame:newViewFrame]; | 160 [[controller_ view] setFrame:newViewFrame]; |
| 161 | 161 |
| 162 NSRect newLabelFrame = [controller_ labelFrame]; | 162 NSRect newLabelFrame = [controller_ labelFrame]; |
| 163 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); | 163 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); | 166 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); |
| 167 | 167 |
| 168 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { | 168 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { |
| 169 // Make sure someone looked at the message, link, and icon. | 169 // Make sure someone looked at the message, link, and icon. |
| 170 EXPECT_TRUE(delegate_.message_text_accessed); | 170 EXPECT_TRUE(delegate_.message_text_accessed()); |
| 171 EXPECT_TRUE(delegate_.link_text_accessed); | 171 EXPECT_TRUE(delegate_.link_text_accessed()); |
| 172 EXPECT_TRUE(delegate_.icon_accessed); | 172 EXPECT_TRUE(delegate_.icon_accessed()); |
| 173 | 173 |
| 174 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. | 174 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 175 [controller_ dismiss:nil]; | 175 [controller_ dismiss:nil]; |
| 176 EXPECT_FALSE(delegate_.link_clicked); | 176 EXPECT_FALSE(delegate_.link_clicked()); |
| 177 EXPECT_TRUE(delegate_.closed); | 177 EXPECT_TRUE(delegate_.closed()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { | 180 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { |
| 181 // Check that clicking on the link calls LinkClicked() on the | 181 // Check that clicking on the link calls LinkClicked() on the |
| 182 // delegate. It should also close the infobar. | 182 // delegate. It should also close the infobar. |
| 183 [controller_ linkClicked]; | 183 [controller_ linkClicked]; |
| 184 EXPECT_TRUE(delegate_.link_clicked); | 184 EXPECT_TRUE(delegate_.link_clicked()); |
| 185 EXPECT_TRUE(delegate_.closed); | 185 EXPECT_TRUE(delegate_.closed()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { | 188 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { |
| 189 delegate_.closes_on_action = false; | 189 delegate_.set_dont_close_on_action(); |
| 190 | 190 |
| 191 // Check that clicking on the link calls LinkClicked() on the | 191 // Check that clicking on the link calls LinkClicked() on the |
| 192 // delegate. It should not close the infobar. | 192 // delegate. It should not close the infobar. |
| 193 [controller_ linkClicked]; | 193 [controller_ linkClicked]; |
| 194 EXPECT_TRUE(delegate_.link_clicked); | 194 EXPECT_TRUE(delegate_.link_clicked()); |
| 195 EXPECT_FALSE(delegate_.closed); | 195 EXPECT_FALSE(delegate_.closed()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); | 198 TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); |
| 199 | 199 |
| 200 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { | 200 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { |
| 201 // Make sure someone looked at the message, link, and icon. | 201 // Make sure someone looked at the message, link, and icon. |
| 202 EXPECT_TRUE(delegate_.message_text_accessed); | 202 EXPECT_TRUE(delegate_.message_text_accessed()); |
| 203 EXPECT_TRUE(delegate_.link_text_accessed); | 203 EXPECT_TRUE(delegate_.link_text_accessed()); |
| 204 EXPECT_TRUE(delegate_.icon_accessed); | 204 EXPECT_TRUE(delegate_.icon_accessed()); |
| 205 | 205 |
| 206 // Check to make sure the infobar message was set properly. | 206 // Check to make sure the infobar message was set properly. |
| 207 EXPECT_EQ(kMockConfirmInfoBarMessage, | 207 EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage, |
| 208 base::SysNSStringToUTF8([controller_.get() labelString])); | 208 base::SysNSStringToUTF8([controller_.get() labelString])); |
| 209 | 209 |
| 210 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. | 210 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 211 [controller_ dismiss:nil]; | 211 [controller_ dismiss:nil]; |
| 212 EXPECT_FALSE(delegate_.ok_clicked); | 212 EXPECT_FALSE(delegate_.ok_clicked()); |
| 213 EXPECT_FALSE(delegate_.cancel_clicked); | 213 EXPECT_FALSE(delegate_.cancel_clicked()); |
| 214 EXPECT_FALSE(delegate_.link_clicked); | 214 EXPECT_FALSE(delegate_.link_clicked()); |
| 215 EXPECT_TRUE(delegate_.closed); | 215 EXPECT_TRUE(delegate_.closed()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { | 218 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { |
| 219 // Check that clicking the OK button calls Accept() and then closes | 219 // Check that clicking the OK button calls Accept() and then closes |
| 220 // the infobar. | 220 // the infobar. |
| 221 [controller_ ok:nil]; | 221 [controller_ ok:nil]; |
| 222 EXPECT_TRUE(delegate_.ok_clicked); | 222 EXPECT_TRUE(delegate_.ok_clicked()); |
| 223 EXPECT_FALSE(delegate_.cancel_clicked); | 223 EXPECT_FALSE(delegate_.cancel_clicked()); |
| 224 EXPECT_FALSE(delegate_.link_clicked); | 224 EXPECT_FALSE(delegate_.link_clicked()); |
| 225 EXPECT_TRUE(delegate_.closed); | 225 EXPECT_TRUE(delegate_.closed()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) { | 228 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) { |
| 229 delegate_.closes_on_action = false; | 229 delegate_.set_dont_close_on_action(); |
| 230 | 230 |
| 231 // Check that clicking the OK button calls Accept() but does not close | 231 // Check that clicking the OK button calls Accept() but does not close |
| 232 // the infobar. | 232 // the infobar. |
| 233 [controller_ ok:nil]; | 233 [controller_ ok:nil]; |
| 234 EXPECT_TRUE(delegate_.ok_clicked); | 234 EXPECT_TRUE(delegate_.ok_clicked()); |
| 235 EXPECT_FALSE(delegate_.cancel_clicked); | 235 EXPECT_FALSE(delegate_.cancel_clicked()); |
| 236 EXPECT_FALSE(delegate_.link_clicked); | 236 EXPECT_FALSE(delegate_.link_clicked()); |
| 237 EXPECT_FALSE(delegate_.closed); | 237 EXPECT_FALSE(delegate_.closed()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { | 240 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { |
| 241 // Check that clicking the cancel button calls Cancel() and closes | 241 // Check that clicking the cancel button calls Cancel() and closes |
| 242 // the infobar. | 242 // the infobar. |
| 243 [controller_ cancel:nil]; | 243 [controller_ cancel:nil]; |
| 244 EXPECT_FALSE(delegate_.ok_clicked); | 244 EXPECT_FALSE(delegate_.ok_clicked()); |
| 245 EXPECT_TRUE(delegate_.cancel_clicked); | 245 EXPECT_TRUE(delegate_.cancel_clicked()); |
| 246 EXPECT_FALSE(delegate_.link_clicked); | 246 EXPECT_FALSE(delegate_.link_clicked()); |
| 247 EXPECT_TRUE(delegate_.closed); | 247 EXPECT_TRUE(delegate_.closed()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) { | 250 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) { |
| 251 delegate_.closes_on_action = false; | 251 delegate_.set_dont_close_on_action(); |
| 252 | 252 |
| 253 // Check that clicking the cancel button calls Cancel() but does not close | 253 // Check that clicking the cancel button calls Cancel() but does not close |
| 254 // the infobar. | 254 // the infobar. |
| 255 [controller_ cancel:nil]; | 255 [controller_ cancel:nil]; |
| 256 EXPECT_FALSE(delegate_.ok_clicked); | 256 EXPECT_FALSE(delegate_.ok_clicked()); |
| 257 EXPECT_TRUE(delegate_.cancel_clicked); | 257 EXPECT_TRUE(delegate_.cancel_clicked()); |
| 258 EXPECT_FALSE(delegate_.link_clicked); | 258 EXPECT_FALSE(delegate_.link_clicked()); |
| 259 EXPECT_FALSE(delegate_.closed); | 259 EXPECT_FALSE(delegate_.closed()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { | 262 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { |
| 263 // Check that clicking on the link calls LinkClicked() on the | 263 // Check that clicking on the link calls LinkClicked() on the |
| 264 // delegate. It should also close the infobar. | 264 // delegate. It should also close the infobar. |
| 265 [controller_ linkClicked]; | 265 [controller_ linkClicked]; |
| 266 EXPECT_FALSE(delegate_.ok_clicked); | 266 EXPECT_FALSE(delegate_.ok_clicked()); |
| 267 EXPECT_FALSE(delegate_.cancel_clicked); | 267 EXPECT_FALSE(delegate_.cancel_clicked()); |
| 268 EXPECT_TRUE(delegate_.link_clicked); | 268 EXPECT_TRUE(delegate_.link_clicked()); |
| 269 EXPECT_TRUE(delegate_.closed); | 269 EXPECT_TRUE(delegate_.closed()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { | 272 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { |
| 273 delegate_.closes_on_action = false; | 273 delegate_.set_dont_close_on_action(); |
| 274 | 274 |
| 275 // Check that clicking on the link calls LinkClicked() on the | 275 // Check that clicking on the link calls LinkClicked() on the |
| 276 // delegate. It should not close the infobar. | 276 // delegate. It should not close the infobar. |
| 277 [controller_ linkClicked]; | 277 [controller_ linkClicked]; |
| 278 EXPECT_FALSE(delegate_.ok_clicked); | 278 EXPECT_FALSE(delegate_.ok_clicked()); |
| 279 EXPECT_FALSE(delegate_.cancel_clicked); | 279 EXPECT_FALSE(delegate_.cancel_clicked()); |
| 280 EXPECT_TRUE(delegate_.link_clicked); | 280 EXPECT_TRUE(delegate_.link_clicked()); |
| 281 EXPECT_FALSE(delegate_.closed); | 281 EXPECT_FALSE(delegate_.closed()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace | 284 } // namespace |
| OLD | NEW |