| 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 | 257 |
| 256 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 258 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 257 base::MessageLoop::current()->Run(); | 259 base::MessageLoop::current()->Run(); |
| 258 } | 260 } |
| 259 | 261 |
| 260 // Crashy. http://crbug.com/86558 | 262 // Crashy. http://crbug.com/86558 |
| 261 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 263 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
| 262 store_ = CreatePasswordStore(); | 264 store_ = CreatePasswordStore(); |
| 263 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 265 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
| 264 | 266 |
| 265 PasswordFormData form_data = { | 267 PasswordFormData form_data = { |
| 266 PasswordForm::SCHEME_HTML, | 268 PasswordForm::SCHEME_HTML, |
| 267 "http://example.com/", | 269 "http://example.com/", |
| 268 "http://example.com/origin", | 270 "http://example.com/origin", |
| 269 "http://example.com/action", | 271 "http://example.com/action", |
| 270 L"submit_element", | 272 L"submit_element", |
| 271 L"username_element", | 273 L"username_element", |
| 272 L"password_element", | 274 L"password_element", |
| 273 L"", | 275 L"", |
| 274 L"", | 276 L"", |
| 275 true, false, 1, | 277 true, false, 1, |
| 276 }; | 278 }; |
| 277 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 279 scoped_ptr<PasswordForm> form = |
| 280 CreatePasswordFormFromDataForTesting(form_data); |
| 278 | 281 |
| 279 MockPasswordStoreConsumer consumer; | 282 MockPasswordStoreConsumer consumer; |
| 280 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 283 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 281 | 284 |
| 282 // Release the PSW and the WDS before the query can return. | 285 // Release the PSW and the WDS before the query can return. |
| 283 store_->Shutdown(); | 286 store_->Shutdown(); |
| 284 store_ = NULL; | 287 store_ = NULL; |
| 285 wds_ = NULL; | 288 wds_ = NULL; |
| 286 | 289 |
| 287 base::MessageLoop::current()->RunUntilIdle(); | 290 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 315 "http://example.com/", | 318 "http://example.com/", |
| 316 "http://example.com/origin", | 319 "http://example.com/origin", |
| 317 "http://example.com/action", | 320 "http://example.com/action", |
| 318 L"submit_element", | 321 L"submit_element", |
| 319 L"username_element", | 322 L"username_element", |
| 320 L"password_element", | 323 L"password_element", |
| 321 L"", | 324 L"", |
| 322 L"", | 325 L"", |
| 323 true, false, 1, | 326 true, false, 1, |
| 324 }; | 327 }; |
| 325 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 328 scoped_ptr<PasswordForm> form = |
| 329 CreatePasswordFormFromDataForTesting(form_data); |
| 326 | 330 |
| 327 PasswordFormData expected_form_data = { | 331 PasswordFormData expected_form_data = { |
| 328 PasswordForm::SCHEME_HTML, | 332 PasswordForm::SCHEME_HTML, |
| 329 "http://example.com/", | 333 "http://example.com/", |
| 330 "http://example.com/origin", | 334 "http://example.com/origin", |
| 331 "http://example.com/action", | 335 "http://example.com/action", |
| 332 L"submit_element", | 336 L"submit_element", |
| 333 L"username_element", | 337 L"username_element", |
| 334 L"password_element", | 338 L"password_element", |
| 335 L"abcdefgh", | 339 L"abcdefgh", |
| 336 L"abcdefghijkl", | 340 L"abcdefghijkl", |
| 337 true, false, 1, | 341 true, false, 1, |
| 338 }; | 342 }; |
| 339 ScopedVector<autofill::PasswordForm> expected_forms; | 343 ScopedVector<autofill::PasswordForm> expected_forms; |
| 340 expected_forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 344 expected_forms.push_back( |
| 345 CreatePasswordFormFromDataForTesting(expected_form_data)); |
| 341 | 346 |
| 342 // The IE7 password should be returned. | 347 // The IE7 password should be returned. |
| 343 EXPECT_CALL(password_consumer, | 348 EXPECT_CALL(password_consumer, |
| 344 OnGetPasswordStoreResultsConstRef( | 349 OnGetPasswordStoreResultsConstRef( |
| 345 ContainsSamePasswordForms(expected_forms.get()))); | 350 ContainsSamePasswordForms(expected_forms.get()))); |
| 346 | 351 |
| 347 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); | 352 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); |
| 348 | 353 |
| 349 MockWebDataServiceConsumer wds_consumer; | 354 MockWebDataServiceConsumer wds_consumer; |
| 350 | 355 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 369 "http://example.com/", | 374 "http://example.com/", |
| 370 "http://example.com/origin", | 375 "http://example.com/origin", |
| 371 "http://example.com/action", | 376 "http://example.com/action", |
| 372 L"submit_element", | 377 L"submit_element", |
| 373 L"username_element", | 378 L"username_element", |
| 374 L"password_element", | 379 L"password_element", |
| 375 L"", | 380 L"", |
| 376 L"", | 381 L"", |
| 377 true, false, 1, | 382 true, false, 1, |
| 378 }; | 383 }; |
| 379 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); | 384 scoped_ptr<PasswordForm> form = |
| 385 CreatePasswordFormFromDataForTesting(form_data); |
| 380 | 386 |
| 381 MockPasswordStoreConsumer consumer; | 387 MockPasswordStoreConsumer consumer; |
| 382 | 388 |
| 383 // Make sure we quit the MessageLoop even if the test fails. | 389 // Make sure we quit the MessageLoop even if the test fails. |
| 384 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 390 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
| 385 .WillByDefault(QuitUIMessageLoop()); | 391 .WillByDefault(QuitUIMessageLoop()); |
| 386 | 392 |
| 387 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 393 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
| 388 | 394 |
| 389 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 395 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 414 | 420 |
| 415 // Make sure we quit the MessageLoop even if the test fails. | 421 // Make sure we quit the MessageLoop even if the test fails. |
| 416 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 422 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
| 417 .WillByDefault(QuitUIMessageLoop()); | 423 .WillByDefault(QuitUIMessageLoop()); |
| 418 | 424 |
| 419 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 425 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
| 420 | 426 |
| 421 store_->GetAutofillableLogins(&consumer); | 427 store_->GetAutofillableLogins(&consumer); |
| 422 base::MessageLoop::current()->Run(); | 428 base::MessageLoop::current()->Run(); |
| 423 } | 429 } |
| OLD | NEW |