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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/autofill/core/browser/autofill_field.h" | 11 #include "components/autofill/core/browser/autofill_field.h" |
12 #include "components/autofill/core/browser/autofill_metrics.h" | 12 #include "components/autofill/core/browser/autofill_metrics.h" |
13 #include "components/autofill/core/browser/form_structure.h" | 13 #include "components/autofill/core/browser/form_structure.h" |
14 #include "components/autofill/core/common/form_data.h" | 14 #include "components/autofill/core/common/form_data.h" |
15 #include "components/autofill/core/common/form_field_data.h" | 15 #include "components/autofill/core/common/form_field_data.h" |
16 #include "components/password_manager/core/browser/password_autofill_manager.h" | |
16 #include "components/password_manager/core/browser/password_generation_manager.h " | 17 #include "components/password_manager/core/browser/password_generation_manager.h " |
17 #include "components/password_manager/core/browser/password_manager.h" | 18 #include "components/password_manager/core/browser/password_manager.h" |
18 #include "components/password_manager/core/browser/password_manager_client.h" | 19 #include "components/password_manager/core/browser/password_manager_client.h" |
19 #include "components/password_manager/core/common/password_manager_pref_names.h" | 20 #include "components/password_manager/core/common/password_manager_pref_names.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 class TestPasswordManagerDriver : public PasswordManagerDriver { | 28 class TestPasswordManagerDriver : public PasswordManagerDriver { |
28 public: | 29 public: |
29 TestPasswordManagerDriver(PasswordManagerClient* client) | 30 TestPasswordManagerDriver(PasswordManagerClient* client) |
30 : password_manager_(client), | 31 : password_manager_(client), |
31 password_generation_manager_(client), | 32 password_generation_manager_(client), |
33 password_autofill_manager_(client, NULL), | |
32 is_off_the_record_(false) {} | 34 is_off_the_record_(false) {} |
33 virtual ~TestPasswordManagerDriver() {} | 35 virtual ~TestPasswordManagerDriver() {} |
34 | 36 |
35 // PasswordManagerDriver implementation. | 37 // PasswordManagerDriver implementation. |
36 virtual void FillPasswordForm(const autofill::PasswordFormFillData& form_data) | 38 virtual void FillPasswordForm(const autofill::PasswordFormFillData& form_data) |
37 OVERRIDE {} | 39 OVERRIDE {} |
38 virtual bool DidLastPageLoadEncounterSSLErrors() OVERRIDE { return false; } | 40 virtual bool DidLastPageLoadEncounterSSLErrors() OVERRIDE { return false; } |
39 virtual bool IsOffTheRecord() OVERRIDE { return is_off_the_record_; } | 41 virtual bool IsOffTheRecord() OVERRIDE { return is_off_the_record_; } |
40 virtual PasswordGenerationManager* GetPasswordGenerationManager() OVERRIDE { | 42 virtual PasswordGenerationManager* GetPasswordGenerationManager() OVERRIDE { |
41 return &password_generation_manager_; | 43 return &password_generation_manager_; |
42 } | 44 } |
43 virtual PasswordManager* GetPasswordManager() OVERRIDE { | 45 virtual PasswordManager* GetPasswordManager() OVERRIDE { |
44 return &password_manager_; | 46 return &password_manager_; |
45 } | 47 } |
46 virtual autofill::AutofillManager* GetAutofillManager() OVERRIDE { | 48 virtual autofill::AutofillManager* GetAutofillManager() OVERRIDE { |
47 return NULL; | 49 return NULL; |
48 } | 50 } |
51 virtual PasswordAutofillManager* GetPasswordAutofillManager() OVERRIDE { | |
52 return &password_autofill_manager_; | |
53 } | |
49 virtual void AllowPasswordGenerationForForm(autofill::PasswordForm* form) | 54 virtual void AllowPasswordGenerationForForm(autofill::PasswordForm* form) |
50 OVERRIDE {} | 55 OVERRIDE {} |
51 virtual void AccountCreationFormsFound( | 56 virtual void AccountCreationFormsFound( |
52 const std::vector<autofill::FormData>& forms) OVERRIDE { | 57 const std::vector<autofill::FormData>& forms) OVERRIDE { |
53 found_account_creation_forms_.insert( | 58 found_account_creation_forms_.insert( |
54 found_account_creation_forms_.begin(), forms.begin(), forms.end()); | 59 found_account_creation_forms_.begin(), forms.begin(), forms.end()); |
55 } | 60 } |
61 virtual void AcceptPasswordAutofillSuggestion( | |
62 const base::string16& username, | |
63 const base::string16& password) OVERRIDE { | |
64 } | |
Ilya Sherman
2014/03/18 00:14:27
nit: Do you need to add these methods? It doesn't
Patrick Dubroy
2014/03/28 15:44:22
See previous comment.
| |
56 | 65 |
57 const std::vector<autofill::FormData>& GetFoundAccountCreationForms() { | 66 const std::vector<autofill::FormData>& GetFoundAccountCreationForms() { |
58 return found_account_creation_forms_; | 67 return found_account_creation_forms_; |
59 } | 68 } |
60 void set_is_off_the_record(bool is_off_the_record) { | 69 void set_is_off_the_record(bool is_off_the_record) { |
61 is_off_the_record_ = is_off_the_record; | 70 is_off_the_record_ = is_off_the_record; |
62 } | 71 } |
63 | 72 |
64 private: | 73 private: |
65 PasswordManager password_manager_; | 74 PasswordManager password_manager_; |
66 PasswordGenerationManager password_generation_manager_; | 75 PasswordGenerationManager password_generation_manager_; |
76 PasswordAutofillManager password_autofill_manager_; | |
67 std::vector<autofill::FormData> found_account_creation_forms_; | 77 std::vector<autofill::FormData> found_account_creation_forms_; |
68 bool is_off_the_record_; | 78 bool is_off_the_record_; |
69 }; | 79 }; |
70 | 80 |
71 class TestPasswordManagerClient : public PasswordManagerClient { | 81 class TestPasswordManagerClient : public PasswordManagerClient { |
72 public: | 82 public: |
73 TestPasswordManagerClient(scoped_ptr<PrefService> prefs) | 83 TestPasswordManagerClient(scoped_ptr<PrefService> prefs) |
74 : prefs_(prefs.Pass()), driver_(this), is_sync_enabled_(false) {} | 84 : prefs_(prefs.Pass()), driver_(this), is_sync_enabled_(false) {} |
75 | 85 |
76 virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save) | 86 virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // Disable password manager by going incognito. Even though password | 221 // Disable password manager by going incognito. Even though password |
212 // syncing is enabled, generation should still | 222 // syncing is enabled, generation should still |
213 // be disabled. | 223 // be disabled. |
214 GetTestDriver()->set_is_off_the_record(true); | 224 GetTestDriver()->set_is_off_the_record(true); |
215 PrefService* prefs = client_->GetPrefs(); | 225 PrefService* prefs = client_->GetPrefs(); |
216 prefs->SetBoolean(prefs::kPasswordManagerEnabled, true); | 226 prefs->SetBoolean(prefs::kPasswordManagerEnabled, true); |
217 client_->set_is_password_sync_enabled(true); | 227 client_->set_is_password_sync_enabled(true); |
218 | 228 |
219 EXPECT_FALSE(IsGenerationEnabled()); | 229 EXPECT_FALSE(IsGenerationEnabled()); |
220 } | 230 } |
OLD | NEW |