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

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

Issue 8919021: [Sync] Rename ModelEnumSet to ModelTypeSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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::ModelEnumSet GetNonPassiveTypes() { 30 syncable::ModelTypeSet GetNonPassiveTypes() {
31 syncable::ModelEnumSet non_passive_types = syncable::ModelEnumSet::All(); 31 syncable::ModelTypeSet non_passive_types = syncable::ModelTypeSet::All();
32 non_passive_types.Remove(syncable::NIGORI); 32 non_passive_types.Remove(syncable::NIGORI);
33 return non_passive_types; 33 return non_passive_types;
34 } 34 }
35 35
36 // Returns all types visible from the setup UI. 36 // Returns all types visible from the setup UI.
37 syncable::ModelEnumSet GetUserVisibleTypes() { 37 syncable::ModelTypeSet GetUserVisibleTypes() {
38 syncable::ModelEnumSet user_visible_types(GetNonPassiveTypes()); 38 syncable::ModelTypeSet user_visible_types(GetNonPassiveTypes());
39 user_visible_types.Remove(syncable::AUTOFILL_PROFILE); 39 user_visible_types.Remove(syncable::AUTOFILL_PROFILE);
40 user_visible_types.Remove(syncable::SEARCH_ENGINES); 40 user_visible_types.Remove(syncable::SEARCH_ENGINES);
41 user_visible_types.Remove(syncable::APP_NOTIFICATIONS); 41 user_visible_types.Remove(syncable::APP_NOTIFICATIONS);
42 return user_visible_types; 42 return user_visible_types;
43 } 43 }
44 44
45 TEST_F(SyncPrefsTest, Basic) { 45 TEST_F(SyncPrefsTest, Basic) {
46 SyncPrefs sync_prefs(&pref_service_); 46 SyncPrefs sync_prefs(&pref_service_);
47 47
48 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 48 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
(...skipping 20 matching lines...) Expand all
69 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 69 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
70 sync_prefs.SetEncryptionBootstrapToken("token"); 70 sync_prefs.SetEncryptionBootstrapToken("token");
71 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken()); 71 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken());
72 } 72 }
73 73
74 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) { 74 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) {
75 SyncPrefs sync_prefs(&pref_service_); 75 SyncPrefs sync_prefs(&pref_service_);
76 76
77 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced()); 77 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
78 78
79 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes(); 79 const syncable::ModelTypeSet non_passive_types = GetNonPassiveTypes();
80 EXPECT_TRUE(non_passive_types.Equals( 80 EXPECT_TRUE(non_passive_types.Equals(
81 sync_prefs.GetPreferredDataTypes(non_passive_types))); 81 sync_prefs.GetPreferredDataTypes(non_passive_types)));
82 const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes(); 82 const syncable::ModelTypeSet user_visible_types = GetUserVisibleTypes();
83 for (syncable::ModelEnumSet::Iterator it = user_visible_types.First(); 83 for (syncable::ModelTypeSet::Iterator it = user_visible_types.First();
84 it.Good(); it.Inc()) { 84 it.Good(); it.Inc()) {
85 syncable::ModelEnumSet preferred_types; 85 syncable::ModelTypeSet preferred_types;
86 preferred_types.Put(it.Get()); 86 preferred_types.Put(it.Get());
87 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types); 87 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
88 EXPECT_TRUE(non_passive_types.Equals( 88 EXPECT_TRUE(non_passive_types.Equals(
89 sync_prefs.GetPreferredDataTypes(non_passive_types))); 89 sync_prefs.GetPreferredDataTypes(non_passive_types)));
90 } 90 }
91 } 91 }
92 92
93 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) { 93 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
94 SyncPrefs sync_prefs(&pref_service_); 94 SyncPrefs sync_prefs(&pref_service_);
95 95
96 sync_prefs.SetKeepEverythingSynced(false); 96 sync_prefs.SetKeepEverythingSynced(false);
97 97
98 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes(); 98 const syncable::ModelTypeSet non_passive_types = GetNonPassiveTypes();
99 EXPECT_TRUE(non_passive_types.Equals( 99 EXPECT_TRUE(non_passive_types.Equals(
100 sync_prefs.GetPreferredDataTypes(non_passive_types))); 100 sync_prefs.GetPreferredDataTypes(non_passive_types)));
101 const syncable::ModelEnumSet user_visible_types = GetUserVisibleTypes(); 101 const syncable::ModelTypeSet user_visible_types = GetUserVisibleTypes();
102 for (syncable::ModelEnumSet::Iterator it = user_visible_types.First(); 102 for (syncable::ModelTypeSet::Iterator it = user_visible_types.First();
103 it.Good(); it.Inc()) { 103 it.Good(); it.Inc()) {
104 syncable::ModelEnumSet preferred_types; 104 syncable::ModelTypeSet preferred_types;
105 preferred_types.Put(it.Get()); 105 preferred_types.Put(it.Get());
106 syncable::ModelEnumSet expected_preferred_types(preferred_types); 106 syncable::ModelTypeSet expected_preferred_types(preferred_types);
107 if (it.Get() == syncable::AUTOFILL) { 107 if (it.Get() == syncable::AUTOFILL) {
108 expected_preferred_types.Put(syncable::AUTOFILL_PROFILE); 108 expected_preferred_types.Put(syncable::AUTOFILL_PROFILE);
109 } 109 }
110 if (it.Get() == syncable::PREFERENCES) { 110 if (it.Get() == syncable::PREFERENCES) {
111 expected_preferred_types.Put(syncable::SEARCH_ENGINES); 111 expected_preferred_types.Put(syncable::SEARCH_ENGINES);
112 } 112 }
113 if (it.Get() == syncable::APPS) { 113 if (it.Get() == syncable::APPS) {
114 expected_preferred_types.Put(syncable::APP_NOTIFICATIONS); 114 expected_preferred_types.Put(syncable::APP_NOTIFICATIONS);
115 } 115 }
116 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types); 116 sync_prefs.SetPreferredDataTypes(non_passive_types, preferred_types);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EXPECT_TRUE(sync_prefs.IsManaged()); 163 EXPECT_TRUE(sync_prefs.IsManaged());
164 sync_prefs.SetManagedForTest(false); 164 sync_prefs.SetManagedForTest(false);
165 EXPECT_FALSE(sync_prefs.IsManaged()); 165 EXPECT_FALSE(sync_prefs.IsManaged());
166 166
167 sync_prefs.RemoveSyncPrefObserver(&mock_sync_pref_observer); 167 sync_prefs.RemoveSyncPrefObserver(&mock_sync_pref_observer);
168 } 168 }
169 169
170 TEST_F(SyncPrefsTest, AcknowledgeSyncedTypes) { 170 TEST_F(SyncPrefsTest, AcknowledgeSyncedTypes) {
171 SyncPrefs sync_prefs(&pref_service_); 171 SyncPrefs sync_prefs(&pref_service_);
172 172
173 syncable::ModelEnumSet expected_acknowledge_synced_types = 173 syncable::ModelTypeSet expected_acknowledge_synced_types =
174 sync_prefs.GetAcknowledgeSyncedTypesForTest(); 174 sync_prefs.GetAcknowledgeSyncedTypesForTest();
175 for (int i = syncable::EXTENSION_SETTINGS; 175 for (int i = syncable::EXTENSION_SETTINGS;
176 i < syncable::MODEL_TYPE_COUNT; ++i) { 176 i < syncable::MODEL_TYPE_COUNT; ++i) {
177 const syncable::ModelType type = syncable::ModelTypeFromInt(i); 177 const syncable::ModelType type = syncable::ModelTypeFromInt(i);
178 syncable::ModelEnumSet acknowledge_synced_types(type); 178 syncable::ModelTypeSet acknowledge_synced_types(type);
179 expected_acknowledge_synced_types.Put(type); 179 expected_acknowledge_synced_types.Put(type);
180 sync_prefs.AcknowledgeSyncedTypes(acknowledge_synced_types); 180 sync_prefs.AcknowledgeSyncedTypes(acknowledge_synced_types);
181 EXPECT_TRUE(expected_acknowledge_synced_types.Equals( 181 EXPECT_TRUE(expected_acknowledge_synced_types.Equals(
182 sync_prefs.GetAcknowledgeSyncedTypesForTest())); 182 sync_prefs.GetAcknowledgeSyncedTypesForTest()));
183 } 183 }
184 } 184 }
185 185
186 TEST_F(SyncPrefsTest, ClearPreferences) { 186 TEST_F(SyncPrefsTest, ClearPreferences) {
187 SyncPrefs sync_prefs(&pref_service_); 187 SyncPrefs sync_prefs(&pref_service_);
188 188
(...skipping 24 matching lines...) Expand all
213 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty()); 213 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
214 } 214 }
215 215
216 TEST_F(SyncPrefsTest, NullPrefService) { 216 TEST_F(SyncPrefsTest, NullPrefService) {
217 SyncPrefs sync_prefs(NULL); 217 SyncPrefs sync_prefs(NULL);
218 218
219 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 219 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
220 EXPECT_FALSE(sync_prefs.IsStartSuppressed()); 220 EXPECT_FALSE(sync_prefs.IsStartSuppressed());
221 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime()); 221 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
222 EXPECT_FALSE(sync_prefs.HasKeepEverythingSynced()); 222 EXPECT_FALSE(sync_prefs.HasKeepEverythingSynced());
223 const syncable::ModelEnumSet non_passive_types = GetNonPassiveTypes(); 223 const syncable::ModelTypeSet non_passive_types = GetNonPassiveTypes();
224 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).Empty()); 224 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).Empty());
225 EXPECT_FALSE(sync_prefs.IsManaged()); 225 EXPECT_FALSE(sync_prefs.IsManaged());
226 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 226 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
227 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty()); 227 EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
228 } 228 }
229 229
230 } // namespace 230 } // namespace
231 231
232 } // 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