1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_icon_mock.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h"
16 #include "components/autofill/core/common/password_form.h"
17 #include "components/password_manager/core/browser/password_form_manager.h"
18 #include "components/password_manager/core/browser/stub_password_manager_client.h"
19 #include "components/password_manager/core/browser/stub_password_manager_driver.h"
20 #include "components/password_manager/core/common/credential_manager_types.h"
21 #include "components/password_manager/core/common/password_manager_ui.h"
22 #include "content/public/browser/navigation_details.h"
23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "content/public/test/web_contents_tester.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h"
28 using ::testing::ElementsAre
;
29 using ::testing::Pointee
;
33 const int64 kSlowNavigationDelayInMS
= 2000;
34 const int64 kQuickNavigationDelayInMS
= 500;
36 // This sublass is used to disable some code paths which are not essential for
38 class TestManagePasswordsUIController
: public ManagePasswordsUIController
{
40 TestManagePasswordsUIController(
41 content::WebContents
* contents
,
42 password_manager::PasswordManagerClient
* client
);
43 ~TestManagePasswordsUIController() override
;
45 base::TimeDelta
Elapsed() const override
;
46 void SetElapsed(base::TimeDelta elapsed
) { elapsed_
= elapsed
; }
48 using ManagePasswordsUIController::DidNavigateMainFrame
;
51 void UpdateBubbleAndIconVisibility() override
;
52 void UpdateAndroidAccountChooserInfoBarVisibility() override
;
53 void SavePasswordInternal() override
{}
54 void NeverSavePasswordInternal() override
{}
56 base::TimeDelta elapsed_
;
59 TestManagePasswordsUIController::TestManagePasswordsUIController(
60 content::WebContents
* contents
,
61 password_manager::PasswordManagerClient
* client
)
62 : ManagePasswordsUIController(contents
) {
63 // Do not silently replace an existing ManagePasswordsUIController because it
64 // unregisters itself in WebContentsDestroyed().
65 EXPECT_FALSE(contents
->GetUserData(UserDataKey()));
66 contents
->SetUserData(UserDataKey(), this);
70 TestManagePasswordsUIController::~TestManagePasswordsUIController() {
73 base::TimeDelta
TestManagePasswordsUIController::Elapsed() const {
77 void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
78 ManagePasswordsUIController::UpdateBubbleAndIconVisibility();
82 void TestManagePasswordsUIController::
83 UpdateAndroidAccountChooserInfoBarVisibility() {
89 class ManagePasswordsUIControllerTest
: public ChromeRenderViewHostTestHarness
{
91 ManagePasswordsUIControllerTest() {}
93 void SetUp() override
{
94 ChromeRenderViewHostTestHarness::SetUp();
96 // Create the test UIController here so that it's bound to
97 // |test_web_contents_|, and will be retrieved correctly via
98 // ManagePasswordsUIController::FromWebContents in |controller()|.
99 new TestManagePasswordsUIController(web_contents(), &client_
);
101 test_local_form_
.origin
= GURL("http://example.com");
102 test_local_form_
.username_value
= base::ASCIIToUTF16("username");
103 test_local_form_
.password_value
= base::ASCIIToUTF16("12345");
105 test_federated_form_
.origin
= GURL("http://example.com");
106 test_federated_form_
.username_value
= base::ASCIIToUTF16("username");
107 test_federated_form_
.federation_url
= GURL("https://federation.test/");
109 // We need to be on a "webby" URL for most tests.
110 content::WebContentsTester::For(web_contents())
111 ->NavigateAndCommit(GURL("http://example.com"));
114 autofill::PasswordForm
& test_local_form() { return test_local_form_
; }
115 autofill::PasswordForm
& test_federated_form() { return test_federated_form_
; }
116 password_manager::CredentialInfo
* credential_info() const {
117 return credential_info_
.get();
120 TestManagePasswordsUIController
* controller() {
121 return static_cast<TestManagePasswordsUIController
*>(
122 ManagePasswordsUIController::FromWebContents(web_contents()));
125 void CredentialCallback(const password_manager::CredentialInfo
& info
) {
126 credential_info_
.reset(new password_manager::CredentialInfo(info
));
129 scoped_ptr
<password_manager::PasswordFormManager
> CreateFormManager();
132 password_manager::StubPasswordManagerClient client_
;
134 autofill::PasswordForm test_local_form_
;
135 autofill::PasswordForm test_federated_form_
;
136 scoped_ptr
<password_manager::CredentialInfo
> credential_info_
;
139 scoped_ptr
<password_manager::PasswordFormManager
>
140 ManagePasswordsUIControllerTest::CreateFormManager() {
141 ScopedVector
<autofill::PasswordForm
> stored_forms
;
142 stored_forms
.push_back(new autofill::PasswordForm(test_local_form()));
143 return ManagePasswordsUIControllerMock::CreateFormManager(
144 &client_
, test_local_form(), stored_forms
.Pass());
147 TEST_F(ManagePasswordsUIControllerTest
, DefaultState
) {
148 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, controller()->state());
149 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
150 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
152 ManagePasswordsIconMock mock
;
153 controller()->UpdateIconAndBubbleState(&mock
);
154 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, mock
.state());
157 TEST_F(ManagePasswordsUIControllerTest
, PasswordAutofilled
) {
158 base::string16 kTestUsername
= test_local_form().username_value
;
159 autofill::PasswordFormMap map
;
160 map
[kTestUsername
] = &test_local_form();
161 controller()->OnPasswordAutofilled(map
);
163 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
164 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
165 EXPECT_EQ(test_local_form().origin
, controller()->origin());
166 ASSERT_EQ(1u, controller()->GetCurrentForms().size());
167 EXPECT_EQ(kTestUsername
, controller()->GetCurrentForms()[0]->username_value
);
169 // Controller should store a separate copy of the form as it doesn't own it.
170 EXPECT_NE(&test_local_form(), controller()->GetCurrentForms()[0]);
172 ManagePasswordsIconMock mock
;
173 controller()->UpdateIconAndBubbleState(&mock
);
174 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
177 TEST_F(ManagePasswordsUIControllerTest
, PasswordSubmitted
) {
178 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
179 CreateFormManager());
180 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
181 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE
,
182 controller()->state());
183 EXPECT_TRUE(controller()->PasswordPendingUserDecision());
185 // TODO(mkwst): This should be the value of test_local_form().origin, but
186 // it's being masked by the stub implementation of
187 // ManagePasswordsUIControllerMock::PendingCredentials.
188 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
190 ManagePasswordsIconMock mock
;
191 controller()->UpdateIconAndBubbleState(&mock
);
192 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE
,
196 TEST_F(ManagePasswordsUIControllerTest
, PasswordSaved
) {
197 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
198 CreateFormManager());
199 test_form_manager
->ProvisionallySave(
201 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES
);
202 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
204 ManagePasswordsIconMock mock
;
205 controller()->UpdateIconAndBubbleState(&mock
);
206 controller()->SavePassword();
207 controller()->UpdateIconAndBubbleState(&mock
);
208 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
211 TEST_F(ManagePasswordsUIControllerTest
, PasswordBlacklisted
) {
212 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
213 CreateFormManager());
214 test_form_manager
->ProvisionallySave(
216 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES
);
217 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
219 ManagePasswordsIconMock mock
;
220 controller()->UpdateIconAndBubbleState(&mock
);
221 controller()->NeverSavePassword();
222 controller()->UpdateIconAndBubbleState(&mock
);
223 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE
, mock
.state());
226 TEST_F(ManagePasswordsUIControllerTest
, QuickNavigations
) {
227 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
228 CreateFormManager());
229 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
230 ManagePasswordsIconMock mock
;
231 controller()->UpdateIconAndBubbleState(&mock
);
232 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE
,
235 // Fake-navigate within a second. We expect the bubble's state to persist
236 // if a navigation occurs too quickly for a user to reasonably have been
237 // able to interact with the bubble. This happens on `accounts.google.com`,
239 controller()->SetElapsed(
240 base::TimeDelta::FromMilliseconds(kQuickNavigationDelayInMS
));
241 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(),
242 content::FrameNavigateParams());
243 controller()->UpdateIconAndBubbleState(&mock
);
245 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE
,
249 TEST_F(ManagePasswordsUIControllerTest
, SlowNavigations
) {
250 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
251 CreateFormManager());
252 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
253 ManagePasswordsIconMock mock
;
254 controller()->UpdateIconAndBubbleState(&mock
);
255 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE
,
258 // Fake-navigate after a second. We expect the bubble's state to be reset
259 // if a navigation occurs after this limit.
260 controller()->SetElapsed(
261 base::TimeDelta::FromMilliseconds(kSlowNavigationDelayInMS
));
262 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(),
263 content::FrameNavigateParams());
264 controller()->UpdateIconAndBubbleState(&mock
);
266 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, mock
.state());
269 TEST_F(ManagePasswordsUIControllerTest
, PasswordSubmittedToNonWebbyURL
) {
270 // Navigate to a non-webby URL, then see what happens!
271 content::WebContentsTester::For(web_contents())
272 ->NavigateAndCommit(GURL("chrome://sign-in"));
274 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
275 CreateFormManager());
276 controller()->OnPasswordSubmitted(test_form_manager
.Pass());
277 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, controller()->state());
278 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
280 // TODO(mkwst): This should be the value of test_local_form().origin, but
281 // it's being masked by the stub implementation of
282 // ManagePasswordsUIControllerMock::PendingCredentials.
283 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
285 ManagePasswordsIconMock mock
;
286 controller()->UpdateIconAndBubbleState(&mock
);
287 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, mock
.state());
290 TEST_F(ManagePasswordsUIControllerTest
, BlacklistBlockedAutofill
) {
291 test_local_form().blacklisted_by_user
= true;
292 base::string16 kTestUsername
= test_local_form().username_value
;
293 autofill::PasswordFormMap map
;
294 map
[kTestUsername
] = &test_local_form();
295 controller()->OnBlacklistBlockedAutofill(map
);
297 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE
, controller()->state());
298 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
299 EXPECT_EQ(test_local_form().origin
, controller()->origin());
300 ASSERT_EQ(1u, controller()->GetCurrentForms().size());
301 EXPECT_EQ(kTestUsername
, controller()->GetCurrentForms()[0]->username_value
);
303 // Controller should store a separate copy of the form as it doesn't own it.
304 EXPECT_NE(&test_local_form(), controller()->GetCurrentForms()[0]);
306 ManagePasswordsIconMock mock
;
307 controller()->UpdateIconAndBubbleState(&mock
);
308 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE
, mock
.state());
311 TEST_F(ManagePasswordsUIControllerTest
, ClickedUnblacklist
) {
312 base::string16 kTestUsername
= base::ASCIIToUTF16("test_username");
313 autofill::PasswordFormMap map
;
314 map
[kTestUsername
] = &test_local_form();
315 test_local_form().blacklisted_by_user
= true;
316 controller()->OnBlacklistBlockedAutofill(map
);
317 controller()->UnblacklistSite();
319 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
320 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
321 EXPECT_EQ(test_local_form().origin
, controller()->origin());
323 ManagePasswordsIconMock mock
;
324 controller()->UpdateIconAndBubbleState(&mock
);
325 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
328 TEST_F(ManagePasswordsUIControllerTest
, UnblacklistedElsewhere
) {
329 test_local_form().blacklisted_by_user
= true;
330 base::string16 kTestUsername
= base::ASCIIToUTF16("test_username");
331 autofill::PasswordFormMap map
;
332 map
[kTestUsername
] = &test_local_form();
333 controller()->OnBlacklistBlockedAutofill(map
);
335 password_manager::PasswordStoreChange
change(
336 password_manager::PasswordStoreChange::REMOVE
, test_local_form());
337 password_manager::PasswordStoreChangeList
list(1, change
);
338 controller()->OnLoginsChanged(list
);
340 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
341 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
342 EXPECT_EQ(test_local_form().origin
, controller()->origin());
344 ManagePasswordsIconMock mock
;
345 controller()->UpdateIconAndBubbleState(&mock
);
346 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
349 TEST_F(ManagePasswordsUIControllerTest
, BlacklistedElsewhere
) {
350 base::string16 kTestUsername
= base::ASCIIToUTF16("test_username");
351 autofill::PasswordFormMap map
;
352 map
[kTestUsername
] = &test_local_form();
353 controller()->OnPasswordAutofilled(map
);
355 test_local_form().blacklisted_by_user
= true;
356 password_manager::PasswordStoreChange
change(
357 password_manager::PasswordStoreChange::ADD
, test_local_form());
358 password_manager::PasswordStoreChangeList
list(1, change
);
359 controller()->OnLoginsChanged(list
);
361 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE
, controller()->state());
362 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
363 EXPECT_EQ(test_local_form().origin
, controller()->origin());
365 ManagePasswordsIconMock mock
;
366 controller()->UpdateIconAndBubbleState(&mock
);
367 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE
, mock
.state());
370 TEST_F(ManagePasswordsUIControllerTest
, AutomaticPasswordSave
) {
371 scoped_ptr
<password_manager::PasswordFormManager
> test_form_manager(
372 CreateFormManager());
374 controller()->OnAutomaticPasswordSave(test_form_manager
.Pass());
375 EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE
, controller()->state());
377 controller()->OnBubbleHidden();
378 ManagePasswordsIconMock mock
;
379 controller()->UpdateIconAndBubbleState(&mock
);
380 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
383 TEST_F(ManagePasswordsUIControllerTest
, ChooseCredentialLocal
) {
384 ScopedVector
<autofill::PasswordForm
> local_credentials
;
385 local_credentials
.push_back(new autofill::PasswordForm(test_local_form()));
386 ScopedVector
<autofill::PasswordForm
> federated_credentials
;
387 GURL
origin("http://example.com");
388 EXPECT_TRUE(controller()->OnChooseCredentials(
389 local_credentials
.Pass(), federated_credentials
.Pass(), origin
,
390 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback
,
391 base::Unretained(this))));
392 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
,
393 controller()->state());
394 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
395 EXPECT_EQ(origin
, controller()->origin());
396 EXPECT_THAT(controller()->GetCurrentForms(),
397 ElementsAre(Pointee(test_local_form())));
399 ManagePasswordsIconMock mock
;
400 controller()->UpdateIconAndBubbleState(&mock
);
401 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
, mock
.state());
403 controller()->ManagePasswordsUIController::ChooseCredential(
405 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL
);
406 controller()->OnBubbleHidden();
407 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
408 ASSERT_TRUE(credential_info());
409 EXPECT_EQ(test_local_form().username_value
, credential_info()->id
);
410 EXPECT_EQ(test_local_form().password_value
, credential_info()->password
);
411 EXPECT_TRUE(credential_info()->federation
.is_empty());
412 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL
,
413 credential_info()->type
);
416 TEST_F(ManagePasswordsUIControllerTest
, ChooseCredentialLocalButFederated
) {
417 ScopedVector
<autofill::PasswordForm
> local_credentials
;
418 local_credentials
.push_back(
419 new autofill::PasswordForm(test_federated_form()));
420 ScopedVector
<autofill::PasswordForm
> federated_credentials
;
421 GURL
origin("http://example.com");
422 EXPECT_TRUE(controller()->OnChooseCredentials(
423 local_credentials
.Pass(), federated_credentials
.Pass(), origin
,
424 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback
,
425 base::Unretained(this))));
426 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
,
427 controller()->state());
428 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
429 EXPECT_EQ(origin
, controller()->origin());
430 EXPECT_THAT(controller()->GetCurrentForms(),
431 ElementsAre(Pointee(test_federated_form())));
433 ManagePasswordsIconMock mock
;
434 controller()->UpdateIconAndBubbleState(&mock
);
435 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
, mock
.state());
437 controller()->ManagePasswordsUIController::ChooseCredential(
438 test_federated_form(),
439 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL
);
440 controller()->OnBubbleHidden();
441 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
442 ASSERT_TRUE(credential_info());
443 EXPECT_EQ(test_federated_form().username_value
, credential_info()->id
);
444 EXPECT_EQ(test_federated_form().federation_url
,
445 credential_info()->federation
);
446 EXPECT_TRUE(credential_info()->password
.empty());
447 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
,
448 credential_info()->type
);
451 TEST_F(ManagePasswordsUIControllerTest
, ChooseCredentialFederated
) {
452 ScopedVector
<autofill::PasswordForm
> local_credentials
;
453 ScopedVector
<autofill::PasswordForm
> federated_credentials
;
454 federated_credentials
.push_back(
455 new autofill::PasswordForm(test_local_form()));
456 GURL
origin("http://example.com");
457 EXPECT_TRUE(controller()->OnChooseCredentials(
458 local_credentials
.Pass(), federated_credentials
.Pass(), origin
,
459 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback
,
460 base::Unretained(this))));
461 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
,
462 controller()->state());
463 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
464 EXPECT_EQ(0u, controller()->GetCurrentForms().size());
465 EXPECT_EQ(origin
, controller()->origin());
467 ManagePasswordsIconMock mock
;
468 controller()->UpdateIconAndBubbleState(&mock
);
469 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
, mock
.state());
471 controller()->ManagePasswordsUIController::ChooseCredential(
473 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
);
474 controller()->OnBubbleHidden();
475 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
476 ASSERT_TRUE(credential_info());
477 EXPECT_EQ(test_local_form().username_value
, credential_info()->id
);
478 EXPECT_TRUE(credential_info()->password
.empty());
479 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
,
480 credential_info()->type
);
483 TEST_F(ManagePasswordsUIControllerTest
, ChooseCredentialCancel
) {
484 ScopedVector
<autofill::PasswordForm
> local_credentials
;
485 local_credentials
.push_back(new autofill::PasswordForm(test_local_form()));
486 ScopedVector
<autofill::PasswordForm
> federated_credentials
;
487 GURL
origin("http://example.com");
488 EXPECT_TRUE(controller()->OnChooseCredentials(
489 local_credentials
.Pass(), federated_credentials
.Pass(), origin
,
490 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback
,
491 base::Unretained(this))));
492 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE
,
493 controller()->state());
494 EXPECT_EQ(origin
, controller()->origin());
495 controller()->ManagePasswordsUIController::ChooseCredential(
497 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY
);
498 controller()->OnBubbleHidden();
499 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
500 ASSERT_TRUE(credential_info());
501 EXPECT_TRUE(credential_info()->federation
.is_empty());
502 EXPECT_TRUE(credential_info()->password
.empty());
503 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY
,
504 credential_info()->type
);
507 TEST_F(ManagePasswordsUIControllerTest
, AutoSignin
) {
508 ScopedVector
<autofill::PasswordForm
> local_credentials
;
509 local_credentials
.push_back(new autofill::PasswordForm(test_local_form()));
510 controller()->OnAutoSignin(local_credentials
.Pass());
511 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE
, controller()->state());
512 EXPECT_EQ(test_local_form().origin
, controller()->origin());
513 ASSERT_FALSE(controller()->GetCurrentForms().empty());
514 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]);
515 ManagePasswordsIconMock mock
;
516 controller()->UpdateIconAndBubbleState(&mock
);
517 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE
, mock
.state());
519 controller()->OnBubbleHidden();
520 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
521 controller()->UpdateIconAndBubbleState(&mock
);
522 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
525 TEST_F(ManagePasswordsUIControllerTest
, AutoSigninClickThrough
) {
526 ScopedVector
<autofill::PasswordForm
> local_credentials
;
527 local_credentials
.push_back(new autofill::PasswordForm(test_local_form()));
528 controller()->OnAutoSignin(local_credentials
.Pass());
529 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE
, controller()->state());
530 EXPECT_EQ(test_local_form().origin
, controller()->origin());
531 ASSERT_FALSE(controller()->GetCurrentForms().empty());
532 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]);
533 ManagePasswordsIconMock mock
;
534 controller()->UpdateIconAndBubbleState(&mock
);
535 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE
, mock
.state());
537 controller()->ManageAccounts();
538 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, controller()->state());
539 controller()->UpdateIconAndBubbleState(&mock
);
540 EXPECT_EQ(password_manager::ui::MANAGE_STATE
, mock
.state());
543 TEST_F(ManagePasswordsUIControllerTest
, InactiveOnPSLMatched
) {
544 base::string16 kTestUsername
= base::ASCIIToUTF16("test_username");
545 autofill::PasswordFormMap map
;
546 autofill::PasswordForm psl_matched_test_form
= test_local_form();
547 psl_matched_test_form
.original_signon_realm
= "http://pslmatched.example.com";
548 map
[kTestUsername
] = &psl_matched_test_form
;
549 controller()->OnPasswordAutofilled(map
);
551 EXPECT_EQ(password_manager::ui::INACTIVE_STATE
, controller()->state());