| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // MockLibsecretLoader, which hooks into the facility normally used to load | 40 // MockLibsecretLoader, which hooks into the facility normally used to load |
| 41 // the libsecret library at runtime to avoid a static dependency on it. | 41 // the libsecret library at runtime to avoid a static dependency on it. |
| 42 | 42 |
| 43 struct MockSecretValue { | 43 struct MockSecretValue { |
| 44 gchar* password; | 44 gchar* password; |
| 45 explicit MockSecretValue(gchar* password) : password(password) {} | 45 explicit MockSecretValue(gchar* password) : password(password) {} |
| 46 ~MockSecretValue() { g_free(password); } | 46 ~MockSecretValue() { g_free(password); } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 struct MockSecretItem { | 49 struct MockSecretItem { |
| 50 MockSecretValue* value; | 50 std::unique_ptr<MockSecretValue> value; |
| 51 GHashTable* attributes; | 51 GHashTable* attributes; |
| 52 | 52 |
| 53 MockSecretItem(MockSecretValue* value, GHashTable* attributes) | 53 MockSecretItem(std::unique_ptr<MockSecretValue> value, GHashTable* attributes) |
| 54 : value(value), attributes(attributes) {} | 54 : value(std::move(value)), attributes(attributes) {} |
| 55 ~MockSecretItem() { | 55 ~MockSecretItem() { |
| 56 delete value; | |
| 57 g_hash_table_destroy(attributes); | 56 g_hash_table_destroy(attributes); |
| 58 } | 57 } |
| 59 | 58 |
| 60 void RemoveAttribute(const char* keyname) { | 59 void RemoveAttribute(const char* keyname) { |
| 61 g_hash_table_remove(attributes, keyname); | 60 g_hash_table_remove(attributes, keyname); |
| 62 } | 61 } |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 bool Matches(MockSecretItem* item, GHashTable* query) { | 64 bool Matches(MockSecretItem* item, GHashTable* query) { |
| 66 GHashTable* attributes = item->attributes; | 65 GHashTable* attributes = item->attributes; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 | 79 |
| 81 bool IsStringAttribute(const SecretSchema* schema, const std::string& name) { | 80 bool IsStringAttribute(const SecretSchema* schema, const std::string& name) { |
| 82 for (size_t i = 0; schema->attributes[i].name; ++i) | 81 for (size_t i = 0; schema->attributes[i].name; ++i) |
| 83 if (name == schema->attributes[i].name) | 82 if (name == schema->attributes[i].name) |
| 84 return schema->attributes[i].type == SECRET_SCHEMA_ATTRIBUTE_STRING; | 83 return schema->attributes[i].type == SECRET_SCHEMA_ATTRIBUTE_STRING; |
| 85 NOTREACHED() << "Requested type of nonexistent attribute"; | 84 NOTREACHED() << "Requested type of nonexistent attribute"; |
| 86 return false; | 85 return false; |
| 87 } | 86 } |
| 88 | 87 |
| 89 // The list of all libsecret items we have stored. | 88 // The list of all libsecret items we have stored. |
| 90 ScopedVector<MockSecretItem>* global_mock_libsecret_items; | 89 std::vector<std::unique_ptr<MockSecretItem>>* global_mock_libsecret_items; |
| 91 bool global_mock_libsecret_reject_local_ids = false; | 90 bool global_mock_libsecret_reject_local_ids = false; |
| 92 | 91 |
| 93 gboolean mock_secret_password_store_sync(const SecretSchema* schema, | 92 gboolean mock_secret_password_store_sync(const SecretSchema* schema, |
| 94 const gchar* collection, | 93 const gchar* collection, |
| 95 const gchar* label, | 94 const gchar* label, |
| 96 const gchar* password, | 95 const gchar* password, |
| 97 GCancellable* cancellable, | 96 GCancellable* cancellable, |
| 98 GError** error, | 97 GError** error, |
| 99 ...) { | 98 ...) { |
| 100 // TODO(crbug.com/660005) We don't read the dummy we store to unlock keyring. | 99 // TODO(crbug.com/660005) We don't read the dummy we store to unlock keyring. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 VLOG(1) << "Adding item attribute " << name << ", value '" << value | 112 VLOG(1) << "Adding item attribute " << name << ", value '" << value |
| 114 << "'"; | 113 << "'"; |
| 115 } else { | 114 } else { |
| 116 uint32_t intvalue = va_arg(ap, uint32_t); | 115 uint32_t intvalue = va_arg(ap, uint32_t); |
| 117 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue; | 116 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue; |
| 118 value = g_strdup_printf("%u", intvalue); | 117 value = g_strdup_printf("%u", intvalue); |
| 119 } | 118 } |
| 120 g_hash_table_insert(attributes, g_strdup(name), value); | 119 g_hash_table_insert(attributes, g_strdup(name), value); |
| 121 } | 120 } |
| 122 va_end(ap); | 121 va_end(ap); |
| 123 MockSecretValue* secret_value = new MockSecretValue(g_strdup(password)); | 122 global_mock_libsecret_items->push_back(base::MakeUnique<MockSecretItem>( |
| 124 MockSecretItem* item = new MockSecretItem(secret_value, attributes); | 123 base::MakeUnique<MockSecretValue>(g_strdup(password)), attributes)); |
| 125 global_mock_libsecret_items->push_back(item); | |
| 126 return true; | 124 return true; |
| 127 } | 125 } |
| 128 | 126 |
| 129 GList* mock_secret_service_search_sync(SecretService* service, | 127 GList* mock_secret_service_search_sync(SecretService* service, |
| 130 const SecretSchema* schema, | 128 const SecretSchema* schema, |
| 131 GHashTable* attributes, | 129 GHashTable* attributes, |
| 132 SecretSearchFlags flags, | 130 SecretSearchFlags flags, |
| 133 GCancellable* cancellable, | 131 GCancellable* cancellable, |
| 134 GError** error) { | 132 GError** error) { |
| 135 EXPECT_TRUE(flags & SECRET_SEARCH_UNLOCK); | 133 EXPECT_TRUE(flags & SECRET_SEARCH_UNLOCK); |
| 136 GList* result = nullptr; | 134 GList* result = nullptr; |
| 137 for (MockSecretItem* item : *global_mock_libsecret_items) { | 135 for (std::unique_ptr<MockSecretItem>& item : *global_mock_libsecret_items) { |
| 138 if (Matches(item, attributes)) | 136 if (Matches(item.get(), attributes)) |
| 139 result = g_list_append(result, item); | 137 result = g_list_append(result, item.get()); |
| 140 } | 138 } |
| 141 return result; | 139 return result; |
| 142 } | 140 } |
| 143 | 141 |
| 144 gboolean mock_secret_password_clear_sync(const SecretSchema* schema, | 142 gboolean mock_secret_password_clear_sync(const SecretSchema* schema, |
| 145 GCancellable* cancellable, | 143 GCancellable* cancellable, |
| 146 GError** error, | 144 GError** error, |
| 147 ...) { | 145 ...) { |
| 148 GHashTable* attributes = | 146 GHashTable* attributes = |
| 149 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | 147 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| 150 va_list ap; | 148 va_list ap; |
| 151 va_start(ap, error); | 149 va_start(ap, error); |
| 152 char* name; | 150 char* name; |
| 153 while ((name = va_arg(ap, gchar*))) { | 151 while ((name = va_arg(ap, gchar*))) { |
| 154 char* value; | 152 char* value; |
| 155 if (IsStringAttribute(schema, name)) { | 153 if (IsStringAttribute(schema, name)) { |
| 156 value = g_strdup(va_arg(ap, gchar*)); | 154 value = g_strdup(va_arg(ap, gchar*)); |
| 157 VLOG(1) << "Adding item attribute " << name << ", value '" << value | 155 VLOG(1) << "Adding item attribute " << name << ", value '" << value |
| 158 << "'"; | 156 << "'"; |
| 159 } else { | 157 } else { |
| 160 uint32_t intvalue = va_arg(ap, uint32_t); | 158 uint32_t intvalue = va_arg(ap, uint32_t); |
| 161 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue; | 159 VLOG(1) << "Adding item attribute " << name << ", value " << intvalue; |
| 162 value = g_strdup_printf("%u", intvalue); | 160 value = g_strdup_printf("%u", intvalue); |
| 163 } | 161 } |
| 164 g_hash_table_insert(attributes, g_strdup(name), value); | 162 g_hash_table_insert(attributes, g_strdup(name), value); |
| 165 } | 163 } |
| 166 va_end(ap); | 164 va_end(ap); |
| 167 | 165 |
| 168 ScopedVector<MockSecretItem> kept_mock_libsecret_items; | 166 std::vector<std::unique_ptr<MockSecretItem>> kept_mock_libsecret_items; |
| 169 kept_mock_libsecret_items.reserve(global_mock_libsecret_items->size()); | 167 kept_mock_libsecret_items.reserve(global_mock_libsecret_items->size()); |
| 170 for (auto*& item : *global_mock_libsecret_items) { | 168 for (std::unique_ptr<MockSecretItem>& item : *global_mock_libsecret_items) { |
| 171 if (!Matches(item, attributes)) { | 169 if (!Matches(item.get(), attributes)) { |
| 172 kept_mock_libsecret_items.push_back(item); | 170 kept_mock_libsecret_items.push_back(std::move(item)); |
| 173 item = nullptr; | |
| 174 } | 171 } |
| 175 } | 172 } |
| 176 global_mock_libsecret_items->swap(kept_mock_libsecret_items); | 173 global_mock_libsecret_items->swap(kept_mock_libsecret_items); |
| 177 | 174 |
| 178 g_hash_table_unref(attributes); | 175 g_hash_table_unref(attributes); |
| 179 return | 176 return |
| 180 global_mock_libsecret_items->size() != kept_mock_libsecret_items.size(); | 177 global_mock_libsecret_items->size() != kept_mock_libsecret_items.size(); |
| 181 } | 178 } |
| 182 | 179 |
| 183 SecretValue* mock_secret_item_get_secret(SecretItem* self) { | 180 SecretValue* mock_secret_item_get_secret(SecretItem* self) { |
| 184 MockSecretValue* mock_value = reinterpret_cast<MockSecretItem*>(self)->value; | 181 MockSecretValue* mock_value = |
| 182 reinterpret_cast<MockSecretItem*>(self)->value.get(); |
| 185 return reinterpret_cast<SecretValue*>(mock_value); | 183 return reinterpret_cast<SecretValue*>(mock_value); |
| 186 } | 184 } |
| 187 | 185 |
| 188 const gchar* mock_secret_value_get_text(SecretValue* value) { | 186 const gchar* mock_secret_value_get_text(SecretValue* value) { |
| 189 return reinterpret_cast<MockSecretValue*>(value)->password; | 187 return reinterpret_cast<MockSecretValue*>(value)->password; |
| 190 } | 188 } |
| 191 | 189 |
| 192 GHashTable* mock_secret_item_get_attributes(SecretItem* self) { | 190 GHashTable* mock_secret_item_get_attributes(SecretItem* self) { |
| 193 // Libsecret backend will make unreference of received attributes, so in | 191 // Libsecret backend will make unreference of received attributes, so in |
| 194 // order to save them we need to increase their reference number. | 192 // order to save them we need to increase their reference number. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 VerifiedAdd(&backend, credentials); | 428 VerifiedAdd(&backend, credentials); |
| 431 | 429 |
| 432 PasswordStore::FormDigest target_form = {PasswordForm::SCHEME_HTML, | 430 PasswordStore::FormDigest target_form = {PasswordForm::SCHEME_HTML, |
| 433 url.spec(), url}; | 431 url.spec(), url}; |
| 434 if (scheme != PasswordForm::SCHEME_HTML) { | 432 if (scheme != PasswordForm::SCHEME_HTML) { |
| 435 // For non-HTML forms, the realm used for authentication | 433 // For non-HTML forms, the realm used for authentication |
| 436 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the | 434 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the |
| 437 // signon_realm. Just use a default value for now. | 435 // signon_realm. Just use a default value for now. |
| 438 target_form.signon_realm.append("Realm"); | 436 target_form.signon_realm.append("Realm"); |
| 439 } | 437 } |
| 440 ScopedVector<autofill::PasswordForm> form_list; | 438 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 441 EXPECT_TRUE(backend.GetLogins(target_form, &form_list)); | 439 EXPECT_TRUE(backend.GetLogins(target_form, &form_list)); |
| 442 | 440 |
| 443 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 441 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 444 if (!global_mock_libsecret_items->empty()) | 442 if (!global_mock_libsecret_items->empty()) |
| 445 CheckMockSecretItem((*global_mock_libsecret_items)[0], credentials, | 443 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), credentials, |
| 446 "chrome-321"); | 444 "chrome-321"); |
| 447 global_mock_libsecret_items->clear(); | 445 global_mock_libsecret_items->clear(); |
| 448 | 446 |
| 449 if (form_list.empty()) | 447 if (form_list.empty()) |
| 450 return false; | 448 return false; |
| 451 EXPECT_EQ(1u, form_list.size()); | 449 EXPECT_EQ(1u, form_list.size()); |
| 452 if (result) | 450 if (result) |
| 453 *result = *form_list[0]; | 451 *result = *form_list[0]; |
| 454 return true; | 452 return true; |
| 455 } | 453 } |
| 456 | 454 |
| 457 // Test that updating does not use PSL matching: Add a www.facebook.com | 455 // Test that updating does not use PSL matching: Add a www.facebook.com |
| 458 // password, then use PSL matching to get a copy of it for m.facebook.com, and | 456 // password, then use PSL matching to get a copy of it for m.facebook.com, and |
| 459 // add that copy as well. Now update the www.facebook.com password -- the | 457 // add that copy as well. Now update the www.facebook.com password -- the |
| 460 // m.facebook.com password should not get updated. Depending on the argument, | 458 // m.facebook.com password should not get updated. Depending on the argument, |
| 461 // the credential update is done via UpdateLogin or AddLogin. | 459 // the credential update is done via UpdateLogin or AddLogin. |
| 462 void CheckPSLUpdate(UpdateType update_type) { | 460 void CheckPSLUpdate(UpdateType update_type) { |
| 463 NativeBackendLibsecret backend(321); | 461 NativeBackendLibsecret backend(321); |
| 464 | 462 |
| 465 VerifiedAdd(&backend, form_facebook_); | 463 VerifiedAdd(&backend, form_facebook_); |
| 466 | 464 |
| 467 // Get the PSL-matched copy of the saved login for m.facebook. | 465 // Get the PSL-matched copy of the saved login for m.facebook. |
| 468 const GURL kMobileURL("http://m.facebook.com/"); | 466 const GURL kMobileURL("http://m.facebook.com/"); |
| 469 PasswordStore::FormDigest m_facebook_lookup = { | 467 PasswordStore::FormDigest m_facebook_lookup = { |
| 470 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; | 468 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; |
| 471 ScopedVector<autofill::PasswordForm> form_list; | 469 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 472 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); | 470 EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list)); |
| 473 | 471 |
| 474 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 472 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 475 EXPECT_EQ(1u, form_list.size()); | 473 EXPECT_EQ(1u, form_list.size()); |
| 476 PasswordForm m_facebook = *form_list[0]; | 474 PasswordForm m_facebook = *form_list[0]; |
| 477 form_list.clear(); | 475 form_list.clear(); |
| 478 m_facebook.origin = kMobileURL; | 476 m_facebook.origin = kMobileURL; |
| 479 m_facebook.signon_realm = kMobileURL.spec(); | 477 m_facebook.signon_realm = kMobileURL.spec(); |
| 480 | 478 |
| 481 // Add the PSL-matched copy to saved logins. | 479 // Add the PSL-matched copy to saved logins. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 date_to_test == CREATED | 575 date_to_test == CREATED |
| 578 ? &NativeBackendLibsecret::RemoveLoginsCreatedBetween | 576 ? &NativeBackendLibsecret::RemoveLoginsCreatedBetween |
| 579 : &NativeBackendLibsecret::RemoveLoginsSyncedBetween; | 577 : &NativeBackendLibsecret::RemoveLoginsSyncedBetween; |
| 580 | 578 |
| 581 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), base::Time(), | 579 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), base::Time(), |
| 582 next_day, &changes).Run()); | 580 next_day, &changes).Run()); |
| 583 CheckPasswordChanges(expected_changes, changes); | 581 CheckPasswordChanges(expected_changes, changes); |
| 584 | 582 |
| 585 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 583 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 586 if (!global_mock_libsecret_items->empty() > 0) | 584 if (!global_mock_libsecret_items->empty() > 0) |
| 587 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_isc_, | 585 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_isc_, |
| 588 "chrome-42"); | 586 "chrome-42"); |
| 589 | 587 |
| 590 // Remove form_isc_. | 588 // Remove form_isc_. |
| 591 expected_changes.clear(); | 589 expected_changes.clear(); |
| 592 expected_changes.push_back( | 590 expected_changes.push_back( |
| 593 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); | 591 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); |
| 594 | 592 |
| 595 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), next_day, | 593 EXPECT_TRUE(base::Bind(method, base::Unretained(&backend), next_day, |
| 596 base::Time(), &changes).Run()); | 594 base::Time(), &changes).Run()); |
| 597 CheckPasswordChanges(expected_changes, changes); | 595 CheckPasswordChanges(expected_changes, changes); |
| 598 | 596 |
| 599 EXPECT_TRUE(global_mock_libsecret_items->empty()); | 597 EXPECT_TRUE(global_mock_libsecret_items->empty()); |
| 600 } | 598 } |
| 601 | 599 |
| 602 base::MessageLoopForUI message_loop_; | 600 base::MessageLoopForUI message_loop_; |
| 603 | 601 |
| 604 // Provide some test forms to avoid having to set them up in each test. | 602 // Provide some test forms to avoid having to set them up in each test. |
| 605 PasswordForm form_google_; | 603 PasswordForm form_google_; |
| 606 PasswordForm form_facebook_; | 604 PasswordForm form_facebook_; |
| 607 PasswordForm form_isc_; | 605 PasswordForm form_isc_; |
| 608 PasswordForm other_auth_; | 606 PasswordForm other_auth_; |
| 609 | 607 |
| 610 ScopedVector<MockSecretItem> mock_libsecret_items_; | 608 std::vector<std::unique_ptr<MockSecretItem>> mock_libsecret_items_; |
| 611 }; | 609 }; |
| 612 | 610 |
| 613 TEST_F(NativeBackendLibsecretTest, BasicAddLogin) { | 611 TEST_F(NativeBackendLibsecretTest, BasicAddLogin) { |
| 614 NativeBackendLibsecret backend(42); | 612 NativeBackendLibsecret backend(42); |
| 615 | 613 |
| 616 VerifiedAdd(&backend, form_google_); | 614 VerifiedAdd(&backend, form_google_); |
| 617 | 615 |
| 618 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 616 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 619 if (!global_mock_libsecret_items->empty()) | 617 if (!global_mock_libsecret_items->empty()) |
| 620 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 618 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 621 "chrome-42"); | 619 "chrome-42"); |
| 622 } | 620 } |
| 623 | 621 |
| 624 TEST_F(NativeBackendLibsecretTest, BasicListLogins) { | 622 TEST_F(NativeBackendLibsecretTest, BasicListLogins) { |
| 625 NativeBackendLibsecret backend(42); | 623 NativeBackendLibsecret backend(42); |
| 626 | 624 |
| 627 VerifiedAdd(&backend, form_google_); | 625 VerifiedAdd(&backend, form_google_); |
| 628 | 626 |
| 629 ScopedVector<autofill::PasswordForm> form_list; | 627 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 630 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); | 628 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); |
| 631 | 629 |
| 632 ASSERT_EQ(1u, form_list.size()); | 630 ASSERT_EQ(1u, form_list.size()); |
| 633 EXPECT_EQ(form_google_, *form_list[0]); | 631 EXPECT_EQ(form_google_, *form_list[0]); |
| 634 | 632 |
| 635 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 633 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 636 if (!global_mock_libsecret_items->empty()) | 634 if (!global_mock_libsecret_items->empty()) |
| 637 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 635 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 638 "chrome-42"); | 636 "chrome-42"); |
| 639 } | 637 } |
| 640 | 638 |
| 641 TEST_F(NativeBackendLibsecretTest, GetAllLogins) { | 639 TEST_F(NativeBackendLibsecretTest, GetAllLogins) { |
| 642 NativeBackendLibsecret backend(42); | 640 NativeBackendLibsecret backend(42); |
| 643 | 641 |
| 644 VerifiedAdd(&backend, form_google_); | 642 VerifiedAdd(&backend, form_google_); |
| 645 VerifiedAdd(&backend, form_facebook_); | 643 VerifiedAdd(&backend, form_facebook_); |
| 646 | 644 |
| 647 ScopedVector<autofill::PasswordForm> form_list; | 645 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 648 EXPECT_TRUE(backend.GetAllLogins(&form_list)); | 646 EXPECT_TRUE(backend.GetAllLogins(&form_list)); |
| 649 | 647 |
| 650 ASSERT_EQ(2u, form_list.size()); | 648 ASSERT_EQ(2u, form_list.size()); |
| 651 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), | 649 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), |
| 652 Pointee(form_facebook_))); | 650 Pointee(form_facebook_))); |
| 653 } | 651 } |
| 654 | 652 |
| 655 // Save a password for www.facebook.com and see it suggested for m.facebook.com. | 653 // Save a password for www.facebook.com and see it suggested for m.facebook.com. |
| 656 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { | 654 TEST_F(NativeBackendLibsecretTest, PSLMatchingPositive) { |
| 657 PasswordForm result; | 655 PasswordForm result; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 NativeBackendLibsecret backend(42); | 704 NativeBackendLibsecret backend(42); |
| 707 | 705 |
| 708 VerifiedAdd(&backend, form_google_); | 706 VerifiedAdd(&backend, form_google_); |
| 709 | 707 |
| 710 PasswordForm new_form_google(form_google_); | 708 PasswordForm new_form_google(form_google_); |
| 711 new_form_google.times_used = 1; | 709 new_form_google.times_used = 1; |
| 712 new_form_google.action = GURL("http://www.google.com/different/login"); | 710 new_form_google.action = GURL("http://www.google.com/different/login"); |
| 713 | 711 |
| 714 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 712 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 715 if (!global_mock_libsecret_items->empty()) { | 713 if (!global_mock_libsecret_items->empty()) { |
| 716 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 714 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 717 "chrome-42"); | 715 "chrome-42"); |
| 718 } | 716 } |
| 719 | 717 |
| 720 // Update login | 718 // Update login |
| 721 VerifiedUpdate(&backend, new_form_google); | 719 VerifiedUpdate(&backend, new_form_google); |
| 722 | 720 |
| 723 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 721 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 724 if (!global_mock_libsecret_items->empty()) | 722 if (!global_mock_libsecret_items->empty()) |
| 725 CheckMockSecretItem((*global_mock_libsecret_items)[0], new_form_google, | 723 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), |
| 726 "chrome-42"); | 724 new_form_google, "chrome-42"); |
| 727 } | 725 } |
| 728 | 726 |
| 729 TEST_F(NativeBackendLibsecretTest, BasicRemoveLogin) { | 727 TEST_F(NativeBackendLibsecretTest, BasicRemoveLogin) { |
| 730 NativeBackendLibsecret backend(42); | 728 NativeBackendLibsecret backend(42); |
| 731 | 729 |
| 732 VerifiedAdd(&backend, form_google_); | 730 VerifiedAdd(&backend, form_google_); |
| 733 | 731 |
| 734 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 732 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 735 if (!global_mock_libsecret_items->empty()) | 733 if (!global_mock_libsecret_items->empty()) |
| 736 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 734 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 737 "chrome-42"); | 735 "chrome-42"); |
| 738 | 736 |
| 739 VerifiedRemove(&backend, form_google_); | 737 VerifiedRemove(&backend, form_google_); |
| 740 | 738 |
| 741 EXPECT_TRUE(global_mock_libsecret_items->empty()); | 739 EXPECT_TRUE(global_mock_libsecret_items->empty()); |
| 742 } | 740 } |
| 743 | 741 |
| 744 // Verify fix for http://crbug.com/408783. | 742 // Verify fix for http://crbug.com/408783. |
| 745 TEST_F(NativeBackendLibsecretTest, RemoveLoginActionMismatch) { | 743 TEST_F(NativeBackendLibsecretTest, RemoveLoginActionMismatch) { |
| 746 NativeBackendLibsecret backend(42); | 744 NativeBackendLibsecret backend(42); |
| 747 | 745 |
| 748 VerifiedAdd(&backend, form_google_); | 746 VerifiedAdd(&backend, form_google_); |
| 749 | 747 |
| 750 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 748 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 751 if (!global_mock_libsecret_items->empty()) | 749 if (!global_mock_libsecret_items->empty()) |
| 752 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 750 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 753 "chrome-42"); | 751 "chrome-42"); |
| 754 | 752 |
| 755 // Action url match not required for removal. | 753 // Action url match not required for removal. |
| 756 form_google_.action = GURL("https://some.other.url.com/path"); | 754 form_google_.action = GURL("https://some.other.url.com/path"); |
| 757 VerifiedRemove(&backend, form_google_); | 755 VerifiedRemove(&backend, form_google_); |
| 758 | 756 |
| 759 EXPECT_TRUE(global_mock_libsecret_items->empty()); | 757 EXPECT_TRUE(global_mock_libsecret_items->empty()); |
| 760 } | 758 } |
| 761 | 759 |
| 762 TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) { | 760 TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) { |
| 763 NativeBackendLibsecret backend(42); | 761 NativeBackendLibsecret backend(42); |
| 764 | 762 |
| 765 // First add an unrelated login. | 763 // First add an unrelated login. |
| 766 VerifiedAdd(&backend, form_google_); | 764 VerifiedAdd(&backend, form_google_); |
| 767 | 765 |
| 768 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 766 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 769 if (!global_mock_libsecret_items->empty()) | 767 if (!global_mock_libsecret_items->empty()) |
| 770 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 768 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 771 "chrome-42"); | 769 "chrome-42"); |
| 772 | 770 |
| 773 // Attempt to remove a login that doesn't exist. | 771 // Attempt to remove a login that doesn't exist. |
| 774 PasswordStoreChangeList changes; | 772 PasswordStoreChangeList changes; |
| 775 EXPECT_TRUE(backend.RemoveLogin(form_isc_, &changes)); | 773 EXPECT_TRUE(backend.RemoveLogin(form_isc_, &changes)); |
| 776 CheckPasswordChanges(PasswordStoreChangeList(), changes); | 774 CheckPasswordChanges(PasswordStoreChangeList(), changes); |
| 777 | 775 |
| 778 // Make sure we can still get the first form back. | 776 // Make sure we can still get the first form back. |
| 779 ScopedVector<autofill::PasswordForm> form_list; | 777 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 780 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); | 778 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); |
| 781 | 779 |
| 782 // Quick check that we got something back. | 780 // Quick check that we got something back. |
| 783 EXPECT_EQ(1u, form_list.size()); | 781 EXPECT_EQ(1u, form_list.size()); |
| 784 form_list.clear(); | 782 form_list.clear(); |
| 785 | 783 |
| 786 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 784 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 787 if (!global_mock_libsecret_items->empty()) | 785 if (!global_mock_libsecret_items->empty()) |
| 788 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 786 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 789 "chrome-42"); | 787 "chrome-42"); |
| 790 } | 788 } |
| 791 | 789 |
| 792 TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) { | 790 TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) { |
| 793 NativeBackendLibsecret backend(42); | 791 NativeBackendLibsecret backend(42); |
| 794 | 792 |
| 795 // First add an unrelated login. | 793 // First add an unrelated login. |
| 796 VerifiedAdd(&backend, form_google_); | 794 VerifiedAdd(&backend, form_google_); |
| 797 | 795 |
| 798 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 796 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 799 if (!global_mock_libsecret_items->empty()) { | 797 if (!global_mock_libsecret_items->empty()) { |
| 800 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 798 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 801 "chrome-42"); | 799 "chrome-42"); |
| 802 } | 800 } |
| 803 | 801 |
| 804 // Attempt to update a login that doesn't exist. | 802 // Attempt to update a login that doesn't exist. |
| 805 PasswordStoreChangeList changes; | 803 PasswordStoreChangeList changes; |
| 806 EXPECT_TRUE(backend.UpdateLogin(form_isc_, &changes)); | 804 EXPECT_TRUE(backend.UpdateLogin(form_isc_, &changes)); |
| 807 CheckPasswordChanges(PasswordStoreChangeList(), changes); | 805 CheckPasswordChanges(PasswordStoreChangeList(), changes); |
| 808 | 806 |
| 809 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 807 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 810 if (!global_mock_libsecret_items->empty()) | 808 if (!global_mock_libsecret_items->empty()) |
| 811 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 809 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 812 "chrome-42"); | 810 "chrome-42"); |
| 813 } | 811 } |
| 814 | 812 |
| 815 TEST_F(NativeBackendLibsecretTest, UpdateSameLogin) { | 813 TEST_F(NativeBackendLibsecretTest, UpdateSameLogin) { |
| 816 NativeBackendLibsecret backend(42); | 814 NativeBackendLibsecret backend(42); |
| 817 | 815 |
| 818 VerifiedAdd(&backend, form_google_); | 816 VerifiedAdd(&backend, form_google_); |
| 819 | 817 |
| 820 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 818 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 821 if (!global_mock_libsecret_items->empty()) { | 819 if (!global_mock_libsecret_items->empty()) { |
| 822 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 820 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 823 "chrome-42"); | 821 "chrome-42"); |
| 824 } | 822 } |
| 825 | 823 |
| 826 // Attempt to update the same login without changing anything. | 824 // Attempt to update the same login without changing anything. |
| 827 PasswordStoreChangeList changes; | 825 PasswordStoreChangeList changes; |
| 828 EXPECT_TRUE(backend.UpdateLogin(form_google_, &changes)); | 826 EXPECT_TRUE(backend.UpdateLogin(form_google_, &changes)); |
| 829 CheckPasswordChanges(PasswordStoreChangeList(), changes); | 827 CheckPasswordChanges(PasswordStoreChangeList(), changes); |
| 830 | 828 |
| 831 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 829 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 832 if (!global_mock_libsecret_items->empty()) { | 830 if (!global_mock_libsecret_items->empty()) { |
| 833 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 831 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 834 "chrome-42"); | 832 "chrome-42"); |
| 835 } | 833 } |
| 836 } | 834 } |
| 837 | 835 |
| 838 TEST_F(NativeBackendLibsecretTest, AddDuplicateLogin) { | 836 TEST_F(NativeBackendLibsecretTest, AddDuplicateLogin) { |
| 839 NativeBackendLibsecret backend(42); | 837 NativeBackendLibsecret backend(42); |
| 840 | 838 |
| 841 VerifiedAdd(&backend, form_google_); | 839 VerifiedAdd(&backend, form_google_); |
| 842 | 840 |
| 843 PasswordStoreChangeList expected_changes; | 841 PasswordStoreChangeList expected_changes; |
| 844 expected_changes.push_back( | 842 expected_changes.push_back( |
| 845 PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); | 843 PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); |
| 846 form_google_.times_used++; | 844 form_google_.times_used++; |
| 847 form_google_.submit_element = UTF8ToUTF16("submit2"); | 845 form_google_.submit_element = UTF8ToUTF16("submit2"); |
| 848 expected_changes.push_back( | 846 expected_changes.push_back( |
| 849 PasswordStoreChange(PasswordStoreChange::ADD, form_google_)); | 847 PasswordStoreChange(PasswordStoreChange::ADD, form_google_)); |
| 850 | 848 |
| 851 PasswordStoreChangeList actual_changes = backend.AddLogin(form_google_); | 849 PasswordStoreChangeList actual_changes = backend.AddLogin(form_google_); |
| 852 CheckPasswordChanges(expected_changes, actual_changes); | 850 CheckPasswordChanges(expected_changes, actual_changes); |
| 853 | 851 |
| 854 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 852 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 855 if (!global_mock_libsecret_items->empty()) | 853 if (!global_mock_libsecret_items->empty()) |
| 856 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 854 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 857 "chrome-42"); | 855 "chrome-42"); |
| 858 } | 856 } |
| 859 | 857 |
| 860 TEST_F(NativeBackendLibsecretTest, AndroidCredentials) { | 858 TEST_F(NativeBackendLibsecretTest, AndroidCredentials) { |
| 861 NativeBackendLibsecret backend(42); | 859 NativeBackendLibsecret backend(42); |
| 862 backend.Init(); | 860 backend.Init(); |
| 863 | 861 |
| 864 PasswordForm observed_android_form; | 862 PasswordForm observed_android_form; |
| 865 observed_android_form.scheme = PasswordForm::SCHEME_HTML; | 863 observed_android_form.scheme = PasswordForm::SCHEME_HTML; |
| 866 observed_android_form.signon_realm = | 864 observed_android_form.signon_realm = |
| 867 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; | 865 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; |
| 868 PasswordForm saved_android_form = observed_android_form; | 866 PasswordForm saved_android_form = observed_android_form; |
| 869 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); | 867 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); |
| 870 saved_android_form.password_value = base::UTF8ToUTF16("password"); | 868 saved_android_form.password_value = base::UTF8ToUTF16("password"); |
| 871 saved_android_form.date_created = base::Time::Now(); | 869 saved_android_form.date_created = base::Time::Now(); |
| 872 | 870 |
| 873 VerifiedAdd(&backend, saved_android_form); | 871 VerifiedAdd(&backend, saved_android_form); |
| 874 | 872 |
| 875 ScopedVector<autofill::PasswordForm> form_list; | 873 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 876 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); | 874 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); |
| 877 | 875 |
| 878 EXPECT_EQ(1u, form_list.size()); | 876 EXPECT_EQ(1u, form_list.size()); |
| 879 EXPECT_EQ(saved_android_form, *form_list[0]); | 877 EXPECT_EQ(saved_android_form, *form_list[0]); |
| 880 } | 878 } |
| 881 | 879 |
| 882 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { | 880 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { |
| 883 CheckRemoveLoginsBetween(CREATED); | 881 CheckRemoveLoginsBetween(CREATED); |
| 884 } | 882 } |
| 885 | 883 |
| 886 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { | 884 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { |
| 887 CheckRemoveLoginsBetween(SYNCED); | 885 CheckRemoveLoginsBetween(SYNCED); |
| 888 } | 886 } |
| 889 | 887 |
| 890 TEST_F(NativeBackendLibsecretTest, DisableAutoSignInForOrigins) { | 888 TEST_F(NativeBackendLibsecretTest, DisableAutoSignInForOrigins) { |
| 891 NativeBackendLibsecret backend(42); | 889 NativeBackendLibsecret backend(42); |
| 892 backend.Init(); | 890 backend.Init(); |
| 893 form_google_.skip_zero_click = false; | 891 form_google_.skip_zero_click = false; |
| 894 form_facebook_.skip_zero_click = false; | 892 form_facebook_.skip_zero_click = false; |
| 895 | 893 |
| 896 VerifiedAdd(&backend, form_google_); | 894 VerifiedAdd(&backend, form_google_); |
| 897 VerifiedAdd(&backend, form_facebook_); | 895 VerifiedAdd(&backend, form_facebook_); |
| 898 | 896 |
| 899 EXPECT_EQ(2u, global_mock_libsecret_items->size()); | 897 EXPECT_EQ(2u, global_mock_libsecret_items->size()); |
| 900 for (auto* item : *global_mock_libsecret_items) | 898 for (const auto& item : *global_mock_libsecret_items) |
| 901 CheckUint32Attribute(item, "should_skip_zero_click", 0); | 899 CheckUint32Attribute(item.get(), "should_skip_zero_click", 0); |
| 902 | 900 |
| 903 // Set the canonical forms to the updated value for the following comparison. | 901 // Set the canonical forms to the updated value for the following comparison. |
| 904 form_google_.skip_zero_click = true; | 902 form_google_.skip_zero_click = true; |
| 905 form_facebook_.skip_zero_click = true; | 903 form_facebook_.skip_zero_click = true; |
| 906 PasswordStoreChangeList expected_changes; | 904 PasswordStoreChangeList expected_changes; |
| 907 expected_changes.push_back( | 905 expected_changes.push_back( |
| 908 PasswordStoreChange(PasswordStoreChange::UPDATE, form_facebook_)); | 906 PasswordStoreChange(PasswordStoreChange::UPDATE, form_facebook_)); |
| 909 | 907 |
| 910 PasswordStoreChangeList changes; | 908 PasswordStoreChangeList changes; |
| 911 EXPECT_TRUE(backend.DisableAutoSignInForOrigins( | 909 EXPECT_TRUE(backend.DisableAutoSignInForOrigins( |
| 912 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), | 910 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), |
| 913 form_facebook_.origin), | 911 form_facebook_.origin), |
| 914 &changes)); | 912 &changes)); |
| 915 CheckPasswordChanges(expected_changes, changes); | 913 CheckPasswordChanges(expected_changes, changes); |
| 916 | 914 |
| 917 EXPECT_EQ(2u, global_mock_libsecret_items->size()); | 915 EXPECT_EQ(2u, global_mock_libsecret_items->size()); |
| 918 CheckStringAttribute((*global_mock_libsecret_items)[0], | 916 CheckStringAttribute((*global_mock_libsecret_items)[0].get(), "origin_url", |
| 919 "origin_url", form_google_.origin.spec()); | 917 form_google_.origin.spec()); |
| 920 CheckUint32Attribute((*global_mock_libsecret_items)[0], | 918 CheckUint32Attribute((*global_mock_libsecret_items)[0].get(), |
| 921 "should_skip_zero_click", 0); | 919 "should_skip_zero_click", 0); |
| 922 CheckStringAttribute((*global_mock_libsecret_items)[1], | 920 CheckStringAttribute((*global_mock_libsecret_items)[1].get(), "origin_url", |
| 923 "origin_url", form_facebook_.origin.spec()); | 921 form_facebook_.origin.spec()); |
| 924 CheckUint32Attribute((*global_mock_libsecret_items)[1], | 922 CheckUint32Attribute((*global_mock_libsecret_items)[1].get(), |
| 925 "should_skip_zero_click", 1); | 923 "should_skip_zero_click", 1); |
| 926 } | 924 } |
| 927 | 925 |
| 928 TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) { | 926 TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) { |
| 929 // Absent attributes should be filled with default values. | 927 // Absent attributes should be filled with default values. |
| 930 NativeBackendLibsecret backend(42); | 928 NativeBackendLibsecret backend(42); |
| 931 | 929 |
| 932 VerifiedAdd(&backend, form_google_); | 930 VerifiedAdd(&backend, form_google_); |
| 933 | 931 |
| 934 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 932 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 935 // Remove a string attribute. | 933 // Remove a string attribute. |
| 936 (*global_mock_libsecret_items)[0]->RemoveAttribute("avatar_url"); | 934 (*global_mock_libsecret_items)[0]->RemoveAttribute("avatar_url"); |
| 937 // Remove an integer attribute. | 935 // Remove an integer attribute. |
| 938 (*global_mock_libsecret_items)[0]->RemoveAttribute("times_used"); | 936 (*global_mock_libsecret_items)[0]->RemoveAttribute("times_used"); |
| 939 | 937 |
| 940 ScopedVector<autofill::PasswordForm> form_list; | 938 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 941 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); | 939 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); |
| 942 | 940 |
| 943 EXPECT_EQ(1u, form_list.size()); | 941 EXPECT_EQ(1u, form_list.size()); |
| 944 EXPECT_EQ(GURL(""), form_list[0]->icon_url); | 942 EXPECT_EQ(GURL(""), form_list[0]->icon_url); |
| 945 EXPECT_EQ(0, form_list[0]->times_used); | 943 EXPECT_EQ(0, form_list[0]->times_used); |
| 946 } | 944 } |
| 947 | 945 |
| 948 TEST_F(NativeBackendLibsecretTest, ReadDuplicateForms) { | 946 TEST_F(NativeBackendLibsecretTest, ReadDuplicateForms) { |
| 949 NativeBackendLibsecret backend(42); | 947 NativeBackendLibsecret backend(42); |
| 950 | 948 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 963 ASSERT_EQ(2u, global_mock_libsecret_items->size()); | 961 ASSERT_EQ(2u, global_mock_libsecret_items->size()); |
| 964 gpointer item_value = g_hash_table_lookup( | 962 gpointer item_value = g_hash_table_lookup( |
| 965 global_mock_libsecret_items->front()->attributes, "origin_url"); | 963 global_mock_libsecret_items->front()->attributes, "origin_url"); |
| 966 ASSERT_TRUE(item_value); | 964 ASSERT_TRUE(item_value); |
| 967 char* substr = strstr(static_cast<char*>(item_value), unique_string); | 965 char* substr = strstr(static_cast<char*>(item_value), unique_string); |
| 968 ASSERT_TRUE(substr); | 966 ASSERT_TRUE(substr); |
| 969 ASSERT_EQ(strlen(unique_string), strlen(unique_string_replacement)); | 967 ASSERT_EQ(strlen(unique_string), strlen(unique_string_replacement)); |
| 970 strncpy(substr, unique_string_replacement, strlen(unique_string)); | 968 strncpy(substr, unique_string_replacement, strlen(unique_string)); |
| 971 | 969 |
| 972 // Now test that GetAutofillableLogins returns only one form. | 970 // Now test that GetAutofillableLogins returns only one form. |
| 973 ScopedVector<autofill::PasswordForm> form_list; | 971 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 974 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); | 972 EXPECT_TRUE(backend.GetAutofillableLogins(&form_list)); |
| 975 | 973 |
| 976 EXPECT_EQ(1u, form_list.size()); | 974 EXPECT_EQ(1u, form_list.size()); |
| 977 EXPECT_EQ(form_google_, *form_list[0]); | 975 EXPECT_EQ(form_google_, *form_list[0]); |
| 978 | 976 |
| 979 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 977 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 980 if (!global_mock_libsecret_items->empty()) { | 978 if (!global_mock_libsecret_items->empty()) { |
| 981 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 979 CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_, |
| 982 "chrome-42"); | 980 "chrome-42"); |
| 983 } | 981 } |
| 984 } | 982 } |
| 985 | 983 |
| 986 // TODO(mdm): add more basic tests here at some point. | 984 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |