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