OLD | NEW |
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/sessions/session_state.h" | 5 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
6 | 6 |
7 #include <string> | |
8 | |
9 #include "base/base64.h" | |
10 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
11 #include "base/test/values_test_util.h" | 8 #include "base/test/values_test_util.h" |
12 #include "base/time.h" | |
13 #include "base/values.h" | 9 #include "base/values.h" |
14 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | |
15 #include "sync/internal_api/public/sessions/sync_source_info.h" | 10 #include "sync/internal_api/public/sessions/sync_source_info.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
17 | 12 |
18 namespace syncer { | 13 namespace syncer { |
19 namespace sessions { | 14 namespace sessions { |
20 namespace { | 15 namespace { |
21 | 16 |
22 using base::ExpectDictBooleanValue; | 17 using base::ExpectDictBooleanValue; |
23 using base::ExpectDictDictionaryValue; | 18 using base::ExpectDictDictionaryValue; |
24 using base::ExpectDictIntegerValue; | 19 using base::ExpectDictIntegerValue; |
25 using base::ExpectDictListValue; | 20 using base::ExpectDictListValue; |
26 using base::ExpectDictStringValue; | 21 using base::ExpectDictStringValue; |
27 | 22 |
28 class SessionStateTest : public testing::Test {}; | 23 class SyncSessionSnapshotTest : public testing::Test {}; |
29 | 24 |
30 TEST_F(SessionStateTest, SyncSourceInfoToValue) { | 25 TEST_F(SyncSessionSnapshotTest, SyncSessionSnapshotToValue) { |
31 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source = | |
32 sync_pb::GetUpdatesCallerInfo::PERIODIC; | |
33 ModelTypeInvalidationMap types; | |
34 types[PREFERENCES].payload = "preferencespayload"; | |
35 types[EXTENSIONS].payload = ""; | |
36 scoped_ptr<DictionaryValue> expected_types_value( | |
37 ModelTypeInvalidationMapToValue(types)); | |
38 | |
39 SyncSourceInfo source_info(updates_source, types); | |
40 | |
41 scoped_ptr<DictionaryValue> value(source_info.ToValue()); | |
42 EXPECT_EQ(2u, value->size()); | |
43 ExpectDictStringValue("PERIODIC", *value, "updatesSource"); | |
44 ExpectDictDictionaryValue(*expected_types_value, *value, "types"); | |
45 } | |
46 | |
47 TEST_F(SessionStateTest, SyncSessionSnapshotToValue) { | |
48 ModelNeutralState model_neutral; | 26 ModelNeutralState model_neutral; |
49 model_neutral.num_server_changes_remaining = 105; | 27 model_neutral.num_server_changes_remaining = 105; |
50 model_neutral.num_successful_commits = 5; | 28 model_neutral.num_successful_commits = 5; |
51 model_neutral.num_successful_bookmark_commits = 10; | 29 model_neutral.num_successful_bookmark_commits = 10; |
52 model_neutral.num_updates_downloaded_total = 100; | 30 model_neutral.num_updates_downloaded_total = 100; |
53 model_neutral.num_tombstone_updates_downloaded_total = 200; | 31 model_neutral.num_tombstone_updates_downloaded_total = 200; |
54 model_neutral.num_reflected_updates_downloaded_total = 50; | 32 model_neutral.num_reflected_updates_downloaded_total = 50; |
55 model_neutral.num_local_overwrites = 15; | 33 model_neutral.num_local_overwrites = 15; |
56 model_neutral.num_server_overwrites = 18; | 34 model_neutral.num_server_overwrites = 18; |
57 | 35 |
58 const bool kIsShareUsable = true; | 36 const bool kIsShareUsable = true; |
59 | 37 |
60 const ModelTypeSet initial_sync_ended(BOOKMARKS, PREFERENCES); | 38 const ModelTypeSet initial_sync_ended(BOOKMARKS, PREFERENCES); |
61 scoped_ptr<ListValue> expected_initial_sync_ended_value( | 39 scoped_ptr<ListValue> expected_initial_sync_ended_value( |
62 ModelTypeSetToValue(initial_sync_ended)); | 40 ModelTypeSetToValue(initial_sync_ended)); |
63 | 41 |
64 ProgressMarkerMap download_progress_markers; | 42 ProgressMarkerMap download_progress_markers; |
65 download_progress_markers[BOOKMARKS] = "test"; | 43 download_progress_markers[BOOKMARKS] = "test"; |
66 download_progress_markers[APPS] = "apps"; | 44 download_progress_markers[APPS] = "apps"; |
67 scoped_ptr<DictionaryValue> expected_download_progress_markers_value( | 45 scoped_ptr<DictionaryValue> expected_download_progress_markers_value( |
68 ProgressMarkerMapToValue(download_progress_markers)); | 46 ProgressMarkerMapToValue(download_progress_markers)); |
69 | 47 |
70 const bool kHasMoreToSync = false; | |
71 const bool kIsSilenced = true; | 48 const bool kIsSilenced = true; |
72 const int kNumEncryptionConflicts = 1054; | 49 const int kNumEncryptionConflicts = 1054; |
73 const int kNumHierarchyConflicts = 1055; | 50 const int kNumHierarchyConflicts = 1055; |
74 const int kNumSimpleConflicts = 1056; | |
75 const int kNumServerConflicts = 1057; | 51 const int kNumServerConflicts = 1057; |
76 | 52 |
77 SyncSourceInfo source; | 53 SyncSourceInfo source; |
78 scoped_ptr<DictionaryValue> expected_source_value(source.ToValue()); | 54 scoped_ptr<DictionaryValue> expected_source_value(source.ToValue()); |
79 | 55 |
80 SyncSessionSnapshot snapshot(model_neutral, | 56 SyncSessionSnapshot snapshot(model_neutral, |
81 kIsShareUsable, | 57 kIsShareUsable, |
82 initial_sync_ended, | 58 initial_sync_ended, |
83 download_progress_markers, | 59 download_progress_markers, |
84 kHasMoreToSync, | |
85 kIsSilenced, | 60 kIsSilenced, |
86 kNumEncryptionConflicts, | 61 kNumEncryptionConflicts, |
87 kNumHierarchyConflicts, | 62 kNumHierarchyConflicts, |
88 kNumSimpleConflicts, | |
89 kNumServerConflicts, | 63 kNumServerConflicts, |
90 source, | 64 source, |
91 false, | 65 false, |
92 0, | 66 0, |
93 base::Time::Now()); | 67 base::Time::Now()); |
94 scoped_ptr<DictionaryValue> value(snapshot.ToValue()); | 68 scoped_ptr<DictionaryValue> value(snapshot.ToValue()); |
95 EXPECT_EQ(20u, value->size()); | 69 EXPECT_EQ(18u, value->size()); |
96 ExpectDictIntegerValue(model_neutral.num_successful_commits, | 70 ExpectDictIntegerValue(model_neutral.num_successful_commits, |
97 *value, "numSuccessfulCommits"); | 71 *value, "numSuccessfulCommits"); |
98 ExpectDictIntegerValue(model_neutral.num_successful_bookmark_commits, | 72 ExpectDictIntegerValue(model_neutral.num_successful_bookmark_commits, |
99 *value, "numSuccessfulBookmarkCommits"); | 73 *value, "numSuccessfulBookmarkCommits"); |
100 ExpectDictIntegerValue(model_neutral.num_updates_downloaded_total, | 74 ExpectDictIntegerValue(model_neutral.num_updates_downloaded_total, |
101 *value, "numUpdatesDownloadedTotal"); | 75 *value, "numUpdatesDownloadedTotal"); |
102 ExpectDictIntegerValue(model_neutral.num_tombstone_updates_downloaded_total, | 76 ExpectDictIntegerValue(model_neutral.num_tombstone_updates_downloaded_total, |
103 *value, "numTombstoneUpdatesDownloadedTotal"); | 77 *value, "numTombstoneUpdatesDownloadedTotal"); |
104 ExpectDictIntegerValue(model_neutral.num_reflected_updates_downloaded_total, | 78 ExpectDictIntegerValue(model_neutral.num_reflected_updates_downloaded_total, |
105 *value, "numReflectedUpdatesDownloadedTotal"); | 79 *value, "numReflectedUpdatesDownloadedTotal"); |
106 ExpectDictIntegerValue(model_neutral.num_local_overwrites, | 80 ExpectDictIntegerValue(model_neutral.num_local_overwrites, |
107 *value, "numLocalOverwrites"); | 81 *value, "numLocalOverwrites"); |
108 ExpectDictIntegerValue(model_neutral.num_server_overwrites, | 82 ExpectDictIntegerValue(model_neutral.num_server_overwrites, |
109 *value, "numServerOverwrites"); | 83 *value, "numServerOverwrites"); |
110 ExpectDictIntegerValue(model_neutral.num_server_changes_remaining, | 84 ExpectDictIntegerValue(model_neutral.num_server_changes_remaining, |
111 *value, "numServerChangesRemaining"); | 85 *value, "numServerChangesRemaining"); |
112 ExpectDictBooleanValue(kIsShareUsable, *value, "isShareUsable"); | 86 ExpectDictBooleanValue(kIsShareUsable, *value, "isShareUsable"); |
113 ExpectDictListValue(*expected_initial_sync_ended_value, *value, | 87 ExpectDictListValue(*expected_initial_sync_ended_value, *value, |
114 "initialSyncEnded"); | 88 "initialSyncEnded"); |
115 ExpectDictDictionaryValue(*expected_download_progress_markers_value, | 89 ExpectDictDictionaryValue(*expected_download_progress_markers_value, |
116 *value, "downloadProgressMarkers"); | 90 *value, "downloadProgressMarkers"); |
117 ExpectDictBooleanValue(kHasMoreToSync, *value, "hasMoreToSync"); | |
118 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced"); | 91 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced"); |
119 ExpectDictIntegerValue(kNumEncryptionConflicts, *value, | 92 ExpectDictIntegerValue(kNumEncryptionConflicts, *value, |
120 "numEncryptionConflicts"); | 93 "numEncryptionConflicts"); |
121 ExpectDictIntegerValue(kNumHierarchyConflicts, *value, | 94 ExpectDictIntegerValue(kNumHierarchyConflicts, *value, |
122 "numHierarchyConflicts"); | 95 "numHierarchyConflicts"); |
123 ExpectDictIntegerValue(kNumSimpleConflicts, *value, | |
124 "numSimpleConflicts"); | |
125 ExpectDictIntegerValue(kNumServerConflicts, *value, | 96 ExpectDictIntegerValue(kNumServerConflicts, *value, |
126 "numServerConflicts"); | 97 "numServerConflicts"); |
127 ExpectDictDictionaryValue(*expected_source_value, *value, "source"); | 98 ExpectDictDictionaryValue(*expected_source_value, *value, "source"); |
128 ExpectDictBooleanValue(false, *value, "notificationsEnabled"); | 99 ExpectDictBooleanValue(false, *value, "notificationsEnabled"); |
129 } | 100 } |
130 | 101 |
131 } // namespace | 102 } // namespace |
132 } // namespace sessions | 103 } // namespace sessions |
133 } // namespace syncer | 104 } // namespace syncer |
OLD | NEW |