Chromium Code Reviews| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/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/confirm_infobar_delegate.h" | 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 12 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 12 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 13 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
| 14 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" | 14 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" |
| 15 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" | 15 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" |
| 16 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 18 | 19 |
| 19 @interface InfoBarController (ExposedForTesting) | 20 @interface InfoBarController (ExposedForTesting) |
| 20 - (NSString*)labelString; | 21 - (NSString*)labelString; |
| 21 - (NSRect)labelFrame; | 22 - (NSRect)labelFrame; |
| 22 @end | 23 @end |
| 23 | 24 |
| 24 @implementation InfoBarController (ExposedForTesting) | 25 @implementation InfoBarController (ExposedForTesting) |
| 25 - (NSString*)labelString { | 26 - (NSString*)labelString { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 EXPECT_FALSE(closed_delegate_link_clicked_); | 191 EXPECT_FALSE(closed_delegate_link_clicked_); |
| 191 } | 192 } |
| 192 | 193 |
| 193 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { | 194 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { |
| 194 // Check that clicking on the link calls LinkClicked() on the | 195 // Check that clicking on the link calls LinkClicked() on the |
| 195 // delegate. It should also close the infobar. | 196 // delegate. It should also close the infobar. |
| 196 [controller_ linkClicked]; | 197 [controller_ linkClicked]; |
| 197 | 198 |
| 198 // Spin the runloop because the invocation for closing the infobar is done on | 199 // Spin the runloop because the invocation for closing the infobar is done on |
| 199 // a 0-timer delayed selector. | 200 // a 0-timer delayed selector. |
| 200 [[NSRunLoop currentRunLoop] runUntilDate: | 201 chrome::testing::NSRunLoopRunAllPending(); |
| 201 [NSDate dateWithTimeIntervalSinceNow:0.1]]; | |
|
Mark Mentovai
2011/08/22 19:44:57
ha.
| |
| 202 | 202 |
| 203 ASSERT_TRUE(delegate_closed()); | 203 ASSERT_TRUE(delegate_closed()); |
| 204 EXPECT_TRUE(closed_delegate_link_clicked_); | 204 EXPECT_TRUE(closed_delegate_link_clicked_); |
| 205 } | 205 } |
| 206 | 206 |
| 207 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { | 207 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { |
| 208 delegate_->set_dont_close_on_action(); | 208 delegate_->set_dont_close_on_action(); |
| 209 | 209 |
| 210 // Check that clicking on the link calls LinkClicked() on the | 210 // Check that clicking on the link calls LinkClicked() on the |
| 211 // delegate. It should not close the infobar. | 211 // delegate. It should not close the infobar. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 const CGFloat width = 20; | 314 const CGFloat width = 20; |
| 315 NSRect newViewFrame = [[controller_ view] frame]; | 315 NSRect newViewFrame = [[controller_ view] frame]; |
| 316 newViewFrame.size.width += width; | 316 newViewFrame.size.width += width; |
| 317 [[controller_ view] setFrame:newViewFrame]; | 317 [[controller_ view] setFrame:newViewFrame]; |
| 318 | 318 |
| 319 NSRect newLabelFrame = [controller_ labelFrame]; | 319 NSRect newLabelFrame = [controller_ labelFrame]; |
| 320 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); | 320 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); |
| 321 } | 321 } |
| 322 | 322 |
| 323 } // namespace | 323 } // namespace |
| OLD | NEW |