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

Side by Side Diff: sync/syncable/model_type_unittest.cc

Issue 1413233003: Organizing model type, notification type, root tag and model type string in map. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« sync/syncable/model_type.cc ('K') | « sync/syncable/model_type.cc ('k') | no next file » | 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 #include "sync/internal_api/public/base/model_type.h" 5 #include "sync/internal_api/public/base/model_type.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h"
10 #include "base/test/values_test_util.h" 11 #include "base/test/values_test_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "sync/protocol/sync.pb.h" 13 #include "sync/protocol/sync.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace syncer { 16 namespace syncer {
16 namespace { 17 namespace {
17 18
18 class ModelTypeTest : public testing::Test {}; 19 class ModelTypeTest : public testing::Test {};
19 20
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 EXPECT_TRUE(specifics.SerializeToString(&tmp)); 138 EXPECT_TRUE(specifics.SerializeToString(&tmp));
138 139
139 sync_pb::EntitySpecifics from_string; 140 sync_pb::EntitySpecifics from_string;
140 EXPECT_TRUE(from_string.ParseFromString(tmp)); 141 EXPECT_TRUE(from_string.ParseFromString(tmp));
141 EXPECT_TRUE(from_string.IsInitialized()); 142 EXPECT_TRUE(from_string.IsInitialized());
142 143
143 EXPECT_EQ(it.Get(), syncer::GetModelTypeFromSpecifics(from_string)); 144 EXPECT_EQ(it.Get(), syncer::GetModelTypeFromSpecifics(from_string));
144 } 145 }
145 } 146 }
146 147
148 TEST_F(ModelTypeTest, ModelTypeToRootTagValues) {
149 ModelTypeSet all_types = ModelTypeSet::All();
150 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
151 ModelType model_type = it.Get();
152 std::string root_tag = ModelTypeToRootTag(model_type);
153 if (IsProxyType(model_type)) {
154 EXPECT_EQ(root_tag, std::string());
155 } else if (IsRealDataType(model_type)) {
156 EXPECT_TRUE(base::StartsWith(root_tag, "google_chrome_",
157 base::CompareCase::INSENSITIVE_ASCII));
158 } else {
159 EXPECT_EQ(root_tag, "INVALID");
160 }
161 }
162 }
163
164 TEST_F(ModelTypeTest, ModelTypeStingMapping) {
Nicolas Zea 2015/10/29 22:50:43 nit: ModelTypeStingMapping -> ModelTypeStringMappi
Deepak 2015/10/30 05:27:34 Done.
165 ModelTypeSet all_types = ModelTypeSet::All();
166 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
167 ModelType model_type = it.Get();
168 const char* model_type_string = ModelTypeToString(model_type);
169 ModelType converted_model_type = ModelTypeFromString(model_type_string);
170 if (IsRealDataType(model_type))
171 EXPECT_EQ(converted_model_type, model_type);
172 else
173 EXPECT_EQ(converted_model_type, UNSPECIFIED);
174 }
175 }
176
177 TEST_F(ModelTypeTest, ModelTypeNotificationTypeMapping) {
178 ModelTypeSet all_types = ModelTypeSet::All();
179 for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
180 ModelType model_type = it.Get();
181 std::string notification_type;
182 bool ret = RealModelTypeToNotificationType(model_type, &notification_type);
183 if (ret) {
184 ModelType notified_model_type;
185 EXPECT_TRUE(NotificationTypeToRealModelType(notification_type,
186 &notified_model_type));
187 EXPECT_EQ(notified_model_type, model_type);
188 } else {
189 EXPECT_FALSE(ProtocolTypes().Has(model_type));
190 EXPECT_TRUE(notification_type.empty());
191 }
192 }
193 }
194
147 } // namespace 195 } // namespace
148 } // namespace syncer 196 } // namespace syncer
OLDNEW
« sync/syncable/model_type.cc ('K') | « sync/syncable/model_type.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698