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

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

Powered by Google App Engine
This is Rietveld 408576698