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 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 struct MockSecretItem { | 41 struct MockSecretItem { |
42 MockSecretValue* value; | 42 MockSecretValue* value; |
43 GHashTable* attributes; | 43 GHashTable* attributes; |
44 | 44 |
45 MockSecretItem(MockSecretValue* value, GHashTable* attributes) | 45 MockSecretItem(MockSecretValue* value, GHashTable* attributes) |
46 : value(value), attributes(attributes) {} | 46 : value(value), attributes(attributes) {} |
47 ~MockSecretItem() { | 47 ~MockSecretItem() { |
48 delete value; | 48 delete value; |
49 g_hash_table_destroy(attributes); | 49 g_hash_table_destroy(attributes); |
50 } | 50 } |
| 51 |
| 52 void RemoveAttribute(const char* keyname) { |
| 53 g_hash_table_remove(attributes, keyname); |
| 54 } |
51 }; | 55 }; |
52 | 56 |
53 bool Matches(MockSecretItem* item, GHashTable* query) { | 57 bool Matches(MockSecretItem* item, GHashTable* query) { |
54 GHashTable* attributes = item->attributes; | 58 GHashTable* attributes = item->attributes; |
55 GHashTableIter iter; | 59 GHashTableIter iter; |
56 gchar* name; | 60 gchar* name; |
57 gchar* query_value; | 61 gchar* query_value; |
58 g_hash_table_iter_init(&iter, query); | 62 g_hash_table_iter_init(&iter, query); |
59 | 63 |
60 while (g_hash_table_iter_next(&iter, reinterpret_cast<gpointer*>(&name), | 64 while (g_hash_table_iter_next(&iter, reinterpret_cast<gpointer*>(&name), |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 } | 815 } |
812 | 816 |
813 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { | 817 TEST_F(NativeBackendLibsecretTest, RemoveLoginsCreatedBetween) { |
814 CheckRemoveLoginsBetween(CREATED); | 818 CheckRemoveLoginsBetween(CREATED); |
815 } | 819 } |
816 | 820 |
817 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { | 821 TEST_F(NativeBackendLibsecretTest, RemoveLoginsSyncedBetween) { |
818 CheckRemoveLoginsBetween(SYNCED); | 822 CheckRemoveLoginsBetween(SYNCED); |
819 } | 823 } |
820 | 824 |
| 825 TEST_F(NativeBackendLibsecretTest, SomeKeyringAttributesAreMissing) { |
| 826 // Absent attributes should be filled with default values. |
| 827 NativeBackendLibsecret backend(42); |
| 828 |
| 829 backend.AddLogin(form_google_); |
| 830 |
| 831 EXPECT_EQ(1u, global_mock_libsecret_items.size()); |
| 832 // Remove a string attribute. |
| 833 global_mock_libsecret_items[0]->RemoveAttribute("avatar_url"); |
| 834 // Remove an integer attribute. |
| 835 global_mock_libsecret_items[0]->RemoveAttribute("ssl_valid"); |
| 836 |
| 837 ScopedVector<autofill::PasswordForm> form_list; |
| 838 backend.GetAutofillableLogins(&form_list); |
| 839 |
| 840 EXPECT_EQ(1u, form_list.size()); |
| 841 EXPECT_EQ(GURL(""), form_list[0]->avatar_url); |
| 842 EXPECT_FALSE(form_list[0]->ssl_valid); |
| 843 } |
| 844 |
821 // TODO(mdm): add more basic tests here at some point. | 845 // TODO(mdm): add more basic tests here at some point. |
OLD | NEW |