Chromium Code Reviews| 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" |
|
Nicolas Zea
2012/10/26 21:14:30
Can this test be placed in sync/sessions? Or at le
rlarocque
2012/10/26 21:41:46
That would have been my first choice, too. But I
| |
| 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 false); | 68 false); |
| 95 scoped_ptr<DictionaryValue> value(snapshot.ToValue()); | 69 scoped_ptr<DictionaryValue> value(snapshot.ToValue()); |
| 96 EXPECT_EQ(20u, value->size()); | 70 EXPECT_EQ(20u, value->size()); |
| 97 ExpectDictIntegerValue(model_neutral.num_successful_commits, | 71 ExpectDictIntegerValue(model_neutral.num_successful_commits, |
| 98 *value, "numSuccessfulCommits"); | 72 *value, "numSuccessfulCommits"); |
| 99 ExpectDictIntegerValue(model_neutral.num_successful_bookmark_commits, | 73 ExpectDictIntegerValue(model_neutral.num_successful_bookmark_commits, |
| 100 *value, "numSuccessfulBookmarkCommits"); | 74 *value, "numSuccessfulBookmarkCommits"); |
| 101 ExpectDictIntegerValue(model_neutral.num_updates_downloaded_total, | 75 ExpectDictIntegerValue(model_neutral.num_updates_downloaded_total, |
| 102 *value, "numUpdatesDownloadedTotal"); | 76 *value, "numUpdatesDownloadedTotal"); |
| 103 ExpectDictIntegerValue(model_neutral.num_tombstone_updates_downloaded_total, | 77 ExpectDictIntegerValue(model_neutral.num_tombstone_updates_downloaded_total, |
| 104 *value, "numTombstoneUpdatesDownloadedTotal"); | 78 *value, "numTombstoneUpdatesDownloadedTotal"); |
| 105 ExpectDictIntegerValue(model_neutral.num_reflected_updates_downloaded_total, | 79 ExpectDictIntegerValue(model_neutral.num_reflected_updates_downloaded_total, |
| 106 *value, "numReflectedUpdatesDownloadedTotal"); | 80 *value, "numReflectedUpdatesDownloadedTotal"); |
| 107 ExpectDictIntegerValue(model_neutral.num_local_overwrites, | 81 ExpectDictIntegerValue(model_neutral.num_local_overwrites, |
| 108 *value, "numLocalOverwrites"); | 82 *value, "numLocalOverwrites"); |
| 109 ExpectDictIntegerValue(model_neutral.num_server_overwrites, | 83 ExpectDictIntegerValue(model_neutral.num_server_overwrites, |
| 110 *value, "numServerOverwrites"); | 84 *value, "numServerOverwrites"); |
| 111 ExpectDictIntegerValue(model_neutral.num_server_changes_remaining, | 85 ExpectDictIntegerValue(model_neutral.num_server_changes_remaining, |
| 112 *value, "numServerChangesRemaining"); | 86 *value, "numServerChangesRemaining"); |
| 113 ExpectDictBooleanValue(kIsShareUsable, *value, "isShareUsable"); | 87 ExpectDictBooleanValue(kIsShareUsable, *value, "isShareUsable"); |
| 114 ExpectDictListValue(*expected_initial_sync_ended_value, *value, | 88 ExpectDictListValue(*expected_initial_sync_ended_value, *value, |
| 115 "initialSyncEnded"); | 89 "initialSyncEnded"); |
| 116 ExpectDictDictionaryValue(*expected_download_progress_markers_value, | 90 ExpectDictDictionaryValue(*expected_download_progress_markers_value, |
| 117 *value, "downloadProgressMarkers"); | 91 *value, "downloadProgressMarkers"); |
| 118 ExpectDictBooleanValue(kHasMoreToSync, *value, "hasMoreToSync"); | |
| 119 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced"); | 92 ExpectDictBooleanValue(kIsSilenced, *value, "isSilenced"); |
| 120 ExpectDictIntegerValue(kNumEncryptionConflicts, *value, | 93 ExpectDictIntegerValue(kNumEncryptionConflicts, *value, |
| 121 "numEncryptionConflicts"); | 94 "numEncryptionConflicts"); |
| 122 ExpectDictIntegerValue(kNumHierarchyConflicts, *value, | 95 ExpectDictIntegerValue(kNumHierarchyConflicts, *value, |
| 123 "numHierarchyConflicts"); | 96 "numHierarchyConflicts"); |
| 124 ExpectDictIntegerValue(kNumSimpleConflicts, *value, | |
| 125 "numSimpleConflicts"); | |
| 126 ExpectDictIntegerValue(kNumServerConflicts, *value, | 97 ExpectDictIntegerValue(kNumServerConflicts, *value, |
| 127 "numServerConflicts"); | 98 "numServerConflicts"); |
| 128 ExpectDictDictionaryValue(*expected_source_value, *value, "source"); | 99 ExpectDictDictionaryValue(*expected_source_value, *value, "source"); |
| 129 ExpectDictBooleanValue(false, *value, "notificationsEnabled"); | 100 ExpectDictBooleanValue(false, *value, "notificationsEnabled"); |
| 130 } | 101 } |
| 131 | 102 |
| 132 } // namespace | 103 } // namespace |
| 133 } // namespace sessions | 104 } // namespace sessions |
| 134 } // namespace syncer | 105 } // namespace syncer |
| OLD | NEW |