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 "testing/gmock/include/gmock/gmock.h" | 5 #include "testing/gmock/include/gmock/gmock.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 "http://a.server.com/", L"abc", L"123", false, | 273 "http://a.server.com/", L"abc", L"123", false, |
| 274 1601, 1, 1, 0, 0, 0 }, | 274 1601, 1, 1, 0, 0, 0 }, |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { | 277 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { |
| 278 // Create our fake KeychainItemRef; see MockAppleKeychain docs. | 278 // Create our fake KeychainItemRef; see MockAppleKeychain docs. |
| 279 SecKeychainItemRef keychain_item = | 279 SecKeychainItemRef keychain_item = |
| 280 reinterpret_cast<SecKeychainItemRef>(i + 1); | 280 reinterpret_cast<SecKeychainItemRef>(i + 1); |
| 281 PasswordForm form; | 281 PasswordForm form; |
| 282 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( | 282 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( |
| 283 *keychain_, keychain_item, &form); | 283 *keychain_, keychain_item, &form, true); |
|
stuartmorgan
2013/09/30 22:39:12
You added a new param, but set it to true in every
Raghu Simha
2013/10/02 02:09:50
I've added a new test for this called TestFillPass
| |
| 284 | 284 |
| 285 EXPECT_TRUE(parsed) << "In iteration " << i; | 285 EXPECT_TRUE(parsed) << "In iteration " << i; |
| 286 | 286 |
| 287 EXPECT_EQ(expected[i].scheme, form.scheme) << "In iteration " << i; | 287 EXPECT_EQ(expected[i].scheme, form.scheme) << "In iteration " << i; |
| 288 EXPECT_EQ(GURL(expected[i].origin), form.origin) << "In iteration " << i; | 288 EXPECT_EQ(GURL(expected[i].origin), form.origin) << "In iteration " << i; |
| 289 EXPECT_EQ(expected[i].ssl_valid, form.ssl_valid) << "In iteration " << i; | 289 EXPECT_EQ(expected[i].ssl_valid, form.ssl_valid) << "In iteration " << i; |
| 290 EXPECT_EQ(std::string(expected[i].signon_realm), form.signon_realm) | 290 EXPECT_EQ(std::string(expected[i].signon_realm), form.signon_realm) |
| 291 << "In iteration " << i; | 291 << "In iteration " << i; |
| 292 if (expected[i].username) { | 292 if (expected[i].username) { |
| 293 EXPECT_EQ(WideToUTF16(expected[i].username), form.username_value) | 293 EXPECT_EQ(WideToUTF16(expected[i].username), form.username_value) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 312 << "In iteration " << i; | 312 << "In iteration " << i; |
| 313 EXPECT_EQ(expected[i].creation_second, exploded_time.second) | 313 EXPECT_EQ(expected[i].creation_second, exploded_time.second) |
| 314 << "In iteration " << i; | 314 << "In iteration " << i; |
| 315 } | 315 } |
| 316 | 316 |
| 317 { | 317 { |
| 318 // Use an invalid ref, to make sure errors are reported. | 318 // Use an invalid ref, to make sure errors are reported. |
| 319 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(99); | 319 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(99); |
| 320 PasswordForm form; | 320 PasswordForm form; |
| 321 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( | 321 bool parsed = internal_keychain_helpers::FillPasswordFormFromKeychainItem( |
| 322 *keychain_, keychain_item, &form); | 322 *keychain_, keychain_item, &form, true); |
| 323 EXPECT_FALSE(parsed); | 323 EXPECT_FALSE(parsed); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 TEST_F(PasswordStoreMacInternalsTest, TestKeychainSearch) { | 327 TEST_F(PasswordStoreMacInternalsTest, TestKeychainSearch) { |
| 328 struct TestDataAndExpectation { | 328 struct TestDataAndExpectation { |
| 329 const PasswordFormData data; | 329 const PasswordFormData data; |
| 330 const size_t expected_fill_matches; | 330 const size_t expected_fill_matches; |
| 331 const size_t expected_merge_matches; | 331 const size_t expected_merge_matches; |
| 332 }; | 332 }; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 | 381 |
| 382 // Check matches treating the form as a fill target. | 382 // Check matches treating the form as a fill target. |
| 383 std::vector<PasswordForm*> matching_items = | 383 std::vector<PasswordForm*> matching_items = |
| 384 keychain_adapter.PasswordsFillingForm(*query_form); | 384 keychain_adapter.PasswordsFillingForm(*query_form); |
| 385 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); | 385 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); |
| 386 STLDeleteElements(&matching_items); | 386 STLDeleteElements(&matching_items); |
| 387 | 387 |
| 388 // Check matches treating the form as a merging target. | 388 // Check matches treating the form as a merging target. |
| 389 EXPECT_EQ(test_data[i].expected_merge_matches > 0, | 389 EXPECT_EQ(test_data[i].expected_merge_matches > 0, |
| 390 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); | 390 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); |
| 391 matching_items = keychain_adapter.PasswordsMergeableWithForm(*query_form); | 391 std::vector<SecKeychainItemRef> keychain_items; |
| 392 std::vector<MacKeychainPasswordFormAdapter::ItemFormPair> item_form_pairs = | |
| 393 internal_keychain_helpers::GetAllKeychainItemAttributesAsPasswordForms( | |
| 394 &keychain_items, *keychain_); | |
| 395 matching_items = | |
| 396 keychain_adapter.ExtractPasswordsMergeableWithForm(item_form_pairs, | |
| 397 *query_form); | |
| 392 EXPECT_EQ(test_data[i].expected_merge_matches, matching_items.size()); | 398 EXPECT_EQ(test_data[i].expected_merge_matches, matching_items.size()); |
| 399 STLDeleteContainerPairSecondPointers(item_form_pairs.begin(), | |
| 400 item_form_pairs.end()); | |
| 401 for (std::vector<SecKeychainItemRef>::iterator i = keychain_items.begin(); | |
| 402 i != keychain_items.end(); ++i) { | |
| 403 keychain_->Free(*i); | |
| 404 } | |
| 393 STLDeleteElements(&matching_items); | 405 STLDeleteElements(&matching_items); |
| 394 | 406 |
| 395 // None of the pre-seeded items are owned by us, so none should match an | 407 // None of the pre-seeded items are owned by us, so none should match an |
| 396 // owned-passwords-only search. | 408 // owned-passwords-only search. |
| 397 matching_items = owned_keychain_adapter.PasswordsFillingForm(*query_form); | 409 matching_items = owned_keychain_adapter.PasswordsFillingForm(*query_form); |
| 398 EXPECT_EQ(0U, matching_items.size()); | 410 EXPECT_EQ(0U, matching_items.size()); |
| 399 STLDeleteElements(&matching_items); | 411 STLDeleteElements(&matching_items); |
| 400 } | 412 } |
| 401 } | 413 } |
| 402 | 414 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 "http://some.domain.com/insecure.html", NULL, | 563 "http://some.domain.com/insecure.html", NULL, |
| 552 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 | 564 NULL, NULL, NULL, L"joe_user", L"updated_password", false, false, 0 |
| 553 }; | 565 }; |
| 554 scoped_ptr<PasswordForm> update_form(CreatePasswordFormFromData(data)); | 566 scoped_ptr<PasswordForm> update_form(CreatePasswordFormFromData(data)); |
| 555 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 567 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
| 556 EXPECT_TRUE(keychain_adapter.AddPassword(*update_form)); | 568 EXPECT_TRUE(keychain_adapter.AddPassword(*update_form)); |
| 557 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(2); | 569 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(2); |
| 558 PasswordForm stored_form; | 570 PasswordForm stored_form; |
| 559 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, | 571 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_, |
| 560 keychain_item, | 572 keychain_item, |
| 561 &stored_form); | 573 &stored_form, |
| 574 true); | |
| 562 EXPECT_EQ(update_form->password_value, stored_form.password_value); | 575 EXPECT_EQ(update_form->password_value, stored_form.password_value); |
| 563 } | 576 } |
| 564 } | 577 } |
| 565 | 578 |
| 566 TEST_F(PasswordStoreMacInternalsTest, TestKeychainRemove) { | 579 TEST_F(PasswordStoreMacInternalsTest, TestKeychainRemove) { |
| 567 struct TestDataAndExpectation { | 580 struct TestDataAndExpectation { |
| 568 PasswordFormData data; | 581 PasswordFormData data; |
| 569 bool should_succeed; | 582 bool should_succeed; |
| 570 }; | 583 }; |
| 571 TestDataAndExpectation test_data[] = { | 584 TestDataAndExpectation test_data[] = { |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1034 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
| 1022 } | 1035 } |
| 1023 STLDeleteElements(&matching_items); | 1036 STLDeleteElements(&matching_items); |
| 1024 | 1037 |
| 1025 login_db_->GetLogins(*query_form, &matching_items); | 1038 login_db_->GetLogins(*query_form, &matching_items); |
| 1026 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1039 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
| 1027 << "iteration " << i; | 1040 << "iteration " << i; |
| 1028 STLDeleteElements(&matching_items); | 1041 STLDeleteElements(&matching_items); |
| 1029 } | 1042 } |
| 1030 } | 1043 } |
| OLD | NEW |