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

Side by Side Diff: chrome/browser/sync/api/sync_event_unittest.cc

Issue 6995008: Implement new SyncAPI and convert Preferences to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Foward Declare++ Created 9 years, 7 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) 2011 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 #include "chrome/browser/sync/api/sync_event.h"
6
7 #include <string>
8
9 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "chrome/browser/sync/protocol/preference_specifics.pb.h"
12 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
13
14 using browser_sync::EntitySpecificsToValue;
15
16 namespace {
17
18 typedef testing::Test SyncEventTest;
19
20 TEST_F(SyncEventTest, LocalDelete) {
21 SyncEvent::SyncEventType event_type = SyncEvent::ACTION_DELETE;
22 std::string tag = "client_tag";
23 SyncEvent e(event_type,
24 SyncData::CreateLocalData(tag));
25 EXPECT_EQ(event_type, e.event_type());
26 EXPECT_EQ(tag, e.sync_data().GetTag());
27 EXPECT_EQ(syncable::UNSPECIFIED, e.sync_data().GetDataType());
28 }
29
30 TEST_F(SyncEventTest, LocalUpdate) {
31 SyncEvent::SyncEventType event_type = SyncEvent::ACTION_UPDATE;
32 sync_pb::EntitySpecifics specifics;
33 sync_pb::PreferenceSpecifics* pref_specifics =
34 specifics.MutableExtension(sync_pb::preference);
35 pref_specifics->set_name("test");
36 std::string tag = "client_tag";
37 SyncEvent e(event_type,
38 SyncData::CreateLocalData(tag, specifics));
39 EXPECT_EQ(event_type, e.event_type());
40 EXPECT_EQ(tag, e.sync_data().GetTag());
41 EXPECT_EQ(syncable::PREFERENCES, e.sync_data().GetDataType());
42 scoped_ptr<DictionaryValue> ref_spec(EntitySpecificsToValue(specifics));
43 scoped_ptr<DictionaryValue> e_spec(EntitySpecificsToValue(
44 e.sync_data().GetSpecifics()));
45 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
46 }
47
48 TEST_F(SyncEventTest, LocalAdd) {
49 SyncEvent::SyncEventType event_type = SyncEvent::ACTION_ADD;
50 sync_pb::EntitySpecifics specifics;
51 sync_pb::PreferenceSpecifics* pref_specifics =
52 specifics.MutableExtension(sync_pb::preference);
53 pref_specifics->set_name("test");
54 std::string tag = "client_tag";
55 SyncEvent e(event_type,
56 SyncData::CreateLocalData(tag, specifics));
57 EXPECT_EQ(event_type, e.event_type());
58 EXPECT_EQ(tag, e.sync_data().GetTag());
59 EXPECT_EQ(syncable::PREFERENCES, e.sync_data().GetDataType());
60 scoped_ptr<DictionaryValue> ref_spec(EntitySpecificsToValue(specifics));
61 scoped_ptr<DictionaryValue> e_spec(EntitySpecificsToValue(
62 e.sync_data().GetSpecifics()));
63 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
64 }
65
66 TEST_F(SyncEventTest, SyncerEvents) {
67 SyncEventList event_list;
68
69 // Create an update.
70 sync_pb::EntitySpecifics update_specifics;
71 sync_pb::PreferenceSpecifics* pref_specifics =
72 update_specifics.MutableExtension(sync_pb::preference);
73 pref_specifics->set_name("update");
74 event_list.push_back(SyncEvent(
75 SyncEvent::ACTION_UPDATE,
76 SyncData::CreateRemoteData(update_specifics)));
77
78 // Create an add.
79 sync_pb::EntitySpecifics add_specifics;
80 pref_specifics =
81 add_specifics.MutableExtension(sync_pb::preference);
82 pref_specifics->set_name("add");
83 event_list.push_back(SyncEvent(
84 SyncEvent::ACTION_ADD,
85 SyncData::CreateRemoteData(add_specifics)));
86
87 // Create a delete.
88 sync_pb::EntitySpecifics delete_specifics;
89 pref_specifics =
90 delete_specifics.MutableExtension(sync_pb::preference);
91 pref_specifics->set_name("add");
92 event_list.push_back(SyncEvent(
93 SyncEvent::ACTION_DELETE,
94 SyncData::CreateRemoteData(delete_specifics)));
95
96 ASSERT_EQ(3U, event_list.size());
97
98 // Verify update.
99 SyncEvent e = event_list[0];
100 EXPECT_EQ(SyncEvent::ACTION_UPDATE, e.event_type());
101 EXPECT_EQ(syncable::PREFERENCES, e.sync_data().GetDataType());
102 scoped_ptr<DictionaryValue> ref_spec(EntitySpecificsToValue(
103 update_specifics));
104 scoped_ptr<DictionaryValue> e_spec(EntitySpecificsToValue(
105 e.sync_data().GetSpecifics()));
106 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
107
108 // Verify add.
109 e = event_list[1];
110 EXPECT_EQ(SyncEvent::ACTION_ADD, e.event_type());
111 EXPECT_EQ(syncable::PREFERENCES, e.sync_data().GetDataType());
112 ref_spec.reset(EntitySpecificsToValue(add_specifics));
113 e_spec.reset(EntitySpecificsToValue(e.sync_data().GetSpecifics()));
114 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
115
116 // Verify delete.
117 e = event_list[2];
118 EXPECT_EQ(SyncEvent::ACTION_DELETE, e.event_type());
119 EXPECT_EQ(syncable::PREFERENCES, e.sync_data().GetDataType());
120 ref_spec.reset(EntitySpecificsToValue(delete_specifics));
121 e_spec.reset(EntitySpecificsToValue(e.sync_data().GetSpecifics()));
122 EXPECT_TRUE(ref_spec->Equals(e_spec.get()));
123 }
124
125 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698