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 <queue> | |
6 | |
5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
6 #include "base/bind.h" | 8 #include "base/bind.h" |
7 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
12 #include "components/password_manager/core/browser/password_form_data.h" | 14 #include "components/password_manager/core/browser/password_form_data.h" |
13 #include "components/password_manager/core/browser/password_store_consumer.h" | 15 #include "components/password_manager/core/browser/password_store_consumer.h" |
14 #include "components/password_manager/core/browser/password_store_default.h" | 16 #include "components/password_manager/core/browser/password_store_default.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
18 using autofill::PasswordForm; | 20 using autofill::PasswordForm; |
19 using base::WaitableEvent; | 21 using base::WaitableEvent; |
20 using testing::_; | 22 using testing::_; |
21 using testing::DoAll; | 23 using testing::DoAll; |
22 using testing::WithArg; | 24 using testing::WithArg; |
23 | 25 |
24 namespace password_manager { | 26 namespace password_manager { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 class MockPasswordStoreConsumer : public PasswordStoreConsumer { | 30 class CheckingPasswordStoreConsumer : public PasswordStoreConsumer { |
29 public: | 31 public: |
30 MOCK_METHOD1(OnGetPasswordStoreResults, | 32 ~CheckingPasswordStoreConsumer() override { |
31 void(const std::vector<PasswordForm*>&)); | 33 EXPECT_FALSE(expected_results_.size()); |
vasilii
2015/02/03 19:22:17
EXPECT_TRUE(expected_results_.empty());
vabr (Chromium)
2015/02/04 16:13:44
Done.
| |
34 } | |
35 | |
36 void OnGetPasswordStoreResults() override { | |
37 ASSERT_TRUE(expected_results_.size()); | |
vasilii
2015/02/03 19:22:17
empty()
vabr (Chromium)
2015/02/04 16:13:44
Done.
| |
38 EXPECT_TRUE(ContainsSamePasswordFormsPtr(*expected_results_.front(), | |
39 results()->get())); | |
40 expected_results_.pop(); | |
41 } | |
42 | |
43 void AddExpectation(const std::vector<PasswordForm*>* expected_result) { | |
44 expected_results_.push(expected_result); | |
45 } | |
46 | |
47 private: | |
48 std::queue<const std::vector<PasswordForm*>*> expected_results_; | |
32 }; | 49 }; |
33 | 50 |
34 class StartSyncFlareMock { | 51 class StartSyncFlareMock { |
35 public: | 52 public: |
36 StartSyncFlareMock() {} | 53 StartSyncFlareMock() {} |
37 ~StartSyncFlareMock() {} | 54 ~StartSyncFlareMock() {} |
38 | 55 |
39 MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType)); | 56 MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType)); |
40 }; | 57 }; |
41 | 58 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 "http://bar.example.com/action", | 140 "http://bar.example.com/action", |
124 L"submit_element", | 141 L"submit_element", |
125 L"username_element", | 142 L"username_element", |
126 L"password_element", | 143 L"password_element", |
127 L"username_value", | 144 L"username_value", |
128 L"", | 145 L"", |
129 true, false, cutoff - 1 }, | 146 true, false, cutoff - 1 }, |
130 }; | 147 }; |
131 | 148 |
132 // Build the forms vector and add the forms to the store. | 149 // Build the forms vector and add the forms to the store. |
133 std::vector<PasswordForm*> all_forms; | 150 ScopedVector<PasswordForm> all_forms; |
134 for (size_t i = 0; i < arraysize(form_data); ++i) { | 151 for (size_t i = 0; i < arraysize(form_data); ++i) { |
135 PasswordForm* form = CreatePasswordFormFromData(form_data[i]); | 152 all_forms.push_back(CreatePasswordFormFromData(form_data[i])); |
136 all_forms.push_back(form); | 153 store->AddLogin(*all_forms.back()); |
137 store->AddLogin(*form); | |
138 } | 154 } |
139 base::MessageLoop::current()->RunUntilIdle(); | 155 base::MessageLoop::current()->RunUntilIdle(); |
140 | 156 |
141 // We expect to get back only the "recent" www.google.com login. | 157 // We expect to get back only the "recent" www.google.com login. |
142 // Theoretically these should never actually exist since there are no longer | 158 // Theoretically these should never actually exist since there are no longer |
143 // any login forms on www.google.com to save, but we technically allow them. | 159 // any login forms on www.google.com to save, but we technically allow them. |
144 // We should not get back the older saved password though. | 160 // We should not get back the older saved password though. |
145 PasswordForm www_google; | 161 PasswordForm www_google; |
146 www_google.scheme = PasswordForm::SCHEME_HTML; | 162 www_google.scheme = PasswordForm::SCHEME_HTML; |
147 www_google.signon_realm = "https://www.google.com"; | 163 www_google.signon_realm = "https://www.google.com"; |
148 std::vector<PasswordForm*> www_google_expected; | 164 std::vector<PasswordForm*> www_google_expected; |
149 www_google_expected.push_back(all_forms[2]); | 165 www_google_expected.push_back(all_forms[2]); |
150 | 166 |
151 // We should still get the accounts.google.com login even though it's older | 167 // We should still get the accounts.google.com login even though it's older |
152 // than our cutoff - this is the new location of all Google login forms. | 168 // than our cutoff - this is the new location of all Google login forms. |
153 PasswordForm accounts_google; | 169 PasswordForm accounts_google; |
154 accounts_google.scheme = PasswordForm::SCHEME_HTML; | 170 accounts_google.scheme = PasswordForm::SCHEME_HTML; |
155 accounts_google.signon_realm = "https://accounts.google.com"; | 171 accounts_google.signon_realm = "https://accounts.google.com"; |
156 std::vector<PasswordForm*> accounts_google_expected; | 172 std::vector<PasswordForm*> accounts_google_expected; |
157 accounts_google_expected.push_back(all_forms[3]); | 173 accounts_google_expected.push_back(all_forms[3]); |
158 | 174 |
159 // Same thing for a generic saved login. | 175 // Same thing for a generic saved login. |
160 PasswordForm bar_example; | 176 PasswordForm bar_example; |
161 bar_example.scheme = PasswordForm::SCHEME_HTML; | 177 bar_example.scheme = PasswordForm::SCHEME_HTML; |
162 bar_example.signon_realm = "http://bar.example.com"; | 178 bar_example.signon_realm = "http://bar.example.com"; |
163 std::vector<PasswordForm*> bar_example_expected; | 179 std::vector<PasswordForm*> bar_example_expected; |
164 bar_example_expected.push_back(all_forms[4]); | 180 bar_example_expected.push_back(all_forms[4]); |
165 | 181 |
166 MockPasswordStoreConsumer consumer; | 182 CheckingPasswordStoreConsumer consumer; |
167 | 183 consumer.AddExpectation(&www_google_expected); |
168 // Expect the appropriate replies, as above, in reverse order than we will | 184 consumer.AddExpectation(&accounts_google_expected); |
169 // issue the queries. Each retires on saturation to avoid matcher spew. | 185 consumer.AddExpectation(&bar_example_expected); |
170 EXPECT_CALL(consumer, OnGetPasswordStoreResults( | |
171 ContainsAllPasswordForms(bar_example_expected))) | |
172 .WillOnce(WithArg<0>(STLDeleteElements0())) | |
173 .RetiresOnSaturation(); | |
174 EXPECT_CALL(consumer, OnGetPasswordStoreResults( | |
175 ContainsAllPasswordForms(accounts_google_expected))) | |
176 .WillOnce(WithArg<0>(STLDeleteElements0())) | |
177 .RetiresOnSaturation(); | |
178 EXPECT_CALL(consumer, OnGetPasswordStoreResults( | |
179 ContainsAllPasswordForms(www_google_expected))) | |
180 .WillOnce(WithArg<0>(STLDeleteElements0())) | |
181 .RetiresOnSaturation(); | |
182 | 186 |
183 store->GetLogins(www_google, PasswordStore::ALLOW_PROMPT, &consumer); | 187 store->GetLogins(www_google, PasswordStore::ALLOW_PROMPT, &consumer); |
184 store->GetLogins(accounts_google, PasswordStore::ALLOW_PROMPT, &consumer); | 188 store->GetLogins(accounts_google, PasswordStore::ALLOW_PROMPT, &consumer); |
185 store->GetLogins(bar_example, PasswordStore::ALLOW_PROMPT, &consumer); | 189 store->GetLogins(bar_example, PasswordStore::ALLOW_PROMPT, &consumer); |
186 | 190 |
187 base::MessageLoop::current()->RunUntilIdle(); | 191 base::MessageLoop::current()->RunUntilIdle(); |
188 | 192 |
189 STLDeleteElements(&all_forms); | |
190 store->Shutdown(); | 193 store->Shutdown(); |
191 base::MessageLoop::current()->RunUntilIdle(); | 194 base::MessageLoop::current()->RunUntilIdle(); |
192 } | 195 } |
193 | 196 |
194 TEST_F(PasswordStoreTest, StartSyncFlare) { | 197 TEST_F(PasswordStoreTest, StartSyncFlare) { |
195 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( | 198 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( |
196 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), | 199 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), |
197 make_scoped_ptr(new LoginDatabase(test_login_db_file_path())))); | 200 make_scoped_ptr(new LoginDatabase(test_login_db_file_path())))); |
198 StartSyncFlareMock mock; | 201 StartSyncFlareMock mock; |
199 store->Init( | 202 store->Init( |
200 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); | 203 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); |
201 { | 204 { |
202 PasswordForm form; | 205 PasswordForm form; |
203 form.origin = GURL("http://accounts.google.com/LoginAuth"); | 206 form.origin = GURL("http://accounts.google.com/LoginAuth"); |
204 form.signon_realm = "http://accounts.google.com/"; | 207 form.signon_realm = "http://accounts.google.com/"; |
205 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS)); | 208 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS)); |
206 store->AddLogin(form); | 209 store->AddLogin(form); |
207 base::MessageLoop::current()->RunUntilIdle(); | 210 base::MessageLoop::current()->RunUntilIdle(); |
208 } | 211 } |
209 store->Shutdown(); | 212 store->Shutdown(); |
210 base::MessageLoop::current()->RunUntilIdle(); | 213 base::MessageLoop::current()->RunUntilIdle(); |
211 } | 214 } |
212 | 215 |
213 } // namespace password_manager | 216 } // namespace password_manager |
OLD | NEW |