| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 item = nullptr; | 170 item = nullptr; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 global_mock_libsecret_items->swap(kept_mock_libsecret_items); | 173 global_mock_libsecret_items->swap(kept_mock_libsecret_items); |
| 174 | 174 |
| 175 g_hash_table_unref(attributes); | 175 g_hash_table_unref(attributes); |
| 176 return | 176 return |
| 177 global_mock_libsecret_items->size() != kept_mock_libsecret_items.size(); | 177 global_mock_libsecret_items->size() != kept_mock_libsecret_items.size(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 MockSecretValue* mock_secret_item_get_secret(MockSecretItem* self) { | 180 SecretValue* mock_secret_item_get_secret(SecretItem* self) { |
| 181 return self->value; | 181 MockSecretValue* mock_value = reinterpret_cast<MockSecretItem*>(self)->value; |
| 182 return reinterpret_cast<SecretValue*>(mock_value); |
| 182 } | 183 } |
| 183 | 184 |
| 184 const gchar* mock_secret_value_get_text(MockSecretValue* value) { | 185 const gchar* mock_secret_value_get_text(SecretValue* value) { |
| 185 return value->password; | 186 return reinterpret_cast<MockSecretValue*>(value)->password; |
| 186 } | 187 } |
| 187 | 188 |
| 188 GHashTable* mock_secret_item_get_attributes(MockSecretItem* self) { | 189 GHashTable* mock_secret_item_get_attributes(SecretItem* self) { |
| 189 // Libsecret backend will make unreference of received attributes, so in | 190 // Libsecret backend will make unreference of received attributes, so in |
| 190 // order to save them we need to increase their reference number. | 191 // order to save them we need to increase their reference number. |
| 191 g_hash_table_ref(self->attributes); | 192 MockSecretItem* mock_ptr = reinterpret_cast<MockSecretItem*>(self); |
| 192 return self->attributes; | 193 g_hash_table_ref(mock_ptr->attributes); |
| 194 return mock_ptr->attributes; |
| 193 } | 195 } |
| 194 | 196 |
| 195 gboolean mock_secret_item_load_secret_sync(MockSecretItem* self, | 197 gboolean mock_secret_item_load_secret_sync(SecretItem* self, |
| 196 GCancellable* cancellable, | 198 GCancellable* cancellable, |
| 197 GError** error) { | 199 GError** error) { |
| 198 return true; | 200 return true; |
| 199 } | 201 } |
| 200 | 202 |
| 201 void mock_secret_value_unref(gpointer value) { | 203 void mock_secret_value_unref(gpointer value) { |
| 202 } | 204 } |
| 203 | 205 |
| 204 // Inherit to get access to protected fields. | 206 // Inherit to get access to protected fields. |
| 205 class MockLibsecretLoader : public LibsecretLoader { | 207 class MockLibsecretLoader : public LibsecretLoader { |
| 206 public: | 208 public: |
| 207 static bool LoadMockLibsecret() { | 209 static bool LoadMockLibsecret() { |
| 208 secret_password_store_sync = &mock_secret_password_store_sync; | 210 secret_password_store_sync = &mock_secret_password_store_sync; |
| 209 secret_service_search_sync = &mock_secret_service_search_sync; | 211 secret_service_search_sync = &mock_secret_service_search_sync; |
| 210 secret_password_clear_sync = &mock_secret_password_clear_sync; | 212 secret_password_clear_sync = &mock_secret_password_clear_sync; |
| 211 secret_item_get_secret = | 213 secret_item_get_secret = &mock_secret_item_get_secret; |
| 212 (decltype(&::secret_item_get_secret)) & mock_secret_item_get_secret; | 214 secret_value_get_text = &mock_secret_value_get_text; |
| 213 secret_value_get_text = | 215 secret_item_get_attributes = &mock_secret_item_get_attributes; |
| 214 (decltype(&::secret_value_get_text)) & mock_secret_value_get_text; | 216 secret_item_load_secret_sync = &mock_secret_item_load_secret_sync; |
| 215 secret_item_get_attributes = (decltype(&::secret_item_get_attributes)) & | 217 secret_value_unref = &mock_secret_value_unref; |
| 216 mock_secret_item_get_attributes; | |
| 217 secret_item_load_secret_sync = (decltype(&::secret_item_load_secret_sync)) & | |
| 218 mock_secret_item_load_secret_sync; | |
| 219 secret_value_unref = | |
| 220 (decltype(&::secret_value_unref)) & mock_secret_value_unref; | |
| 221 libsecret_loaded_ = true; | 218 libsecret_loaded_ = true; |
| 222 // Reset the state of the mock library. | 219 // Reset the state of the mock library. |
| 223 global_mock_libsecret_items->clear(); | 220 global_mock_libsecret_items->clear(); |
| 224 global_mock_libsecret_reject_local_ids = false; | 221 global_mock_libsecret_reject_local_ids = false; |
| 225 return true; | 222 return true; |
| 226 } | 223 } |
| 227 }; | 224 }; |
| 228 | 225 |
| 229 void CheckPasswordChanges(const PasswordStoreChangeList& expected_list, | 226 void CheckPasswordChanges(const PasswordStoreChangeList& expected_list, |
| 230 const PasswordStoreChangeList& actual_list) { | 227 const PasswordStoreChangeList& actual_list) { |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 EXPECT_EQ(form_google_, *form_list[0]); | 974 EXPECT_EQ(form_google_, *form_list[0]); |
| 978 | 975 |
| 979 EXPECT_EQ(1u, global_mock_libsecret_items->size()); | 976 EXPECT_EQ(1u, global_mock_libsecret_items->size()); |
| 980 if (!global_mock_libsecret_items->empty()) { | 977 if (!global_mock_libsecret_items->empty()) { |
| 981 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, | 978 CheckMockSecretItem((*global_mock_libsecret_items)[0], form_google_, |
| 982 "chrome-42"); | 979 "chrome-42"); |
| 983 } | 980 } |
| 984 } | 981 } |
| 985 | 982 |
| 986 // TODO(mdm): add more basic tests here at some point. | 983 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |