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