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