Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / passwords / manage_passwords_ui_controller_unittest.cc
blob1697393c94c7e6980f6ef26bcc7058f9a7617ad3
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.
5 #include "base/bind.h"
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;
31 namespace {
33 const int64 kSlowNavigationDelayInMS = 6000;
34 const int64 kQuickNavigationDelayInMS = 500;
36 // This sublass is used to disable some code paths which are not essential for
37 // testing.
38 class TestManagePasswordsUIController : public ManagePasswordsUIController {
39 public:
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; }
47 bool opened_bubble() const { return opened_bubble_; }
49 using ManagePasswordsUIController::DidNavigateMainFrame;
51 private:
52 void UpdateBubbleAndIconVisibility() override;
53 void UpdateAndroidAccountChooserInfoBarVisibility() override;
54 void SavePasswordInternal() override {}
55 void UpdatePasswordInternal(
56 const autofill::PasswordForm& password_form) override {}
57 void NeverSavePasswordInternal() override;
59 base::TimeDelta elapsed_;
60 bool opened_bubble_;
63 TestManagePasswordsUIController::TestManagePasswordsUIController(
64 content::WebContents* contents,
65 password_manager::PasswordManagerClient* client)
66 : ManagePasswordsUIController(contents) {
67 // Do not silently replace an existing ManagePasswordsUIController because it
68 // unregisters itself in WebContentsDestroyed().
69 EXPECT_FALSE(contents->GetUserData(UserDataKey()));
70 contents->SetUserData(UserDataKey(), this);
71 set_client(client);
74 TestManagePasswordsUIController::~TestManagePasswordsUIController() {
77 base::TimeDelta TestManagePasswordsUIController::Elapsed() const {
78 return elapsed_;
81 void TestManagePasswordsUIController::UpdateBubbleAndIconVisibility() {
82 opened_bubble_ = IsAutomaticallyOpeningBubble();
83 ManagePasswordsUIController::UpdateBubbleAndIconVisibility();
84 if (opened_bubble_)
85 OnBubbleShown();
88 void TestManagePasswordsUIController::
89 UpdateAndroidAccountChooserInfoBarVisibility() {
90 OnBubbleShown();
93 void TestManagePasswordsUIController::NeverSavePasswordInternal() {
94 autofill::PasswordForm blacklisted;
95 blacklisted.origin = this->origin();
96 blacklisted.signon_realm = blacklisted.origin.spec();
97 blacklisted.blacklisted_by_user = true;
98 password_manager::PasswordStoreChange change(
99 password_manager::PasswordStoreChange::ADD, blacklisted);
100 password_manager::PasswordStoreChangeList list(1, change);
101 OnLoginsChanged(list);
104 } // namespace
106 class ManagePasswordsUIControllerTest : public ChromeRenderViewHostTestHarness {
107 public:
108 ManagePasswordsUIControllerTest() {}
110 void SetUp() override {
111 ChromeRenderViewHostTestHarness::SetUp();
113 // Create the test UIController here so that it's bound to
114 // |test_web_contents_|, and will be retrieved correctly via
115 // ManagePasswordsUIController::FromWebContents in |controller()|.
116 new TestManagePasswordsUIController(web_contents(), &client_);
118 test_local_form_.origin = GURL("http://example.com");
119 test_local_form_.username_value = base::ASCIIToUTF16("username");
120 test_local_form_.password_value = base::ASCIIToUTF16("12345");
122 test_federated_form_.origin = GURL("http://example.com");
123 test_federated_form_.username_value = base::ASCIIToUTF16("username");
124 test_federated_form_.federation_url = GURL("https://federation.test/");
126 // We need to be on a "webby" URL for most tests.
127 content::WebContentsTester::For(web_contents())
128 ->NavigateAndCommit(GURL("http://example.com"));
131 autofill::PasswordForm& test_local_form() { return test_local_form_; }
132 autofill::PasswordForm& test_federated_form() { return test_federated_form_; }
133 password_manager::CredentialInfo* credential_info() const {
134 return credential_info_.get();
137 TestManagePasswordsUIController* controller() {
138 return static_cast<TestManagePasswordsUIController*>(
139 ManagePasswordsUIController::FromWebContents(web_contents()));
142 void CredentialCallback(const password_manager::CredentialInfo& info) {
143 credential_info_.reset(new password_manager::CredentialInfo(info));
146 password_manager::StubPasswordManagerClient* client() {
147 return &client_;
150 scoped_ptr<password_manager::PasswordFormManager> CreateFormManager();
152 private:
153 password_manager::StubPasswordManagerClient client_;
155 autofill::PasswordForm test_local_form_;
156 autofill::PasswordForm test_federated_form_;
157 scoped_ptr<password_manager::CredentialInfo> credential_info_;
160 scoped_ptr<password_manager::PasswordFormManager>
161 ManagePasswordsUIControllerTest::CreateFormManager() {
162 ScopedVector<autofill::PasswordForm> stored_forms;
163 stored_forms.push_back(new autofill::PasswordForm(test_local_form()));
164 return ManagePasswordsUIControllerMock::CreateFormManager(
165 &client_, test_local_form(), stored_forms.Pass());
168 TEST_F(ManagePasswordsUIControllerTest, DefaultState) {
169 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
170 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
171 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
173 ManagePasswordsIconMock mock;
174 controller()->UpdateIconAndBubbleState(&mock);
175 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
178 TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
179 scoped_ptr<autofill::PasswordForm> test_form(
180 new autofill::PasswordForm(test_local_form()));
181 autofill::PasswordForm* test_form_ptr = test_form.get();
182 base::string16 kTestUsername = test_form->username_value;
183 autofill::PasswordFormMap map;
184 map.insert(kTestUsername, test_form.Pass());
185 controller()->OnPasswordAutofilled(map);
187 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
188 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
189 EXPECT_EQ(test_form_ptr->origin, controller()->origin());
190 ASSERT_EQ(1u, controller()->GetCurrentForms().size());
191 EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value);
193 // Controller should store a separate copy of the form as it doesn't own it.
194 EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0]);
196 ManagePasswordsIconMock mock;
197 controller()->UpdateIconAndBubbleState(&mock);
198 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
201 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
202 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
203 CreateFormManager());
204 controller()->OnPasswordSubmitted(test_form_manager.Pass());
205 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
206 controller()->state());
207 EXPECT_TRUE(controller()->PasswordPendingUserDecision());
208 EXPECT_TRUE(controller()->opened_bubble());
210 // TODO(mkwst): This should be the value of test_local_form().origin, but
211 // it's being masked by the stub implementation of
212 // ManagePasswordsUIControllerMock::PendingCredentials.
213 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
215 ManagePasswordsIconMock mock;
216 controller()->UpdateIconAndBubbleState(&mock);
217 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
218 mock.state());
221 TEST_F(ManagePasswordsUIControllerTest, BlacklistedFormPasswordSubmitted) {
222 autofill::PasswordForm blacklisted;
223 blacklisted.origin = test_local_form().origin;
224 blacklisted.signon_realm = blacklisted.origin.spec();
225 blacklisted.blacklisted_by_user = true;
226 ScopedVector<autofill::PasswordForm> stored_forms;
227 stored_forms.push_back(new autofill::PasswordForm(blacklisted));
228 scoped_ptr<password_manager::PasswordFormManager> test_form_manager =
229 ManagePasswordsUIControllerMock::CreateFormManager(
230 client(), test_local_form(), stored_forms.Pass());
232 controller()->OnPasswordSubmitted(test_form_manager.Pass());
233 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
234 controller()->state());
235 EXPECT_TRUE(controller()->PasswordPendingUserDecision());
236 EXPECT_FALSE(controller()->opened_bubble());
238 ManagePasswordsIconMock mock;
239 controller()->UpdateIconAndBubbleState(&mock);
240 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, mock.state());
243 TEST_F(ManagePasswordsUIControllerTest, PasswordSaved) {
244 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
245 CreateFormManager());
246 test_form_manager->ProvisionallySave(
247 test_local_form(),
248 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
249 controller()->OnPasswordSubmitted(test_form_manager.Pass());
251 ManagePasswordsIconMock mock;
252 controller()->UpdateIconAndBubbleState(&mock);
253 controller()->SavePassword();
254 controller()->UpdateIconAndBubbleState(&mock);
255 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
258 TEST_F(ManagePasswordsUIControllerTest, PasswordBlacklisted) {
259 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
260 CreateFormManager());
261 test_form_manager->ProvisionallySave(
262 test_local_form(),
263 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
264 controller()->OnPasswordSubmitted(test_form_manager.Pass());
266 ManagePasswordsIconMock mock;
267 controller()->NeverSavePassword();
268 controller()->UpdateIconAndBubbleState(&mock);
269 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE, mock.state());
272 TEST_F(ManagePasswordsUIControllerTest, QuickNavigations) {
273 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
274 CreateFormManager());
275 controller()->OnPasswordSubmitted(test_form_manager.Pass());
276 ManagePasswordsIconMock mock;
277 controller()->UpdateIconAndBubbleState(&mock);
278 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
279 mock.state());
281 // Fake-navigate within a second. We expect the bubble's state to persist
282 // if a navigation occurs too quickly for a user to reasonably have been
283 // able to interact with the bubble. This happens on `accounts.google.com`,
284 // for instance.
285 controller()->SetElapsed(
286 base::TimeDelta::FromMilliseconds(kQuickNavigationDelayInMS));
287 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(),
288 content::FrameNavigateParams());
289 controller()->UpdateIconAndBubbleState(&mock);
291 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
292 mock.state());
295 TEST_F(ManagePasswordsUIControllerTest, SlowNavigations) {
296 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
297 CreateFormManager());
298 controller()->OnPasswordSubmitted(test_form_manager.Pass());
299 ManagePasswordsIconMock mock;
300 controller()->UpdateIconAndBubbleState(&mock);
301 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_STATE,
302 mock.state());
304 // Fake-navigate after a second. We expect the bubble's state to be reset
305 // if a navigation occurs after this limit.
306 controller()->SetElapsed(
307 base::TimeDelta::FromMilliseconds(kSlowNavigationDelayInMS));
308 controller()->DidNavigateMainFrame(content::LoadCommittedDetails(),
309 content::FrameNavigateParams());
310 controller()->UpdateIconAndBubbleState(&mock);
312 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
315 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmittedToNonWebbyURL) {
316 // Navigate to a non-webby URL, then see what happens!
317 content::WebContentsTester::For(web_contents())
318 ->NavigateAndCommit(GURL("chrome://sign-in"));
320 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
321 CreateFormManager());
322 controller()->OnPasswordSubmitted(test_form_manager.Pass());
323 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
324 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
326 // TODO(mkwst): This should be the value of test_local_form().origin, but
327 // it's being masked by the stub implementation of
328 // ManagePasswordsUIControllerMock::PendingCredentials.
329 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
331 ManagePasswordsIconMock mock;
332 controller()->UpdateIconAndBubbleState(&mock);
333 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
336 TEST_F(ManagePasswordsUIControllerTest, BlacklistBlockedAutofill) {
337 scoped_ptr<autofill::PasswordForm> test_form(
338 new autofill::PasswordForm(test_local_form()));
339 test_form->blacklisted_by_user = true;
340 base::string16 kTestUsername = test_form->username_value;
341 autofill::PasswordFormMap map;
342 map.insert(kTestUsername, test_form.Pass());
343 controller()->OnBlacklistBlockedAutofill(map);
345 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
346 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
348 ManagePasswordsIconMock mock;
349 controller()->UpdateIconAndBubbleState(&mock);
350 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
353 TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) {
354 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
355 autofill::PasswordFormMap map;
356 map.insert(kTestUsername,
357 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
358 controller()->OnPasswordAutofilled(map);
360 test_local_form().blacklisted_by_user = true;
361 password_manager::PasswordStoreChange change(
362 password_manager::PasswordStoreChange::ADD, test_local_form());
363 password_manager::PasswordStoreChangeList list(1, change);
364 controller()->OnLoginsChanged(list);
366 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
367 EXPECT_EQ(test_local_form().origin, controller()->origin());
369 ManagePasswordsIconMock mock;
370 controller()->UpdateIconAndBubbleState(&mock);
371 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
374 TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) {
375 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
376 CreateFormManager());
378 controller()->OnAutomaticPasswordSave(test_form_manager.Pass());
379 EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE, controller()->state());
381 controller()->OnBubbleHidden();
382 ManagePasswordsIconMock mock;
383 controller()->UpdateIconAndBubbleState(&mock);
384 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
387 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
388 ScopedVector<autofill::PasswordForm> local_credentials;
389 local_credentials.push_back(new autofill::PasswordForm(test_local_form()));
390 ScopedVector<autofill::PasswordForm> federated_credentials;
391 GURL origin("http://example.com");
392 EXPECT_TRUE(controller()->OnChooseCredentials(
393 local_credentials.Pass(), federated_credentials.Pass(), origin,
394 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
395 base::Unretained(this))));
396 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
397 controller()->state());
398 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
399 EXPECT_EQ(origin, controller()->origin());
400 EXPECT_THAT(controller()->GetCurrentForms(),
401 ElementsAre(Pointee(test_local_form())));
403 ManagePasswordsIconMock mock;
404 controller()->UpdateIconAndBubbleState(&mock);
405 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, mock.state());
407 controller()->ManagePasswordsUIController::ChooseCredential(
408 test_local_form(),
409 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
410 controller()->OnBubbleHidden();
411 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
412 ASSERT_TRUE(credential_info());
413 EXPECT_EQ(test_local_form().username_value, credential_info()->id);
414 EXPECT_EQ(test_local_form().password_value, credential_info()->password);
415 EXPECT_TRUE(credential_info()->federation.is_empty());
416 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD,
417 credential_info()->type);
420 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
421 ScopedVector<autofill::PasswordForm> local_credentials;
422 local_credentials.push_back(
423 new autofill::PasswordForm(test_federated_form()));
424 ScopedVector<autofill::PasswordForm> federated_credentials;
425 GURL origin("http://example.com");
426 EXPECT_TRUE(controller()->OnChooseCredentials(
427 local_credentials.Pass(), federated_credentials.Pass(), origin,
428 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
429 base::Unretained(this))));
430 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
431 controller()->state());
432 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
433 EXPECT_EQ(origin, controller()->origin());
434 EXPECT_THAT(controller()->GetCurrentForms(),
435 ElementsAre(Pointee(test_federated_form())));
437 ManagePasswordsIconMock mock;
438 controller()->UpdateIconAndBubbleState(&mock);
439 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, mock.state());
441 controller()->ManagePasswordsUIController::ChooseCredential(
442 test_federated_form(),
443 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
444 controller()->OnBubbleHidden();
445 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
446 ASSERT_TRUE(credential_info());
447 EXPECT_EQ(test_federated_form().username_value, credential_info()->id);
448 EXPECT_EQ(test_federated_form().federation_url,
449 credential_info()->federation);
450 EXPECT_TRUE(credential_info()->password.empty());
451 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED,
452 credential_info()->type);
455 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialFederated) {
456 ScopedVector<autofill::PasswordForm> local_credentials;
457 ScopedVector<autofill::PasswordForm> federated_credentials;
458 federated_credentials.push_back(
459 new autofill::PasswordForm(test_local_form()));
460 GURL origin("http://example.com");
461 EXPECT_TRUE(controller()->OnChooseCredentials(
462 local_credentials.Pass(), federated_credentials.Pass(), origin,
463 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
464 base::Unretained(this))));
465 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
466 controller()->state());
467 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
468 EXPECT_EQ(0u, controller()->GetCurrentForms().size());
469 EXPECT_EQ(origin, controller()->origin());
471 ManagePasswordsIconMock mock;
472 controller()->UpdateIconAndBubbleState(&mock);
473 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, mock.state());
475 controller()->ManagePasswordsUIController::ChooseCredential(
476 test_local_form(),
477 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED);
478 controller()->OnBubbleHidden();
479 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
480 ASSERT_TRUE(credential_info());
481 EXPECT_EQ(test_local_form().username_value, credential_info()->id);
482 EXPECT_TRUE(credential_info()->password.empty());
483 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED,
484 credential_info()->type);
487 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
488 ScopedVector<autofill::PasswordForm> local_credentials;
489 local_credentials.push_back(new autofill::PasswordForm(test_local_form()));
490 ScopedVector<autofill::PasswordForm> federated_credentials;
491 GURL origin("http://example.com");
492 EXPECT_TRUE(controller()->OnChooseCredentials(
493 local_credentials.Pass(), federated_credentials.Pass(), origin,
494 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
495 base::Unretained(this))));
496 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
497 controller()->state());
498 EXPECT_EQ(origin, controller()->origin());
499 controller()->ManagePasswordsUIController::ChooseCredential(
500 test_local_form(),
501 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
502 controller()->OnBubbleHidden();
503 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
504 ASSERT_TRUE(credential_info());
505 EXPECT_TRUE(credential_info()->federation.is_empty());
506 EXPECT_TRUE(credential_info()->password.empty());
507 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY,
508 credential_info()->type);
511 TEST_F(ManagePasswordsUIControllerTest, AutoSignin) {
512 ScopedVector<autofill::PasswordForm> local_credentials;
513 local_credentials.push_back(new autofill::PasswordForm(test_local_form()));
514 controller()->OnAutoSignin(local_credentials.Pass());
515 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->state());
516 EXPECT_EQ(test_local_form().origin, controller()->origin());
517 ASSERT_FALSE(controller()->GetCurrentForms().empty());
518 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]);
519 ManagePasswordsIconMock mock;
520 controller()->UpdateIconAndBubbleState(&mock);
521 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, mock.state());
523 controller()->OnBubbleHidden();
524 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
525 controller()->UpdateIconAndBubbleState(&mock);
526 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
529 TEST_F(ManagePasswordsUIControllerTest, AutoSigninClickThrough) {
530 ScopedVector<autofill::PasswordForm> local_credentials;
531 local_credentials.push_back(new autofill::PasswordForm(test_local_form()));
532 controller()->OnAutoSignin(local_credentials.Pass());
533 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, controller()->state());
534 EXPECT_EQ(test_local_form().origin, controller()->origin());
535 ASSERT_FALSE(controller()->GetCurrentForms().empty());
536 EXPECT_EQ(test_local_form(), *controller()->GetCurrentForms()[0]);
537 ManagePasswordsIconMock mock;
538 controller()->UpdateIconAndBubbleState(&mock);
539 EXPECT_EQ(password_manager::ui::AUTO_SIGNIN_STATE, mock.state());
541 controller()->ManageAccounts();
542 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
543 controller()->UpdateIconAndBubbleState(&mock);
544 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
547 TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) {
548 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
549 autofill::PasswordFormMap map;
550 scoped_ptr<autofill::PasswordForm> psl_matched_test_form(
551 new autofill::PasswordForm(test_local_form()));
552 psl_matched_test_form->original_signon_realm =
553 "http://pslmatched.example.com";
554 map.insert(kTestUsername, psl_matched_test_form.Pass());
555 controller()->OnPasswordAutofilled(map);
557 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
560 TEST_F(ManagePasswordsUIControllerTest, UpdatePasswordSubmitted) {
561 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
562 CreateFormManager());
563 controller()->OnUpdatePasswordSubmitted(test_form_manager.Pass());
564 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE,
565 controller()->state());
567 ManagePasswordsIconMock mock;
568 controller()->UpdateIconAndBubbleState(&mock);
569 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, mock.state());
572 TEST_F(ManagePasswordsUIControllerTest, PasswordUpdated) {
573 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
574 CreateFormManager());
575 test_form_manager->ProvisionallySave(
576 test_local_form(),
577 password_manager::PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
578 controller()->OnUpdatePasswordSubmitted(test_form_manager.Pass());
580 ManagePasswordsIconMock mock;
581 controller()->UpdateIconAndBubbleState(&mock);
582 EXPECT_EQ(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, mock.state());
583 controller()->UpdatePassword(autofill::PasswordForm());
584 controller()->UpdateIconAndBubbleState(&mock);
585 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());