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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
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 "components/sync/protocol/proto_value_conversions.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "sync/internal_api/public/base/model_type.h" 15 #include "components/sync/base/model_type.h"
16 #include "sync/protocol/app_notification_specifics.pb.h" 16 #include "components/sync/protocol/app_notification_specifics.pb.h"
17 #include "sync/protocol/app_setting_specifics.pb.h" 17 #include "components/sync/protocol/app_setting_specifics.pb.h"
18 #include "sync/protocol/app_specifics.pb.h" 18 #include "components/sync/protocol/app_specifics.pb.h"
19 #include "sync/protocol/autofill_specifics.pb.h" 19 #include "components/sync/protocol/autofill_specifics.pb.h"
20 #include "sync/protocol/bookmark_specifics.pb.h" 20 #include "components/sync/protocol/bookmark_specifics.pb.h"
21 #include "sync/protocol/device_info_specifics.pb.h" 21 #include "components/sync/protocol/device_info_specifics.pb.h"
22 #include "sync/protocol/encryption.pb.h" 22 #include "components/sync/protocol/encryption.pb.h"
23 #include "sync/protocol/experiments_specifics.pb.h" 23 #include "components/sync/protocol/experiments_specifics.pb.h"
24 #include "sync/protocol/extension_setting_specifics.pb.h" 24 #include "components/sync/protocol/extension_setting_specifics.pb.h"
25 #include "sync/protocol/extension_specifics.pb.h" 25 #include "components/sync/protocol/extension_specifics.pb.h"
26 #include "sync/protocol/favicon_image_specifics.pb.h" 26 #include "components/sync/protocol/favicon_image_specifics.pb.h"
27 #include "sync/protocol/favicon_tracking_specifics.pb.h" 27 #include "components/sync/protocol/favicon_tracking_specifics.pb.h"
28 #include "sync/protocol/managed_user_setting_specifics.pb.h" 28 #include "components/sync/protocol/managed_user_setting_specifics.pb.h"
29 #include "sync/protocol/managed_user_shared_setting_specifics.pb.h" 29 #include "components/sync/protocol/managed_user_shared_setting_specifics.pb.h"
30 #include "sync/protocol/managed_user_specifics.pb.h" 30 #include "components/sync/protocol/managed_user_specifics.pb.h"
31 #include "sync/protocol/managed_user_whitelist_specifics.pb.h" 31 #include "components/sync/protocol/managed_user_whitelist_specifics.pb.h"
32 #include "sync/protocol/nigori_specifics.pb.h" 32 #include "components/sync/protocol/nigori_specifics.pb.h"
33 #include "sync/protocol/password_specifics.pb.h" 33 #include "components/sync/protocol/password_specifics.pb.h"
34 #include "sync/protocol/preference_specifics.pb.h" 34 #include "components/sync/protocol/preference_specifics.pb.h"
35 #include "sync/protocol/priority_preference_specifics.pb.h" 35 #include "components/sync/protocol/priority_preference_specifics.pb.h"
36 #include "sync/protocol/search_engine_specifics.pb.h" 36 #include "components/sync/protocol/search_engine_specifics.pb.h"
37 #include "sync/protocol/session_specifics.pb.h" 37 #include "components/sync/protocol/session_specifics.pb.h"
38 #include "sync/protocol/sync.pb.h" 38 #include "components/sync/protocol/sync.pb.h"
39 #include "sync/protocol/theme_specifics.pb.h" 39 #include "components/sync/protocol/theme_specifics.pb.h"
40 #include "sync/protocol/typed_url_specifics.pb.h" 40 #include "components/sync/protocol/typed_url_specifics.pb.h"
41 #include "sync/protocol/wifi_credential_specifics.pb.h" 41 #include "components/sync/protocol/wifi_credential_specifics.pb.h"
42 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
43 43
44 namespace syncer { 44 namespace syncer {
45 namespace { 45 namespace {
46 46
47 class ProtoValueConversionsTest : public testing::Test { 47 class ProtoValueConversionsTest : public testing::Test {
48 protected: 48 protected:
49 template <class T> 49 template <class T>
50 void TestSpecificsToValue( 50 void TestSpecificsToValue(
51 std::unique_ptr<base::DictionaryValue> (*specifics_to_value)(const T&)) { 51 std::unique_ptr<base::DictionaryValue> (*specifics_to_value)(const T&)) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 292
293 TEST_F(ProtoValueConversionsTest, WifiCredentialSpecificsToValue) { 293 TEST_F(ProtoValueConversionsTest, WifiCredentialSpecificsToValue) {
294 TestSpecificsToValue(WifiCredentialSpecificsToValue); 294 TestSpecificsToValue(WifiCredentialSpecificsToValue);
295 } 295 }
296 296
297 // TODO(akalin): Figure out how to better test EntitySpecificsToValue. 297 // TODO(akalin): Figure out how to better test EntitySpecificsToValue.
298 298
299 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) { 299 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
300 sync_pb::EntitySpecifics specifics; 300 sync_pb::EntitySpecifics specifics;
301 // Touch the extensions to make sure it shows up in the generated 301 // Touch the extensions to make sure it shows up in the generated
302 // value. 302 // value.
303 #define SET_FIELD(key) (void)specifics.mutable_##key() 303 #define SET_FIELD(key) (void)specifics.mutable_##key()
304 304
305 SET_FIELD(app); 305 SET_FIELD(app);
306 SET_FIELD(app_list); 306 SET_FIELD(app_list);
307 SET_FIELD(app_notification); 307 SET_FIELD(app_notification);
308 SET_FIELD(app_setting); 308 SET_FIELD(app_setting);
309 SET_FIELD(arc_package); 309 SET_FIELD(arc_package);
310 SET_FIELD(article); 310 SET_FIELD(article);
311 SET_FIELD(autofill); 311 SET_FIELD(autofill);
312 SET_FIELD(autofill_profile); 312 SET_FIELD(autofill_profile);
(...skipping 22 matching lines...) Expand all
335 SET_FIELD(typed_url); 335 SET_FIELD(typed_url);
336 SET_FIELD(wifi_credential); 336 SET_FIELD(wifi_credential);
337 SET_FIELD(autofill_wallet); 337 SET_FIELD(autofill_wallet);
338 SET_FIELD(wallet_metadata); 338 SET_FIELD(wallet_metadata);
339 339
340 #undef SET_FIELD 340 #undef SET_FIELD
341 341
342 std::unique_ptr<base::DictionaryValue> value( 342 std::unique_ptr<base::DictionaryValue> value(
343 EntitySpecificsToValue(specifics)); 343 EntitySpecificsToValue(specifics));
344 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE - 344 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE -
345 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1), 345 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1),
346 static_cast<int>(value->size())); 346 static_cast<int>(value->size()));
347 } 347 }
348 348
349 namespace { 349 namespace {
350 // Returns whether the given value has specifics under the entries in the given 350 // Returns whether the given value has specifics under the entries in the given
351 // path. 351 // path.
352 bool ValueHasSpecifics(const base::DictionaryValue& value, 352 bool ValueHasSpecifics(const base::DictionaryValue& value,
353 const std::string& path) { 353 const std::string& path) {
354 const base::ListValue* entities_list = NULL; 354 const base::ListValue* entities_list = NULL;
355 const base::DictionaryValue* entry_dictionary = NULL; 355 const base::DictionaryValue* entry_dictionary = NULL;
356 const base::DictionaryValue* specifics_dictionary = NULL; 356 const base::DictionaryValue* specifics_dictionary = NULL;
357 357
358 if (!value.GetList(path, &entities_list)) 358 if (!value.GetList(path, &entities_list))
359 return false; 359 return false;
360 360
361 if (!entities_list->GetDictionary(0, &entry_dictionary)) 361 if (!entities_list->GetDictionary(0, &entry_dictionary))
362 return false; 362 return false;
363 363
364 return entry_dictionary->GetDictionary("specifics", 364 return entry_dictionary->GetDictionary("specifics", &specifics_dictionary);
365 &specifics_dictionary);
366 } 365 }
367 } // namespace 366 } // namespace
368 367
369 // Create a ClientToServerMessage with an EntitySpecifics. Converting it to 368 // Create a ClientToServerMessage with an EntitySpecifics. Converting it to
370 // a value should respect the |include_specifics| flag. 369 // a value should respect the |include_specifics| flag.
371 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) { 370 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) {
372 sync_pb::ClientToServerMessage message; 371 sync_pb::ClientToServerMessage message;
373 sync_pb::CommitMessage* commit_message = message.mutable_commit(); 372 sync_pb::CommitMessage* commit_message = message.mutable_commit();
374 sync_pb::SyncEntity* entity = commit_message->add_entries(); 373 sync_pb::SyncEntity* entity = commit_message->add_entries();
375 entity->mutable_specifics(); 374 entity->mutable_specifics();
376 375
377 std::unique_ptr<base::DictionaryValue> value_with_specifics( 376 std::unique_ptr<base::DictionaryValue> value_with_specifics(
378 ClientToServerMessageToValue(message, true /* include_specifics */)); 377 ClientToServerMessageToValue(message, true /* include_specifics */));
379 EXPECT_FALSE(value_with_specifics->empty()); 378 EXPECT_FALSE(value_with_specifics->empty());
380 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()), 379 EXPECT_TRUE(
381 "commit.entries")); 380 ValueHasSpecifics(*(value_with_specifics.get()), "commit.entries"));
382 381
383 std::unique_ptr<base::DictionaryValue> value_without_specifics( 382 std::unique_ptr<base::DictionaryValue> value_without_specifics(
384 ClientToServerMessageToValue(message, false /* include_specifics */)); 383 ClientToServerMessageToValue(message, false /* include_specifics */));
385 EXPECT_FALSE(value_without_specifics->empty()); 384 EXPECT_FALSE(value_without_specifics->empty());
386 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 385 EXPECT_FALSE(
387 "commit.entries")); 386 ValueHasSpecifics(*(value_without_specifics.get()), "commit.entries"));
388 } 387 }
389 388
390 // Create a ClientToServerResponse with an EntitySpecifics. Converting it to 389 // Create a ClientToServerResponse with an EntitySpecifics. Converting it to
391 // a value should respect the |include_specifics| flag. 390 // a value should respect the |include_specifics| flag.
392 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) { 391 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) {
393 sync_pb::ClientToServerResponse message; 392 sync_pb::ClientToServerResponse message;
394 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates(); 393 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates();
395 sync_pb::SyncEntity* entity = response->add_entries(); 394 sync_pb::SyncEntity* entity = response->add_entries();
396 entity->mutable_specifics(); 395 entity->mutable_specifics();
397 396
398 std::unique_ptr<base::DictionaryValue> value_with_specifics( 397 std::unique_ptr<base::DictionaryValue> value_with_specifics(
399 ClientToServerResponseToValue(message, true /* include_specifics */)); 398 ClientToServerResponseToValue(message, true /* include_specifics */));
400 EXPECT_FALSE(value_with_specifics->empty()); 399 EXPECT_FALSE(value_with_specifics->empty());
401 EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()), 400 EXPECT_TRUE(
402 "get_updates.entries")); 401 ValueHasSpecifics(*(value_with_specifics.get()), "get_updates.entries"));
403 402
404 std::unique_ptr<base::DictionaryValue> value_without_specifics( 403 std::unique_ptr<base::DictionaryValue> value_without_specifics(
405 ClientToServerResponseToValue(message, false /* include_specifics */)); 404 ClientToServerResponseToValue(message, false /* include_specifics */));
406 EXPECT_FALSE(value_without_specifics->empty()); 405 EXPECT_FALSE(value_without_specifics->empty());
407 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 406 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
408 "get_updates.entries")); 407 "get_updates.entries"));
409 } 408 }
410 409
411 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) { 410 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) {
412 TestSpecificsToValue(AttachmentIdProtoToValue); 411 TestSpecificsToValue(AttachmentIdProtoToValue);
413 } 412 }
414 413
415 } // namespace 414 } // namespace
416 } // namespace syncer 415 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/protocol/proto_value_conversions.cc ('k') | components/sync/protocol/protocol.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698