| OLD | NEW |
| 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 "chrome/browser/ui/passwords/manage_passwords_test.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_test.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_command_controller.h" | 17 #include "chrome/browser/ui/browser_command_controller.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" | 19 #include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/interactive_test_utils.h" | 22 #include "chrome/test/base/interactive_test_utils.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ManagePasswordsTest::SetupManagingPasswords() { | 63 void ManagePasswordsTest::SetupManagingPasswords() { |
| 63 std::map<base::string16, const autofill::PasswordForm*> map; | 64 std::map<base::string16, const autofill::PasswordForm*> map; |
| 64 map.insert(std::make_pair(base::ASCIIToUTF16(kTestUsername), test_form())); | 65 map.insert(std::make_pair(base::ASCIIToUTF16(kTestUsername), test_form())); |
| 65 GetController()->OnPasswordAutofilled(map, map.begin()->second->origin, | 66 GetController()->OnPasswordAutofilled(map, map.begin()->second->origin, |
| 66 nullptr); | 67 nullptr); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ManagePasswordsTest::SetupPendingPassword() { | 70 void ManagePasswordsTest::SetupPendingPassword() { |
| 70 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 71 scoped_refptr<password_manager::PasswordFormManager> test_form_manager( |
| 71 new password_manager::PasswordFormManager( | 72 new password_manager::PasswordFormManager( |
| 72 nullptr, &client_, driver_.AsWeakPtr(), *test_form(), | 73 nullptr, &client_, driver_.AsWeakPtr(), *test_form(), |
| 73 base::WrapUnique(new password_manager::StubFormSaver), &fetcher_)); | 74 base::WrapUnique(new password_manager::StubFormSaver), &fetcher_)); |
| 74 fetcher_.SetNonFederated(std::vector<const autofill::PasswordForm*>(), 0u); | 75 fetcher_.SetNonFederated(std::vector<const autofill::PasswordForm*>(), 0u); |
| 75 GetController()->OnPasswordSubmitted(std::move(test_form_manager)); | 76 GetController()->OnPasswordSubmitted(std::move(test_form_manager)); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void ManagePasswordsTest::SetupAutomaticPassword() { | 79 void ManagePasswordsTest::SetupAutomaticPassword() { |
| 79 std::unique_ptr<password_manager::PasswordFormManager> test_form_manager( | 80 scoped_refptr<password_manager::PasswordFormManager> test_form_manager( |
| 80 new password_manager::PasswordFormManager( | 81 new password_manager::PasswordFormManager( |
| 81 nullptr, &client_, driver_.AsWeakPtr(), *test_form(), | 82 nullptr, &client_, driver_.AsWeakPtr(), *test_form(), |
| 82 base::WrapUnique(new password_manager::StubFormSaver), &fetcher_)); | 83 base::WrapUnique(new password_manager::StubFormSaver), &fetcher_)); |
| 83 fetcher_.SetNonFederated(std::vector<const autofill::PasswordForm*>(), 0u); | 84 fetcher_.SetNonFederated(std::vector<const autofill::PasswordForm*>(), 0u); |
| 84 GetController()->OnAutomaticPasswordSave(std::move(test_form_manager)); | 85 GetController()->OnAutomaticPasswordSave(std::move(test_form_manager)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void ManagePasswordsTest::SetupAutoSignin( | 88 void ManagePasswordsTest::SetupAutoSignin( |
| 88 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials) { | 89 std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials) { |
| 89 ASSERT_FALSE(local_credentials.empty()); | 90 ASSERT_FALSE(local_credentials.empty()); |
| 90 GURL origin = local_credentials[0]->origin; | 91 GURL origin = local_credentials[0]->origin; |
| 91 GetController()->OnAutoSignin(std::move(local_credentials), origin); | 92 GetController()->OnAutoSignin(std::move(local_credentials), origin); |
| 92 } | 93 } |
| 93 | 94 |
| 94 std::unique_ptr<base::HistogramSamples> ManagePasswordsTest::GetSamples( | 95 std::unique_ptr<base::HistogramSamples> ManagePasswordsTest::GetSamples( |
| 95 const char* histogram) { | 96 const char* histogram) { |
| 96 // Ensure that everything has been properly recorded before pulling samples. | 97 // Ensure that everything has been properly recorded before pulling samples. |
| 97 content::RunAllPendingInMessageLoop(); | 98 content::RunAllPendingInMessageLoop(); |
| 98 return histogram_tester_.GetHistogramSamplesSinceCreation(histogram); | 99 return histogram_tester_.GetHistogramSamplesSinceCreation(histogram); |
| 99 } | 100 } |
| 100 | 101 |
| 101 PasswordsClientUIDelegate* ManagePasswordsTest::GetController() { | 102 PasswordsClientUIDelegate* ManagePasswordsTest::GetController() { |
| 102 return PasswordsClientUIDelegateFromWebContents( | 103 return PasswordsClientUIDelegateFromWebContents( |
| 103 browser()->tab_strip_model()->GetActiveWebContents()); | 104 browser()->tab_strip_model()->GetActiveWebContents()); |
| 104 } | 105 } |
| OLD | NEW |