OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/ui/settings/password_details_collection_view_control
ler.h" | 5 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control
ler.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #import "base/mac/scoped_nsobject.h" | |
9 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
10 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
11 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" | 10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
12 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" | 11 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" |
13 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 12 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |
14 #import "ios/chrome/browser/web/chrome_web_test.h" | 13 #import "ios/chrome/browser/web/chrome_web_test.h" |
15 #include "ios/chrome/grit/ios_strings.h" | 14 #include "ios/chrome/grit/ios_strings.h" |
16 #include "ios/web/public/test/test_web_thread_bundle.h" | 15 #include "ios/web/public/test/test_web_thread_bundle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
21 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> | 24 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> |
22 | 25 |
23 @property(nonatomic, copy) NSString* localizedReasonForAuthentication; | 26 @property(nonatomic, copy) NSString* localizedReasonForAuthentication; |
24 | 27 |
25 @end | 28 @end |
26 | 29 |
27 @implementation MockReauthenticationModule | 30 @implementation MockReauthenticationModule |
28 | 31 |
29 @synthesize localizedReasonForAuthentication = | 32 @synthesize localizedReasonForAuthentication = |
30 _localizedReasonForAuthentication; | 33 _localizedReasonForAuthentication; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 int kPasswordItem = 0; | 77 int kPasswordItem = 0; |
75 | 78 |
76 class PasswordDetailsCollectionViewControllerTest | 79 class PasswordDetailsCollectionViewControllerTest |
77 : public CollectionViewControllerTest { | 80 : public CollectionViewControllerTest { |
78 protected: | 81 protected: |
79 PasswordDetailsCollectionViewControllerTest() | 82 PasswordDetailsCollectionViewControllerTest() |
80 : thread_bundle_(web::TestWebThreadBundle::REAL_DB_THREAD) {} | 83 : thread_bundle_(web::TestWebThreadBundle::REAL_DB_THREAD) {} |
81 void SetUp() override { | 84 void SetUp() override { |
82 CollectionViewControllerTest::SetUp(); | 85 CollectionViewControllerTest::SetUp(); |
83 origin_ = @"testorigin.com"; | 86 origin_ = @"testorigin.com"; |
84 delegate_.reset([[MockSavePasswordsCollectionViewController alloc] init]); | 87 delegate_ = [[MockSavePasswordsCollectionViewController alloc] init]; |
85 reauthenticationModule_.reset([[MockReauthenticationModule alloc] init]); | 88 reauthenticationModule_ = [[MockReauthenticationModule alloc] init]; |
86 } | 89 } |
87 | 90 |
88 CollectionViewController* NewController() override NS_RETURNS_RETAINED { | 91 CollectionViewController* InstantiateController() override { |
89 return [[PasswordDetailsCollectionViewController alloc] | 92 return [[PasswordDetailsCollectionViewController alloc] |
90 initWithPasswordForm:*(new autofill::PasswordForm()) | 93 initWithPasswordForm:*(new autofill::PasswordForm()) |
91 delegate:delegate_ | 94 delegate:delegate_ |
92 reauthenticationModule:reauthenticationModule_ | 95 reauthenticationModule:reauthenticationModule_ |
93 username:kUsername | 96 username:kUsername |
94 password:kPassword | 97 password:kPassword |
95 origin:origin_]; | 98 origin:origin_]; |
96 } | 99 } |
97 | 100 |
98 void CreateControllerWithOrigin(NSString* test_origin) { | 101 void CreateControllerWithOrigin(NSString* test_origin) { |
99 origin_ = test_origin; | 102 origin_ = test_origin; |
100 CreateController(); | 103 CreateController(); |
101 } | 104 } |
102 | 105 |
103 web::TestWebThreadBundle thread_bundle_; | 106 web::TestWebThreadBundle thread_bundle_; |
104 base::scoped_nsobject<MockSavePasswordsCollectionViewController> delegate_; | 107 MockSavePasswordsCollectionViewController* delegate_; |
105 base::scoped_nsobject<MockReauthenticationModule> reauthenticationModule_; | 108 MockReauthenticationModule* reauthenticationModule_; |
106 NSString* origin_; | 109 NSString* origin_; |
107 }; | 110 }; |
108 | 111 |
109 TEST_F(PasswordDetailsCollectionViewControllerTest, TestInitialization) { | 112 TEST_F(PasswordDetailsCollectionViewControllerTest, TestInitialization) { |
110 CreateController(); | 113 CreateController(); |
111 CheckController(); | 114 CheckController(); |
112 EXPECT_EQ(2, NumberOfSections()); | 115 EXPECT_EQ(2, NumberOfSections()); |
113 // Username section | 116 // Username section |
114 EXPECT_EQ(1, NumberOfItemsInSection(kUsernameSection)); | 117 EXPECT_EQ(1, NumberOfItemsInSection(kUsernameSection)); |
115 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME, | 118 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 CreateController(); | 161 CreateController(); |
159 [controller() collectionView:[controller() collectionView] | 162 [controller() collectionView:[controller() collectionView] |
160 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem | 163 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem |
161 inSection:kPasswordSection]]; | 164 inSection:kPasswordSection]]; |
162 PasswordDetailsItem* passwordItem = | 165 PasswordDetailsItem* passwordItem = |
163 GetCollectionViewItem(kPasswordSection, kPasswordItem); | 166 GetCollectionViewItem(kPasswordSection, kPasswordItem); |
164 EXPECT_NSEQ(kPassword, passwordItem.text); | 167 EXPECT_NSEQ(kPassword, passwordItem.text); |
165 EXPECT_TRUE(passwordItem.showingText); | 168 EXPECT_TRUE(passwordItem.showingText); |
166 EXPECT_NSEQ( | 169 EXPECT_NSEQ( |
167 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW), | 170 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_SHOW), |
168 reauthenticationModule_.get().localizedReasonForAuthentication); | 171 reauthenticationModule_.localizedReasonForAuthentication); |
169 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON, | 172 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON, |
170 kPasswordSection, kShowHideButtonItem); | 173 kPasswordSection, kShowHideButtonItem); |
171 } | 174 } |
172 | 175 |
173 TEST_F(PasswordDetailsCollectionViewControllerTest, HidePassword) { | 176 TEST_F(PasswordDetailsCollectionViewControllerTest, HidePassword) { |
174 CreateController(); | 177 CreateController(); |
175 // First show the password. | 178 // First show the password. |
176 [controller() collectionView:[controller() collectionView] | 179 [controller() collectionView:[controller() collectionView] |
177 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem | 180 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem |
178 inSection:kPasswordSection]]; | 181 inSection:kPasswordSection]]; |
(...skipping 11 matching lines...) Expand all Loading... |
190 | 193 |
191 TEST_F(PasswordDetailsCollectionViewControllerTest, CopyPassword) { | 194 TEST_F(PasswordDetailsCollectionViewControllerTest, CopyPassword) { |
192 CreateController(); | 195 CreateController(); |
193 [controller() collectionView:[controller() collectionView] | 196 [controller() collectionView:[controller() collectionView] |
194 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kCopyButtonItem | 197 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kCopyButtonItem |
195 inSection:kPasswordSection]]; | 198 inSection:kPasswordSection]]; |
196 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 199 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
197 EXPECT_NSEQ(kPassword, generalPasteboard.string); | 200 EXPECT_NSEQ(kPassword, generalPasteboard.string); |
198 EXPECT_NSEQ( | 201 EXPECT_NSEQ( |
199 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY), | 202 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY), |
200 reauthenticationModule_.get().localizedReasonForAuthentication); | 203 reauthenticationModule_.localizedReasonForAuthentication); |
201 } | 204 } |
202 | 205 |
203 TEST_F(PasswordDetailsCollectionViewControllerTest, DeletePassword) { | 206 TEST_F(PasswordDetailsCollectionViewControllerTest, DeletePassword) { |
204 CreateController(); | 207 CreateController(); |
205 [controller() collectionView:[controller() collectionView] | 208 [controller() collectionView:[controller() collectionView] |
206 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kDeleteButtonItem | 209 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kDeleteButtonItem |
207 inSection:kPasswordSection]]; | 210 inSection:kPasswordSection]]; |
208 EXPECT_EQ(1, delegate_.get().numberOfCallsToDeletePassword); | 211 EXPECT_EQ(1, delegate_.numberOfCallsToDeletePassword); |
209 } | 212 } |
210 | 213 |
211 } // namespace | 214 } // namespace |
OLD | NEW |