OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/password_manager/mock_password_store.h" | 10 #include "chrome/browser/password_manager/mock_password_store.h" |
11 #include "chrome/browser/password_manager/password_manager.h" | 11 #include "chrome/browser/password_manager/password_manager.h" |
12 #include "chrome/browser/password_manager/password_manager_delegate.h" | 12 #include "chrome/browser/password_manager/password_manager_delegate.h" |
13 #include "chrome/browser/password_manager/password_store.h" | 13 #include "chrome/browser/password_manager/password_store.h" |
14 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
18 #include "chrome/test/base/testing_pref_service_syncable.h" | 18 #include "chrome/test/base/testing_pref_service_syncable.h" |
19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/browser/navigation_details.h" | 20 #include "content/public/browser/navigation_details.h" |
21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
22 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 using content::PasswordForm; | 26 using autofill::PasswordForm; |
27 using testing::_; | 27 using testing::_; |
28 using testing::DoAll; | 28 using testing::DoAll; |
29 using testing::Exactly; | 29 using testing::Exactly; |
30 using testing::Return; | 30 using testing::Return; |
31 using testing::WithArg; | 31 using testing::WithArg; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 class MockPasswordManagerDelegate : public PasswordManagerDelegate { | 35 class MockPasswordManagerDelegate : public PasswordManagerDelegate { |
36 public: | 36 public: |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 form.username_element = ASCIIToUTF16("EmailField"); | 132 form.username_element = ASCIIToUTF16("EmailField"); |
133 form.password_element = ASCIIToUTF16("PasswdField"); | 133 form.password_element = ASCIIToUTF16("PasswdField"); |
134 form.username_value = ASCIIToUTF16("twitter"); | 134 form.username_value = ASCIIToUTF16("twitter"); |
135 form.password_value = ASCIIToUTF16("password"); | 135 form.password_value = ASCIIToUTF16("password"); |
136 form.password_autocomplete_set = true; | 136 form.password_autocomplete_set = true; |
137 form.submit_element = ASCIIToUTF16("signIn"); | 137 form.submit_element = ASCIIToUTF16("signIn"); |
138 form.signon_realm = "https://twitter.com"; | 138 form.signon_realm = "https://twitter.com"; |
139 return form; | 139 return form; |
140 } | 140 } |
141 | 141 |
142 bool FormsAreEqual(const content::PasswordForm& lhs, | 142 bool FormsAreEqual(const autofill::PasswordForm& lhs, |
143 const content::PasswordForm& rhs) { | 143 const autofill::PasswordForm& rhs) { |
144 if (lhs.origin != rhs.origin) | 144 if (lhs.origin != rhs.origin) |
145 return false; | 145 return false; |
146 if (lhs.action != rhs.action) | 146 if (lhs.action != rhs.action) |
147 return false; | 147 return false; |
148 if (lhs.username_element != rhs.username_element) | 148 if (lhs.username_element != rhs.username_element) |
149 return false; | 149 return false; |
150 if (lhs.password_element != rhs.password_element) | 150 if (lhs.password_element != rhs.password_element) |
151 return false; | 151 return false; |
152 if (lhs.username_value != rhs.username_value) | 152 if (lhs.username_value != rhs.username_value) |
153 return false; | 153 return false; |
154 if (lhs.password_value != rhs.password_value) | 154 if (lhs.password_value != rhs.password_value) |
155 return false; | 155 return false; |
156 if (lhs.password_autocomplete_set != rhs.password_autocomplete_set) | 156 if (lhs.password_autocomplete_set != rhs.password_autocomplete_set) |
157 return false; | 157 return false; |
158 if (lhs.submit_element != rhs.submit_element) | 158 if (lhs.submit_element != rhs.submit_element) |
159 return false; | 159 return false; |
160 if (lhs.signon_realm != rhs.signon_realm) | 160 if (lhs.signon_realm != rhs.signon_realm) |
161 return false; | 161 return false; |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 TestPasswordManager* manager() { | 165 TestPasswordManager* manager() { |
166 return manager_; | 166 return manager_; |
167 } | 167 } |
168 | 168 |
169 void OnPasswordFormSubmitted(const content::PasswordForm& form) { | 169 void OnPasswordFormSubmitted(const autofill::PasswordForm& form) { |
170 manager()->OnPasswordFormSubmitted(form); | 170 manager()->OnPasswordFormSubmitted(form); |
171 } | 171 } |
172 | 172 |
173 PasswordManager::PasswordSubmittedCallback SubmissionCallback() { | 173 PasswordManager::PasswordSubmittedCallback SubmissionCallback() { |
174 return base::Bind(&PasswordManagerTest::FormSubmitted, | 174 return base::Bind(&PasswordManagerTest::FormSubmitted, |
175 base::Unretained(this)); | 175 base::Unretained(this)); |
176 } | 176 } |
177 | 177 |
178 void FormSubmitted(const content::PasswordForm& form) { | 178 void FormSubmitted(const autofill::PasswordForm& form) { |
179 submitted_form_ = form; | 179 submitted_form_ = form; |
180 } | 180 } |
181 | 181 |
182 scoped_refptr<MockPasswordStore> store_; | 182 scoped_refptr<MockPasswordStore> store_; |
183 TestPasswordManager* manager_; | 183 TestPasswordManager* manager_; |
184 MockPasswordManagerDelegate delegate_; // Owned by manager_. | 184 MockPasswordManagerDelegate delegate_; // Owned by manager_. |
185 PasswordForm submitted_form_; | 185 PasswordForm submitted_form_; |
186 }; | 186 }; |
187 | 187 |
188 MATCHER_P(FormMatches, form, "") { | 188 MATCHER_P(FormMatches, form, "") { |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 manager()->ProvisionallySavePassword(login_form); | 586 manager()->ProvisionallySavePassword(login_form); |
587 | 587 |
588 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); | 588 PasswordForm failed_login_form(MakeTwitterFailedLoginForm()); |
589 observed.clear(); | 589 observed.clear(); |
590 observed.push_back(failed_login_form); | 590 observed.push_back(failed_login_form); |
591 // A PasswordForm appears, and is visible in the layout: | 591 // A PasswordForm appears, and is visible in the layout: |
592 // No expected calls to the PasswordStore... | 592 // No expected calls to the PasswordStore... |
593 manager()->OnPasswordFormsParsed(observed); | 593 manager()->OnPasswordFormsParsed(observed); |
594 manager()->OnPasswordFormsRendered(observed); | 594 manager()->OnPasswordFormsRendered(observed); |
595 } | 595 } |
OLD | NEW |