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

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

Issue 674633002: sync: add WIFI_CREDENTIALS protobuf, ModelType, and preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@local-master
Patch Set: Created 6 years, 2 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 "sync/protocol/proto_value_conversions.h"
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 19 matching lines...) Expand all
30 #include "sync/protocol/managed_user_specifics.pb.h" 30 #include "sync/protocol/managed_user_specifics.pb.h"
31 #include "sync/protocol/nigori_specifics.pb.h" 31 #include "sync/protocol/nigori_specifics.pb.h"
32 #include "sync/protocol/password_specifics.pb.h" 32 #include "sync/protocol/password_specifics.pb.h"
33 #include "sync/protocol/preference_specifics.pb.h" 33 #include "sync/protocol/preference_specifics.pb.h"
34 #include "sync/protocol/priority_preference_specifics.pb.h" 34 #include "sync/protocol/priority_preference_specifics.pb.h"
35 #include "sync/protocol/search_engine_specifics.pb.h" 35 #include "sync/protocol/search_engine_specifics.pb.h"
36 #include "sync/protocol/session_specifics.pb.h" 36 #include "sync/protocol/session_specifics.pb.h"
37 #include "sync/protocol/sync.pb.h" 37 #include "sync/protocol/sync.pb.h"
38 #include "sync/protocol/theme_specifics.pb.h" 38 #include "sync/protocol/theme_specifics.pb.h"
39 #include "sync/protocol/typed_url_specifics.pb.h" 39 #include "sync/protocol/typed_url_specifics.pb.h"
40 #include "sync/protocol/wifi_credential_specifics.pb.h"
40 #include "sync/util/time.h" 41 #include "sync/util/time.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 43
43 namespace syncer { 44 namespace syncer {
44 namespace { 45 namespace {
45 46
46 class ProtoValueConversionsTest : public testing::Test { 47 class ProtoValueConversionsTest : public testing::Test {
47 protected: 48 protected:
48 template <class T> 49 template <class T>
49 void TestSpecificsToValue( 50 void TestSpecificsToValue(
50 base::DictionaryValue* (*specifics_to_value)(const T&)) { 51 base::DictionaryValue* (*specifics_to_value)(const T&)) {
51 const T& specifics(T::default_instance()); 52 const T& specifics(T::default_instance());
52 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics)); 53 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics));
53 // We can't do much but make sure that this doesn't crash. 54 // We can't do much but make sure that this doesn't crash.
54 } 55 }
55 }; 56 };
56 57
57 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { 58 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
58 // If this number changes, that means we added or removed a data 59 // If this number changes, that means we added or removed a data
59 // type. Don't forget to add a unit test for {New 60 // type. Don't forget to add a unit test for {New
60 // type}SpecificsToValue below. 61 // type}SpecificsToValue below.
61 EXPECT_EQ(33, MODEL_TYPE_COUNT); 62 EXPECT_EQ(34, MODEL_TYPE_COUNT);
62 63
63 // We'd also like to check if we changed any field in our messages. 64 // We'd also like to check if we changed any field in our messages.
64 // However, that's hard to do: sizeof could work, but it's 65 // However, that's hard to do: sizeof could work, but it's
65 // platform-dependent. default_instance().ByteSize() won't change 66 // platform-dependent. default_instance().ByteSize() won't change
66 // for most changes, since most of our fields are optional. So we 67 // for most changes, since most of our fields are optional. So we
67 // just settle for comments in the proto files. 68 // just settle for comments in the proto files.
68 } 69 }
69 70
70 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { 71 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) {
71 TestSpecificsToValue(EncryptedDataToValue); 72 TestSpecificsToValue(EncryptedDataToValue);
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 501 }
501 502
502 TEST_F(ProtoValueConversionsTest, DictionarySpecificsToValue) { 503 TEST_F(ProtoValueConversionsTest, DictionarySpecificsToValue) {
503 TestSpecificsToValue(DictionarySpecificsToValue); 504 TestSpecificsToValue(DictionarySpecificsToValue);
504 } 505 }
505 506
506 TEST_F(ProtoValueConversionsTest, ArticleSpecificsToValue) { 507 TEST_F(ProtoValueConversionsTest, ArticleSpecificsToValue) {
507 TestSpecificsToValue(ArticleSpecificsToValue); 508 TestSpecificsToValue(ArticleSpecificsToValue);
508 } 509 }
509 510
511 TEST_F(ProtoValueConversionsTest, WifiCredentialSpecificsToValue) {
512 TestSpecificsToValue(WifiCredentialSpecificsToValue);
513 }
514
510 // TODO(akalin): Figure out how to better test EntitySpecificsToValue. 515 // TODO(akalin): Figure out how to better test EntitySpecificsToValue.
511 516
512 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) { 517 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
513 sync_pb::EntitySpecifics specifics; 518 sync_pb::EntitySpecifics specifics;
514 // Touch the extensions to make sure it shows up in the generated 519 // Touch the extensions to make sure it shows up in the generated
515 // value. 520 // value.
516 #define SET_FIELD(key) (void)specifics.mutable_##key() 521 #define SET_FIELD(key) (void)specifics.mutable_##key()
517 522
518 SET_FIELD(app); 523 SET_FIELD(app);
519 SET_FIELD(app_list); 524 SET_FIELD(app_list);
(...skipping 18 matching lines...) Expand all
538 SET_FIELD(nigori); 543 SET_FIELD(nigori);
539 SET_FIELD(password); 544 SET_FIELD(password);
540 SET_FIELD(preference); 545 SET_FIELD(preference);
541 SET_FIELD(priority_preference); 546 SET_FIELD(priority_preference);
542 SET_FIELD(search_engine); 547 SET_FIELD(search_engine);
543 SET_FIELD(session); 548 SET_FIELD(session);
544 SET_FIELD(synced_notification); 549 SET_FIELD(synced_notification);
545 SET_FIELD(synced_notification_app_info); 550 SET_FIELD(synced_notification_app_info);
546 SET_FIELD(theme); 551 SET_FIELD(theme);
547 SET_FIELD(typed_url); 552 SET_FIELD(typed_url);
553 SET_FIELD(wifi_credential);
548 554
549 #undef SET_FIELD 555 #undef SET_FIELD
550 556
551 scoped_ptr<base::DictionaryValue> value(EntitySpecificsToValue(specifics)); 557 scoped_ptr<base::DictionaryValue> value(EntitySpecificsToValue(specifics));
552 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE - 558 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE -
553 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1), 559 (LAST_PROXY_TYPE - FIRST_PROXY_TYPE + 1),
554 static_cast<int>(value->size())); 560 static_cast<int>(value->size()));
555 } 561 }
556 562
557 namespace { 563 namespace {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 621 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
616 "get_updates.entries")); 622 "get_updates.entries"));
617 } 623 }
618 624
619 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) { 625 TEST_F(ProtoValueConversionsTest, AttachmentIdProtoToValue) {
620 TestSpecificsToValue(AttachmentIdProtoToValue); 626 TestSpecificsToValue(AttachmentIdProtoToValue);
621 } 627 }
622 628
623 } // namespace 629 } // namespace
624 } // namespace syncer 630 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698