OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/protocol/proto_value_conversions.h" | 7 #include "chrome/browser/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/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
13 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 13 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
14 #include "chrome/browser/sync/protocol/encryption.pb.h" | 14 #include "chrome/browser/sync/protocol/encryption.pb.h" |
15 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
16 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
17 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
18 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 19 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" |
19 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
20 #include "chrome/browser/sync/protocol/sync.pb.h" | 21 #include "chrome/browser/sync/protocol/sync.pb.h" |
21 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
22 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 23 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
23 #include "chrome/browser/sync/syncable/model_type.h" | 24 #include "chrome/browser/sync/syncable/model_type.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace browser_sync { | 27 namespace browser_sync { |
27 namespace { | 28 namespace { |
28 | 29 |
29 class ProtoValueConversionsTest : public testing::Test { | 30 class ProtoValueConversionsTest : public testing::Test { |
30 protected: | 31 protected: |
31 template <class T> | 32 template <class T> |
32 void TestSpecificsToValue( | 33 void TestSpecificsToValue( |
33 DictionaryValue* (*specifics_to_value)(const T&)) { | 34 DictionaryValue* (*specifics_to_value)(const T&)) { |
34 const T& specifics(T::default_instance()); | 35 const T& specifics(T::default_instance()); |
35 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); | 36 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); |
36 // We can't do much but make sure that the returned value has | 37 // We can't do much but make sure that the returned value has |
37 // something in it. | 38 // something in it. |
38 EXPECT_FALSE(value->empty()); | 39 EXPECT_FALSE(value->empty()); |
39 } | 40 } |
40 }; | 41 }; |
41 | 42 |
42 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { | 43 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { |
43 // If this number changes, that means we added or removed a data | 44 // If this number changes, that means we added or removed a data |
44 // type. Don't forget to add a unit test for {New | 45 // type. Don't forget to add a unit test for {New |
45 // type}SpecificsToValue below. | 46 // type}SpecificsToValue below. |
46 EXPECT_EQ(13, syncable::MODEL_TYPE_COUNT); | 47 EXPECT_EQ(14, syncable::MODEL_TYPE_COUNT); |
47 | 48 |
48 // We'd also like to check if we changed any field in our messages. | 49 // We'd also like to check if we changed any field in our messages. |
49 // However, that's hard to do: sizeof could work, but it's | 50 // However, that's hard to do: sizeof could work, but it's |
50 // platform-dependent. default_instance().ByteSize() won't change | 51 // platform-dependent. default_instance().ByteSize() won't change |
51 // for most changes, since most of our fields are optional. So we | 52 // for most changes, since most of our fields are optional. So we |
52 // just settle for comments in the proto files. | 53 // just settle for comments in the proto files. |
53 } | 54 } |
54 | 55 |
55 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { | 56 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { |
56 TestSpecificsToValue(EncryptedDataToValue); | 57 TestSpecificsToValue(EncryptedDataToValue); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 112 } |
112 | 113 |
113 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { | 114 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { |
114 TestSpecificsToValue(PasswordSpecificsToValue); | 115 TestSpecificsToValue(PasswordSpecificsToValue); |
115 } | 116 } |
116 | 117 |
117 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { | 118 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { |
118 TestSpecificsToValue(PreferenceSpecificsToValue); | 119 TestSpecificsToValue(PreferenceSpecificsToValue); |
119 } | 120 } |
120 | 121 |
| 122 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) { |
| 123 TestSpecificsToValue(SearchEngineSpecificsToValue); |
| 124 } |
| 125 |
121 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) { | 126 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) { |
122 TestSpecificsToValue(SessionSpecificsToValue); | 127 TestSpecificsToValue(SessionSpecificsToValue); |
123 } | 128 } |
124 | 129 |
125 TEST_F(ProtoValueConversionsTest, ThemeSpecificsToValue) { | 130 TEST_F(ProtoValueConversionsTest, ThemeSpecificsToValue) { |
126 TestSpecificsToValue(ThemeSpecificsToValue); | 131 TestSpecificsToValue(ThemeSpecificsToValue); |
127 } | 132 } |
128 | 133 |
129 TEST_F(ProtoValueConversionsTest, TypedUrlSpecificsToValue) { | 134 TEST_F(ProtoValueConversionsTest, TypedUrlSpecificsToValue) { |
130 TestSpecificsToValue(TypedUrlSpecificsToValue); | 135 TestSpecificsToValue(TypedUrlSpecificsToValue); |
131 } | 136 } |
132 | 137 |
133 // TODO(akalin): Figure out how to better test EntitySpecificsToValue. | 138 // TODO(akalin): Figure out how to better test EntitySpecificsToValue. |
134 | 139 |
135 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) { | 140 TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) { |
136 sync_pb::EntitySpecifics specifics; | 141 sync_pb::EntitySpecifics specifics; |
137 // Touch the extensions to make sure it shows up in the generated | 142 // Touch the extensions to make sure it shows up in the generated |
138 // value. | 143 // value. |
139 #define SET_EXTENSION(key) (void)specifics.MutableExtension(sync_pb::key) | 144 #define SET_EXTENSION(key) (void)specifics.MutableExtension(sync_pb::key) |
140 | 145 |
141 SET_EXTENSION(app); | 146 SET_EXTENSION(app); |
142 SET_EXTENSION(autofill); | 147 SET_EXTENSION(autofill); |
143 SET_EXTENSION(autofill_profile); | 148 SET_EXTENSION(autofill_profile); |
144 SET_EXTENSION(bookmark); | 149 SET_EXTENSION(bookmark); |
145 SET_EXTENSION(extension); | 150 SET_EXTENSION(extension); |
146 SET_EXTENSION(nigori); | 151 SET_EXTENSION(nigori); |
147 SET_EXTENSION(password); | 152 SET_EXTENSION(password); |
148 SET_EXTENSION(preference); | 153 SET_EXTENSION(preference); |
| 154 SET_EXTENSION(search_engine); |
149 SET_EXTENSION(session); | 155 SET_EXTENSION(session); |
150 SET_EXTENSION(theme); | 156 SET_EXTENSION(theme); |
151 SET_EXTENSION(typed_url); | 157 SET_EXTENSION(typed_url); |
152 | 158 |
153 #undef SET_EXTENSION | 159 #undef SET_EXTENSION |
154 | 160 |
155 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); | 161 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); |
156 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, | 162 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, |
157 static_cast<int>(value->size())); | 163 static_cast<int>(value->size())); |
158 } | 164 } |
159 | 165 |
160 } // namespace | 166 } // namespace |
161 } // namespace browser_sync | 167 } // namespace browser_sync |
OLD | NEW |