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

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

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Keep this file in sync with the .proto files in this directory.
6
7 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "chrome/browser/sync/syncable/model_type.h"
12 #include "sync/protocol/app_notification_specifics.pb.h"
13 #include "sync/protocol/app_setting_specifics.pb.h"
14 #include "sync/protocol/app_specifics.pb.h"
15 #include "sync/protocol/autofill_specifics.pb.h"
16 #include "sync/protocol/bookmark_specifics.pb.h"
17 #include "sync/protocol/encryption.pb.h"
18 #include "sync/protocol/extension_setting_specifics.pb.h"
19 #include "sync/protocol/extension_specifics.pb.h"
20 #include "sync/protocol/nigori_specifics.pb.h"
21 #include "sync/protocol/password_specifics.pb.h"
22 #include "sync/protocol/preference_specifics.pb.h"
23 #include "sync/protocol/search_engine_specifics.pb.h"
24 #include "sync/protocol/session_specifics.pb.h"
25 #include "sync/protocol/sync.pb.h"
26 #include "sync/protocol/theme_specifics.pb.h"
27 #include "sync/protocol/typed_url_specifics.pb.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29
30 namespace browser_sync {
31 namespace {
32
33 class ProtoValueConversionsTest : public testing::Test {
34 protected:
35 template <class T>
36 void TestSpecificsToValue(
37 DictionaryValue* (*specifics_to_value)(const T&)) {
38 const T& specifics(T::default_instance());
39 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics));
40 // We can't do much but make sure that the returned value has
41 // something in it.
42 EXPECT_FALSE(value->empty());
43 }
44 };
45
46 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
47 // If this number changes, that means we added or removed a data
48 // type. Don't forget to add a unit test for {New
49 // type}SpecificsToValue below.
50 EXPECT_EQ(17, syncable::MODEL_TYPE_COUNT);
51
52 // We'd also like to check if we changed any field in our messages.
53 // However, that's hard to do: sizeof could work, but it's
54 // platform-dependent. default_instance().ByteSize() won't change
55 // for most changes, since most of our fields are optional. So we
56 // just settle for comments in the proto files.
57 }
58
59 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) {
60 TestSpecificsToValue(EncryptedDataToValue);
61 }
62
63 TEST_F(ProtoValueConversionsTest, SessionHeaderToValue) {
64 TestSpecificsToValue(SessionHeaderToValue);
65 }
66
67 TEST_F(ProtoValueConversionsTest, SessionTabToValue) {
68 TestSpecificsToValue(SessionTabToValue);
69 }
70
71 TEST_F(ProtoValueConversionsTest, SessionWindowToValue) {
72 TestSpecificsToValue(SessionWindowToValue);
73 }
74
75 TEST_F(ProtoValueConversionsTest, TabNavigationToValue) {
76 TestSpecificsToValue(TabNavigationToValue);
77 }
78
79 TEST_F(ProtoValueConversionsTest, PasswordSpecificsData) {
80 sync_pb::PasswordSpecificsData specifics;
81 specifics.set_password_value("secret");
82 scoped_ptr<DictionaryValue> value(PasswordSpecificsDataToValue(specifics));
83 EXPECT_FALSE(value->empty());
84 std::string password_value;
85 EXPECT_TRUE(value->GetString("password_value", &password_value));
86 EXPECT_EQ("<redacted>", password_value);
87 }
88
89 TEST_F(ProtoValueConversionsTest, AppNotificationToValue) {
90 TestSpecificsToValue(AppNotificationToValue);
91 }
92
93 TEST_F(ProtoValueConversionsTest, AppSettingSpecificsToValue) {
94 sync_pb::AppNotificationSettings specifics;
95 specifics.set_disabled(true);
96 specifics.set_oauth_client_id("some_id_value");
97 scoped_ptr<DictionaryValue> value(AppSettingsToValue(specifics));
98 EXPECT_FALSE(value->empty());
99 bool disabled_value = false;
100 std::string oauth_client_id_value;
101 EXPECT_TRUE(value->GetBoolean("disabled", &disabled_value));
102 EXPECT_EQ(true, disabled_value);
103 EXPECT_TRUE(value->GetString("oauth_client_id", &oauth_client_id_value));
104 EXPECT_EQ("some_id_value", oauth_client_id_value);
105 }
106
107 TEST_F(ProtoValueConversionsTest, AppSpecificsToValue) {
108 TestSpecificsToValue(AppSpecificsToValue);
109 }
110
111 TEST_F(ProtoValueConversionsTest, AutofillSpecificsToValue) {
112 TestSpecificsToValue(AutofillSpecificsToValue);
113 }
114
115 TEST_F(ProtoValueConversionsTest, AutofillProfileSpecificsToValue) {
116 TestSpecificsToValue(AutofillProfileSpecificsToValue);
117 }
118
119 TEST_F(ProtoValueConversionsTest, BookmarkSpecificsToValue) {
120 TestSpecificsToValue(BookmarkSpecificsToValue);
121 }
122
123 TEST_F(ProtoValueConversionsTest, ExtensionSettingSpecificsToValue) {
124 TestSpecificsToValue(ExtensionSettingSpecificsToValue);
125 }
126
127 TEST_F(ProtoValueConversionsTest, ExtensionSpecificsToValue) {
128 TestSpecificsToValue(ExtensionSpecificsToValue);
129 }
130
131 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) {
132 TestSpecificsToValue(NigoriSpecificsToValue);
133 }
134
135 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) {
136 TestSpecificsToValue(PasswordSpecificsToValue);
137 }
138
139 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) {
140 TestSpecificsToValue(PreferenceSpecificsToValue);
141 }
142
143 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) {
144 TestSpecificsToValue(SearchEngineSpecificsToValue);
145 }
146
147 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) {
148 TestSpecificsToValue(SessionSpecificsToValue);
149 }
150
151 TEST_F(ProtoValueConversionsTest, ThemeSpecificsToValue) {
152 TestSpecificsToValue(ThemeSpecificsToValue);
153 }
154
155 TEST_F(ProtoValueConversionsTest, TypedUrlSpecificsToValue) {
156 TestSpecificsToValue(TypedUrlSpecificsToValue);
157 }
158
159 // TODO(akalin): Figure out how to better test EntitySpecificsToValue.
160
161 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
162 sync_pb::EntitySpecifics specifics;
163 // Touch the extensions to make sure it shows up in the generated
164 // value.
165 #define SET_FIELD(key) (void)specifics.mutable_##key()
166
167 SET_FIELD(app);
168 SET_FIELD(app_notification);
169 SET_FIELD(app_setting);
170 SET_FIELD(autofill);
171 SET_FIELD(autofill_profile);
172 SET_FIELD(bookmark);
173 SET_FIELD(extension);
174 SET_FIELD(extension_setting);
175 SET_FIELD(nigori);
176 SET_FIELD(password);
177 SET_FIELD(preference);
178 SET_FIELD(search_engine);
179 SET_FIELD(session);
180 SET_FIELD(theme);
181 SET_FIELD(typed_url);
182
183 #undef SET_FIELD
184
185 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics));
186 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE,
187 static_cast<int>(value->size()));
188 }
189
190 } // namespace
191 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/protocol/proto_value_conversions.cc ('k') | chrome/browser/sync/protocol/service_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698