| 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" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/password_manager/password_store_win.h" | 19 #include "chrome/browser/password_manager/password_store_win.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/os_crypt/ie7_password_win.h" | 21 #include "components/os_crypt/ie7_password_win.h" |
| 22 #include "components/password_manager/core/browser/password_form_data.h" | 22 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 23 #include "components/password_manager/core/browser/password_store_consumer.h" | 23 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 24 #include "components/password_manager/core/browser/webdata/logins_table.h" | 24 #include "components/password_manager/core/browser/webdata/logins_table.h" |
| 25 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" | 25 #include "components/password_manager/core/browser/webdata/password_web_data_ser
vice_win.h" |
| 26 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 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 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 "http://example.com/", | 223 "http://example.com/", |
| 224 "http://example.com/origin", | 224 "http://example.com/origin", |
| 225 "http://example.com/action", | 225 "http://example.com/action", |
| 226 L"submit_element", | 226 L"submit_element", |
| 227 L"username_element", | 227 L"username_element", |
| 228 L"password_element", | 228 L"password_element", |
| 229 L"", | 229 L"", |
| 230 L"", | 230 L"", |
| 231 true, false, 1, | 231 true, false, 1, |
| 232 }; | 232 }; |
| 233 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 233 scoped_ptr<PasswordForm> form = |
| 234 CreatePasswordFormFromDataForTesting(form_data); |
| 234 | 235 |
| 235 // The returned form will not have 'action' or '*_element' fields set. This | 236 // The returned form will not have 'action' or '*_element' fields set. This |
| 236 // is because credentials imported from IE don't have this information. | 237 // is because credentials imported from IE don't have this information. |
| 237 PasswordFormData expected_form_data = { | 238 PasswordFormData expected_form_data = { |
| 238 PasswordForm::SCHEME_HTML, | 239 PasswordForm::SCHEME_HTML, |
| 239 "http://example.com/", | 240 "http://example.com/", |
| 240 "http://example.com/origin", | 241 "http://example.com/origin", |
| 241 "", | 242 "", |
| 242 L"", | 243 L"", |
| 243 L"", | 244 L"", |
| 244 L"", | 245 L"", |
| 245 L"abcdefgh", | 246 L"abcdefgh", |
| 246 L"abcdefghijkl", | 247 L"abcdefghijkl", |
| 247 true, false, 1, | 248 true, false, 1, |
| 248 }; | 249 }; |
| 249 ScopedVector<autofill::PasswordForm> expected_forms; | 250 ScopedVector<autofill::PasswordForm> expected_forms; |
| 250 expected_forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 251 expected_forms.push_back( |
| 252 CreatePasswordFormFromDataForTesting(expected_form_data)); |
| 251 | 253 |
| 252 // The IE7 password should be returned. | 254 // The IE7 password should be returned. |
| 253 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( | 255 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( |
| 254 ContainsSamePasswordForms(expected_forms.get()))) | 256 ContainsSamePasswordForms(expected_forms.get()))) |
| 255 .WillOnce(QuitUIMessageLoop()); | 257 .WillOnce(QuitUIMessageLoop()); |
| 256 | 258 |
| 257 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 259 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 258 base::MessageLoop::current()->Run(); | 260 base::MessageLoop::current()->Run(); |
| 259 } | 261 } |
| 260 | 262 |
| 261 // Crashy. http://crbug.com/86558 | 263 // Crashy. http://crbug.com/86558 |
| 262 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 264 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
| 263 store_ = CreatePasswordStore(); | 265 store_ = CreatePasswordStore(); |
| 264 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 266 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 265 | 267 |
| 266 PasswordFormData form_data = { | 268 PasswordFormData form_data = { |
| 267 PasswordForm::SCHEME_HTML, | 269 PasswordForm::SCHEME_HTML, |
| 268 "http://example.com/", | 270 "http://example.com/", |
| 269 "http://example.com/origin", | 271 "http://example.com/origin", |
| 270 "http://example.com/action", | 272 "http://example.com/action", |
| 271 L"submit_element", | 273 L"submit_element", |
| 272 L"username_element", | 274 L"username_element", |
| 273 L"password_element", | 275 L"password_element", |
| 274 L"", | 276 L"", |
| 275 L"", | 277 L"", |
| 276 true, false, 1, | 278 true, false, 1, |
| 277 }; | 279 }; |
| 278 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 280 scoped_ptr<PasswordForm> form = |
| 281 CreatePasswordFormFromDataForTesting(form_data); |
| 279 | 282 |
| 280 MockPasswordStoreConsumer consumer; | 283 MockPasswordStoreConsumer consumer; |
| 281 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 284 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 282 | 285 |
| 283 // Release the PSW and the WDS before the query can return. | 286 // Release the PSW and the WDS before the query can return. |
| 284 store_->Shutdown(); | 287 store_->Shutdown(); |
| 285 store_ = NULL; | 288 store_ = NULL; |
| 286 wds_ = NULL; | 289 wds_ = NULL; |
| 287 | 290 |
| 288 base::MessageLoop::current()->RunUntilIdle(); | 291 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 316 "http://example.com/", | 319 "http://example.com/", |
| 317 "http://example.com/origin", | 320 "http://example.com/origin", |
| 318 "http://example.com/action", | 321 "http://example.com/action", |
| 319 L"submit_element", | 322 L"submit_element", |
| 320 L"username_element", | 323 L"username_element", |
| 321 L"password_element", | 324 L"password_element", |
| 322 L"", | 325 L"", |
| 323 L"", | 326 L"", |
| 324 true, false, 1, | 327 true, false, 1, |
| 325 }; | 328 }; |
| 326 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 329 scoped_ptr<PasswordForm> form = |
| 330 CreatePasswordFormFromDataForTesting(form_data); |
| 327 | 331 |
| 328 PasswordFormData expected_form_data = { | 332 PasswordFormData expected_form_data = { |
| 329 PasswordForm::SCHEME_HTML, | 333 PasswordForm::SCHEME_HTML, |
| 330 "http://example.com/", | 334 "http://example.com/", |
| 331 "http://example.com/origin", | 335 "http://example.com/origin", |
| 332 "http://example.com/action", | 336 "http://example.com/action", |
| 333 L"submit_element", | 337 L"submit_element", |
| 334 L"username_element", | 338 L"username_element", |
| 335 L"password_element", | 339 L"password_element", |
| 336 L"abcdefgh", | 340 L"abcdefgh", |
| 337 L"abcdefghijkl", | 341 L"abcdefghijkl", |
| 338 true, false, 1, | 342 true, false, 1, |
| 339 }; | 343 }; |
| 340 ScopedVector<autofill::PasswordForm> expected_forms; | 344 ScopedVector<autofill::PasswordForm> expected_forms; |
| 341 expected_forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 345 expected_forms.push_back( |
| 346 CreatePasswordFormFromDataForTesting(expected_form_data)); |
| 342 | 347 |
| 343 // The IE7 password should be returned. | 348 // The IE7 password should be returned. |
| 344 EXPECT_CALL(password_consumer, | 349 EXPECT_CALL(password_consumer, |
| 345 OnGetPasswordStoreResultsConstRef(ContainsSamePasswordForms( | 350 OnGetPasswordStoreResultsConstRef(ContainsSamePasswordForms( |
| 346 expected_forms.get()))).WillOnce(QuitUIMessageLoop()); | 351 expected_forms.get()))).WillOnce(QuitUIMessageLoop()); |
| 347 | 352 |
| 348 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); | 353 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); |
| 349 | 354 |
| 350 MockWebDataServiceConsumer wds_consumer; | 355 MockWebDataServiceConsumer wds_consumer; |
| 351 | 356 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 371 "http://example.com/", | 376 "http://example.com/", |
| 372 "http://example.com/origin", | 377 "http://example.com/origin", |
| 373 "http://example.com/action", | 378 "http://example.com/action", |
| 374 L"submit_element", | 379 L"submit_element", |
| 375 L"username_element", | 380 L"username_element", |
| 376 L"password_element", | 381 L"password_element", |
| 377 L"", | 382 L"", |
| 378 L"", | 383 L"", |
| 379 true, false, 1, | 384 true, false, 1, |
| 380 }; | 385 }; |
| 381 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 386 scoped_ptr<PasswordForm> form = |
| 387 CreatePasswordFormFromDataForTesting(form_data); |
| 382 | 388 |
| 383 MockPasswordStoreConsumer consumer; | 389 MockPasswordStoreConsumer consumer; |
| 384 | 390 |
| 385 // Make sure we quit the MessageLoop even if the test fails. | 391 // Make sure we quit the MessageLoop even if the test fails. |
| 386 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 392 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
| 387 .WillByDefault(QuitUIMessageLoop()); | 393 .WillByDefault(QuitUIMessageLoop()); |
| 388 | 394 |
| 389 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())) | 395 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())) |
| 390 .WillOnce(QuitUIMessageLoop()); | 396 .WillOnce(QuitUIMessageLoop()); |
| 391 | 397 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 419 // Make sure we quit the MessageLoop even if the test fails. | 425 // Make sure we quit the MessageLoop even if the test fails. |
| 420 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 426 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
| 421 .WillByDefault(QuitUIMessageLoop()); | 427 .WillByDefault(QuitUIMessageLoop()); |
| 422 | 428 |
| 423 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())) | 429 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())) |
| 424 .WillOnce(QuitUIMessageLoop()); | 430 .WillOnce(QuitUIMessageLoop()); |
| 425 | 431 |
| 426 store_->GetAutofillableLogins(&consumer); | 432 store_->GetAutofillableLogins(&consumer); |
| 427 base::MessageLoop::current()->Run(); | 433 base::MessageLoop::current()->Run(); |
| 428 } | 434 } |
| OLD | NEW |