Chromium Code Reviews| 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 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
| 10 #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 " |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 - (void)deletePassword:(const autofill::PasswordForm&)passwordForm { | 61 - (void)deletePassword:(const autofill::PasswordForm&)passwordForm { |
| 62 ++_numberOfCallsToDeletePassword; | 62 ++_numberOfCallsToDeletePassword; |
| 63 } | 63 } |
| 64 | 64 |
| 65 @end | 65 @end |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 NSString* kUsername = @"testusername"; | 69 NSString* kUsername = @"testusername"; |
| 70 NSString* kPassword = @"testpassword"; | 70 NSString* kPassword = @"testpassword"; |
| 71 int kShowHideButtonItem = 1; | 71 |
| 72 int kCopyButtonItem = 2; | |
| 73 int kDeleteButtonItem = 3; | |
| 74 int kUsernameSection = 0; | 72 int kUsernameSection = 0; |
| 75 int kUsernameItem = 0; | 73 int kUsernameItem = 0; |
| 74 int kCopyUsernameButtonItem = 1; | |
|
vabr (Chromium)
2017/05/01 18:49:53
I just noticed that this all should be const, give
| |
| 75 | |
| 76 int kPasswordSection = 1; | 76 int kPasswordSection = 1; |
| 77 int kPasswordItem = 0; | 77 int kPasswordItem = 0; |
| 78 int kShowHideButtonItem = 1; | |
| 79 int kCopyPasswordButtonItem = 2; | |
| 80 int kDeleteButtonItem = 3; | |
| 78 | 81 |
| 79 class PasswordDetailsCollectionViewControllerTest | 82 class PasswordDetailsCollectionViewControllerTest |
| 80 : public CollectionViewControllerTest { | 83 : public CollectionViewControllerTest { |
| 81 protected: | 84 protected: |
| 82 PasswordDetailsCollectionViewControllerTest() | 85 PasswordDetailsCollectionViewControllerTest() |
| 83 : thread_bundle_(web::TestWebThreadBundle::REAL_DB_THREAD) {} | 86 : thread_bundle_(web::TestWebThreadBundle::REAL_DB_THREAD) {} |
| 84 void SetUp() override { | 87 void SetUp() override { |
| 85 CollectionViewControllerTest::SetUp(); | 88 CollectionViewControllerTest::SetUp(); |
| 86 origin_ = @"testorigin.com"; | 89 origin_ = @"testorigin.com"; |
| 87 delegate_ = [[MockSavePasswordsCollectionViewController alloc] init]; | 90 delegate_ = [[MockSavePasswordsCollectionViewController alloc] init]; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 107 MockSavePasswordsCollectionViewController* delegate_; | 110 MockSavePasswordsCollectionViewController* delegate_; |
| 108 MockReauthenticationModule* reauthenticationModule_; | 111 MockReauthenticationModule* reauthenticationModule_; |
| 109 NSString* origin_; | 112 NSString* origin_; |
| 110 }; | 113 }; |
| 111 | 114 |
| 112 TEST_F(PasswordDetailsCollectionViewControllerTest, TestInitialization) { | 115 TEST_F(PasswordDetailsCollectionViewControllerTest, TestInitialization) { |
| 113 CreateController(); | 116 CreateController(); |
| 114 CheckController(); | 117 CheckController(); |
| 115 EXPECT_EQ(2, NumberOfSections()); | 118 EXPECT_EQ(2, NumberOfSections()); |
| 116 // Username section | 119 // Username section |
| 117 EXPECT_EQ(1, NumberOfItemsInSection(kUsernameSection)); | 120 EXPECT_EQ(2, NumberOfItemsInSection(kUsernameSection)); |
| 118 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME, | 121 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME, |
| 119 kUsernameSection); | 122 kUsernameSection); |
| 120 PasswordDetailsItem* usernameItem = | 123 PasswordDetailsItem* usernameItem = |
| 121 GetCollectionViewItem(kUsernameSection, kUsernameItem); | 124 GetCollectionViewItem(kUsernameSection, kUsernameItem); |
| 122 EXPECT_NSEQ(kUsername, usernameItem.text); | 125 EXPECT_NSEQ(kUsername, usernameItem.text); |
| 123 EXPECT_TRUE(usernameItem.showingText); | 126 EXPECT_TRUE(usernameItem.showingText); |
| 127 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON, | |
| 128 kUsernameSection, kCopyUsernameButtonItem); | |
| 124 // Password section | 129 // Password section |
| 125 EXPECT_EQ(4, NumberOfItemsInSection(kPasswordSection)); | 130 EXPECT_EQ(4, NumberOfItemsInSection(kPasswordSection)); |
| 126 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD, | 131 CheckSectionHeaderWithId(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD, |
| 127 kPasswordSection); | 132 kPasswordSection); |
| 128 PasswordDetailsItem* passwordItem = | 133 PasswordDetailsItem* passwordItem = |
| 129 GetCollectionViewItem(kPasswordSection, kPasswordItem); | 134 GetCollectionViewItem(kPasswordSection, kPasswordItem); |
| 130 EXPECT_NSEQ(kPassword, passwordItem.text); | 135 EXPECT_NSEQ(kPassword, passwordItem.text); |
| 131 EXPECT_FALSE(passwordItem.showingText); | 136 EXPECT_FALSE(passwordItem.showingText); |
| 132 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON, | 137 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON, |
| 133 kPasswordSection, kShowHideButtonItem); | 138 kPasswordSection, kShowHideButtonItem); |
| 134 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON, | 139 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON, |
| 135 kPasswordSection, kCopyButtonItem); | 140 kPasswordSection, kCopyPasswordButtonItem); |
| 136 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON, | 141 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON, |
| 137 kPasswordSection, kDeleteButtonItem); | 142 kPasswordSection, kDeleteButtonItem); |
| 138 } | 143 } |
| 139 | 144 |
| 140 struct SimplifyOriginTestData { | 145 struct SimplifyOriginTestData { |
| 141 NSString* origin; | 146 NSString* origin; |
| 142 NSString* expectedSimplifiedOrigin; | 147 NSString* expectedSimplifiedOrigin; |
| 143 }; | 148 }; |
| 144 | 149 |
| 145 TEST_F(PasswordDetailsCollectionViewControllerTest, SimplifyOrigin) { | 150 TEST_F(PasswordDetailsCollectionViewControllerTest, SimplifyOrigin) { |
| 146 SimplifyOriginTestData test_data[] = { | 151 SimplifyOriginTestData test_data[] = { |
| 147 {@"http://test.com/index.php", @"test.com"}, | 152 {@"http://test.com/index.php", @"test.com"}, |
| 148 {@"test.com/index.php", @"test.com"}, | 153 {@"test.com/index.php", @"test.com"}, |
| 149 {@"test.com", @"test.com"}}; | 154 {@"test.com", @"test.com"}}; |
| 150 | 155 |
| 151 for (size_t i = 0; i < arraysize(test_data); i++) { | 156 for (size_t i = 0; i < arraysize(test_data); i++) { |
| 152 SimplifyOriginTestData& data = test_data[i]; | 157 SimplifyOriginTestData& data = test_data[i]; |
| 153 CreateControllerWithOrigin(data.origin); | 158 CreateControllerWithOrigin(data.origin); |
| 154 EXPECT_NSEQ(data.expectedSimplifiedOrigin, controller().title) | 159 EXPECT_NSEQ(data.expectedSimplifiedOrigin, controller().title) |
| 155 << " for origin " << base::SysNSStringToUTF8(test_data[i].origin); | 160 << " for origin " << base::SysNSStringToUTF8(test_data[i].origin); |
| 156 ResetController(); | 161 ResetController(); |
| 157 } | 162 } |
| 158 } | 163 } |
| 159 | 164 |
| 165 TEST_F(PasswordDetailsCollectionViewControllerTest, CopyUsername) { | |
| 166 CreateController(); | |
| 167 [controller() collectionView:[controller() collectionView] | |
| 168 didSelectItemAtIndexPath:[NSIndexPath | |
| 169 indexPathForRow:kCopyUsernameButtonItem | |
| 170 inSection:kUsernameSection]]; | |
| 171 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | |
| 172 EXPECT_NSEQ(kUsername, generalPasteboard.string); | |
| 173 } | |
| 174 | |
| 160 TEST_F(PasswordDetailsCollectionViewControllerTest, ShowPassword) { | 175 TEST_F(PasswordDetailsCollectionViewControllerTest, ShowPassword) { |
| 161 CreateController(); | 176 CreateController(); |
| 162 [controller() collectionView:[controller() collectionView] | 177 [controller() collectionView:[controller() collectionView] |
| 163 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem | 178 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kShowHideButtonItem |
| 164 inSection:kPasswordSection]]; | 179 inSection:kPasswordSection]]; |
| 165 PasswordDetailsItem* passwordItem = | 180 PasswordDetailsItem* passwordItem = |
| 166 GetCollectionViewItem(kPasswordSection, kPasswordItem); | 181 GetCollectionViewItem(kPasswordSection, kPasswordItem); |
| 167 EXPECT_NSEQ(kPassword, passwordItem.text); | 182 EXPECT_NSEQ(kPassword, passwordItem.text); |
| 168 EXPECT_TRUE(passwordItem.showingText); | 183 EXPECT_TRUE(passwordItem.showingText); |
| 169 EXPECT_NSEQ( | 184 EXPECT_NSEQ( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 187 GetCollectionViewItem(kPasswordSection, kPasswordItem); | 202 GetCollectionViewItem(kPasswordSection, kPasswordItem); |
| 188 EXPECT_NSEQ(kPassword, passwordItem.text); | 203 EXPECT_NSEQ(kPassword, passwordItem.text); |
| 189 EXPECT_FALSE(passwordItem.showingText); | 204 EXPECT_FALSE(passwordItem.showingText); |
| 190 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON, | 205 CheckTextCellTitleWithId(IDS_IOS_SETTINGS_PASSWORD_SHOW_BUTTON, |
| 191 kPasswordSection, kShowHideButtonItem); | 206 kPasswordSection, kShowHideButtonItem); |
| 192 } | 207 } |
| 193 | 208 |
| 194 TEST_F(PasswordDetailsCollectionViewControllerTest, CopyPassword) { | 209 TEST_F(PasswordDetailsCollectionViewControllerTest, CopyPassword) { |
| 195 CreateController(); | 210 CreateController(); |
| 196 [controller() collectionView:[controller() collectionView] | 211 [controller() collectionView:[controller() collectionView] |
| 197 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kCopyButtonItem | 212 didSelectItemAtIndexPath:[NSIndexPath |
| 198 inSection:kPasswordSection]]; | 213 indexPathForRow:kCopyPasswordButtonItem |
| 214 inSection:kPasswordSection]]; | |
| 199 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; | 215 UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| 200 EXPECT_NSEQ(kPassword, generalPasteboard.string); | 216 EXPECT_NSEQ(kPassword, generalPasteboard.string); |
| 201 EXPECT_NSEQ( | 217 EXPECT_NSEQ( |
| 202 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY), | 218 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_REAUTH_REASON_COPY), |
| 203 reauthenticationModule_.localizedReasonForAuthentication); | 219 reauthenticationModule_.localizedReasonForAuthentication); |
| 204 } | 220 } |
| 205 | 221 |
| 206 TEST_F(PasswordDetailsCollectionViewControllerTest, DeletePassword) { | 222 TEST_F(PasswordDetailsCollectionViewControllerTest, DeletePassword) { |
| 207 CreateController(); | 223 CreateController(); |
| 208 [controller() collectionView:[controller() collectionView] | 224 [controller() collectionView:[controller() collectionView] |
| 209 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kDeleteButtonItem | 225 didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:kDeleteButtonItem |
| 210 inSection:kPasswordSection]]; | 226 inSection:kPasswordSection]]; |
| 211 EXPECT_EQ(1, delegate_.numberOfCallsToDeletePassword); | 227 EXPECT_EQ(1, delegate_.numberOfCallsToDeletePassword); |
| 212 } | 228 } |
| 213 | 229 |
| 214 } // namespace | 230 } // namespace |
| OLD | NEW |