Use app list item shadow for app list folders.
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_components_factory_impl_unittest.cc
bloba484b44a2bb381bc40c591023da923aec5dc167f
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
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/signin/core/browser/profile_oauth2_token_service.h"
20 #include "components/sync_driver/data_type_controller.h"
21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "google_apis/gaia/gaia_constants.h"
23 #include "google_apis/gaia/oauth2_token_service.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/app_list/app_list_switches.h"
27 using sync_driver::DataTypeController;
29 class ProfileSyncComponentsFactoryImplTest : public testing::Test {
30 protected:
31 ProfileSyncComponentsFactoryImplTest()
32 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {}
34 void SetUp() override {
35 profile_.reset(new TestingProfile());
36 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe"));
37 command_line_.reset(new base::CommandLine(program_path));
38 scope_set_.insert(GaiaConstants::kChromeSyncOAuth2Scope);
41 // Returns the collection of default datatypes.
42 static std::vector<syncer::ModelType> DefaultDatatypes() {
43 std::vector<syncer::ModelType> datatypes;
44 datatypes.push_back(syncer::APPS);
45 #if defined(ENABLE_APP_LIST)
46 if (app_list::switches::IsAppListSyncEnabled())
47 datatypes.push_back(syncer::APP_LIST);
48 #endif
49 datatypes.push_back(syncer::APP_SETTINGS);
50 datatypes.push_back(syncer::AUTOFILL);
51 datatypes.push_back(syncer::AUTOFILL_PROFILE);
52 datatypes.push_back(syncer::AUTOFILL_WALLET_DATA);
53 datatypes.push_back(syncer::BOOKMARKS);
54 datatypes.push_back(syncer::DEVICE_INFO);
55 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
56 datatypes.push_back(syncer::DICTIONARY);
57 #endif
58 datatypes.push_back(syncer::EXTENSIONS);
59 datatypes.push_back(syncer::EXTENSION_SETTINGS);
60 datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES);
61 datatypes.push_back(syncer::PASSWORDS);
62 datatypes.push_back(syncer::PREFERENCES);
63 datatypes.push_back(syncer::PRIORITY_PREFERENCES);
64 datatypes.push_back(syncer::SEARCH_ENGINES);
65 datatypes.push_back(syncer::SESSIONS);
66 datatypes.push_back(syncer::PROXY_TABS);
67 datatypes.push_back(syncer::THEMES);
68 datatypes.push_back(syncer::TYPED_URLS);
69 datatypes.push_back(syncer::FAVICON_TRACKING);
70 datatypes.push_back(syncer::FAVICON_IMAGES);
71 datatypes.push_back(syncer::SUPERVISED_USERS);
72 datatypes.push_back(syncer::SUPERVISED_USER_SETTINGS);
73 datatypes.push_back(syncer::SUPERVISED_USER_SHARED_SETTINGS);
74 datatypes.push_back(syncer::SUPERVISED_USER_WHITELISTS);
76 return datatypes;
79 // Returns the number of default datatypes.
80 static size_t DefaultDatatypesCount() {
81 return DefaultDatatypes().size();
84 // Asserts that all the default datatypes are in |map|, except
85 // for |exception_type|, which unless it is UNDEFINED, is asserted to
86 // not be in |map|.
87 static void CheckDefaultDatatypesInMapExcept(
88 DataTypeController::StateMap* map,
89 syncer::ModelTypeSet exception_types) {
90 std::vector<syncer::ModelType> defaults = DefaultDatatypes();
91 std::vector<syncer::ModelType>::iterator iter;
92 for (iter = defaults.begin(); iter != defaults.end(); ++iter) {
93 if (exception_types.Has(*iter))
94 EXPECT_EQ(0U, map->count(*iter))
95 << *iter << " found in dataypes map, shouldn't be there.";
96 else
97 EXPECT_EQ(1U, map->count(*iter))
98 << *iter << " not found in datatypes map";
102 // Asserts that if you disable types via the command line, all other types
103 // are enabled.
104 void TestSwitchDisablesType(syncer::ModelTypeSet types) {
105 command_line_->AppendSwitchASCII(switches::kDisableSyncTypes,
106 syncer::ModelTypeSetToString(types));
107 GURL sync_service_url =
108 ProfileSyncService::GetSyncServiceURL(*command_line_);
109 ProfileOAuth2TokenService* token_service =
110 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
111 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService(
112 scoped_ptr<ProfileSyncComponentsFactory>(
113 new ProfileSyncComponentsFactoryImpl(
114 profile_.get(),
115 command_line_.get(),
116 ProfileSyncService::GetSyncServiceURL(*command_line_),
117 token_service,
118 profile_->GetRequestContext())),
119 profile_.get(),
120 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL),
121 token_service,
122 browser_sync::MANUAL_START));
123 pss->factory()->RegisterDataTypes(pss.get());
124 DataTypeController::StateMap controller_states;
125 pss->GetDataTypeControllerStates(&controller_states);
126 EXPECT_EQ(DefaultDatatypesCount() - types.Size(), controller_states.size());
127 CheckDefaultDatatypesInMapExcept(&controller_states, types);
130 content::TestBrowserThreadBundle thread_bundle_;
131 scoped_ptr<Profile> profile_;
132 scoped_ptr<base::CommandLine> command_line_;
133 OAuth2TokenService::ScopeSet scope_set_;
136 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) {
137 ProfileOAuth2TokenService* token_service =
138 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
139 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService(
140 scoped_ptr<ProfileSyncComponentsFactory>(
141 new ProfileSyncComponentsFactoryImpl(
142 profile_.get(),
143 command_line_.get(),
144 ProfileSyncService::GetSyncServiceURL(*command_line_),
145 token_service,
146 profile_->GetRequestContext())),
147 profile_.get(),
148 make_scoped_ptr<SupervisedUserSigninManagerWrapper>(NULL),
149 token_service,
150 browser_sync::MANUAL_START));
151 pss->factory()->RegisterDataTypes(pss.get());
152 DataTypeController::StateMap controller_states;
153 pss->GetDataTypeControllerStates(&controller_states);
154 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size());
155 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::ModelTypeSet());
158 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableOne) {
159 TestSwitchDisablesType(syncer::ModelTypeSet(syncer::AUTOFILL));
162 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableMultiple) {
163 TestSwitchDisablesType(
164 syncer::ModelTypeSet(syncer::AUTOFILL_PROFILE, syncer::BOOKMARKS));