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

Side by Side Diff: components/sync/driver/sync_prefs_unittest.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 months 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
« no previous file with comments | « components/sync/driver/sync_prefs.cc ('k') | components/sync/driver/sync_service.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) 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 "components/sync/driver/sync_prefs.h" 5 #include "components/sync/driver/sync_prefs.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "components/pref_registry/testing_pref_service_syncable.h" 14 #include "components/pref_registry/testing_pref_service_syncable.h"
15 #include "components/prefs/pref_notifier_impl.h" 15 #include "components/prefs/pref_notifier_impl.h"
16 #include "components/prefs/pref_value_store.h" 16 #include "components/prefs/pref_value_store.h"
17 #include "components/prefs/testing_pref_service.h" 17 #include "components/prefs/testing_pref_service.h"
18 #include "components/sync/base/model_type.h" 18 #include "components/sync/base/model_type.h"
19 #include "components/sync/driver/pref_names.h" 19 #include "components/sync/driver/pref_names.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace sync_driver { 23 namespace syncer {
24 24
25 namespace { 25 namespace {
26 26
27 using ::testing::InSequence; 27 using ::testing::InSequence;
28 using ::testing::StrictMock; 28 using ::testing::StrictMock;
29 29
30 class SyncPrefsTest : public testing::Test { 30 class SyncPrefsTest : public testing::Test {
31 protected: 31 protected:
32 void SetUp() override { 32 void SetUp() override {
33 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); 33 SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 66 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
67 sync_prefs.SetEncryptionBootstrapToken("token"); 67 sync_prefs.SetEncryptionBootstrapToken("token");
68 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken()); 68 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken());
69 } 69 }
70 70
71 TEST_F(SyncPrefsTest, DefaultTypes) { 71 TEST_F(SyncPrefsTest, DefaultTypes) {
72 SyncPrefs sync_prefs(&pref_service_); 72 SyncPrefs sync_prefs(&pref_service_);
73 sync_prefs.SetKeepEverythingSynced(false); 73 sync_prefs.SetKeepEverythingSynced(false);
74 74
75 // Only bookmarks and device info are enabled by default. 75 // Only bookmarks and device info are enabled by default.
76 syncer::ModelTypeSet expected(syncer::BOOKMARKS, syncer::DEVICE_INFO); 76 ModelTypeSet expected(BOOKMARKS, DEVICE_INFO);
77 syncer::ModelTypeSet preferred_types = 77 ModelTypeSet preferred_types = sync_prefs.GetPreferredDataTypes(UserTypes());
78 sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
79 EXPECT_EQ(expected, preferred_types); 78 EXPECT_EQ(expected, preferred_types);
80 79
81 // Simulate an upgrade to delete directives + proxy tabs support. None of the 80 // Simulate an upgrade to delete directives + proxy tabs support. None of the
82 // new types or their pref group types should be registering, ensuring they 81 // new types or their pref group types should be registering, ensuring they
83 // don't have pref values. 82 // don't have pref values.
84 syncer::ModelTypeSet registered_types = syncer::UserTypes(); 83 ModelTypeSet registered_types = UserTypes();
85 registered_types.Remove(syncer::PROXY_TABS); 84 registered_types.Remove(PROXY_TABS);
86 registered_types.Remove(syncer::TYPED_URLS); 85 registered_types.Remove(TYPED_URLS);
87 registered_types.Remove(syncer::SESSIONS); 86 registered_types.Remove(SESSIONS);
88 registered_types.Remove(syncer::HISTORY_DELETE_DIRECTIVES); 87 registered_types.Remove(HISTORY_DELETE_DIRECTIVES);
89 88
90 // Enable all other types. 89 // Enable all other types.
91 sync_prefs.SetPreferredDataTypes(registered_types, registered_types); 90 sync_prefs.SetPreferredDataTypes(registered_types, registered_types);
92 91
93 // Manually enable typed urls (to simulate the old world). 92 // Manually enable typed urls (to simulate the old world).
94 pref_service_.SetBoolean(prefs::kSyncTypedUrls, true); 93 pref_service_.SetBoolean(prefs::kSyncTypedUrls, true);
95 94
96 // Proxy tabs should not be enabled (since sessions wasn't), but history 95 // Proxy tabs should not be enabled (since sessions wasn't), but history
97 // delete directives should (since typed urls was). 96 // delete directives should (since typed urls was).
98 preferred_types = sync_prefs.GetPreferredDataTypes(syncer::UserTypes()); 97 preferred_types = sync_prefs.GetPreferredDataTypes(UserTypes());
99 EXPECT_FALSE(preferred_types.Has(syncer::PROXY_TABS)); 98 EXPECT_FALSE(preferred_types.Has(PROXY_TABS));
100 EXPECT_TRUE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES)); 99 EXPECT_TRUE(preferred_types.Has(HISTORY_DELETE_DIRECTIVES));
101 100
102 // Now manually enable sessions, which should result in proxy tabs also being 101 // Now manually enable sessions, which should result in proxy tabs also being
103 // enabled. Also, manually disable typed urls, which should mean that history 102 // enabled. Also, manually disable typed urls, which should mean that history
104 // delete directives are not enabled. 103 // delete directives are not enabled.
105 pref_service_.SetBoolean(prefs::kSyncTypedUrls, false); 104 pref_service_.SetBoolean(prefs::kSyncTypedUrls, false);
106 pref_service_.SetBoolean(prefs::kSyncSessions, true); 105 pref_service_.SetBoolean(prefs::kSyncSessions, true);
107 preferred_types = sync_prefs.GetPreferredDataTypes(syncer::UserTypes()); 106 preferred_types = sync_prefs.GetPreferredDataTypes(UserTypes());
108 EXPECT_TRUE(preferred_types.Has(syncer::PROXY_TABS)); 107 EXPECT_TRUE(preferred_types.Has(PROXY_TABS));
109 EXPECT_FALSE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES)); 108 EXPECT_FALSE(preferred_types.Has(HISTORY_DELETE_DIRECTIVES));
110 } 109 }
111 110
112 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) { 111 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) {
113 SyncPrefs sync_prefs(&pref_service_); 112 SyncPrefs sync_prefs(&pref_service_);
114 113
115 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced()); 114 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
116 115
117 const syncer::ModelTypeSet user_types = syncer::UserTypes(); 116 const ModelTypeSet user_types = UserTypes();
118 EXPECT_EQ(user_types, sync_prefs.GetPreferredDataTypes(user_types)); 117 EXPECT_EQ(user_types, sync_prefs.GetPreferredDataTypes(user_types));
119 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes(); 118 const ModelTypeSet user_visible_types = UserSelectableTypes();
120 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First(); 119 for (ModelTypeSet::Iterator it = user_visible_types.First(); it.Good();
121 it.Good(); it.Inc()) { 120 it.Inc()) {
122 syncer::ModelTypeSet preferred_types; 121 ModelTypeSet preferred_types;
123 preferred_types.Put(it.Get()); 122 preferred_types.Put(it.Get());
124 sync_prefs.SetPreferredDataTypes(user_types, preferred_types); 123 sync_prefs.SetPreferredDataTypes(user_types, preferred_types);
125 EXPECT_EQ(user_types, sync_prefs.GetPreferredDataTypes(user_types)); 124 EXPECT_EQ(user_types, sync_prefs.GetPreferredDataTypes(user_types));
126 } 125 }
127 } 126 }
128 127
129 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) { 128 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
130 SyncPrefs sync_prefs(&pref_service_); 129 SyncPrefs sync_prefs(&pref_service_);
131 130
132 sync_prefs.SetKeepEverythingSynced(false); 131 sync_prefs.SetKeepEverythingSynced(false);
133 132
134 const syncer::ModelTypeSet user_types = syncer::UserTypes(); 133 const ModelTypeSet user_types = UserTypes();
135 EXPECT_NE(user_types, sync_prefs.GetPreferredDataTypes(user_types)); 134 EXPECT_NE(user_types, sync_prefs.GetPreferredDataTypes(user_types));
136 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes(); 135 const ModelTypeSet user_visible_types = UserSelectableTypes();
137 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First(); 136 for (ModelTypeSet::Iterator it = user_visible_types.First(); it.Good();
138 it.Good(); it.Inc()) { 137 it.Inc()) {
139 syncer::ModelTypeSet preferred_types; 138 ModelTypeSet preferred_types;
140 preferred_types.Put(it.Get()); 139 preferred_types.Put(it.Get());
141 syncer::ModelTypeSet expected_preferred_types(preferred_types); 140 ModelTypeSet expected_preferred_types(preferred_types);
142 if (it.Get() == syncer::AUTOFILL) { 141 if (it.Get() == AUTOFILL) {
143 expected_preferred_types.Put(syncer::AUTOFILL_PROFILE); 142 expected_preferred_types.Put(AUTOFILL_PROFILE);
144 expected_preferred_types.Put(syncer::AUTOFILL_WALLET_DATA); 143 expected_preferred_types.Put(AUTOFILL_WALLET_DATA);
145 expected_preferred_types.Put(syncer::AUTOFILL_WALLET_METADATA); 144 expected_preferred_types.Put(AUTOFILL_WALLET_METADATA);
146 } 145 }
147 if (it.Get() == syncer::PREFERENCES) { 146 if (it.Get() == PREFERENCES) {
148 expected_preferred_types.Put(syncer::DICTIONARY); 147 expected_preferred_types.Put(DICTIONARY);
149 expected_preferred_types.Put(syncer::PRIORITY_PREFERENCES); 148 expected_preferred_types.Put(PRIORITY_PREFERENCES);
150 expected_preferred_types.Put(syncer::SEARCH_ENGINES); 149 expected_preferred_types.Put(SEARCH_ENGINES);
151 } 150 }
152 if (it.Get() == syncer::APPS) { 151 if (it.Get() == APPS) {
153 expected_preferred_types.Put(syncer::APP_LIST); 152 expected_preferred_types.Put(APP_LIST);
154 expected_preferred_types.Put(syncer::APP_NOTIFICATIONS); 153 expected_preferred_types.Put(APP_NOTIFICATIONS);
155 expected_preferred_types.Put(syncer::APP_SETTINGS); 154 expected_preferred_types.Put(APP_SETTINGS);
156 expected_preferred_types.Put(syncer::ARC_PACKAGE); 155 expected_preferred_types.Put(ARC_PACKAGE);
157 expected_preferred_types.Put(syncer::READING_LIST); 156 expected_preferred_types.Put(READING_LIST);
158 } 157 }
159 if (it.Get() == syncer::EXTENSIONS) { 158 if (it.Get() == EXTENSIONS) {
160 expected_preferred_types.Put(syncer::EXTENSION_SETTINGS); 159 expected_preferred_types.Put(EXTENSION_SETTINGS);
161 } 160 }
162 if (it.Get() == syncer::TYPED_URLS) { 161 if (it.Get() == TYPED_URLS) {
163 expected_preferred_types.Put(syncer::HISTORY_DELETE_DIRECTIVES); 162 expected_preferred_types.Put(HISTORY_DELETE_DIRECTIVES);
164 expected_preferred_types.Put(syncer::SESSIONS); 163 expected_preferred_types.Put(SESSIONS);
165 expected_preferred_types.Put(syncer::FAVICON_IMAGES); 164 expected_preferred_types.Put(FAVICON_IMAGES);
166 expected_preferred_types.Put(syncer::FAVICON_TRACKING); 165 expected_preferred_types.Put(FAVICON_TRACKING);
167 } 166 }
168 if (it.Get() == syncer::PROXY_TABS) { 167 if (it.Get() == PROXY_TABS) {
169 expected_preferred_types.Put(syncer::SESSIONS); 168 expected_preferred_types.Put(SESSIONS);
170 expected_preferred_types.Put(syncer::FAVICON_IMAGES); 169 expected_preferred_types.Put(FAVICON_IMAGES);
171 expected_preferred_types.Put(syncer::FAVICON_TRACKING); 170 expected_preferred_types.Put(FAVICON_TRACKING);
172 } 171 }
173 172
174 // Device info is always preferred. 173 // Device info is always preferred.
175 expected_preferred_types.Put(syncer::DEVICE_INFO); 174 expected_preferred_types.Put(DEVICE_INFO);
176 175
177 sync_prefs.SetPreferredDataTypes(user_types, preferred_types); 176 sync_prefs.SetPreferredDataTypes(user_types, preferred_types);
178 EXPECT_EQ(expected_preferred_types, 177 EXPECT_EQ(expected_preferred_types,
179 sync_prefs.GetPreferredDataTypes(user_types)); 178 sync_prefs.GetPreferredDataTypes(user_types));
180 } 179 }
181 } 180 }
182 181
183 class MockSyncPrefObserver : public SyncPrefObserver { 182 class MockSyncPrefObserver : public SyncPrefObserver {
184 public: 183 public:
185 MOCK_METHOD1(OnSyncManagedPrefChange, void(bool)); 184 MOCK_METHOD1(OnSyncManagedPrefChange, void(bool));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 sync_prefs.ClearPreferences(); 222 sync_prefs.ClearPreferences();
224 223
225 EXPECT_FALSE(sync_prefs.IsFirstSetupComplete()); 224 EXPECT_FALSE(sync_prefs.IsFirstSetupComplete());
226 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime()); 225 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
227 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 226 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
228 } 227 }
229 228
230 // Device info should always be enabled. 229 // Device info should always be enabled.
231 TEST_F(SyncPrefsTest, DeviceInfo) { 230 TEST_F(SyncPrefsTest, DeviceInfo) {
232 SyncPrefs sync_prefs(&pref_service_); 231 SyncPrefs sync_prefs(&pref_service_);
233 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(syncer::UserTypes()) 232 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(UserTypes()).Has(DEVICE_INFO));
234 .Has(syncer::DEVICE_INFO));
235 sync_prefs.SetKeepEverythingSynced(true); 233 sync_prefs.SetKeepEverythingSynced(true);
236 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(syncer::UserTypes()) 234 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(UserTypes()).Has(DEVICE_INFO));
237 .Has(syncer::DEVICE_INFO));
238 sync_prefs.SetKeepEverythingSynced(false); 235 sync_prefs.SetKeepEverythingSynced(false);
239 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(syncer::UserTypes()) 236 EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(UserTypes()).Has(DEVICE_INFO));
240 .Has(syncer::DEVICE_INFO));
241 } 237 }
242 238
243 // Verify that invalidation versions are persisted and loaded correctly. 239 // Verify that invalidation versions are persisted and loaded correctly.
244 TEST_F(SyncPrefsTest, InvalidationVersions) { 240 TEST_F(SyncPrefsTest, InvalidationVersions) {
245 std::map<syncer::ModelType, int64_t> versions; 241 std::map<ModelType, int64_t> versions;
246 versions[syncer::BOOKMARKS] = 10; 242 versions[BOOKMARKS] = 10;
247 versions[syncer::SESSIONS] = 20; 243 versions[SESSIONS] = 20;
248 versions[syncer::PREFERENCES] = 30; 244 versions[PREFERENCES] = 30;
249 245
250 SyncPrefs sync_prefs(&pref_service_); 246 SyncPrefs sync_prefs(&pref_service_);
251 sync_prefs.UpdateInvalidationVersions(versions); 247 sync_prefs.UpdateInvalidationVersions(versions);
252 248
253 std::map<syncer::ModelType, int64_t> versions2; 249 std::map<ModelType, int64_t> versions2;
254 sync_prefs.GetInvalidationVersions(&versions2); 250 sync_prefs.GetInvalidationVersions(&versions2);
255 251
256 EXPECT_EQ(versions.size(), versions2.size()); 252 EXPECT_EQ(versions.size(), versions2.size());
257 for (auto map_iter : versions2) { 253 for (auto map_iter : versions2) {
258 EXPECT_EQ(versions[map_iter.first], map_iter.second); 254 EXPECT_EQ(versions[map_iter.first], map_iter.second);
259 } 255 }
260 } 256 }
261 257
262 } // namespace 258 } // namespace
263 259
264 } // namespace sync_driver 260 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/sync_prefs.cc ('k') | components/sync/driver/sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698