| 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/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 11 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/confirm_infobar_delegate.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_container_controller.h" | 13 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 14 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
| 15 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" | 15 #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" |
| 16 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" | 16 #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" |
| 17 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 17 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 19 #import "content/public/browser/web_contents.h" | 19 #import "content/public/browser/web_contents.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 22 | 22 |
| 23 using content::WebContents; | 23 using content::WebContents; |
| 24 | 24 |
| 25 @interface InfoBarController (ExposedForTesting) | 25 @interface InfoBarController (ExposedForTesting) |
| 26 - (NSString*)labelString; | 26 - (NSString*)labelString; |
| 27 - (NSRect)labelFrame; | 27 - (NSRect)labelFrame; |
| 28 @end | 28 @end |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 namespace { | 92 namespace { |
| 93 | 93 |
| 94 /////////////////////////////////////////////////////////////////////////// | 94 /////////////////////////////////////////////////////////////////////////// |
| 95 // Test fixtures | 95 // Test fixtures |
| 96 | 96 |
| 97 class LinkInfoBarControllerTest : public CocoaProfileTest, | 97 class LinkInfoBarControllerTest : public CocoaProfileTest, |
| 98 public MockLinkInfoBarDelegate::Owner { | 98 public MockLinkInfoBarDelegate::Owner { |
| 99 public: | 99 public: |
| 100 virtual void SetUp() { | 100 virtual void SetUp() { |
| 101 CocoaProfileTest::SetUp(); | 101 CocoaProfileTest::SetUp(); |
| 102 tab_contents_.reset(new TabContentsWrapper(WebContents::Create( | 102 tab_contents_.reset(new TabContents(WebContents::Create( |
| 103 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); | 103 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); |
| 104 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); | 104 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); |
| 105 | 105 |
| 106 delegate_ = new MockLinkInfoBarDelegate(this); | 106 delegate_ = new MockLinkInfoBarDelegate(this); |
| 107 controller_.reset([[TestLinkInfoBarController alloc] | 107 controller_.reset([[TestLinkInfoBarController alloc] |
| 108 initWithDelegate:delegate_ | 108 initWithDelegate:delegate_ |
| 109 owner:tab_contents_.get()->infobar_tab_helper()]); | 109 owner:tab_contents_.get()->infobar_tab_helper()]); |
| 110 container_.reset( | 110 container_.reset( |
| 111 [[InfoBarContainerTest alloc] initWithController:controller_]); | 111 [[InfoBarContainerTest alloc] initWithController:controller_]); |
| 112 [controller_ setContainerController:container_]; | 112 [controller_ setContainerController:container_]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 scoped_nsobject<id> container_; | 128 scoped_nsobject<id> container_; |
| 129 scoped_nsobject<LinkInfoBarController> controller_; | 129 scoped_nsobject<LinkInfoBarController> controller_; |
| 130 bool closed_delegate_link_clicked_; | 130 bool closed_delegate_link_clicked_; |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 virtual void OnInfoBarDelegateClosed() { | 133 virtual void OnInfoBarDelegateClosed() { |
| 134 closed_delegate_link_clicked_ = delegate_->link_clicked(); | 134 closed_delegate_link_clicked_ = delegate_->link_clicked(); |
| 135 delegate_ = NULL; | 135 delegate_ = NULL; |
| 136 } | 136 } |
| 137 | 137 |
| 138 scoped_ptr<TabContentsWrapper> tab_contents_; | 138 scoped_ptr<TabContents> tab_contents_; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 class ConfirmInfoBarControllerTest : public CocoaProfileTest, | 141 class ConfirmInfoBarControllerTest : public CocoaProfileTest, |
| 142 public MockConfirmInfoBarDelegate::Owner { | 142 public MockConfirmInfoBarDelegate::Owner { |
| 143 public: | 143 public: |
| 144 virtual void SetUp() { | 144 virtual void SetUp() { |
| 145 CocoaProfileTest::SetUp(); | 145 CocoaProfileTest::SetUp(); |
| 146 tab_contents_.reset(new TabContentsWrapper(WebContents::Create( | 146 tab_contents_.reset(new TabContents(WebContents::Create( |
| 147 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); | 147 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); |
| 148 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); | 148 tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); |
| 149 | 149 |
| 150 delegate_ = new MockConfirmInfoBarDelegate(this); | 150 delegate_ = new MockConfirmInfoBarDelegate(this); |
| 151 controller_.reset([[TestConfirmInfoBarController alloc] | 151 controller_.reset([[TestConfirmInfoBarController alloc] |
| 152 initWithDelegate:delegate_ | 152 initWithDelegate:delegate_ |
| 153 owner:tab_contents_.get()->infobar_tab_helper()]); | 153 owner:tab_contents_.get()->infobar_tab_helper()]); |
| 154 container_.reset( | 154 container_.reset( |
| 155 [[InfoBarContainerTest alloc] initWithController:controller_]); | 155 [[InfoBarContainerTest alloc] initWithController:controller_]); |
| 156 [controller_ setContainerController:container_]; | 156 [controller_ setContainerController:container_]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 bool closed_delegate_link_clicked_; | 178 bool closed_delegate_link_clicked_; |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 virtual void OnInfoBarDelegateClosed() { | 181 virtual void OnInfoBarDelegateClosed() { |
| 182 closed_delegate_ok_clicked_ = delegate_->ok_clicked(); | 182 closed_delegate_ok_clicked_ = delegate_->ok_clicked(); |
| 183 closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); | 183 closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); |
| 184 closed_delegate_link_clicked_ = delegate_->link_clicked(); | 184 closed_delegate_link_clicked_ = delegate_->link_clicked(); |
| 185 delegate_ = NULL; | 185 delegate_ = NULL; |
| 186 } | 186 } |
| 187 | 187 |
| 188 scoped_ptr<TabContentsWrapper> tab_contents_; | 188 scoped_ptr<TabContents> tab_contents_; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 | 191 |
| 192 //////////////////////////////////////////////////////////////////////////// | 192 //////////////////////////////////////////////////////////////////////////// |
| 193 // Tests | 193 // Tests |
| 194 | 194 |
| 195 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); | 195 TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); |
| 196 | 196 |
| 197 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { | 197 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { |
| 198 // Make sure someone looked at the message, link, and icon. | 198 // Make sure someone looked at the message, link, and icon. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 const CGFloat width = 20; | 329 const CGFloat width = 20; |
| 330 NSRect newViewFrame = [[controller_ view] frame]; | 330 NSRect newViewFrame = [[controller_ view] frame]; |
| 331 newViewFrame.size.width += width; | 331 newViewFrame.size.width += width; |
| 332 [[controller_ view] setFrame:newViewFrame]; | 332 [[controller_ view] setFrame:newViewFrame]; |
| 333 | 333 |
| 334 NSRect newLabelFrame = [controller_ labelFrame]; | 334 NSRect newLabelFrame = [controller_ labelFrame]; |
| 335 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); | 335 EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); |
| 336 } | 336 } |
| 337 | 337 |
| 338 } // namespace | 338 } // namespace |
| OLD | NEW |