Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: sync/protocol/proto_value_conversions_unittest.cc

Issue 17034006: Add base namespace to more values in sync and elsewhere. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync_protocol_error.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Keep this file in sync with the .proto files in this directory. 5 // Keep this file in sync with the .proto files in this directory.
6 6
7 #include "sync/protocol/proto_value_conversions.h" 7 #include "sync/protocol/proto_value_conversions.h"
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 24 matching lines...) Expand all
35 #include "sync/protocol/typed_url_specifics.pb.h" 35 #include "sync/protocol/typed_url_specifics.pb.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 37
38 namespace syncer { 38 namespace syncer {
39 namespace { 39 namespace {
40 40
41 class ProtoValueConversionsTest : public testing::Test { 41 class ProtoValueConversionsTest : public testing::Test {
42 protected: 42 protected:
43 template <class T> 43 template <class T>
44 void TestSpecificsToValue( 44 void TestSpecificsToValue(
45 DictionaryValue* (*specifics_to_value)(const T&)) { 45 base::DictionaryValue* (*specifics_to_value)(const T&)) {
46 const T& specifics(T::default_instance()); 46 const T& specifics(T::default_instance());
47 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); 47 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics));
48 // We can't do much but make sure that this doesn't crash. 48 // We can't do much but make sure that this doesn't crash.
49 } 49 }
50 }; 50 };
51 51
52 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { 52 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
53 // If this number changes, that means we added or removed a data 53 // If this number changes, that means we added or removed a data
54 // type. Don't forget to add a unit test for {New 54 // type. Don't forget to add a unit test for {New
55 // type}SpecificsToValue below. 55 // type}SpecificsToValue below.
56 EXPECT_EQ(28, MODEL_TYPE_COUNT); 56 EXPECT_EQ(28, MODEL_TYPE_COUNT);
57 57
(...skipping 20 matching lines...) Expand all
78 TestSpecificsToValue(SessionWindowToValue); 78 TestSpecificsToValue(SessionWindowToValue);
79 } 79 }
80 80
81 TEST_F(ProtoValueConversionsTest, TabNavigationToValue) { 81 TEST_F(ProtoValueConversionsTest, TabNavigationToValue) {
82 TestSpecificsToValue(TabNavigationToValue); 82 TestSpecificsToValue(TabNavigationToValue);
83 } 83 }
84 84
85 TEST_F(ProtoValueConversionsTest, PasswordSpecificsData) { 85 TEST_F(ProtoValueConversionsTest, PasswordSpecificsData) {
86 sync_pb::PasswordSpecificsData specifics; 86 sync_pb::PasswordSpecificsData specifics;
87 specifics.set_password_value("secret"); 87 specifics.set_password_value("secret");
88 scoped_ptr<DictionaryValue> value(PasswordSpecificsDataToValue(specifics)); 88 scoped_ptr<base::DictionaryValue> value(
89 PasswordSpecificsDataToValue(specifics));
89 EXPECT_FALSE(value->empty()); 90 EXPECT_FALSE(value->empty());
90 std::string password_value; 91 std::string password_value;
91 EXPECT_TRUE(value->GetString("password_value", &password_value)); 92 EXPECT_TRUE(value->GetString("password_value", &password_value));
92 EXPECT_EQ("<redacted>", password_value); 93 EXPECT_EQ("<redacted>", password_value);
93 } 94 }
94 95
95 TEST_F(ProtoValueConversionsTest, AppNotificationToValue) { 96 TEST_F(ProtoValueConversionsTest, AppNotificationToValue) {
96 TestSpecificsToValue(AppNotificationToValue); 97 TestSpecificsToValue(AppNotificationToValue);
97 } 98 }
98 99
99 TEST_F(ProtoValueConversionsTest, AppSettingSpecificsToValue) { 100 TEST_F(ProtoValueConversionsTest, AppSettingSpecificsToValue) {
100 sync_pb::AppNotificationSettings specifics; 101 sync_pb::AppNotificationSettings specifics;
101 specifics.set_disabled(true); 102 specifics.set_disabled(true);
102 specifics.set_oauth_client_id("some_id_value"); 103 specifics.set_oauth_client_id("some_id_value");
103 scoped_ptr<DictionaryValue> value(AppSettingsToValue(specifics)); 104 scoped_ptr<base::DictionaryValue> value(AppSettingsToValue(specifics));
104 EXPECT_FALSE(value->empty()); 105 EXPECT_FALSE(value->empty());
105 bool disabled_value = false; 106 bool disabled_value = false;
106 std::string oauth_client_id_value; 107 std::string oauth_client_id_value;
107 EXPECT_TRUE(value->GetBoolean("disabled", &disabled_value)); 108 EXPECT_TRUE(value->GetBoolean("disabled", &disabled_value));
108 EXPECT_EQ(true, disabled_value); 109 EXPECT_EQ(true, disabled_value);
109 EXPECT_TRUE(value->GetString("oauth_client_id", &oauth_client_id_value)); 110 EXPECT_TRUE(value->GetString("oauth_client_id", &oauth_client_id_value));
110 EXPECT_EQ("some_id_value", oauth_client_id_value); 111 EXPECT_EQ("some_id_value", oauth_client_id_value);
111 } 112 }
112 113
113 TEST_F(ProtoValueConversionsTest, AppSpecificsToValue) { 114 TEST_F(ProtoValueConversionsTest, AppSpecificsToValue) {
(...skipping 11 matching lines...) Expand all
125 TEST_F(ProtoValueConversionsTest, BookmarkSpecificsToValue) { 126 TEST_F(ProtoValueConversionsTest, BookmarkSpecificsToValue) {
126 TestSpecificsToValue(BookmarkSpecificsToValue); 127 TestSpecificsToValue(BookmarkSpecificsToValue);
127 } 128 }
128 129
129 TEST_F(ProtoValueConversionsTest, BookmarkSpecificsData) { 130 TEST_F(ProtoValueConversionsTest, BookmarkSpecificsData) {
130 const base::Time creation_time(base::Time::Now()); 131 const base::Time creation_time(base::Time::Now());
131 const std::string icon_url = "http://www.google.com/favicon.ico"; 132 const std::string icon_url = "http://www.google.com/favicon.ico";
132 sync_pb::BookmarkSpecifics specifics; 133 sync_pb::BookmarkSpecifics specifics;
133 specifics.set_creation_time_us(creation_time.ToInternalValue()); 134 specifics.set_creation_time_us(creation_time.ToInternalValue());
134 specifics.set_icon_url(icon_url); 135 specifics.set_icon_url(icon_url);
135 scoped_ptr<DictionaryValue> value(BookmarkSpecificsToValue(specifics)); 136 scoped_ptr<base::DictionaryValue> value(BookmarkSpecificsToValue(specifics));
136 EXPECT_FALSE(value->empty()); 137 EXPECT_FALSE(value->empty());
137 std::string encoded_time; 138 std::string encoded_time;
138 EXPECT_TRUE(value->GetString("creation_time_us", &encoded_time)); 139 EXPECT_TRUE(value->GetString("creation_time_us", &encoded_time));
139 EXPECT_EQ(base::Int64ToString(creation_time.ToInternalValue()), encoded_time); 140 EXPECT_EQ(base::Int64ToString(creation_time.ToInternalValue()), encoded_time);
140 std::string encoded_icon_url; 141 std::string encoded_icon_url;
141 EXPECT_TRUE(value->GetString("icon_url", &encoded_icon_url)); 142 EXPECT_TRUE(value->GetString("icon_url", &encoded_icon_url));
142 EXPECT_EQ(icon_url, encoded_icon_url); 143 EXPECT_EQ(icon_url, encoded_icon_url);
143 } 144 }
144 145
145 TEST_F(ProtoValueConversionsTest, PriorityPreferenceSpecificsToValue) { 146 TEST_F(ProtoValueConversionsTest, PriorityPreferenceSpecificsToValue) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 SET_FIELD(preference); 248 SET_FIELD(preference);
248 SET_FIELD(priority_preference); 249 SET_FIELD(priority_preference);
249 SET_FIELD(search_engine); 250 SET_FIELD(search_engine);
250 SET_FIELD(session); 251 SET_FIELD(session);
251 SET_FIELD(synced_notification); 252 SET_FIELD(synced_notification);
252 SET_FIELD(theme); 253 SET_FIELD(theme);
253 SET_FIELD(typed_url); 254 SET_FIELD(typed_url);
254 255
255 #undef SET_FIELD 256 #undef SET_FIELD
256 257
257 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); 258 scoped_ptr<base::DictionaryValue> value(EntitySpecificsToValue(specifics));
258 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE - 259 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE -
259 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1), 260 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1),
260 static_cast<int>(value->size())); 261 static_cast<int>(value->size()));
261 } 262 }
262 263
263 namespace { 264 namespace {
264 // Returns whether the given value has specifics under the entries in the given 265 // Returns whether the given value has specifics under the entries in the given
265 // path. 266 // path.
266 bool ValueHasSpecifics(const DictionaryValue& value, 267 bool ValueHasSpecifics(const base::DictionaryValue& value,
267 const std::string& path) { 268 const std::string& path) {
268 const ListValue* entities_list = NULL; 269 const base::ListValue* entities_list = NULL;
269 const DictionaryValue* entry_dictionary = NULL; 270 const base::DictionaryValue* entry_dictionary = NULL;
270 const DictionaryValue* specifics_dictionary = NULL; 271 const base::DictionaryValue* specifics_dictionary = NULL;
271 272
272 if (!value.GetList(path, &entities_list)) 273 if (!value.GetList(path, &entities_list))
273 return false; 274 return false;
274 275
275 if (!entities_list->GetDictionary(0, &entry_dictionary)) 276 if (!entities_list->GetDictionary(0, &entry_dictionary))
276 return false; 277 return false;
277 278
278 return entry_dictionary->GetDictionary("specifics", 279 return entry_dictionary->GetDictionary("specifics",
279 &specifics_dictionary); 280 &specifics_dictionary);
280 } 281 }
281 } // namespace 282 } // namespace
282 283
283 // Create a ClientToServerMessage with an EntitySpecifics. Converting it to 284 // Create a ClientToServerMessage with an EntitySpecifics. Converting it to
284 // a value should respect the |include_specifics| flag. 285 // a value should respect the |include_specifics| flag.
285 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) { 286 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) {
286 sync_pb::ClientToServerMessage message; 287 sync_pb::ClientToServerMessage message;
287 sync_pb::CommitMessage* commit_message = message.mutable_commit(); 288 sync_pb::CommitMessage* commit_message = message.mutable_commit();
288 sync_pb::SyncEntity* entity = commit_message->add_entries(); 289 sync_pb::SyncEntity* entity = commit_message->add_entries();
289 entity->mutable_specifics(); 290 entity->mutable_specifics();
290 291
291 scoped_ptr<DictionaryValue> value_with_specifics( 292 scoped_ptr<base::DictionaryValue> value_with_specifics(
292 ClientToServerMessageToValue(message, true /* include_specifics */)); 293 ClientToServerMessageToValue(message, true /* include_specifics */));
293 EXPECT_FALSE(value_with_specifics->empty()); 294 EXPECT_FALSE(value_with_specifics->empty());
294 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()), 295 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()),
295 "commit.entries")); 296 "commit.entries"));
296 297
297 scoped_ptr<DictionaryValue> value_without_specifics( 298 scoped_ptr<base::DictionaryValue> value_without_specifics(
298 ClientToServerMessageToValue(message, false /* include_specifics */)); 299 ClientToServerMessageToValue(message, false /* include_specifics */));
299 EXPECT_FALSE(value_without_specifics->empty()); 300 EXPECT_FALSE(value_without_specifics->empty());
300 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 301 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
301 "commit.entries")); 302 "commit.entries"));
302 } 303 }
303 304
304 // Create a ClientToServerResponse with an EntitySpecifics. Converting it to 305 // Create a ClientToServerResponse with an EntitySpecifics. Converting it to
305 // a value should respect the |include_specifics| flag. 306 // a value should respect the |include_specifics| flag.
306 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) { 307 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) {
307 sync_pb::ClientToServerResponse message; 308 sync_pb::ClientToServerResponse message;
308 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates(); 309 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates();
309 sync_pb::SyncEntity* entity = response->add_entries(); 310 sync_pb::SyncEntity* entity = response->add_entries();
310 entity->mutable_specifics(); 311 entity->mutable_specifics();
311 312
312 scoped_ptr<DictionaryValue> value_with_specifics( 313 scoped_ptr<base::DictionaryValue> value_with_specifics(
313 ClientToServerResponseToValue(message, true /* include_specifics */)); 314 ClientToServerResponseToValue(message, true /* include_specifics */));
314 EXPECT_FALSE(value_with_specifics->empty()); 315 EXPECT_FALSE(value_with_specifics->empty());
315 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()), 316 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()),
316 "get_updates.entries")); 317 "get_updates.entries"));
317 318
318 scoped_ptr<DictionaryValue> value_without_specifics( 319 scoped_ptr<base::DictionaryValue> value_without_specifics(
319 ClientToServerResponseToValue(message, false /* include_specifics */)); 320 ClientToServerResponseToValue(message, false /* include_specifics */));
320 EXPECT_FALSE(value_without_specifics->empty()); 321 EXPECT_FALSE(value_without_specifics->empty());
321 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 322 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
322 "get_updates.entries")); 323 "get_updates.entries"));
323 } 324 }
324 325
325 } // namespace 326 } // namespace
326 } // namespace syncer 327 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync_protocol_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698