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

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

Issue 733463003: Show user credentials chooser bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge with trunk Created 6 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 2014 The Chromium Authors. All rights reserved. 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 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 "base/bind.h"
5 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "base/time/time.h" 8 #include "base/time/time.h"
8 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_icon_mock.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_icon_mock.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" 13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
15 #include "components/autofill/core/common/password_form.h" 16 #include "components/autofill/core/common/password_form.h"
17 #include "components/password_manager/content/common/credential_manager_types.h"
16 #include "components/password_manager/core/browser/password_form_manager.h" 18 #include "components/password_manager/core/browser/password_form_manager.h"
17 #include "components/password_manager/core/browser/stub_password_manager_client. h" 19 #include "components/password_manager/core/browser/stub_password_manager_client. h"
18 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 20 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
19 #include "components/password_manager/core/common/password_manager_ui.h" 21 #include "components/password_manager/core/common/password_manager_ui.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "content/public/test/web_contents_tester.h" 23 #include "content/public/test/web_contents_tester.h"
22 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
24 26
25 namespace { 27 namespace {
(...skipping 22 matching lines...) Expand all
48 50
49 void SetUp() override { 51 void SetUp() override {
50 ChromeRenderViewHostTestHarness::SetUp(); 52 ChromeRenderViewHostTestHarness::SetUp();
51 53
52 // Create the test UIController here so that it's bound to 54 // Create the test UIController here so that it's bound to
53 // |test_web_contents_|, and will be retrieved correctly via 55 // |test_web_contents_|, and will be retrieved correctly via
54 // ManagePasswordsUIController::FromWebContents in |controller()|. 56 // ManagePasswordsUIController::FromWebContents in |controller()|.
55 new ManagePasswordsUIControllerMock(web_contents()); 57 new ManagePasswordsUIControllerMock(web_contents());
56 58
57 test_form_.origin = GURL("http://example.com"); 59 test_form_.origin = GURL("http://example.com");
60 test_form_.username_value = base::ASCIIToUTF16("username");
61 test_form_.password_value = base::ASCIIToUTF16("12345");
58 62
59 // We need to be on a "webby" URL for most tests. 63 // We need to be on a "webby" URL for most tests.
60 content::WebContentsTester::For(web_contents()) 64 content::WebContentsTester::For(web_contents())
61 ->NavigateAndCommit(GURL("http://example.com")); 65 ->NavigateAndCommit(GURL("http://example.com"));
62 } 66 }
63 67
64 autofill::PasswordForm& test_form() { return test_form_; } 68 autofill::PasswordForm& test_form() { return test_form_; }
69 password_manager::CredentialInfo* credential_info() const {
70 return credential_info_.get();
71 }
65 72
66 ManagePasswordsUIControllerMock* controller() { 73 ManagePasswordsUIControllerMock* controller() {
67 return static_cast<ManagePasswordsUIControllerMock*>( 74 return static_cast<ManagePasswordsUIControllerMock*>(
68 ManagePasswordsUIController::FromWebContents(web_contents())); 75 ManagePasswordsUIController::FromWebContents(web_contents()));
69 } 76 }
70 77
78 void CredentialCallback(const password_manager::CredentialInfo& info) {
79 credential_info_.reset(new password_manager::CredentialInfo(info));
80 }
81
71 private: 82 private:
72 autofill::PasswordForm test_form_; 83 autofill::PasswordForm test_form_;
84 scoped_ptr<password_manager::CredentialInfo> credential_info_;
73 }; 85 };
74 86
75 TEST_F(ManagePasswordsUIControllerTest, DefaultState) { 87 TEST_F(ManagePasswordsUIControllerTest, DefaultState) {
76 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state()); 88 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
77 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 89 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
78 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin()); 90 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
79 91
80 ManagePasswordsIconMock mock; 92 ManagePasswordsIconMock mock;
81 controller()->UpdateIconAndBubbleState(&mock); 93 controller()->UpdateIconAndBubbleState(&mock);
82 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state()); 94 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 new password_manager::PasswordFormManager( 329 new password_manager::PasswordFormManager(
318 NULL, &client, &driver, test_form(), false)); 330 NULL, &client, &driver, test_form(), false));
319 331
320 controller()->OnAutomaticPasswordSave(test_form_manager.Pass()); 332 controller()->OnAutomaticPasswordSave(test_form_manager.Pass());
321 EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE, controller()->state()); 333 EXPECT_EQ(password_manager::ui::CONFIRMATION_STATE, controller()->state());
322 334
323 ManagePasswordsIconMock mock; 335 ManagePasswordsIconMock mock;
324 controller()->UpdateIconAndBubbleState(&mock); 336 controller()->UpdateIconAndBubbleState(&mock);
325 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state()); 337 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
326 } 338 }
339
340 TEST_F(ManagePasswordsUIControllerTest, ChooseCredential) {
341 ScopedVector<autofill::PasswordForm> credentials;
342 credentials.push_back(new autofill::PasswordForm(test_form()));
343 EXPECT_TRUE(controller()->OnChooseCredentials(
344 credentials.Pass(),
345 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
346 base::Unretained(this))));
347 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_AND_BUBBLE_STATE,
348 controller()->state());
349 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
350 EXPECT_EQ(test_form().origin, controller()->origin());
351 EXPECT_EQ(autofill::ConstPasswordFormMap(), controller()->best_matches());
352
353 ManagePasswordsIconMock mock;
354 controller()->UpdateIconAndBubbleState(&mock);
355 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, mock.state());
356
357 controller()->ManagePasswordsUIController::ChooseCredential(true,
358 test_form());
359 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
360 ASSERT_TRUE(credential_info());
361 EXPECT_EQ(test_form().username_value, credential_info()->id);
362 EXPECT_EQ(test_form().password_value, credential_info()->password);
363 EXPECT_EQ(password_manager::CREDENTIAL_TYPE_LOCAL, credential_info()->type);
364 }
365
366 TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
367 ScopedVector<autofill::PasswordForm> credentials;
368 credentials.push_back(new autofill::PasswordForm(test_form()));
369 EXPECT_TRUE(controller()->OnChooseCredentials(
370 credentials.Pass(),
371 base::Bind(&ManagePasswordsUIControllerTest::CredentialCallback,
372 base::Unretained(this))));
373 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_AND_BUBBLE_STATE,
374 controller()->state());
375
376 controller()->ManagePasswordsUIController::ChooseCredential(false,
377 test_form());
378 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
379 ASSERT_TRUE(credential_info());
380 EXPECT_EQ(password_manager::CREDENTIAL_TYPE_EMPTY, credential_info()->type);
381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698