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

Side by Side Diff: components/sync_driver/sync_prefs_unittest.cc

Issue 195873020: [Sync] Move SyncPrefs into sync_driver component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rerererebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « components/sync_driver/sync_prefs.cc ('k') | no next file » | 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 "chrome/browser/sync/sync_prefs.h" 5 #include "components/sync_driver/sync_prefs.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_notifier_impl.h"
10 #include "base/prefs/pref_value_store.h"
11 #include "base/prefs/testing_pref_service.h"
9 #include "base/time/time.h" 12 #include "base/time/time.h"
10 #include "chrome/common/chrome_switches.h" 13 #include "components/sync_driver/pref_names.h"
11 #include "chrome/common/pref_names.h" 14 #include "components/user_prefs/pref_registry_syncable.h"
12 #include "chrome/test/base/testing_pref_service_syncable.h"
13 #include "sync/internal_api/public/base/model_type.h" 15 #include "sync/internal_api/public/base/model_type.h"
14 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace browser_sync { 19 template <>
20 TestingPrefServiceBase<PrefService, user_prefs::PrefRegistrySyncable>::
21 TestingPrefServiceBase(TestingPrefStore* managed_prefs,
22 TestingPrefStore* user_prefs,
23 TestingPrefStore* recommended_prefs,
24 user_prefs::PrefRegistrySyncable* pref_registry,
25 PrefNotifierImpl* pref_notifier)
26 : PrefService(
27 pref_notifier,
28 new PrefValueStore(managed_prefs,
29 NULL, // supervised_user_prefs
30 NULL, // extension_prefs
31 NULL, // command_line_prefs
32 user_prefs,
33 recommended_prefs,
34 pref_registry->defaults().get(),
35 pref_notifier),
36 user_prefs,
37 pref_registry,
38 base::Bind(&TestingPrefServiceBase<
39 PrefService,
40 user_prefs::PrefRegistrySyncable>::HandleReadError),
41 false),
42 managed_prefs_(managed_prefs),
43 user_prefs_(user_prefs),
44 recommended_prefs_(recommended_prefs) {}
45
46 namespace sync_driver {
18 47
19 namespace { 48 namespace {
20 49
21 using ::testing::InSequence; 50 using ::testing::InSequence;
22 using ::testing::StrictMock; 51 using ::testing::StrictMock;
23 52
53 // Test version of PrefServiceSyncable.
54 class TestingPrefServiceSyncable
55 : public TestingPrefServiceBase<PrefService,
56 user_prefs::PrefRegistrySyncable> {
57 public:
58 TestingPrefServiceSyncable();
59 virtual ~TestingPrefServiceSyncable();
60
61 user_prefs::PrefRegistrySyncable* registry();
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable);
65 };
66
67 TestingPrefServiceSyncable::TestingPrefServiceSyncable()
68 : TestingPrefServiceBase<PrefService, user_prefs::PrefRegistrySyncable>(
69 new TestingPrefStore(),
70 new TestingPrefStore(),
71 new TestingPrefStore(),
72 new user_prefs::PrefRegistrySyncable(),
73 new PrefNotifierImpl()) {}
74
75 TestingPrefServiceSyncable::~TestingPrefServiceSyncable() {}
76
77 user_prefs::PrefRegistrySyncable* TestingPrefServiceSyncable::registry() {
78 return static_cast<user_prefs::PrefRegistrySyncable*>(
79 DeprecatedGetPrefRegistry());
80 }
81
24 class SyncPrefsTest : public testing::Test { 82 class SyncPrefsTest : public testing::Test {
25 protected: 83 protected:
26 virtual void SetUp() OVERRIDE { 84 virtual void SetUp() OVERRIDE {
27 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); 85 SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
28 } 86 }
29 87
30 TestingPrefServiceSyncable pref_service_; 88 TestingPrefServiceSyncable pref_service_;
31 89
32 private: 90 private:
33 base::MessageLoop loop_; 91 base::MessageLoop loop_;
(...skipping 26 matching lines...) Expand all
60 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 118 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
61 sync_prefs.SetEncryptionBootstrapToken("token"); 119 sync_prefs.SetEncryptionBootstrapToken("token");
62 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken()); 120 EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken());
63 } 121 }
64 122
65 TEST_F(SyncPrefsTest, DefaultTypes) { 123 TEST_F(SyncPrefsTest, DefaultTypes) {
66 SyncPrefs sync_prefs(&pref_service_); 124 SyncPrefs sync_prefs(&pref_service_);
67 sync_prefs.SetKeepEverythingSynced(false); 125 sync_prefs.SetKeepEverythingSynced(false);
68 126
69 // Only bookmarks are enabled by default. 127 // Only bookmarks are enabled by default.
70 syncer::ModelTypeSet preferred_types = sync_prefs.GetPreferredDataTypes( 128 syncer::ModelTypeSet preferred_types =
71 syncer::UserTypes()); 129 sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
72 EXPECT_TRUE(preferred_types.Equals(syncer::ModelTypeSet(syncer::BOOKMARKS))); 130 EXPECT_TRUE(preferred_types.Equals(syncer::ModelTypeSet(syncer::BOOKMARKS)));
73 131
74 // Simulate an upgrade to delete directives + proxy tabs support. None of the 132 // Simulate an upgrade to delete directives + proxy tabs support. None of the
75 // new types or their pref group types should be registering, ensuring they 133 // new types or their pref group types should be registering, ensuring they
76 // don't have pref values. 134 // don't have pref values.
77 syncer::ModelTypeSet registered_types = syncer::UserTypes(); 135 syncer::ModelTypeSet registered_types = syncer::UserTypes();
78 registered_types.Remove(syncer::PROXY_TABS); 136 registered_types.Remove(syncer::PROXY_TABS);
79 registered_types.Remove(syncer::TYPED_URLS); 137 registered_types.Remove(syncer::TYPED_URLS);
80 registered_types.Remove(syncer::SESSIONS); 138 registered_types.Remove(syncer::SESSIONS);
81 registered_types.Remove(syncer::HISTORY_DELETE_DIRECTIVES); 139 registered_types.Remove(syncer::HISTORY_DELETE_DIRECTIVES);
82 140
83 // Enable all other types. 141 // Enable all other types.
84 sync_prefs.SetPreferredDataTypes(registered_types, 142 sync_prefs.SetPreferredDataTypes(registered_types, registered_types);
85 registered_types);
86 143
87 // Manually enable typed urls (to simulate the old world). 144 // Manually enable typed urls (to simulate the old world).
88 pref_service_.SetBoolean(prefs::kSyncTypedUrls, true); 145 pref_service_.SetBoolean(prefs::kSyncTypedUrls, true);
89 146
90 // Proxy tabs should not be enabled (since sessions wasn't), but history 147 // Proxy tabs should not be enabled (since sessions wasn't), but history
91 // delete directives should (since typed urls was). 148 // delete directives should (since typed urls was).
92 preferred_types = 149 preferred_types = sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
93 sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
94 EXPECT_FALSE(preferred_types.Has(syncer::PROXY_TABS)); 150 EXPECT_FALSE(preferred_types.Has(syncer::PROXY_TABS));
95 EXPECT_TRUE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES)); 151 EXPECT_TRUE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES));
96 152
97 // Now manually enable sessions, which should result in proxy tabs also being 153 // Now manually enable sessions, which should result in proxy tabs also being
98 // enabled. Also, manually disable typed urls, which should mean that history 154 // enabled. Also, manually disable typed urls, which should mean that history
99 // delete directives are not enabled. 155 // delete directives are not enabled.
100 pref_service_.SetBoolean(prefs::kSyncTypedUrls, false); 156 pref_service_.SetBoolean(prefs::kSyncTypedUrls, false);
101 pref_service_.SetBoolean(prefs::kSyncSessions, true); 157 pref_service_.SetBoolean(prefs::kSyncSessions, true);
102 preferred_types = 158 preferred_types = sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
103 sync_prefs.GetPreferredDataTypes(syncer::UserTypes());
104 EXPECT_TRUE(preferred_types.Has(syncer::PROXY_TABS)); 159 EXPECT_TRUE(preferred_types.Has(syncer::PROXY_TABS));
105 EXPECT_FALSE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES)); 160 EXPECT_FALSE(preferred_types.Has(syncer::HISTORY_DELETE_DIRECTIVES));
106 } 161 }
107 162
108 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) { 163 TEST_F(SyncPrefsTest, PreferredTypesKeepEverythingSynced) {
109 SyncPrefs sync_prefs(&pref_service_); 164 SyncPrefs sync_prefs(&pref_service_);
110 165
111 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced()); 166 EXPECT_TRUE(sync_prefs.HasKeepEverythingSynced());
112 167
113 const syncer::ModelTypeSet user_types = syncer::UserTypes(); 168 const syncer::ModelTypeSet user_types = syncer::UserTypes();
114 EXPECT_TRUE(user_types.Equals( 169 EXPECT_TRUE(user_types.Equals(sync_prefs.GetPreferredDataTypes(user_types)));
115 sync_prefs.GetPreferredDataTypes(user_types)));
116 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes(); 170 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes();
117 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First(); 171 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First();
118 it.Good(); it.Inc()) { 172 it.Good();
173 it.Inc()) {
119 syncer::ModelTypeSet preferred_types; 174 syncer::ModelTypeSet preferred_types;
120 preferred_types.Put(it.Get()); 175 preferred_types.Put(it.Get());
121 sync_prefs.SetPreferredDataTypes(user_types, preferred_types); 176 sync_prefs.SetPreferredDataTypes(user_types, preferred_types);
122 EXPECT_TRUE(user_types.Equals( 177 EXPECT_TRUE(
123 sync_prefs.GetPreferredDataTypes(user_types))); 178 user_types.Equals(sync_prefs.GetPreferredDataTypes(user_types)));
124 } 179 }
125 } 180 }
126 181
127 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) { 182 TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
128 SyncPrefs sync_prefs(&pref_service_); 183 SyncPrefs sync_prefs(&pref_service_);
129 184
130 sync_prefs.SetKeepEverythingSynced(false); 185 sync_prefs.SetKeepEverythingSynced(false);
131 186
132 const syncer::ModelTypeSet user_types = syncer::UserTypes(); 187 const syncer::ModelTypeSet user_types = syncer::UserTypes();
133 EXPECT_FALSE(user_types.Equals( 188 EXPECT_FALSE(user_types.Equals(sync_prefs.GetPreferredDataTypes(user_types)));
134 sync_prefs.GetPreferredDataTypes(user_types)));
135 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes(); 189 const syncer::ModelTypeSet user_visible_types = syncer::UserSelectableTypes();
136 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First(); 190 for (syncer::ModelTypeSet::Iterator it = user_visible_types.First();
137 it.Good(); it.Inc()) { 191 it.Good();
192 it.Inc()) {
138 syncer::ModelTypeSet preferred_types; 193 syncer::ModelTypeSet preferred_types;
139 preferred_types.Put(it.Get()); 194 preferred_types.Put(it.Get());
140 syncer::ModelTypeSet expected_preferred_types(preferred_types); 195 syncer::ModelTypeSet expected_preferred_types(preferred_types);
141 if (it.Get() == syncer::AUTOFILL) { 196 if (it.Get() == syncer::AUTOFILL) {
142 expected_preferred_types.Put(syncer::AUTOFILL_PROFILE); 197 expected_preferred_types.Put(syncer::AUTOFILL_PROFILE);
143 } 198 }
144 if (it.Get() == syncer::PREFERENCES) { 199 if (it.Get() == syncer::PREFERENCES) {
145 expected_preferred_types.Put(syncer::DICTIONARY); 200 expected_preferred_types.Put(syncer::DICTIONARY);
146 expected_preferred_types.Put(syncer::PRIORITY_PREFERENCES); 201 expected_preferred_types.Put(syncer::PRIORITY_PREFERENCES);
147 expected_preferred_types.Put(syncer::SEARCH_ENGINES); 202 expected_preferred_types.Put(syncer::SEARCH_ENGINES);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 sync_prefs.ClearPreferences(); 284 sync_prefs.ClearPreferences();
230 285
231 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted()); 286 EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
232 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime()); 287 EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
233 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty()); 288 EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
234 } 289 }
235 290
236 } // namespace 291 } // namespace
237 292
238 } // namespace browser_sync 293 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/sync_prefs.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698