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 "sync/internal_api/public/sessions/sync_session_snapshot.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/test/values_test_util.h"
9 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace syncer {
13 namespace sessions {
14 namespace {
15
16 using base::ExpectDictBooleanValue;
17 using base::ExpectDictDictionaryValue;
18 using base::ExpectDictIntegerValue;
19 using base::ExpectDictListValue;
20 using base::ExpectDictStringValue;
21
22 class SyncSessionSnapshotTest : public testing::Test {};
23
TEST_F(SyncSessionSnapshotTest,SyncSessionSnapshotToValue)24 TEST_F(SyncSessionSnapshotTest, SyncSessionSnapshotToValue) {
25 ModelNeutralState model_neutral;
26 model_neutral.num_successful_commits = 5;
27 model_neutral.num_successful_bookmark_commits = 10;
28 model_neutral.num_updates_downloaded_total = 100;
29 model_neutral.num_tombstone_updates_downloaded_total = 200;
30 model_neutral.num_reflected_updates_downloaded_total = 50;
31 model_neutral.num_local_overwrites = 15;
32 model_neutral.num_server_overwrites = 18;
33
34 ProgressMarkerMap download_progress_markers;
35 download_progress_markers[BOOKMARKS] = "test";
36 download_progress_markers[APPS] = "apps";
37 scoped_ptr<base::DictionaryValue> expected_download_progress_markers_value(
38 ProgressMarkerMapToValue(download_progress_markers));
39
40 const bool kIsSilenced = true;
41 const int kNumEncryptionConflicts = 1054;
42 const int kNumHierarchyConflicts = 1055;
43 const int kNumServerConflicts = 1057;
44
45 SyncSessionSnapshot snapshot(model_neutral,
46 download_progress_markers,
47 kIsSilenced,
48 kNumEncryptionConflicts,
49 kNumHierarchyConflicts,
50 kNumServerConflicts,
51 false,
52 0,
53 base::Time::Now(),
54 std::vector<int>(MODEL_TYPE_COUNT,0),
55 std::vector<int>(MODEL_TYPE_COUNT, 0),
56 sync_pb::GetUpdatesCallerInfo::UNKNOWN);
57 scoped_ptr<base::DictionaryValue> value(snapshot.ToValue());
58 EXPECT_EQ(16u, value->size());
59 ExpectDictIntegerValue(model_neutral.num_successful_commits,
60 *value, "numSuccessfulCommits");
61 ExpectDictIntegerValue(model_neutral.num_successful_bookmark_commits,
62 *value, "numSuccessfulBookmarkCommits");
63 ExpectDictIntegerValue(model_neutral.num_updates_downloaded_total,
64 *value, "numUpdatesDownloadedTotal");
65 ExpectDictIntegerValue(model_neutral.num_tombstone_updates_downloaded_total,
66 *value, "numTombstoneUpdatesDownloadedTotal");
67 ExpectDictIntegerValue(model_neutral.num_reflected_updates_downloaded_total,
68 *value, "numReflectedUpdatesDownloadedTotal");
69 ExpectDictIntegerValue(model_neutral.num_local_overwrites,
70 *value, "numLocalOverwrites");
71 ExpectDictIntegerValue(model_neutral.num_server_overwrites,
72 *value, "numServerOverwrites");
73 ExpectDictDictionaryValue(*expected_download_progress_markers_value,
74 *value, "downloadProgressMarkers");
75 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced");
76 ExpectDictIntegerValue(kNumEncryptionConflicts, *value,
77 "numEncryptionConflicts");
78 ExpectDictIntegerValue(kNumHierarchyConflicts, *value,
79 "numHierarchyConflicts");
80 ExpectDictIntegerValue(kNumServerConflicts, *value,
81 "numServerConflicts");
82 ExpectDictBooleanValue(false, *value, "notificationsEnabled");
83 }
84
85 } // namespace
86 } // namespace sessions
87 } // namespace syncer
88