Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: chrome/browser/ui/passwords/password_dialog_controller_impl_unittest.cc

Issue 2531863002: Delete all the traces of federation providers in the account chooser. (Closed)
Patch Set: android2 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/ui/passwords/password_dialog_controller_impl.h" 5 #include "chrome/browser/ui/passwords/password_dialog_controller_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 DISALLOW_COPY_AND_ASSIGN(MockPasswordPrompt); 45 DISALLOW_COPY_AND_ASSIGN(MockPasswordPrompt);
46 }; 46 };
47 47
48 autofill::PasswordForm GetLocalForm() { 48 autofill::PasswordForm GetLocalForm() {
49 autofill::PasswordForm form; 49 autofill::PasswordForm form;
50 form.username_value = base::ASCIIToUTF16(kUsername); 50 form.username_value = base::ASCIIToUTF16(kUsername);
51 form.origin = GURL("http://example.com"); 51 form.origin = GURL("http://example.com");
52 return form; 52 return form;
53 } 53 }
54 54
55 autofill::PasswordForm GetFederationProviderForm() {
56 autofill::PasswordForm form;
57 form.username_value = base::ASCIIToUTF16(kUsername);
58 form.origin = GURL("http://idp.com");
59 return form;
60 }
61
62 class PasswordDialogControllerTest : public testing::Test { 55 class PasswordDialogControllerTest : public testing::Test {
63 public: 56 public:
64 PasswordDialogControllerTest() 57 PasswordDialogControllerTest()
65 : controller_(&profile_, &ui_controller_mock_) { 58 : controller_(&profile_, &ui_controller_mock_) {
66 } 59 }
67 60
68 PasswordsModelDelegateMock& ui_controller_mock() { 61 PasswordsModelDelegateMock& ui_controller_mock() {
69 return ui_controller_mock_; 62 return ui_controller_mock_;
70 } 63 }
71 64
72 PasswordDialogControllerImpl& controller() { return controller_; } 65 PasswordDialogControllerImpl& controller() { return controller_; }
73 66
74 PrefService* prefs() { return profile_.GetPrefs(); } 67 PrefService* prefs() { return profile_.GetPrefs(); }
75 68
76 private: 69 private:
77 content::TestBrowserThreadBundle thread_bundle_; 70 content::TestBrowserThreadBundle thread_bundle_;
78 TestingProfile profile_; 71 TestingProfile profile_;
79 StrictMock<PasswordsModelDelegateMock> ui_controller_mock_; 72 StrictMock<PasswordsModelDelegateMock> ui_controller_mock_;
80 PasswordDialogControllerImpl controller_; 73 PasswordDialogControllerImpl controller_;
81 }; 74 };
82 75
83 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) { 76 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) {
84 base::HistogramTester histogram_tester; 77 base::HistogramTester histogram_tester;
85 StrictMock<MockPasswordPrompt> prompt; 78 StrictMock<MockPasswordPrompt> prompt;
86 autofill::PasswordForm local_form = GetLocalForm(); 79 autofill::PasswordForm local_form = GetLocalForm();
87 autofill::PasswordForm local_form2 = local_form; 80 autofill::PasswordForm local_form2 = local_form;
88 local_form2.username_value = base::ASCIIToUTF16(kUsername2); 81 local_form2.username_value = base::ASCIIToUTF16(kUsername2);
89 autofill::PasswordForm idp_form = GetFederationProviderForm();
90 std::vector<std::unique_ptr<autofill::PasswordForm>> locals; 82 std::vector<std::unique_ptr<autofill::PasswordForm>> locals;
91 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form)); 83 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form));
92 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form2)); 84 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form2));
93 autofill::PasswordForm* local_form_ptr = locals[0].get(); 85 autofill::PasswordForm* local_form_ptr = locals[0].get();
94 std::vector<std::unique_ptr<autofill::PasswordForm>> federations;
95 federations.push_back(base::MakeUnique<autofill::PasswordForm>(idp_form));
96 86
97 EXPECT_CALL(prompt, ShowAccountChooser()); 87 EXPECT_CALL(prompt, ShowAccountChooser());
98 controller().ShowAccountChooser(&prompt, 88 controller().ShowAccountChooser(&prompt, std::move(locals));
99 std::move(locals), std::move(federations));
100 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form), 89 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form),
101 Pointee(local_form2))); 90 Pointee(local_form2)));
102 EXPECT_THAT(controller().GetFederationsForms(),
103 ElementsAre(Pointee(idp_form)));
104 EXPECT_FALSE(controller().ShouldShowSignInButton()); 91 EXPECT_FALSE(controller().ShouldShowSignInButton());
105 92
106 // Close the dialog. 93 // Close the dialog.
107 EXPECT_CALL(prompt, ControllerGone()); 94 EXPECT_CALL(prompt, ControllerGone());
108 EXPECT_CALL(ui_controller_mock(), ChooseCredential( 95 EXPECT_CALL(ui_controller_mock(), ChooseCredential(
109 local_form, 96 local_form,
110 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); 97 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD));
111 controller().OnChooseCredentials( 98 controller().OnChooseCredentials(
112 *local_form_ptr, 99 *local_form_ptr,
113 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); 100 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
114 histogram_tester.ExpectUniqueSample( 101 histogram_tester.ExpectUniqueSample(
115 "PasswordManager.AccountChooserDialogMultipleAccounts", 102 "PasswordManager.AccountChooserDialogMultipleAccounts",
116 password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1); 103 password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
117 histogram_tester.ExpectTotalCount( 104 histogram_tester.ExpectTotalCount(
118 "PasswordManager.AccountChooserDialogOneAccount", 0); 105 "PasswordManager.AccountChooserDialogOneAccount", 0);
119 } 106 }
120 107
121 TEST_F(PasswordDialogControllerTest, ShowAccountChooserAndSignIn) { 108 TEST_F(PasswordDialogControllerTest, ShowAccountChooserAndSignIn) {
122 base::HistogramTester histogram_tester; 109 base::HistogramTester histogram_tester;
123 StrictMock<MockPasswordPrompt> prompt; 110 StrictMock<MockPasswordPrompt> prompt;
124 autofill::PasswordForm local_form = GetLocalForm(); 111 autofill::PasswordForm local_form = GetLocalForm();
125 std::vector<std::unique_ptr<autofill::PasswordForm>> locals; 112 std::vector<std::unique_ptr<autofill::PasswordForm>> locals;
126 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form)); 113 locals.push_back(base::MakeUnique<autofill::PasswordForm>(local_form));
127 std::vector<std::unique_ptr<autofill::PasswordForm>> federations;
128 114
129 EXPECT_CALL(prompt, ShowAccountChooser()); 115 EXPECT_CALL(prompt, ShowAccountChooser());
130 controller().ShowAccountChooser(&prompt, 116 controller().ShowAccountChooser(&prompt, std::move(locals));
131 std::move(locals), std::move(federations));
132 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form))); 117 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form)));
133 EXPECT_THAT(controller().GetFederationsForms(), testing::IsEmpty());
134 EXPECT_TRUE(controller().ShouldShowSignInButton()); 118 EXPECT_TRUE(controller().ShouldShowSignInButton());
135 119
136 // Close the dialog. 120 // Close the dialog.
137 EXPECT_CALL(prompt, ControllerGone()); 121 EXPECT_CALL(prompt, ControllerGone());
138 EXPECT_CALL(ui_controller_mock(), ChooseCredential( 122 EXPECT_CALL(ui_controller_mock(), ChooseCredential(
139 local_form, 123 local_form,
140 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); 124 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD));
141 controller().OnSignInClicked(); 125 controller().OnSignInClicked();
142 histogram_tester.ExpectUniqueSample( 126 histogram_tester.ExpectUniqueSample(
143 "PasswordManager.AccountChooserDialogOneAccount", 127 "PasswordManager.AccountChooserDialogOneAccount",
144 password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN, 1); 128 password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN, 1);
145 histogram_tester.ExpectTotalCount( 129 histogram_tester.ExpectTotalCount(
146 "PasswordManager.AccountChooserDialogMultipleAccounts", 0); 130 "PasswordManager.AccountChooserDialogMultipleAccounts", 0);
147 } 131 }
148 132
149 TEST_F(PasswordDialogControllerTest, AccountChooserClosed) { 133 TEST_F(PasswordDialogControllerTest, AccountChooserClosed) {
150 base::HistogramTester histogram_tester; 134 base::HistogramTester histogram_tester;
151 StrictMock<MockPasswordPrompt> prompt; 135 StrictMock<MockPasswordPrompt> prompt;
152 std::vector<std::unique_ptr<autofill::PasswordForm>> locals; 136 std::vector<std::unique_ptr<autofill::PasswordForm>> locals;
153 locals.push_back(base::MakeUnique<autofill::PasswordForm>(GetLocalForm())); 137 locals.push_back(base::MakeUnique<autofill::PasswordForm>(GetLocalForm()));
154 EXPECT_CALL(prompt, ShowAccountChooser()); 138 EXPECT_CALL(prompt, ShowAccountChooser());
155 controller().ShowAccountChooser(&prompt, std::move(locals), 139 controller().ShowAccountChooser(&prompt, std::move(locals));
156 PasswordDialogController::FormsVector());
157 140
158 EXPECT_CALL(ui_controller_mock(), OnDialogHidden()); 141 EXPECT_CALL(ui_controller_mock(), OnDialogHidden());
159 controller().OnCloseDialog(); 142 controller().OnCloseDialog();
160 histogram_tester.ExpectUniqueSample( 143 histogram_tester.ExpectUniqueSample(
161 "PasswordManager.AccountChooserDialogOneAccount", 144 "PasswordManager.AccountChooserDialogOneAccount",
162 password_manager::metrics_util::ACCOUNT_CHOOSER_DISMISSED, 1); 145 password_manager::metrics_util::ACCOUNT_CHOOSER_DISMISSED, 1);
163 histogram_tester.ExpectTotalCount( 146 histogram_tester.ExpectTotalCount(
164 "PasswordManager.AccountChooserDialogMultipleAccounts", 0); 147 "PasswordManager.AccountChooserDialogMultipleAccounts", 0);
165 } 148 }
166 149
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 "PasswordManager.AutoSigninFirstRunDialog", 210 "PasswordManager.AutoSigninFirstRunDialog",
228 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1); 211 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1);
229 } 212 }
230 213
231 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) { 214 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) {
232 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage()); 215 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage());
233 controller().OnSmartLockLinkClicked(); 216 controller().OnSmartLockLinkClicked();
234 } 217 }
235 218
236 } // namespace 219 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698