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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "components/webdata/common/web_database_service.h" | 27 #include "components/webdata/common/web_database_service.h" |
| 28 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
| 29 #include "crypto/wincrypt_shim.h" | 29 #include "crypto/wincrypt_shim.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using autofill::PasswordForm; | 33 using autofill::PasswordForm; |
| 34 using base::WaitableEvent; | 34 using base::WaitableEvent; |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 using password_manager::LoginDatabase; | 36 using password_manager::LoginDatabase; |
| 37 using password_manager::ContainsAllPasswordForms; | |
| 38 using password_manager::PasswordFormData; | 37 using password_manager::PasswordFormData; |
| 39 using password_manager::PasswordStore; | 38 using password_manager::PasswordStore; |
| 40 using password_manager::PasswordStoreConsumer; | 39 using password_manager::PasswordStoreConsumer; |
| 41 using testing::_; | 40 using testing::_; |
| 42 using testing::DoAll; | 41 using testing::DoAll; |
| 43 using testing::WithArg; | 42 using testing::WithArg; |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 class MockPasswordStoreConsumer : public PasswordStoreConsumer { | 46 class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
| 48 public: | 47 public: |
| 49 MOCK_METHOD1(OnGetPasswordStoreResults, | 48 MOCK_METHOD0(OnGetPasswordStoreResults, void()); |
| 50 void(const std::vector<autofill::PasswordForm*>&)); | |
| 51 }; | 49 }; |
| 52 | 50 |
| 53 class MockWebDataServiceConsumer : public WebDataServiceConsumer { | 51 class MockWebDataServiceConsumer : public WebDataServiceConsumer { |
| 54 public: | 52 public: |
| 55 MOCK_METHOD2(OnWebDataServiceRequestDone, | 53 MOCK_METHOD2(OnWebDataServiceRequestDone, |
| 56 void(PasswordWebDataService::Handle, const WDTypedResult*)); | 54 void(PasswordWebDataService::Handle, const WDTypedResult*)); |
| 57 }; | 55 }; |
| 58 | 56 |
| 59 } // anonymous namespace | 57 } // anonymous namespace |
| 60 | 58 |
| 61 typedef std::vector<PasswordForm*> VectorOfForms; | |
| 62 | |
| 63 class PasswordStoreWinTest : public testing::Test { | 59 class PasswordStoreWinTest : public testing::Test { |
| 64 protected: | 60 protected: |
| 65 PasswordStoreWinTest() | 61 PasswordStoreWinTest() |
| 66 : ui_thread_(BrowserThread::UI, &message_loop_), | 62 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 67 db_thread_(BrowserThread::DB) { | 63 db_thread_(BrowserThread::DB) { |
| 68 } | 64 } |
| 69 | 65 |
| 70 bool CreateIE7PasswordInfo(const std::wstring& url, const base::Time& created, | 66 bool CreateIE7PasswordInfo(const std::wstring& url, const base::Time& created, |
| 71 IE7PasswordInfo* info) { | 67 IE7PasswordInfo* info) { |
| 72 // Copied from chrome/browser/importer/importer_unittest.cc | 68 // Copied from chrome/browser/importer/importer_unittest.cc |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 200 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 205 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 201 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 206 done.Wait(); | 202 done.Wait(); |
| 207 | 203 |
| 208 store_ = CreatePasswordStore(); | 204 store_ = CreatePasswordStore(); |
| 209 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 205 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 210 | 206 |
| 211 MockPasswordStoreConsumer consumer; | 207 MockPasswordStoreConsumer consumer; |
| 212 | 208 |
| 213 // Make sure we quit the MessageLoop even if the test fails. | 209 // Make sure we quit the MessageLoop even if the test fails. |
| 214 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 210 ON_CALL(consumer, OnGetPasswordStoreResults()) |
| 215 .WillByDefault(QuitUIMessageLoop()); | 211 .WillByDefault(QuitUIMessageLoop()); |
| 216 | 212 |
| 217 PasswordFormData form_data = { | 213 PasswordFormData form_data = { |
| 218 PasswordForm::SCHEME_HTML, | 214 PasswordForm::SCHEME_HTML, |
| 219 "http://example.com/", | 215 "http://example.com/", |
| 220 "http://example.com/origin", | 216 "http://example.com/origin", |
| 221 "http://example.com/action", | 217 "http://example.com/action", |
| 222 L"submit_element", | 218 L"submit_element", |
| 223 L"username_element", | 219 L"username_element", |
| 224 L"password_element", | 220 L"password_element", |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 235 "http://example.com/", | 231 "http://example.com/", |
| 236 "http://example.com/origin", | 232 "http://example.com/origin", |
| 237 "", | 233 "", |
| 238 L"", | 234 L"", |
| 239 L"", | 235 L"", |
| 240 L"", | 236 L"", |
| 241 L"abcdefgh", | 237 L"abcdefgh", |
| 242 L"abcdefghijkl", | 238 L"abcdefghijkl", |
| 243 true, false, 1, | 239 true, false, 1, |
| 244 }; | 240 }; |
| 245 std::vector<PasswordForm*> forms; | 241 scoped_ptr<autofill::PasswordForm> expected_form( |
| 246 forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 242 CreatePasswordFormFromData(expected_form_data)); |
|
vasilii
2015/02/03 19:22:16
Did you consider changing this function to return
vabr (Chromium)
2015/02/04 16:13:44
Good idea! Done.
I updated both copies of the fun
| |
| 247 | 243 |
| 248 // The IE7 password should be returned. | 244 // The IE7 password should be returned. |
| 249 EXPECT_CALL(consumer, | 245 EXPECT_CALL(consumer, OnGetPasswordStoreResults()) |
| 250 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms))) | |
| 251 .WillOnce(QuitUIMessageLoop()); | 246 .WillOnce(QuitUIMessageLoop()); |
| 252 | 247 |
| 253 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 248 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 254 base::MessageLoop::current()->Run(); | 249 base::MessageLoop::current()->Run(); |
| 255 | 250 |
| 256 STLDeleteElements(&forms); | 251 EXPECT_EQ(1u, consumer.results()->size()); |
| 252 EXPECT_EQ(*expected_form, *consumer.results()->back()); | |
| 257 } | 253 } |
| 258 | 254 |
| 259 // Crashy. http://crbug.com/86558 | 255 // Crashy. http://crbug.com/86558 |
| 260 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 256 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
| 261 store_ = CreatePasswordStore(); | 257 store_ = CreatePasswordStore(); |
| 262 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 258 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 263 | 259 |
| 264 PasswordFormData form_data = { | 260 PasswordFormData form_data = { |
| 265 PasswordForm::SCHEME_HTML, | 261 PasswordForm::SCHEME_HTML, |
| 266 "http://example.com/", | 262 "http://example.com/", |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 WaitableEvent done(false, false); | 295 WaitableEvent done(false, false); |
| 300 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 296 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 301 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 297 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 302 done.Wait(); | 298 done.Wait(); |
| 303 | 299 |
| 304 store_ = CreatePasswordStore(); | 300 store_ = CreatePasswordStore(); |
| 305 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 301 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 306 | 302 |
| 307 MockPasswordStoreConsumer password_consumer; | 303 MockPasswordStoreConsumer password_consumer; |
| 308 // Make sure we quit the MessageLoop even if the test fails. | 304 // Make sure we quit the MessageLoop even if the test fails. |
| 309 ON_CALL(password_consumer, OnGetPasswordStoreResults(_)) | 305 ON_CALL(password_consumer, OnGetPasswordStoreResults()) |
| 310 .WillByDefault(QuitUIMessageLoop()); | 306 .WillByDefault(QuitUIMessageLoop()); |
| 311 | 307 |
| 312 PasswordFormData form_data = { | 308 PasswordFormData form_data = { |
| 313 PasswordForm::SCHEME_HTML, | 309 PasswordForm::SCHEME_HTML, |
| 314 "http://example.com/", | 310 "http://example.com/", |
| 315 "http://example.com/origin", | 311 "http://example.com/origin", |
| 316 "http://example.com/action", | 312 "http://example.com/action", |
| 317 L"submit_element", | 313 L"submit_element", |
| 318 L"username_element", | 314 L"username_element", |
| 319 L"password_element", | 315 L"password_element", |
| 320 L"", | 316 L"", |
| 321 L"", | 317 L"", |
| 322 true, false, 1, | 318 true, false, 1, |
| 323 }; | 319 }; |
| 324 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 320 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
| 325 | 321 |
| 326 PasswordFormData expected_form_data = { | 322 PasswordFormData expected_form_data = { |
| 327 PasswordForm::SCHEME_HTML, | 323 PasswordForm::SCHEME_HTML, |
| 328 "http://example.com/", | 324 "http://example.com/", |
| 329 "http://example.com/origin", | 325 "http://example.com/origin", |
| 330 "http://example.com/action", | 326 "http://example.com/action", |
| 331 L"submit_element", | 327 L"submit_element", |
| 332 L"username_element", | 328 L"username_element", |
| 333 L"password_element", | 329 L"password_element", |
| 334 L"abcdefgh", | 330 L"abcdefgh", |
| 335 L"abcdefghijkl", | 331 L"abcdefghijkl", |
| 336 true, false, 1, | 332 true, false, 1, |
| 337 }; | 333 }; |
| 338 std::vector<PasswordForm*> forms; | 334 scoped_ptr<autofill::PasswordForm> expected_form( |
| 339 forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 335 CreatePasswordFormFromData(expected_form_data)); |
| 340 | 336 |
| 341 // The IE7 password should be returned. | 337 // The IE7 password should be returned. |
| 342 EXPECT_CALL(password_consumer, | 338 EXPECT_CALL(password_consumer, OnGetPasswordStoreResults()) |
| 343 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms))) | |
| 344 .WillOnce(QuitUIMessageLoop()); | 339 .WillOnce(QuitUIMessageLoop()); |
| 345 | 340 |
| 346 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); | 341 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); |
| 347 | 342 |
| 348 MockWebDataServiceConsumer wds_consumer; | 343 MockWebDataServiceConsumer wds_consumer; |
| 349 | 344 |
| 350 EXPECT_CALL(wds_consumer, | 345 EXPECT_CALL(wds_consumer, |
| 351 OnWebDataServiceRequestDone(_, _)) | 346 OnWebDataServiceRequestDone(_, _)) |
| 352 .WillOnce(QuitUIMessageLoop()); | 347 .WillOnce(QuitUIMessageLoop()); |
| 353 | 348 |
| 354 wds_->GetIE7Login(password_info, &wds_consumer); | 349 wds_->GetIE7Login(password_info, &wds_consumer); |
| 355 | 350 |
| 356 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin | 351 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin |
| 357 // schedules on the DB thread and once for the one we just scheduled on the UI | 352 // schedules on the DB thread and once for the one we just scheduled on the UI |
| 358 // thread. | 353 // thread. |
| 359 base::MessageLoop::current()->Run(); | 354 base::MessageLoop::current()->Run(); |
| 360 base::MessageLoop::current()->Run(); | 355 base::MessageLoop::current()->Run(); |
| 361 | 356 |
| 362 STLDeleteElements(&forms); | 357 EXPECT_EQ(1u, password_consumer.results()->size()); |
| 358 EXPECT_EQ(*expected_form, *password_consumer.results()->back()); | |
| 363 } | 359 } |
| 364 | 360 |
| 365 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 361 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
| 366 store_ = CreatePasswordStore(); | 362 store_ = CreatePasswordStore(); |
| 367 store_->Init(syncer::SyncableService::StartSyncFlare()); | 363 store_->Init(syncer::SyncableService::StartSyncFlare()); |
| 368 | 364 |
| 369 PasswordFormData form_data = { | 365 PasswordFormData form_data = { |
| 370 PasswordForm::SCHEME_HTML, | 366 PasswordForm::SCHEME_HTML, |
| 371 "http://example.com/", | 367 "http://example.com/", |
| 372 "http://example.com/origin", | 368 "http://example.com/origin", |
| 373 "http://example.com/action", | 369 "http://example.com/action", |
| 374 L"submit_element", | 370 L"submit_element", |
| 375 L"username_element", | 371 L"username_element", |
| 376 L"password_element", | 372 L"password_element", |
| 377 L"", | 373 L"", |
| 378 L"", | 374 L"", |
| 379 true, false, 1, | 375 true, false, 1, |
| 380 }; | 376 }; |
| 381 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 377 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); |
| 382 | 378 |
| 383 MockPasswordStoreConsumer consumer; | 379 MockPasswordStoreConsumer consumer; |
| 384 | 380 |
| 385 // Make sure we quit the MessageLoop even if the test fails. | 381 // Make sure we quit the MessageLoop even if the test fails. |
| 386 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 382 ON_CALL(consumer, OnGetPasswordStoreResults()) |
| 387 .WillByDefault(QuitUIMessageLoop()); | 383 .WillByDefault(QuitUIMessageLoop()); |
| 388 | 384 |
| 389 VectorOfForms expect_none; | 385 EXPECT_CALL(consumer, OnGetPasswordStoreResults()) |
| 390 // expect that we get no results; | 386 .WillOnce(QuitUIMessageLoop()); |
| 391 EXPECT_CALL(consumer, | |
| 392 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
| 393 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
| 394 | 387 |
| 395 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 388 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 396 base::MessageLoop::current()->Run(); | 389 base::MessageLoop::current()->Run(); |
| 390 | |
| 391 EXPECT_EQ(0u, consumer.results()->size()); | |
| 397 } | 392 } |
| 398 | 393 |
| 399 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { | 394 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { |
| 400 store_ = CreatePasswordStore(); | 395 store_ = CreatePasswordStore(); |
| 401 store_->Init(syncer::SyncableService::StartSyncFlare()); | 396 store_->Init(syncer::SyncableService::StartSyncFlare()); |
| 402 | 397 |
| 403 MockPasswordStoreConsumer consumer; | 398 MockPasswordStoreConsumer consumer; |
| 404 | 399 |
| 405 // Make sure we quit the MessageLoop even if the test fails. | 400 // Make sure we quit the MessageLoop even if the test fails. |
| 406 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 401 ON_CALL(consumer, OnGetPasswordStoreResults()) |
| 407 .WillByDefault(QuitUIMessageLoop()); | 402 .WillByDefault(QuitUIMessageLoop()); |
| 408 | 403 |
| 409 VectorOfForms expect_none; | 404 EXPECT_CALL(consumer, OnGetPasswordStoreResults()) |
| 410 // expect that we get no results; | 405 .WillOnce(QuitUIMessageLoop()); |
| 411 EXPECT_CALL( | |
| 412 consumer, | |
| 413 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
| 414 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
| 415 | 406 |
| 416 store_->GetBlacklistLogins(&consumer); | 407 store_->GetBlacklistLogins(&consumer); |
| 417 base::MessageLoop::current()->Run(); | 408 base::MessageLoop::current()->Run(); |
| 409 | |
| 410 EXPECT_EQ(0u, consumer.results()->size()); | |
| 418 } | 411 } |
| 419 | 412 |
| 420 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { | 413 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { |
| 421 store_ = CreatePasswordStore(); | 414 store_ = CreatePasswordStore(); |
| 422 store_->Init(syncer::SyncableService::StartSyncFlare()); | 415 store_->Init(syncer::SyncableService::StartSyncFlare()); |
| 423 | 416 |
| 424 MockPasswordStoreConsumer consumer; | 417 MockPasswordStoreConsumer consumer; |
| 425 | 418 |
| 426 // Make sure we quit the MessageLoop even if the test fails. | 419 // Make sure we quit the MessageLoop even if the test fails. |
| 427 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 420 ON_CALL(consumer, OnGetPasswordStoreResults()) |
| 428 .WillByDefault(QuitUIMessageLoop()); | 421 .WillByDefault(QuitUIMessageLoop()); |
| 429 | 422 |
| 430 VectorOfForms expect_none; | 423 EXPECT_CALL(consumer, OnGetPasswordStoreResults()) |
| 431 // expect that we get no results; | 424 .WillOnce(QuitUIMessageLoop()); |
| 432 EXPECT_CALL( | |
| 433 consumer, | |
| 434 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
| 435 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
| 436 | 425 |
| 437 store_->GetAutofillableLogins(&consumer); | 426 store_->GetAutofillableLogins(&consumer); |
| 438 base::MessageLoop::current()->Run(); | 427 base::MessageLoop::current()->Run(); |
| 428 | |
| 429 EXPECT_EQ(0u, consumer.results()->size()); | |
| 439 } | 430 } |
| OLD | NEW |