OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Cocoa/Cocoa.h> |
| 6 |
| 7 #include "base/scoped_nsobject.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 11 #import "chrome/browser/cocoa/infobar_controller.h" |
| 12 #include "chrome/browser/cocoa/infobar_test_helper.h" |
| 13 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" |
| 16 |
| 17 @interface InfoBarController (ExposedForTesting) |
| 18 - (NSTextField*)label; |
| 19 @end |
| 20 |
| 21 @implementation InfoBarController (ExposedForTesting) |
| 22 - (NSTextField*)label { |
| 23 return label_; |
| 24 } |
| 25 @end |
| 26 |
| 27 namespace { |
| 28 |
| 29 /////////////////////////////////////////////////////////////////////////// |
| 30 // Test fixtures |
| 31 |
| 32 class AlertInfoBarControllerTest : public PlatformTest { |
| 33 public: |
| 34 virtual void SetUp() { |
| 35 PlatformTest::SetUp(); |
| 36 |
| 37 controller_.reset( |
| 38 [[AlertInfoBarController alloc] initWithDelegate:&delegate_]); |
| 39 [helper_.contentView() addSubview:[controller_ view]]; |
| 40 } |
| 41 |
| 42 protected: |
| 43 CocoaTestHelper helper_; |
| 44 MockAlertInfoBarDelegate delegate_; |
| 45 scoped_nsobject<AlertInfoBarController> controller_; |
| 46 }; |
| 47 |
| 48 class LinkInfoBarControllerTest : public PlatformTest { |
| 49 public: |
| 50 virtual void SetUp() { |
| 51 PlatformTest::SetUp(); |
| 52 |
| 53 controller_.reset( |
| 54 [[LinkInfoBarController alloc] initWithDelegate:&delegate_]); |
| 55 [helper_.contentView() addSubview:[controller_ view]]; |
| 56 } |
| 57 |
| 58 protected: |
| 59 CocoaTestHelper helper_; |
| 60 MockLinkInfoBarDelegate delegate_; |
| 61 scoped_nsobject<LinkInfoBarController> controller_; |
| 62 }; |
| 63 |
| 64 class ConfirmInfoBarControllerTest : public PlatformTest { |
| 65 public: |
| 66 virtual void SetUp() { |
| 67 PlatformTest::SetUp(); |
| 68 |
| 69 controller_.reset( |
| 70 [[ConfirmInfoBarController alloc] initWithDelegate:&delegate_]); |
| 71 [helper_.contentView() addSubview:[controller_ view]]; |
| 72 } |
| 73 |
| 74 protected: |
| 75 CocoaTestHelper helper_; |
| 76 MockConfirmInfoBarDelegate delegate_; |
| 77 scoped_nsobject<ConfirmInfoBarController> controller_; |
| 78 }; |
| 79 |
| 80 |
| 81 //////////////////////////////////////////////////////////////////////////// |
| 82 // Tests |
| 83 |
| 84 TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) { |
| 85 // Make sure someone looked at the message and icon. |
| 86 EXPECT_TRUE(delegate_.message_text_accessed); |
| 87 EXPECT_TRUE(delegate_.icon_accessed); |
| 88 |
| 89 // Check to make sure the infobar message was set properly. |
| 90 EXPECT_EQ(std::wstring(kMockAlertInfoBarMessage), |
| 91 base::SysNSStringToWide([[controller_.get() label] stringValue])); |
| 92 |
| 93 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 94 [controller_ dismiss:nil]; |
| 95 EXPECT_TRUE(delegate_.closed); |
| 96 } |
| 97 |
| 98 TEST_F(AlertInfoBarControllerTest, DeallocController) { |
| 99 // Test that dealloc'ing the controller does not send an |
| 100 // InfoBarClosed() message to the delegate. |
| 101 controller_.reset(nil); |
| 102 EXPECT_FALSE(delegate_.closed); |
| 103 } |
| 104 |
| 105 TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { |
| 106 // Make sure someone looked at the message, link, and icon. |
| 107 EXPECT_TRUE(delegate_.message_text_accessed); |
| 108 EXPECT_TRUE(delegate_.link_text_accessed); |
| 109 EXPECT_TRUE(delegate_.icon_accessed); |
| 110 |
| 111 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 112 [controller_ dismiss:nil]; |
| 113 EXPECT_FALSE(delegate_.link_clicked); |
| 114 EXPECT_TRUE(delegate_.closed); |
| 115 } |
| 116 |
| 117 TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { |
| 118 // Check that clicking on the link calls LinkClicked() on the |
| 119 // delegate. It should also close the infobar. |
| 120 [controller_ linkClicked]; |
| 121 EXPECT_TRUE(delegate_.link_clicked); |
| 122 EXPECT_TRUE(delegate_.closed); |
| 123 } |
| 124 |
| 125 TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { |
| 126 delegate_.closes_on_action = false; |
| 127 |
| 128 // Check that clicking on the link calls LinkClicked() on the |
| 129 // delegate. It should not close the infobar. |
| 130 [controller_ linkClicked]; |
| 131 EXPECT_TRUE(delegate_.link_clicked); |
| 132 EXPECT_FALSE(delegate_.closed); |
| 133 } |
| 134 |
| 135 TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { |
| 136 // Make sure someone looked at the message and icon. |
| 137 EXPECT_TRUE(delegate_.message_text_accessed); |
| 138 EXPECT_TRUE(delegate_.icon_accessed); |
| 139 |
| 140 // Check to make sure the infobar message was set properly. |
| 141 EXPECT_EQ(std::wstring(kMockConfirmInfoBarMessage), |
| 142 base::SysNSStringToWide([[controller_.get() label] stringValue])); |
| 143 |
| 144 // Check that dismissing the infobar calls InfoBarClosed() on the delegate. |
| 145 [controller_ dismiss:nil]; |
| 146 EXPECT_FALSE(delegate_.ok_clicked); |
| 147 EXPECT_FALSE(delegate_.cancel_clicked); |
| 148 EXPECT_TRUE(delegate_.closed); |
| 149 } |
| 150 |
| 151 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { |
| 152 // Check that clicking the OK button calls Accept() and then closes |
| 153 // the infobar. |
| 154 [controller_ ok:nil]; |
| 155 EXPECT_TRUE(delegate_.ok_clicked); |
| 156 EXPECT_FALSE(delegate_.cancel_clicked); |
| 157 EXPECT_TRUE(delegate_.closed); |
| 158 } |
| 159 |
| 160 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) { |
| 161 delegate_.closes_on_action = false; |
| 162 |
| 163 // Check that clicking the OK button calls Accept() but does not close |
| 164 // the infobar. |
| 165 [controller_ ok:nil]; |
| 166 EXPECT_TRUE(delegate_.ok_clicked); |
| 167 EXPECT_FALSE(delegate_.cancel_clicked); |
| 168 EXPECT_FALSE(delegate_.closed); |
| 169 } |
| 170 |
| 171 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { |
| 172 // Check that clicking the cancel button calls Cancel() and closes |
| 173 // the infobar. |
| 174 [controller_ cancel:nil]; |
| 175 EXPECT_FALSE(delegate_.ok_clicked); |
| 176 EXPECT_TRUE(delegate_.cancel_clicked); |
| 177 EXPECT_TRUE(delegate_.closed); |
| 178 } |
| 179 |
| 180 TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) { |
| 181 delegate_.closes_on_action = false; |
| 182 |
| 183 // Check that clicking the cancel button calls Cancel() but does not close |
| 184 // the infobar. |
| 185 [controller_ cancel:nil]; |
| 186 EXPECT_FALSE(delegate_.ok_clicked); |
| 187 EXPECT_TRUE(delegate_.cancel_clicked); |
| 188 EXPECT_FALSE(delegate_.closed); |
| 189 } |
| 190 |
| 191 } // namespace |
OLD | NEW |