OLD | NEW |
| (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 #include "chrome/browser/sync/sessions/session_state.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/base64.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/test/values_test_util.h" | |
12 #include "base/time.h" | |
13 #include "base/values.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace browser_sync { | |
17 namespace sessions { | |
18 namespace { | |
19 | |
20 using base::ExpectDictBooleanValue; | |
21 using base::ExpectDictDictionaryValue; | |
22 using base::ExpectDictIntegerValue; | |
23 using base::ExpectDictListValue; | |
24 using base::ExpectDictStringValue; | |
25 | |
26 class SessionStateTest : public testing::Test {}; | |
27 | |
28 TEST_F(SessionStateTest, SyncSourceInfoToValue) { | |
29 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source = | |
30 sync_pb::GetUpdatesCallerInfo::PERIODIC; | |
31 syncable::ModelTypePayloadMap types; | |
32 types[syncable::PREFERENCES] = "preferencespayload"; | |
33 types[syncable::EXTENSIONS] = ""; | |
34 scoped_ptr<DictionaryValue> expected_types_value( | |
35 syncable::ModelTypePayloadMapToValue(types)); | |
36 | |
37 SyncSourceInfo source_info(updates_source, types); | |
38 | |
39 scoped_ptr<DictionaryValue> value(source_info.ToValue()); | |
40 EXPECT_EQ(2u, value->size()); | |
41 ExpectDictStringValue("PERIODIC", *value, "updatesSource"); | |
42 ExpectDictDictionaryValue(*expected_types_value, *value, "types"); | |
43 } | |
44 | |
45 TEST_F(SessionStateTest, SyncerStatusToValue) { | |
46 SyncerStatus status; | |
47 status.invalid_store = true; | |
48 status.num_successful_commits = 5; | |
49 status.num_successful_bookmark_commits = 10; | |
50 status.num_updates_downloaded_total = 100; | |
51 status.num_tombstone_updates_downloaded_total = 200; | |
52 status.num_local_overwrites = 15; | |
53 status.num_server_overwrites = 18; | |
54 | |
55 scoped_ptr<DictionaryValue> value(status.ToValue()); | |
56 EXPECT_EQ(7u, value->size()); | |
57 ExpectDictBooleanValue(status.invalid_store, *value, "invalidStore"); | |
58 ExpectDictIntegerValue(status.num_successful_commits, | |
59 *value, "numSuccessfulCommits"); | |
60 ExpectDictIntegerValue(status.num_successful_bookmark_commits, | |
61 *value, "numSuccessfulBookmarkCommits"); | |
62 ExpectDictIntegerValue(status.num_updates_downloaded_total, | |
63 *value, "numUpdatesDownloadedTotal"); | |
64 ExpectDictIntegerValue(status.num_tombstone_updates_downloaded_total, | |
65 *value, "numTombstoneUpdatesDownloadedTotal"); | |
66 ExpectDictIntegerValue(status.num_local_overwrites, | |
67 *value, "numLocalOverwrites"); | |
68 ExpectDictIntegerValue(status.num_server_overwrites, | |
69 *value, "numServerOverwrites"); | |
70 } | |
71 | |
72 TEST_F(SessionStateTest, DownloadProgressMarkersToValue) { | |
73 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; | |
74 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
75 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
76 std::string marker(i, i); | |
77 download_progress_markers[i] = marker; | |
78 } | |
79 | |
80 scoped_ptr<DictionaryValue> value( | |
81 DownloadProgressMarkersToValue(download_progress_markers)); | |
82 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, | |
83 static_cast<int>(value->size())); | |
84 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
85 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
86 syncable::ModelType model_type = syncable::ModelTypeFromInt(i); | |
87 std::string marker(i, i); | |
88 std::string expected_value; | |
89 EXPECT_TRUE(base::Base64Encode(marker, &expected_value)); | |
90 ExpectDictStringValue(expected_value, | |
91 *value, syncable::ModelTypeToString(model_type)); | |
92 } | |
93 } | |
94 | |
95 TEST_F(SessionStateTest, SyncSessionSnapshotToValue) { | |
96 SyncerStatus syncer_status; | |
97 syncer_status.num_successful_commits = 500; | |
98 scoped_ptr<DictionaryValue> expected_syncer_status_value( | |
99 syncer_status.ToValue()); | |
100 | |
101 ErrorCounters errors; | |
102 | |
103 const int kNumServerChangesRemaining = 105; | |
104 const bool kIsShareUsable = true; | |
105 | |
106 const syncable::ModelTypeSet initial_sync_ended( | |
107 syncable::BOOKMARKS, syncable::PREFERENCES); | |
108 scoped_ptr<ListValue> expected_initial_sync_ended_value( | |
109 syncable::ModelTypeSetToValue(initial_sync_ended)); | |
110 | |
111 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; | |
112 download_progress_markers[syncable::BOOKMARKS] = "test"; | |
113 download_progress_markers[syncable::APPS] = "apps"; | |
114 scoped_ptr<DictionaryValue> expected_download_progress_markers_value( | |
115 DownloadProgressMarkersToValue(download_progress_markers)); | |
116 | |
117 const bool kHasMoreToSync = false; | |
118 const bool kIsSilenced = true; | |
119 const int kUnsyncedCount = 1053; | |
120 const int kNumEncryptionConflicts = 1054; | |
121 const int kNumHierarchyConflicts = 1055; | |
122 const int kNumSimpleConflicts = 1056; | |
123 const int kNumServerConflicts = 1057; | |
124 const bool kDidCommitItems = true; | |
125 | |
126 SyncSourceInfo source; | |
127 scoped_ptr<DictionaryValue> expected_source_value(source.ToValue()); | |
128 | |
129 SyncSessionSnapshot snapshot(syncer_status, | |
130 errors, | |
131 kNumServerChangesRemaining, | |
132 kIsShareUsable, | |
133 initial_sync_ended, | |
134 download_progress_markers, | |
135 kHasMoreToSync, | |
136 kIsSilenced, | |
137 kUnsyncedCount, | |
138 kNumEncryptionConflicts, | |
139 kNumHierarchyConflicts, | |
140 kNumSimpleConflicts, | |
141 kNumServerConflicts, | |
142 kDidCommitItems, | |
143 source, | |
144 0, | |
145 base::Time::Now(), | |
146 false); | |
147 scoped_ptr<DictionaryValue> value(snapshot.ToValue()); | |
148 EXPECT_EQ(15u, value->size()); | |
149 ExpectDictDictionaryValue(*expected_syncer_status_value, *value, | |
150 "syncerStatus"); | |
151 ExpectDictIntegerValue(kNumServerChangesRemaining, *value, | |
152 "numServerChangesRemaining"); | |
153 ExpectDictBooleanValue(kIsShareUsable, *value, "isShareUsable"); | |
154 ExpectDictListValue(*expected_initial_sync_ended_value, *value, | |
155 "initialSyncEnded"); | |
156 ExpectDictDictionaryValue(*expected_download_progress_markers_value, | |
157 *value, "downloadProgressMarkers"); | |
158 ExpectDictBooleanValue(kHasMoreToSync, *value, "hasMoreToSync"); | |
159 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced"); | |
160 ExpectDictIntegerValue(kUnsyncedCount, *value, "unsyncedCount"); | |
161 ExpectDictIntegerValue(kNumEncryptionConflicts, *value, | |
162 "numEncryptionConflicts"); | |
163 ExpectDictIntegerValue(kNumHierarchyConflicts, *value, | |
164 "numHierarchyConflicts"); | |
165 ExpectDictIntegerValue(kNumSimpleConflicts, *value, | |
166 "numSimpleConflicts"); | |
167 ExpectDictIntegerValue(kNumServerConflicts, *value, | |
168 "numServerConflicts"); | |
169 ExpectDictBooleanValue(kDidCommitItems, *value, | |
170 "didCommitItems"); | |
171 ExpectDictDictionaryValue(*expected_source_value, *value, "source"); | |
172 } | |
173 | |
174 } // namespace | |
175 } // namespace sessions | |
176 } // namespace browser_sync | |
OLD | NEW |