| 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 "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 9 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #import "chrome/browser/ui/cocoa/bubble_combobox.h" | 13 #import "chrome/browser/ui/cocoa/bubble_combobox.h" |
| 12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 14 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 13 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" | 15 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" |
| 14 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" | 16 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" |
| 15 #include "chrome/browser/ui/cocoa/passwords/base_passwords_controller_test.h" | 17 #include "chrome/browser/ui/cocoa/passwords/base_passwords_controller_test.h" |
| 16 #include "chrome/browser/ui/passwords/account_chooser_more_combobox_model.h" | 18 #include "chrome/browser/ui/passwords/account_chooser_more_combobox_model.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 52 } |
| 51 | 53 |
| 52 @end | 54 @end |
| 53 | 55 |
| 54 namespace { | 56 namespace { |
| 55 | 57 |
| 56 // Returns a PasswordForm with only a username. | 58 // Returns a PasswordForm with only a username. |
| 57 scoped_ptr<autofill::PasswordForm> Credential(const char* username) { | 59 scoped_ptr<autofill::PasswordForm> Credential(const char* username) { |
| 58 scoped_ptr<autofill::PasswordForm> credential(new autofill::PasswordForm); | 60 scoped_ptr<autofill::PasswordForm> credential(new autofill::PasswordForm); |
| 59 credential->username_value = base::ASCIIToUTF16(username); | 61 credential->username_value = base::ASCIIToUTF16(username); |
| 60 return credential.Pass(); | 62 return credential; |
| 61 } | 63 } |
| 62 | 64 |
| 63 // Tests for the account chooser view of the password management bubble. | 65 // Tests for the account chooser view of the password management bubble. |
| 64 class ManagePasswordsBubbleAccountChooserViewControllerTest | 66 class ManagePasswordsBubbleAccountChooserViewControllerTest |
| 65 : public ManagePasswordsControllerTest { | 67 : public ManagePasswordsControllerTest { |
| 66 public: | 68 public: |
| 67 ManagePasswordsBubbleAccountChooserViewControllerTest() : controller_(nil) {} | 69 ManagePasswordsBubbleAccountChooserViewControllerTest() : controller_(nil) {} |
| 68 | 70 |
| 69 void SetUp() override { | 71 void SetUp() override { |
| 70 ManagePasswordsControllerTest::SetUp(); | 72 ManagePasswordsControllerTest::SetUp(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 95 base::scoped_nsobject<ManagePasswordsBubbleAccountChooserViewController> | 97 base::scoped_nsobject<ManagePasswordsBubbleAccountChooserViewController> |
| 96 controller_; | 98 controller_; |
| 97 base::scoped_nsobject<ContentViewDelegateMock> delegate_; | 99 base::scoped_nsobject<ContentViewDelegateMock> delegate_; |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, ConfiguresViews) { | 102 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, ConfiguresViews) { |
| 101 ScopedVector<const autofill::PasswordForm> local_forms; | 103 ScopedVector<const autofill::PasswordForm> local_forms; |
| 102 local_forms.push_back(Credential("pizza")); | 104 local_forms.push_back(Credential("pizza")); |
| 103 ScopedVector<const autofill::PasswordForm> federated_forms; | 105 ScopedVector<const autofill::PasswordForm> federated_forms; |
| 104 federated_forms.push_back(Credential("taco")); | 106 federated_forms.push_back(Credential("taco")); |
| 105 SetUpAccountChooser(local_forms.Pass(), federated_forms.Pass()); | 107 SetUpAccountChooser(std::move(local_forms), std::move(federated_forms)); |
| 106 // Trigger creation of controller and check the views. | 108 // Trigger creation of controller and check the views. |
| 107 NSTableView* view = controller().credentialsView; | 109 NSTableView* view = controller().credentialsView; |
| 108 ASSERT_NSNE(nil, view); | 110 ASSERT_NSNE(nil, view); |
| 109 ASSERT_EQ(2U, view.numberOfRows); | 111 ASSERT_EQ(2U, view.numberOfRows); |
| 110 EXPECT_NSEQ( | 112 EXPECT_NSEQ( |
| 111 @"pizza", | 113 @"pizza", |
| 112 base::mac::ObjCCastStrict<CredentialItemView>( | 114 base::mac::ObjCCastStrict<CredentialItemView>( |
| 113 base::mac::ObjCCastStrict<CredentialItemCell>( | 115 base::mac::ObjCCastStrict<CredentialItemCell>( |
| 114 [view.delegate tableView:view dataCellForTableColumn:nil row:0]) | 116 [view.delegate tableView:view dataCellForTableColumn:nil row:0]) |
| 115 .view).upperLabel.stringValue); | 117 .view).upperLabel.stringValue); |
| 116 EXPECT_NSEQ( | 118 EXPECT_NSEQ( |
| 117 @"taco", | 119 @"taco", |
| 118 base::mac::ObjCCastStrict<CredentialItemView>( | 120 base::mac::ObjCCastStrict<CredentialItemView>( |
| 119 base::mac::ObjCCastStrict<CredentialItemCell>( | 121 base::mac::ObjCCastStrict<CredentialItemCell>( |
| 120 [view.delegate tableView:view dataCellForTableColumn:nil row:1]) | 122 [view.delegate tableView:view dataCellForTableColumn:nil row:1]) |
| 121 .view).upperLabel.stringValue); | 123 .view).upperLabel.stringValue); |
| 122 EXPECT_TRUE(avatar_manager().fetchedAvatars.empty()); | 124 EXPECT_TRUE(avatar_manager().fetchedAvatars.empty()); |
| 123 } | 125 } |
| 124 | 126 |
| 125 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, | 127 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, |
| 126 ForwardsAvatarFetchToManager) { | 128 ForwardsAvatarFetchToManager) { |
| 127 ScopedVector<const autofill::PasswordForm> local_forms; | 129 ScopedVector<const autofill::PasswordForm> local_forms; |
| 128 scoped_ptr<autofill::PasswordForm> form = Credential("taco"); | 130 scoped_ptr<autofill::PasswordForm> form = Credential("taco"); |
| 129 form->icon_url = GURL("http://foo"); | 131 form->icon_url = GURL("http://foo"); |
| 130 local_forms.push_back(form.Pass()); | 132 local_forms.push_back(std::move(form)); |
| 131 SetUpAccountChooser(local_forms.Pass(), | 133 SetUpAccountChooser(std::move(local_forms), |
| 132 ScopedVector<const autofill::PasswordForm>()); | 134 ScopedVector<const autofill::PasswordForm>()); |
| 133 // Trigger creation of the controller and check the fetched URLs. | 135 // Trigger creation of the controller and check the fetched URLs. |
| 134 controller(); | 136 controller(); |
| 135 EXPECT_FALSE(avatar_manager().fetchedAvatars.empty()); | 137 EXPECT_FALSE(avatar_manager().fetchedAvatars.empty()); |
| 136 EXPECT_TRUE(std::find(avatar_manager().fetchedAvatars.begin(), | 138 EXPECT_TRUE(std::find(avatar_manager().fetchedAvatars.begin(), |
| 137 avatar_manager().fetchedAvatars.end(), | 139 avatar_manager().fetchedAvatars.end(), |
| 138 GURL("http://foo")) != | 140 GURL("http://foo")) != |
| 139 avatar_manager().fetchedAvatars.end()); | 141 avatar_manager().fetchedAvatars.end()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, | 144 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, |
| 143 SelectingCredentialInformsModelAndClosesDialog) { | 145 SelectingCredentialInformsModelAndClosesDialog) { |
| 144 ScopedVector<const autofill::PasswordForm> local_forms; | 146 ScopedVector<const autofill::PasswordForm> local_forms; |
| 145 local_forms.push_back(Credential("pizza")); | 147 local_forms.push_back(Credential("pizza")); |
| 146 ScopedVector<const autofill::PasswordForm> federated_forms; | 148 ScopedVector<const autofill::PasswordForm> federated_forms; |
| 147 federated_forms.push_back(Credential("taco")); | 149 federated_forms.push_back(Credential("taco")); |
| 148 SetUpAccountChooser(local_forms.Pass(), federated_forms.Pass()); | 150 SetUpAccountChooser(std::move(local_forms), std::move(federated_forms)); |
| 149 EXPECT_CALL(*ui_controller(), | 151 EXPECT_CALL(*ui_controller(), |
| 150 ChooseCredential( | 152 ChooseCredential( |
| 151 *Credential("taco"), | 153 *Credential("taco"), |
| 152 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED)); | 154 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED)); |
| 153 [controller().credentialsView | 155 [controller().credentialsView |
| 154 selectRowIndexes:[NSIndexSet indexSetWithIndex:1] | 156 selectRowIndexes:[NSIndexSet indexSetWithIndex:1] |
| 155 byExtendingSelection:NO]; | 157 byExtendingSelection:NO]; |
| 156 EXPECT_TRUE(delegate().dismissed); | 158 EXPECT_TRUE(delegate().dismissed); |
| 157 } | 159 } |
| 158 | 160 |
| 159 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, | 161 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, |
| 160 SelectingNopeDismissesDialog) { | 162 SelectingNopeDismissesDialog) { |
| 161 ScopedVector<const autofill::PasswordForm> local_forms; | 163 ScopedVector<const autofill::PasswordForm> local_forms; |
| 162 local_forms.push_back(Credential("pizza")); | 164 local_forms.push_back(Credential("pizza")); |
| 163 SetUpAccountChooser(local_forms.Pass(), | 165 SetUpAccountChooser(std::move(local_forms), |
| 164 ScopedVector<const autofill::PasswordForm>()); | 166 ScopedVector<const autofill::PasswordForm>()); |
| 165 [controller().cancelButton performClick:nil]; | 167 [controller().cancelButton performClick:nil]; |
| 166 EXPECT_TRUE(delegate().dismissed); | 168 EXPECT_TRUE(delegate().dismissed); |
| 167 } | 169 } |
| 168 | 170 |
| 169 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, | 171 TEST_F(ManagePasswordsBubbleAccountChooserViewControllerTest, |
| 170 SelectingSettingsShowsSettingsPage) { | 172 SelectingSettingsShowsSettingsPage) { |
| 171 SetUpAccountChooser(ScopedVector<const autofill::PasswordForm>(), | 173 SetUpAccountChooser(ScopedVector<const autofill::PasswordForm>(), |
| 172 ScopedVector<const autofill::PasswordForm>()); | 174 ScopedVector<const autofill::PasswordForm>()); |
| 173 BubbleCombobox* moreButton = controller().moreButton; | 175 BubbleCombobox* moreButton = controller().moreButton; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 184 ScopedVector<const autofill::PasswordForm>()); | 186 ScopedVector<const autofill::PasswordForm>()); |
| 185 BubbleCombobox* moreButton = controller().moreButton; | 187 BubbleCombobox* moreButton = controller().moreButton; |
| 186 EXPECT_TRUE(moreButton); | 188 EXPECT_TRUE(moreButton); |
| 187 [[moreButton menu] performActionForItemAtIndex: | 189 [[moreButton menu] performActionForItemAtIndex: |
| 188 AccountChooserMoreComboboxModel::INDEX_LEARN_MORE]; | 190 AccountChooserMoreComboboxModel::INDEX_LEARN_MORE]; |
| 189 EXPECT_TRUE(delegate().dismissed); | 191 EXPECT_TRUE(delegate().dismissed); |
| 190 // TODO(dconnelly): Test this when the article is written. | 192 // TODO(dconnelly): Test this when the article is written. |
| 191 } | 193 } |
| 192 | 194 |
| 193 } // namespace | 195 } // namespace |
| OLD | NEW |