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

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

Issue 1421003007: [Sync] Componentize ProfileSyncComponentsFactoryImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/sync/profile_sync_service_factory.h" 7 #include "chrome/browser/sync/profile_sync_service_factory.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "components/browser_sync/browser/profile_sync_service.h"
10 #include "components/browser_sync/common/browser_sync_switches.h" 11 #include "components/browser_sync/common/browser_sync_switches.h"
12 #include "components/sync_driver/data_type_controller.h"
11 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "sync/internal_api/public/base/model_type.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/app_list/app_list_switches.h"
17
18 using sync_driver::DataTypeController;
13 19
14 class ProfileSyncServiceFactoryTest : public testing::Test { 20 class ProfileSyncServiceFactoryTest : public testing::Test {
15 protected: 21 protected:
16 ProfileSyncServiceFactoryTest() {} 22 ProfileSyncServiceFactoryTest() : profile_(new TestingProfile()) {}
17 23
18 void SetUp() override { 24 // Returns the collection of default datatypes.
19 profile_.reset(new TestingProfile()); 25 std::vector<syncer::ModelType> DefaultDatatypes() {
26 std::vector<syncer::ModelType> datatypes;
27 datatypes.push_back(syncer::APPS);
28 #if defined(ENABLE_APP_LIST)
29 if (app_list::switches::IsAppListSyncEnabled())
30 datatypes.push_back(syncer::APP_LIST);
31 #endif
32 datatypes.push_back(syncer::APP_SETTINGS);
33 datatypes.push_back(syncer::AUTOFILL);
34 datatypes.push_back(syncer::AUTOFILL_PROFILE);
35 datatypes.push_back(syncer::AUTOFILL_WALLET_DATA);
36 datatypes.push_back(syncer::AUTOFILL_WALLET_METADATA);
37 datatypes.push_back(syncer::BOOKMARKS);
38 datatypes.push_back(syncer::DEVICE_INFO);
39 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
40 datatypes.push_back(syncer::DICTIONARY);
41 #endif
42 datatypes.push_back(syncer::EXTENSIONS);
43 datatypes.push_back(syncer::EXTENSION_SETTINGS);
44 datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES);
45 datatypes.push_back(syncer::PASSWORDS);
46 datatypes.push_back(syncer::PREFERENCES);
47 datatypes.push_back(syncer::PRIORITY_PREFERENCES);
48 datatypes.push_back(syncer::SEARCH_ENGINES);
49 datatypes.push_back(syncer::SESSIONS);
50 datatypes.push_back(syncer::PROXY_TABS);
51 datatypes.push_back(syncer::THEMES);
52 datatypes.push_back(syncer::TYPED_URLS);
53 datatypes.push_back(syncer::FAVICON_TRACKING);
54 datatypes.push_back(syncer::FAVICON_IMAGES);
55 datatypes.push_back(syncer::SUPERVISED_USERS);
56 datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS);
57 datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS);
58 datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS);
59
60 return datatypes;
20 } 61 }
21 62
63 // Returns the number of default datatypes.
64 size_t DefaultDatatypesCount() {
65 return DefaultDatatypes().size();
66 }
67
68 // Asserts that all the default datatypes are in |map|, except
69 // for |exception_type|, which unless it is UNDEFINED, is asserted to
70 // not be in |map|.
71 void CheckDefaultDatatypesInMapExcept(
72 DataTypeController::StateMap* map,
73 syncer::ModelTypeSet exception_types) {
74 std::vector<syncer::ModelType> defaults = DefaultDatatypes();
75 std::vector<syncer::ModelType>::iterator iter;
76 for (iter = defaults.begin(); iter != defaults.end(); ++iter) {
77 if (exception_types.Has(*iter))
78 EXPECT_EQ(0U, map->count(*iter))
79 << *iter << " found in dataypes map, shouldn't be there.";
80 else
81 EXPECT_EQ(1U, map->count(*iter))
82 << *iter << " not found in datatypes map";
83 }
84 }
85
86 void SetDisabledTypes(syncer::ModelTypeSet disabled_types) {
87 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
88 switches::kDisableSyncTypes,
89 syncer::ModelTypeSetToString(disabled_types));
90 }
91
92 Profile* profile() { return profile_.get(); }
93
94 private:
22 content::TestBrowserThreadBundle thread_bundle_; 95 content::TestBrowserThreadBundle thread_bundle_;
23 scoped_ptr<Profile> profile_; 96 scoped_ptr<Profile> profile_;
24 }; 97 };
25 98
26 // Verify that the disable sync flag disables creation of the sync service. 99 // Verify that the disable sync flag disables creation of the sync service.
27 TEST_F(ProfileSyncServiceFactoryTest, DisableSyncFlag) { 100 TEST_F(ProfileSyncServiceFactoryTest, DisableSyncFlag) {
28 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); 101 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
29 EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile_.get())); 102 EXPECT_EQ(nullptr, ProfileSyncServiceFactory::GetForProfile(profile()));
30 } 103 }
104
105 // Verify that a normal (no command line flags) PSS can be created and
106 // properly initialized.
107 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDefault) {
108 ProfileSyncService* pss =
109 ProfileSyncServiceFactory::GetForProfile(profile());
110 DataTypeController::StateMap controller_states;
111 pss->GetDataTypeControllerStates(&controller_states);
112 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size());
113 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet());
114 }
115
116 // Verify that a PSS with a disabled datatype can be created and properly
117 // initialized.
118 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableOne) {
119 syncer::ModelTypeSet disabled_types(syncer::AUTOFILL);
120 SetDisabledTypes(disabled_types);
121 ProfileSyncService* pss =
122 ProfileSyncServiceFactory::GetForProfile(profile());
123 DataTypeController::StateMap controller_states;
124 pss->GetDataTypeControllerStates(&controller_states);
125 EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(),
126 controller_states.size());
127 CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types);
128 }
129
130 // Verify that a PSS with multiple disabled datatypes can be created and
131 // properly initialized.
132 TEST_F(ProfileSyncServiceFactoryTest, CreatePSSDisableMultiple) {
133 syncer::ModelTypeSet disabled_types(syncer::AUTOFILL_PROFILE,
134 syncer::BOOKMARKS);
135 SetDisabledTypes(disabled_types);
136 ProfileSyncService* pss =
137 ProfileSyncServiceFactory::GetForProfile(profile());
138 DataTypeController::StateMap controller_states;
139 pss->GetDataTypeControllerStates(&controller_states);
140 EXPECT_EQ(DefaultDatatypesCount() - disabled_types.Size(),
141 controller_states.size());
142 CheckDefaultDatatypesInMapExcept(&controller_states, disabled_types);
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698