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 "base/location.h" | 5 #include "base/location.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
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/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 class TestPasswordManager : public PasswordManager { | 131 class TestPasswordManager : public PasswordManager { |
132 public: | 132 public: |
133 explicit TestPasswordManager(TestPasswordManagerClient* client) | 133 explicit TestPasswordManager(TestPasswordManagerClient* client) |
134 : PasswordManager(client), wait_for_username_(false) {} | 134 : PasswordManager(client), wait_for_username_(false) {} |
135 | 135 |
136 void Autofill(password_manager::PasswordManagerDriver* driver, | 136 void Autofill(password_manager::PasswordManagerDriver* driver, |
137 const autofill::PasswordForm& form_for_autofill, | 137 const autofill::PasswordForm& form_for_autofill, |
138 const autofill::PasswordFormMap& best_matches, | 138 const autofill::PasswordFormMap& best_matches, |
139 const autofill::PasswordForm& preferred_match, | 139 const autofill::PasswordForm& preferred_match, |
140 bool wait_for_username) const override { | 140 bool wait_for_username) const override { |
141 best_matches_ = best_matches; | 141 best_matches_ = &best_matches; |
142 wait_for_username_ = wait_for_username; | 142 wait_for_username_ = wait_for_username; |
143 } | 143 } |
144 | 144 |
145 const autofill::PasswordFormMap& GetLatestBestMatches() { | 145 const autofill::PasswordFormMap& GetLatestBestMatches() { |
146 return best_matches_; | 146 return *best_matches_; |
147 } | 147 } |
148 | 148 |
149 bool GetLatestWaitForUsername() { return wait_for_username_; } | 149 bool GetLatestWaitForUsername() { return wait_for_username_; } |
150 | 150 |
151 private: | 151 private: |
| 152 // Points to a PasswordFormMap owned by PasswordFormManager. |
152 // Marked mutable to get around constness of Autofill(). | 153 // Marked mutable to get around constness of Autofill(). |
153 // TODO(vabr): This should be rewritten as a mock of PasswordManager, and the | 154 // TODO(vabr): This should be rewritten as a mock of PasswordManager, and the |
154 // interesting arguments should be saved via GMock actions instead. | 155 // interesting arguments should be saved via GMock actions instead. |
155 mutable autofill::PasswordFormMap best_matches_; | 156 mutable const autofill::PasswordFormMap* best_matches_; |
156 mutable bool wait_for_username_; | 157 mutable bool wait_for_username_; |
157 }; | 158 }; |
158 | 159 |
159 } // namespace | 160 } // namespace |
160 | 161 |
161 class PasswordFormManagerTest : public testing::Test { | 162 class PasswordFormManagerTest : public testing::Test { |
162 public: | 163 public: |
163 PasswordFormManagerTest() {} | 164 PasswordFormManagerTest() {} |
164 | 165 |
165 // Types of possible outcomes of simulated matching, see | 166 // Types of possible outcomes of simulated matching, see |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return &p->pending_credentials_; | 215 return &p->pending_credentials_; |
215 } | 216 } |
216 | 217 |
217 void SimulateMatchingPhase(PasswordFormManager* p, | 218 void SimulateMatchingPhase(PasswordFormManager* p, |
218 ResultOfSimulatedMatching result) { | 219 ResultOfSimulatedMatching result) { |
219 // Roll up the state to mock out the matching phase. | 220 // Roll up the state to mock out the matching phase. |
220 p->state_ = PasswordFormManager::POST_MATCHING_PHASE; | 221 p->state_ = PasswordFormManager::POST_MATCHING_PHASE; |
221 if (result == RESULT_NO_MATCH) | 222 if (result == RESULT_NO_MATCH) |
222 return; | 223 return; |
223 | 224 |
224 PasswordForm* match = new PasswordForm(saved_match_); | 225 scoped_ptr<PasswordForm> match(new PasswordForm(saved_match_)); |
225 // Heap-allocated form is owned by p. | 226 p->preferred_match_ = match.get(); |
226 p->best_matches_[match->username_value] = match; | 227 base::string16 username = match->username_value; |
227 p->preferred_match_ = match; | 228 p->best_matches_.insert(username, match.Pass()); |
228 } | 229 } |
229 | 230 |
230 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) { | 231 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) { |
231 p->SanitizePossibleUsernames(form); | 232 p->SanitizePossibleUsernames(form); |
232 } | 233 } |
233 | 234 |
234 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { | 235 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { |
235 return p->ShouldIgnoreResult(*form); | 236 return p->ShouldIgnoreResult(*form); |
236 } | 237 } |
237 | 238 |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 manager_creds.OnGetPasswordStoreResults(simulated_results.Pass()); | 1539 manager_creds.OnGetPasswordStoreResults(simulated_results.Pass()); |
1539 Mock::VerifyAndClearExpectations(client()->mock_driver()); | 1540 Mock::VerifyAndClearExpectations(client()->mock_driver()); |
1540 | 1541 |
1541 // Check that Autofill message was sent. | 1542 // Check that Autofill message was sent. |
1542 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); | 1543 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); |
1543 // Check that we suggest, not autofill. | 1544 // Check that we suggest, not autofill. |
1544 EXPECT_TRUE(password_manager.GetLatestWaitForUsername()); | 1545 EXPECT_TRUE(password_manager.GetLatestWaitForUsername()); |
1545 } | 1546 } |
1546 | 1547 |
1547 } // namespace password_manager | 1548 } // namespace password_manager |
OLD | NEW |