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

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

Issue 1992633003: Add "Sign In" button to the account chooser on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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 13 matching lines...) Expand all
24 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 namespace { 27 namespace {
28 28
29 using testing::ElementsAre; 29 using testing::ElementsAre;
30 using testing::Pointee; 30 using testing::Pointee;
31 using testing::StrictMock; 31 using testing::StrictMock;
32 32
33 const char kUsername[] = "user1"; 33 const char kUsername[] = "user1";
34 const char kUsername2[] = "user2";
34 35
35 class MockPasswordPrompt : public AccountChooserPrompt, 36 class MockPasswordPrompt : public AccountChooserPrompt,
36 public AutoSigninFirstRunPrompt { 37 public AutoSigninFirstRunPrompt {
37 public: 38 public:
38 MockPasswordPrompt() = default; 39 MockPasswordPrompt() = default;
39 40
40 MOCK_METHOD0(ShowAccountChooser, void()); 41 MOCK_METHOD0(ShowAccountChooser, void());
41 MOCK_METHOD0(ShowAutoSigninPrompt, void()); 42 MOCK_METHOD0(ShowAutoSigninPrompt, void());
42 MOCK_METHOD0(ControllerGone, void()); 43 MOCK_METHOD0(ControllerGone, void());
43 44
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 std::unique_ptr<content::WebContents> test_web_contents_; 84 std::unique_ptr<content::WebContents> test_web_contents_;
84 // Owned by |test_web_contents_|. 85 // Owned by |test_web_contents_|.
85 ManagePasswordsUIControllerMock* ui_controller_mock_; 86 ManagePasswordsUIControllerMock* ui_controller_mock_;
86 PasswordDialogControllerImpl controller_; 87 PasswordDialogControllerImpl controller_;
87 }; 88 };
88 89
89 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) { 90 TEST_F(PasswordDialogControllerTest, ShowAccountChooser) {
90 base::HistogramTester histogram_tester; 91 base::HistogramTester histogram_tester;
91 StrictMock<MockPasswordPrompt> prompt; 92 StrictMock<MockPasswordPrompt> prompt;
92 autofill::PasswordForm local_form = GetLocalForm(); 93 autofill::PasswordForm local_form = GetLocalForm();
94 autofill::PasswordForm local_form2 = local_form;
95 local_form2.username_value = base::ASCIIToUTF16(kUsername2);
93 autofill::PasswordForm idp_form = GetFederationProviderForm(); 96 autofill::PasswordForm idp_form = GetFederationProviderForm();
94 std::vector<std::unique_ptr<autofill::PasswordForm>> locals; 97 std::vector<std::unique_ptr<autofill::PasswordForm>> locals;
95 locals.push_back(base::WrapUnique(new autofill::PasswordForm(local_form))); 98 locals.push_back(base::WrapUnique(new autofill::PasswordForm(local_form)));
99 locals.push_back(base::WrapUnique(new autofill::PasswordForm(local_form2)));
96 autofill::PasswordForm* local_form_ptr = locals[0].get(); 100 autofill::PasswordForm* local_form_ptr = locals[0].get();
97 std::vector<std::unique_ptr<autofill::PasswordForm>> federations; 101 std::vector<std::unique_ptr<autofill::PasswordForm>> federations;
98 federations.push_back(base::WrapUnique(new autofill::PasswordForm(idp_form))); 102 federations.push_back(base::WrapUnique(new autofill::PasswordForm(idp_form)));
99 103
100 EXPECT_CALL(prompt, ShowAccountChooser()); 104 EXPECT_CALL(prompt, ShowAccountChooser());
101 controller().ShowAccountChooser(&prompt, 105 controller().ShowAccountChooser(&prompt,
102 std::move(locals), std::move(federations)); 106 std::move(locals), std::move(federations));
103 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form))); 107 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form),
108 Pointee(local_form2)));
104 EXPECT_THAT(controller().GetFederationsForms(), 109 EXPECT_THAT(controller().GetFederationsForms(),
105 ElementsAre(Pointee(idp_form))); 110 ElementsAre(Pointee(idp_form)));
111 EXPECT_FALSE(controller().ShouldShowSignInButton());
106 112
107 // Close the dialog. 113 // Close the dialog.
108 EXPECT_CALL(prompt, ControllerGone()); 114 EXPECT_CALL(prompt, ControllerGone());
109 EXPECT_CALL(ui_controller_mock(), ChooseCredential( 115 EXPECT_CALL(ui_controller_mock(), ChooseCredential(
110 local_form, 116 local_form,
111 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); 117 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD));
112 controller().OnChooseCredentials( 118 controller().OnChooseCredentials(
113 *local_form_ptr, 119 *local_form_ptr,
114 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); 120 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
115 histogram_tester.ExpectUniqueSample( 121 histogram_tester.ExpectUniqueSample(
116 "PasswordManager.AccountChooserDialog", 122 "PasswordManager.AccountChooserDialog",
117 password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1); 123 password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
118 } 124 }
119 125
126 TEST_F(PasswordDialogControllerTest, ShowAccountChooserAndSignIn) {
127 base::HistogramTester histogram_tester;
128 StrictMock<MockPasswordPrompt> prompt;
129 autofill::PasswordForm local_form = GetLocalForm();
130 std::vector<std::unique_ptr<autofill::PasswordForm>> locals;
131 locals.push_back(base::WrapUnique(new autofill::PasswordForm(local_form)));
132 std::vector<std::unique_ptr<autofill::PasswordForm>> federations;
133
134 EXPECT_CALL(prompt, ShowAccountChooser());
135 controller().ShowAccountChooser(&prompt,
136 std::move(locals), std::move(federations));
137 EXPECT_THAT(controller().GetLocalForms(), ElementsAre(Pointee(local_form)));
138 EXPECT_THAT(controller().GetFederationsForms(), testing::IsEmpty());
139 EXPECT_TRUE(controller().ShouldShowSignInButton());
140
141 // Close the dialog.
142 EXPECT_CALL(prompt, ControllerGone());
143 EXPECT_CALL(ui_controller_mock(), ChooseCredential(
144 local_form,
145 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD));
146 controller().OnSignInClicked();
147 histogram_tester.ExpectUniqueSample(
148 "PasswordManager.AccountChooserDialog",
149 password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN, 1);
150 }
151
120 TEST_F(PasswordDialogControllerTest, AccountChooserClosed) { 152 TEST_F(PasswordDialogControllerTest, AccountChooserClosed) {
121 base::HistogramTester histogram_tester; 153 base::HistogramTester histogram_tester;
122 StrictMock<MockPasswordPrompt> prompt; 154 StrictMock<MockPasswordPrompt> prompt;
123 EXPECT_CALL(prompt, ShowAccountChooser()); 155 EXPECT_CALL(prompt, ShowAccountChooser());
124 controller().ShowAccountChooser(&prompt, 156 controller().ShowAccountChooser(&prompt,
125 PasswordDialogController::FormsVector(), 157 PasswordDialogController::FormsVector(),
126 PasswordDialogController::FormsVector()); 158 PasswordDialogController::FormsVector());
127 159
128 EXPECT_CALL(ui_controller_mock(), OnDialogHidden()); 160 EXPECT_CALL(ui_controller_mock(), OnDialogHidden());
129 controller().OnCloseDialog(); 161 controller().OnCloseDialog();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 "PasswordManager.AutoSigninFirstRunDialog", 227 "PasswordManager.AutoSigninFirstRunDialog",
196 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1); 228 password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF, 1);
197 } 229 }
198 230
199 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) { 231 TEST_F(PasswordDialogControllerTest, OnBrandLinkClicked) {
200 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage()); 232 EXPECT_CALL(ui_controller_mock(), NavigateToSmartLockHelpPage());
201 controller().OnSmartLockLinkClicked(); 233 controller().OnSmartLockLinkClicked();
202 } 234 }
203 235
204 } // namespace 236 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698