NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_components_factory_impl_unittest.cc
bloba59df7458c72a7e49a302e373c9445b7b3cc0c2e
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.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
14 #include "chrome/browser/sync/profile_sync_service.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "components/sync_driver/data_type_controller.h"
19 #include "content/public/test/test_browser_thread.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 using browser_sync::DataTypeController;
23 using content::BrowserThread;
25 class ProfileSyncComponentsFactoryImplTest : public testing::Test {
26 protected:
27 ProfileSyncComponentsFactoryImplTest()
28 : ui_thread_(BrowserThread::UI, &message_loop_) {}
30 virtual void SetUp() {
31 profile_.reset(new TestingProfile());
32 base::FilePath program_path(FILE_PATH_LITERAL("chrome.exe"));
33 command_line_.reset(new CommandLine(program_path));
36 // Returns the collection of default datatypes.
37 static std::vector<syncer::ModelType> DefaultDatatypes() {
38 std::vector<syncer::ModelType> datatypes;
39 datatypes.push_back(syncer::APPS);
40 datatypes.push_back(syncer::APP_SETTINGS);
41 datatypes.push_back(syncer::AUTOFILL);
42 datatypes.push_back(syncer::AUTOFILL_PROFILE);
43 datatypes.push_back(syncer::BOOKMARKS);
44 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_CHROMEOS)
45 datatypes.push_back(syncer::DICTIONARY);
46 #endif
47 datatypes.push_back(syncer::EXTENSIONS);
48 datatypes.push_back(syncer::EXTENSION_SETTINGS);
49 datatypes.push_back(syncer::HISTORY_DELETE_DIRECTIVES);
50 datatypes.push_back(syncer::PASSWORDS);
51 datatypes.push_back(syncer::PREFERENCES);
52 datatypes.push_back(syncer::PRIORITY_PREFERENCES);
53 datatypes.push_back(syncer::SEARCH_ENGINES);
54 datatypes.push_back(syncer::SESSIONS);
55 datatypes.push_back(syncer::PROXY_TABS);
56 datatypes.push_back(syncer::THEMES);
57 datatypes.push_back(syncer::TYPED_URLS);
58 datatypes.push_back(syncer::FAVICON_TRACKING);
59 datatypes.push_back(syncer::FAVICON_IMAGES);
60 datatypes.push_back(syncer::SYNCED_NOTIFICATIONS);
61 datatypes.push_back(syncer::MANAGED_USERS);
62 datatypes.push_back(syncer::MANAGED_USER_SHARED_SETTINGS);
64 return datatypes;
67 // Returns the number of default datatypes.
68 static size_t DefaultDatatypesCount() {
69 return DefaultDatatypes().size();
72 // Asserts that all the default datatypes are in |map|, except
73 // for |exception_type|, which unless it is UNDEFINED, is asserted to
74 // not be in |map|.
75 static void CheckDefaultDatatypesInMapExcept(
76 DataTypeController::StateMap* map,
77 syncer::ModelType exception_type) {
78 std::vector<syncer::ModelType> defaults = DefaultDatatypes();
79 std::vector<syncer::ModelType>::iterator iter;
80 for (iter = defaults.begin(); iter != defaults.end(); ++iter) {
81 if (exception_type != syncer::UNSPECIFIED && exception_type == *iter)
82 EXPECT_EQ(0U, map->count(*iter))
83 << *iter << " found in dataypes map, shouldn't be there.";
84 else
85 EXPECT_EQ(1U, map->count(*iter))
86 << *iter << " not found in datatypes map";
90 // Asserts that if you apply the command line switch |cmd_switch|,
91 // all types are enabled except for |type|, which is disabled.
92 void TestSwitchDisablesType(const char* cmd_switch,
93 syncer::ModelType type) {
94 command_line_->AppendSwitch(cmd_switch);
95 scoped_ptr<ProfileSyncService> pss(
96 new ProfileSyncService(
97 new ProfileSyncComponentsFactoryImpl(profile_.get(),
98 command_line_.get()),
99 profile_.get(),
100 NULL,
101 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()),
102 ProfileSyncService::MANUAL_START));
103 pss->factory()->RegisterDataTypes(pss.get());
104 DataTypeController::StateMap controller_states;
105 pss->GetDataTypeControllerStates(&controller_states);
106 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size());
107 CheckDefaultDatatypesInMapExcept(&controller_states, type);
110 base::MessageLoop message_loop_;
111 content::TestBrowserThread ui_thread_;
112 scoped_ptr<Profile> profile_;
113 scoped_ptr<CommandLine> command_line_;
116 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) {
117 scoped_ptr<ProfileSyncService> pss(new ProfileSyncService(
118 new ProfileSyncComponentsFactoryImpl(profile_.get(), command_line_.get()),
119 profile_.get(),
120 NULL,
121 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()),
122 ProfileSyncService::MANUAL_START));
123 pss->factory()->RegisterDataTypes(pss.get());
124 DataTypeController::StateMap controller_states;
125 pss->GetDataTypeControllerStates(&controller_states);
126 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size());
127 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::UNSPECIFIED);
130 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) {
131 TestSwitchDisablesType(switches::kDisableSyncAutofill,
132 syncer::AUTOFILL);
135 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) {
136 TestSwitchDisablesType(switches::kDisableSyncBookmarks,
137 syncer::BOOKMARKS);
140 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) {
141 TestSwitchDisablesType(switches::kDisableSyncPreferences,
142 syncer::PREFERENCES);
145 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) {
146 TestSwitchDisablesType(switches::kDisableSyncThemes,
147 syncer::THEMES);
150 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) {
151 TestSwitchDisablesType(switches::kDisableSyncExtensions,
152 syncer::EXTENSIONS);
155 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) {
156 TestSwitchDisablesType(switches::kDisableSyncApps,
157 syncer::APPS);
160 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) {
161 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile,
162 syncer::AUTOFILL_PROFILE);
165 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) {
166 TestSwitchDisablesType(switches::kDisableSyncPasswords,
167 syncer::PASSWORDS);