Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/sync/sync_prefs_unittest.cc

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup pass #2 Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/sync_prefs.cc ('k') | chrome/browser/sync/sync_setup_flow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/sync_prefs.h" 5 #include "chrome/browser/sync/sync_prefs.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "chrome/browser/sync/syncable/model_type.h" 9 #include "chrome/browser/sync/syncable/model_type.h"
10 #include "chrome/test/base/testing_pref_service.h" 10 #include "chrome/test/base/testing_pref_service.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace browser_sync { 14 namespace browser_sync {
15 15
16 namespace { 16 namespace {
17 17
18 using ::testing::InSequence; 18 using ::testing::InSequence;
19 using ::testing::StrictMock; 19 using ::testing::StrictMock;
20 20
21 class SyncPrefsTest : public testing::Test { 21 class SyncPrefsTest : public testing::Test {
22 protected: 22 protected:
23 TestingPrefService pref_service_; 23 TestingPrefService pref_service_;
24 24
25 private: 25 private:
26 MessageLoop loop_; 26 MessageLoop loop_;
27 }; 27 };
28 28
29 // Get all types with a user-facing component. 29 // Get all types with a user-facing component.
30 syncable::ModelTypeSet GetNonPassiveTypes() { 30 syncable::ModelEnumSet GetNonPassiveTypes() {
31 syncable::ModelTypeSet all_types; 31 syncable::ModelEnumSet non_passive_types = syncable::ModelEnumSet::All();
32 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 32 non_passive_types.Remove(syncable::NIGORI);
33 i < syncable::MODEL_TYPE_COUNT; ++i) { 33 return non_passive_types;
34 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
35 all_types.insert(type);
36 }
37 all_types.erase(syncable::NIGORI);
38 return all_types;
39 } 34 }
40 35
41 // Returns all types visible from the setup UI. 36 // Returns all types visible from the setup UI.
42 syncable::ModelTypeSet GetUserVisibleTypes() { 37 syncable::ModelEnumSet GetUserVisibleTypes() {
43 syncable::ModelTypeSet user_visible_types(GetNonPassiveTypes()); 38 syncable::ModelEnumSet user_visible_types(GetNonPassiveTypes());
44 user_visible_types.erase(syncable::AUTOFILL_PROFILE); 39 user_visible_types.Remove(syncable::AUTOFILL_PROFILE);
45 user_visible_types.erase(syncable::SEARCH_ENGINES); 40 user_visible_types.Remove(syncable::SEARCH_ENGINES);
46 user_visible_types.erase(syncable::APP_NOTIFICATIONS); 41 user_visible_types.Remove(syncable::APP_NOTIFICATIONS);
47 return user_visible_types; 42 return user_visible_types;
48 } 43 }
49 44
50 TEST_F(SyncPrefsTest, Basic) { 45 TEST_F(SyncPrefsTest, Basic) {
51 SyncPrefs sync_prefs(&pref_service_); 46 SyncPrefs sync_prefs(&pref_service_);
52 47
53 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 48 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
54 sync_prefs.SetSyncSetupCompleted(); 49 sync_prefs.SetSyncSetupCompleted();
55 EXPECT_TRUE(sync_prefs.HasSyncSetupCompleted()); 50 EXPECT_TRUE(sync_prefs.HasSyncSetupCompleted());
56 51
(...skipping 17 matching lines...) Expand all
74 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 69 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
75 sync_prefs.SetEncryptionBootstrapToken("token"); 70 sync_prefs.SetEncryptionBootstrapToken("token");
76 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken()); 71 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken());
77 } 72 }
78 73
79 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) { 74 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) {
80 SyncPrefs sync_prefs(&pref_service_); 75 SyncPrefs sync_prefs(&pref_service_);
81 76
82 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced()); 77 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
83 78
84 const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes(); 79 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
85 EXPECT_EQ(non_passive_types, 80 EXPECT_TRUE(non_passive_types.Equals(
86 sync_prefs.GetPreferredDataTypes(non_passive_types)); 81 sync_prefs.GetPreferredDataTypes(non_passive_types)));
87 const syncable::ModelTypeSet& user_visible_types = GetUserVisibleTypes(); 82 const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes();
88 for (syncable::ModelTypeSet::const_iterator it = user_visible_types.begin(); 83 for (syncable::ModelEnumSet::Iterator it = user_visible_types.First();
89 it != user_visible_types.end(); ++it) { 84 it.Good(); it.Inc()) {
90 syncable::ModelTypeSet preferred_types; 85 syncable::ModelEnumSet preferred_types;
91 preferred_types.insert(*it); 86 preferred_types.Put(it.Get());
92 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types); 87 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
93 EXPECT_EQ(non_passive_types, 88 EXPECT_TRUE(non_passive_types.Equals(
94 sync_prefs.GetPreferredDataTypes(non_passive_types)); 89 sync_prefs.GetPreferredDataTypes(non_passive_types)));
95 } 90 }
96 } 91 }
97 92
98 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) { 93 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
99 SyncPrefs sync_prefs(&pref_service_); 94 SyncPrefs sync_prefs(&pref_service_);
100 95
101 sync_prefs.SetKeepEverythingSynced(false); 96 sync_prefs.SetKeepEverythingSynced(false);
102 97
103 const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes(); 98 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
104 EXPECT_EQ(non_passive_types, 99 EXPECT_TRUE(non_passive_types.Equals(
105 sync_prefs.GetPreferredDataTypes(non_passive_types)); 100 sync_prefs.GetPreferredDataTypes(non_passive_types)));
106 const syncable::ModelTypeSet& user_visible_types = GetUserVisibleTypes(); 101 const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes();
107 for (syncable::ModelTypeSet::const_iterator it = user_visible_types.begin(); 102 for (syncable::ModelEnumSet::Iterator it = user_visible_types.First();
108 it != user_visible_types.end(); ++it) { 103 it.Good(); it.Inc()) {
109 syncable::ModelTypeSet preferred_types; 104 syncable::ModelEnumSet preferred_types;
110 preferred_types.insert(*it); 105 preferred_types.Put(it.Get());
111 syncable::ModelTypeSet expected_preferred_types(preferred_types); 106 syncable::ModelEnumSet expected_preferred_types(preferred_types);
112 if (*it == syncable::AUTOFILL) { 107 if (it.Get() == syncable::AUTOFILL) {
113 expected_preferred_types.insert(syncable::AUTOFILL_PROFILE); 108 expected_preferred_types.Put(syncable::AUTOFILL_PROFILE);
114 } 109 }
115 if (*it == syncable::PREFERENCES) { 110 if (it.Get() == syncable::PREFERENCES) {
116 expected_preferred_types.insert(syncable::SEARCH_ENGINES); 111 expected_preferred_types.Put(syncable::SEARCH_ENGINES);
117 } 112 }
118 if (*it == syncable::APPS) { 113 if (it.Get() == syncable::APPS) {
119 expected_preferred_types.insert(syncable::APP_NOTIFICATIONS); 114 expected_preferred_types.Put(syncable::APP_NOTIFICATIONS);
120 } 115 }
121 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types); 116 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
122 EXPECT_EQ(expected_preferred_types, 117 EXPECT_TRUE(expected_preferred_types.Equals(
123 sync_prefs.GetPreferredDataTypes(non_passive_types)); 118 sync_prefs.GetPreferredDataTypes(non_passive_types)));
124 } 119 }
125 } 120 }
126 121
127 TEST_F(SyncPrefsTest, MaxInvalidationVersions) { 122 TEST_F(SyncPrefsTest, MaxInvalidationVersions) {
128 SyncPrefs sync_prefs(&pref_service_); 123 SyncPrefs sync_prefs(&pref_service_);
129 124
130 sync_notifier::InvalidationVersionMap expected_max_versions; 125 sync_notifier::InvalidationVersionMap expected_max_versions;
131 EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions()); 126 EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
132 127
133 expected_max_versions[syncable::BOOKMARKS] = 2; 128 expected_max_versions[syncable::BOOKMARKS] = 2;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 EXPECT_TRUE(sync_prefs.IsManaged()); 163 EXPECT_TRUE(sync_prefs.IsManaged());
169 sync_prefs.SetManagedForTest(false); 164 sync_prefs.SetManagedForTest(false);
170 EXPECT_FALSE(sync_prefs.IsManaged()); 165 EXPECT_FALSE(sync_prefs.IsManaged());
171 166
172 sync_prefs.RemoveSyncPrefObserver(&mock_sync_pref_observer); 167 sync_prefs.RemoveSyncPrefObserver(&mock_sync_pref_observer);
173 } 168 }
174 169
175 TEST_F(SyncPrefsTest, AcknowledgeSyncedTypes) { 170 TEST_F(SyncPrefsTest, AcknowledgeSyncedTypes) {
176 SyncPrefs sync_prefs(&pref_service_); 171 SyncPrefs sync_prefs(&pref_service_);
177 172
178 syncable::ModelTypeSet expected_acknowledge_synced_types = 173 syncable::ModelEnumSet expected_acknowledge_synced_types =
179 sync_prefs.GetAcknowledgeSyncedTypesForTest(); 174 sync_prefs.GetAcknowledgeSyncedTypesForTest();
180 for (int i = syncable::EXTENSION_SETTINGS; 175 for (int i = syncable::EXTENSION_SETTINGS;
181 i < syncable::MODEL_TYPE_COUNT; ++i) { 176 i < syncable::MODEL_TYPE_COUNT; ++i) {
182 const syncable::ModelType type = syncable::ModelTypeFromInt(i); 177 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
183 syncable::ModelTypeSet acknowledge_synced_types; 178 syncable::ModelEnumSet acknowledge_synced_types(type);
184 acknowledge_synced_types.insert(type); 179 expected_acknowledge_synced_types.Put(type);
185 expected_acknowledge_synced_types.insert(type);
186 sync_prefs.AcknowledgeSyncedTypes(acknowledge_synced_types); 180 sync_prefs.AcknowledgeSyncedTypes(acknowledge_synced_types);
187 EXPECT_EQ(expected_acknowledge_synced_types, 181 EXPECT_TRUE(expected_acknowledge_synced_types.Equals(
188 sync_prefs.GetAcknowledgeSyncedTypesForTest()); 182 sync_prefs.GetAcknowledgeSyncedTypesForTest()));
189 } 183 }
190 } 184 }
191 185
192 TEST_F(SyncPrefsTest, ClearPreferences) { 186 TEST_F(SyncPrefsTest, ClearPreferences) {
193 SyncPrefs sync_prefs(&pref_service_); 187 SyncPrefs sync_prefs(&pref_service_);
194 188
195 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 189 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
196 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime()); 190 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
197 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 191 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
198 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty()); 192 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
(...skipping 20 matching lines...) Expand all
219 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty()); 213 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
220 } 214 }
221 215
222 TEST_F(SyncPrefsTest, NullPrefService) { 216 TEST_F(SyncPrefsTest, NullPrefService) {
223 SyncPrefs sync_prefs(NULL); 217 SyncPrefs sync_prefs(NULL);
224 218
225 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 219 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
226 EXPECT_FALSE(sync_prefs.IsStartSuppressed()); 220 EXPECT_FALSE(sync_prefs.IsStartSuppressed());
227 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime()); 221 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
228 EXPECT_FALSE(sync_prefs.HasKeepEverythingSynced()); 222 EXPECT_FALSE(sync_prefs.HasKeepEverythingSynced());
229 const syncable::ModelTypeSet& non_passive_types = GetNonPassiveTypes(); 223 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes();
230 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).empty()); 224 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).Empty());
231 EXPECT_FALSE(sync_prefs.IsManaged()); 225 EXPECT_FALSE(sync_prefs.IsManaged());
232 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 226 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
233 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty()); 227 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
234 } 228 }
235 229
236 } // namespace 230 } // namespace
237 231
238 } // namespace browser_sync 232 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_prefs.cc ('k') | chrome/browser/sync/sync_setup_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698