| Index: chrome/browser/password_manager/native_backend_libsecret_unittest.cc
|
| diff --git a/chrome/browser/password_manager/native_backend_libsecret_unittest.cc b/chrome/browser/password_manager/native_backend_libsecret_unittest.cc
|
| index 32a6d70cd62d390bfd24b79970cf6928c9c2feea..132f4ce0c53bd183daf5fbdbf31050a986590aee 100644
|
| --- a/chrome/browser/password_manager/native_backend_libsecret_unittest.cc
|
| +++ b/chrome/browser/password_manager/native_backend_libsecret_unittest.cc
|
| @@ -47,13 +47,12 @@ struct MockSecretValue {
|
| };
|
|
|
| struct MockSecretItem {
|
| - MockSecretValue* value;
|
| + std::unique_ptr<MockSecretValue> value;
|
| GHashTable* attributes;
|
|
|
| - MockSecretItem(MockSecretValue* value, GHashTable* attributes)
|
| - : value(value), attributes(attributes) {}
|
| + MockSecretItem(std::unique_ptr<MockSecretValue> value, GHashTable* attributes)
|
| + : value(std::move(value)), attributes(attributes) {}
|
| ~MockSecretItem() {
|
| - delete value;
|
| g_hash_table_destroy(attributes);
|
| }
|
|
|
| @@ -87,7 +86,7 @@ bool IsStringAttribute(const SecretSchema* schema, const std::string& name) {
|
| }
|
|
|
| // The list of all libsecret items we have stored.
|
| -ScopedVector<MockSecretItem>* global_mock_libsecret_items;
|
| +std::vector<std::unique_ptr<MockSecretItem>>* global_mock_libsecret_items;
|
| bool global_mock_libsecret_reject_local_ids = false;
|
|
|
| gboolean mock_secret_password_store_sync(const SecretSchema* schema,
|
| @@ -120,9 +119,8 @@ gboolean mock_secret_password_store_sync(const SecretSchema* schema,
|
| g_hash_table_insert(attributes, g_strdup(name), value);
|
| }
|
| va_end(ap);
|
| - MockSecretValue* secret_value = new MockSecretValue(g_strdup(password));
|
| - MockSecretItem* item = new MockSecretItem(secret_value, attributes);
|
| - global_mock_libsecret_items->push_back(item);
|
| + global_mock_libsecret_items->push_back(base::MakeUnique<MockSecretItem>(
|
| + base::MakeUnique<MockSecretValue>(g_strdup(password)), attributes));
|
| return true;
|
| }
|
|
|
| @@ -134,9 +132,9 @@ GList* mock_secret_service_search_sync(SecretService* service,
|
| GError** error) {
|
| EXPECT_TRUE(flags & SECRET_SEARCH_UNLOCK);
|
| GList* result = nullptr;
|
| - for (MockSecretItem* item : *global_mock_libsecret_items) {
|
| - if (Matches(item, attributes))
|
| - result = g_list_append(result, item);
|
| + for (std::unique_ptr<MockSecretItem>& item : *global_mock_libsecret_items) {
|
| + if (Matches(item.get(), attributes))
|
| + result = g_list_append(result, item.get());
|
| }
|
| return result;
|
| }
|
| @@ -165,12 +163,11 @@ gboolean mock_secret_password_clear_sync(const SecretSchema* schema,
|
| }
|
| va_end(ap);
|
|
|
| - ScopedVector<MockSecretItem> kept_mock_libsecret_items;
|
| + std::vector<std::unique_ptr<MockSecretItem>> kept_mock_libsecret_items;
|
| kept_mock_libsecret_items.reserve(global_mock_libsecret_items->size());
|
| - for (auto*& item : *global_mock_libsecret_items) {
|
| - if (!Matches(item, attributes)) {
|
| - kept_mock_libsecret_items.push_back(item);
|
| - item = nullptr;
|
| + for (std::unique_ptr<MockSecretItem>& item : *global_mock_libsecret_items) {
|
| + if (!Matches(item.get(), attributes)) {
|
| + kept_mock_libsecret_items.push_back(std::move(item));
|
| }
|
| }
|
| global_mock_libsecret_items->swap(kept_mock_libsecret_items);
|
| @@ -181,7 +178,8 @@ gboolean mock_secret_password_clear_sync(const SecretSchema* schema,
|
| }
|
|
|
| SecretValue* mock_secret_item_get_secret(SecretItem* self) {
|
| - MockSecretValue* mock_value = reinterpret_cast<MockSecretItem*>(self)->value;
|
| + MockSecretValue* mock_value =
|
| + reinterpret_cast<MockSecretItem*>(self)->value.get();
|
| return reinterpret_cast<SecretValue*>(mock_value);
|
| }
|
|
|
| @@ -437,12 +435,12 @@ class NativeBackendLibsecretTest : public testing::Test {
|
| // signon_realm. Just use a default value for now.
|
| target_form.signon_realm.append("Realm");
|
| }
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetLogins(target_form, &form_list));
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], credentials,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), credentials,
|
| "chrome-321");
|
| global_mock_libsecret_items->clear();
|
|
|
| @@ -468,7 +466,7 @@ class NativeBackendLibsecretTest : public testing::Test {
|
| const GURL kMobileURL("http://m.facebook.com/");
|
| PasswordStore::FormDigest m_facebook_lookup = {
|
| PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL};
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetLogins(m_facebook_lookup, &form_list));
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| @@ -584,7 +582,7 @@ class NativeBackendLibsecretTest : public testing::Test {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty() > 0)
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_isc_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_isc_,
|
| "chrome-42");
|
|
|
| // Remove form_isc_.
|
| @@ -607,7 +605,7 @@ class NativeBackendLibsecretTest : public testing::Test {
|
| PasswordForm form_isc_;
|
| PasswordForm other_auth_;
|
|
|
| - ScopedVector<MockSecretItem> mock_libsecret_items_;
|
| + std::vector<std::unique_ptr<MockSecretItem>> mock_libsecret_items_;
|
| };
|
|
|
| TEST_F(NativeBackendLibsecretTest, BasicAddLogin) {
|
| @@ -617,7 +615,7 @@ TEST_F(NativeBackendLibsecretTest, BasicAddLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -626,7 +624,7 @@ TEST_F(NativeBackendLibsecretTest, BasicListLogins) {
|
|
|
| VerifiedAdd(&backend, form_google_);
|
|
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAutofillableLogins(&form_list));
|
|
|
| ASSERT_EQ(1u, form_list.size());
|
| @@ -634,7 +632,7 @@ TEST_F(NativeBackendLibsecretTest, BasicListLogins) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -644,7 +642,7 @@ TEST_F(NativeBackendLibsecretTest, GetAllLogins) {
|
| VerifiedAdd(&backend, form_google_);
|
| VerifiedAdd(&backend, form_facebook_);
|
|
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAllLogins(&form_list));
|
|
|
| ASSERT_EQ(2u, form_list.size());
|
| @@ -713,7 +711,7 @@ TEST_F(NativeBackendLibsecretTest, BasicUpdateLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty()) {
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -722,8 +720,8 @@ TEST_F(NativeBackendLibsecretTest, BasicUpdateLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], new_form_google,
|
| - "chrome-42");
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(),
|
| + new_form_google, "chrome-42");
|
| }
|
|
|
| TEST_F(NativeBackendLibsecretTest, BasicRemoveLogin) {
|
| @@ -733,7 +731,7 @@ TEST_F(NativeBackendLibsecretTest, BasicRemoveLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
|
|
| VerifiedRemove(&backend, form_google_);
|
| @@ -749,7 +747,7 @@ TEST_F(NativeBackendLibsecretTest, RemoveLoginActionMismatch) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
|
|
| // Action url match not required for removal.
|
| @@ -767,7 +765,7 @@ TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
|
|
| // Attempt to remove a login that doesn't exist.
|
| @@ -776,7 +774,7 @@ TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) {
|
| CheckPasswordChanges(PasswordStoreChangeList(), changes);
|
|
|
| // Make sure we can still get the first form back.
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAutofillableLogins(&form_list));
|
|
|
| // Quick check that we got something back.
|
| @@ -785,7 +783,7 @@ TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -797,7 +795,7 @@ TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty()) {
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -808,7 +806,7 @@ TEST_F(NativeBackendLibsecretTest, UpdateNonexistentLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -819,7 +817,7 @@ TEST_F(NativeBackendLibsecretTest, UpdateSameLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty()) {
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -830,7 +828,7 @@ TEST_F(NativeBackendLibsecretTest, UpdateSameLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty()) {
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
| }
|
| @@ -853,7 +851,7 @@ TEST_F(NativeBackendLibsecretTest, AddDuplicateLogin) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty())
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
|
|
| @@ -872,7 +870,7 @@ TEST_F(NativeBackendLibsecretTest, AndroidCredentials) {
|
|
|
| VerifiedAdd(&backend, saved_android_form);
|
|
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAutofillableLogins(&form_list));
|
|
|
| EXPECT_EQ(1u, form_list.size());
|
| @@ -897,8 +895,8 @@ TEST_F(NativeBackendLibsecretTest, DisableAutoSignInForOrigins) {
|
| VerifiedAdd(&backend, form_facebook_);
|
|
|
| EXPECT_EQ(2u, global_mock_libsecret_items->size());
|
| - for (auto* item : *global_mock_libsecret_items)
|
| - CheckUint32Attribute(item, "should_skip_zero_click", 0);
|
| + for (const auto& item : *global_mock_libsecret_items)
|
| + CheckUint32Attribute(item.get(), "should_skip_zero_click", 0);
|
|
|
| // Set the canonical forms to the updated value for the following comparison.
|
| form_google_.skip_zero_click = true;
|
| @@ -915,13 +913,13 @@ TEST_F(NativeBackendLibsecretTest, DisableAutoSignInForOrigins) {
|
| CheckPasswordChanges(expected_changes, changes);
|
|
|
| EXPECT_EQ(2u, global_mock_libsecret_items->size());
|
| - CheckStringAttribute((*global_mock_libsecret_items)[0],
|
| - "origin_url", form_google_.origin.spec());
|
| - CheckUint32Attribute((*global_mock_libsecret_items)[0],
|
| + CheckStringAttribute((*global_mock_libsecret_items)[0].get(), "origin_url",
|
| + form_google_.origin.spec());
|
| + CheckUint32Attribute((*global_mock_libsecret_items)[0].get(),
|
| "should_skip_zero_click", 0);
|
| - CheckStringAttribute((*global_mock_libsecret_items)[1],
|
| - "origin_url", form_facebook_.origin.spec());
|
| - CheckUint32Attribute((*global_mock_libsecret_items)[1],
|
| + CheckStringAttribute((*global_mock_libsecret_items)[1].get(), "origin_url",
|
| + form_facebook_.origin.spec());
|
| + CheckUint32Attribute((*global_mock_libsecret_items)[1].get(),
|
| "should_skip_zero_click", 1);
|
| }
|
|
|
| @@ -937,7 +935,7 @@ TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) {
|
| // Remove an integer attribute.
|
| (*global_mock_libsecret_items)[0]->RemoveAttribute("times_used");
|
|
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAutofillableLogins(&form_list));
|
|
|
| EXPECT_EQ(1u, form_list.size());
|
| @@ -970,7 +968,7 @@ TEST_F(NativeBackendLibsecretTest, ReadDuplicateForms) {
|
| strncpy(substr, unique_string_replacement, strlen(unique_string));
|
|
|
| // Now test that GetAutofillableLogins returns only one form.
|
| - ScopedVector<autofill::PasswordForm> form_list;
|
| + std::vector<std::unique_ptr<PasswordForm>> form_list;
|
| EXPECT_TRUE(backend.GetAutofillableLogins(&form_list));
|
|
|
| EXPECT_EQ(1u, form_list.size());
|
| @@ -978,7 +976,7 @@ TEST_F(NativeBackendLibsecretTest, ReadDuplicateForms) {
|
|
|
| EXPECT_EQ(1u, global_mock_libsecret_items->size());
|
| if (!global_mock_libsecret_items->empty()) {
|
| - CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_,
|
| + CheckMockSecretItem((*global_mock_libsecret_items)[0].get(), form_google_,
|
| "chrome-42");
|
| }
|
| }
|
|
|