Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_components_factory_impl_unittest.cc
blob0447108e5d6941fde5b588434705bc3239f9aa91
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/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h"
11 #include "chrome/browser/sync/glue/data_type_controller.h"
12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/test/test_browser_thread.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 using browser_sync::DataTypeController;
20 using content::BrowserThread;
22 class ProfileSyncComponentsFactoryImplTest : public testing::Test {
23 protected:
24 ProfileSyncComponentsFactoryImplTest()
25 : ui_thread_(BrowserThread::UI, &message_loop_) {}
27 virtual void SetUp() {
28 profile_.reset(new TestingProfile());
29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe"));
30 command_line_.reset(new CommandLine(program_path));
33 // Returns the collection of default datatypes.
34 static std::vector<syncer::ModelType> DefaultDatatypes() {
35 std::vector<syncer::ModelType> datatypes;
36 datatypes.push_back(syncer::APPS);
37 datatypes.push_back(syncer::APP_NOTIFICATIONS);
38 datatypes.push_back(syncer::APP_SETTINGS);
39 datatypes.push_back(syncer::AUTOFILL);
40 datatypes.push_back(syncer::AUTOFILL_PROFILE);
41 datatypes.push_back(syncer::BOOKMARKS);
42 datatypes.push_back(syncer::EXTENSIONS);
43 datatypes.push_back(syncer::EXTENSION_SETTINGS);
44 datatypes.push_back(syncer::PASSWORDS);
45 datatypes.push_back(syncer::PREFERENCES);
46 datatypes.push_back(syncer::SEARCH_ENGINES);
47 datatypes.push_back(syncer::SESSIONS);
48 datatypes.push_back(syncer::THEMES);
49 datatypes.push_back(syncer::TYPED_URLS);
50 return datatypes;
53 // Returns the number of default datatypes.
54 static size_t DefaultDatatypesCount() {
55 return DefaultDatatypes().size();
58 // Asserts that all the default datatypes are in |map|, except
59 // for |exception_type|, which unless it is UNDEFINED, is asserted to
60 // not be in |map|.
61 static void CheckDefaultDatatypesInMapExcept(
62 DataTypeController::StateMap* map,
63 syncer::ModelType exception_type) {
64 std::vector<syncer::ModelType> defaults = DefaultDatatypes();
65 std::vector<syncer::ModelType>::iterator iter;
66 for (iter = defaults.begin(); iter != defaults.end(); ++iter) {
67 if (exception_type != syncer::UNSPECIFIED && exception_type == *iter)
68 EXPECT_EQ(0U, map->count(*iter))
69 << *iter << " found in dataypes map, shouldn't be there.";
70 else
71 EXPECT_EQ(1U, map->count(*iter))
72 << *iter << " not found in datatypes map";
76 // Asserts that if you apply the command line switch |cmd_switch|,
77 // all types are enabled except for |type|, which is disabled.
78 void TestSwitchDisablesType(const char* cmd_switch,
79 syncer::ModelType type) {
80 command_line_->AppendSwitch(cmd_switch);
81 scoped_ptr<ProfileSyncService> pss(
82 new ProfileSyncService(
83 new ProfileSyncComponentsFactoryImpl(profile_.get(),
84 command_line_.get()),
85 profile_.get(),
86 NULL,
87 ProfileSyncService::MANUAL_START));
88 pss->factory()->RegisterDataTypes(pss.get());
89 DataTypeController::StateMap controller_states;
90 pss->GetDataTypeControllerStates(&controller_states);
91 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size());
92 CheckDefaultDatatypesInMapExcept(&controller_states, type);
95 MessageLoop message_loop_;
96 content::TestBrowserThread ui_thread_;
97 scoped_ptr<Profile> profile_;
98 scoped_ptr<CommandLine> command_line_;
101 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) {
102 scoped_ptr<ProfileSyncService> pss(
103 new ProfileSyncService(
104 new ProfileSyncComponentsFactoryImpl(profile_.get(),
105 command_line_.get()),
106 profile_.get(),
107 NULL,
108 ProfileSyncService::MANUAL_START));
109 pss->factory()->RegisterDataTypes(pss.get());
110 DataTypeController::StateMap controller_states;
111 pss->GetDataTypeControllerStates(&controller_states);
112 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size());
113 CheckDefaultDatatypesInMapExcept(&controller_states, syncer::UNSPECIFIED);
116 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) {
117 TestSwitchDisablesType(switches::kDisableSyncAutofill,
118 syncer::AUTOFILL);
121 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableBookmarks) {
122 TestSwitchDisablesType(switches::kDisableSyncBookmarks,
123 syncer::BOOKMARKS);
126 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePreferences) {
127 TestSwitchDisablesType(switches::kDisableSyncPreferences,
128 syncer::PREFERENCES);
131 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableThemes) {
132 TestSwitchDisablesType(switches::kDisableSyncThemes,
133 syncer::THEMES);
136 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableExtensions) {
137 TestSwitchDisablesType(switches::kDisableSyncExtensions,
138 syncer::EXTENSIONS);
141 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableApps) {
142 TestSwitchDisablesType(switches::kDisableSyncApps,
143 syncer::APPS);
146 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) {
147 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile,
148 syncer::AUTOFILL_PROFILE);
151 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) {
152 TestSwitchDisablesType(switches::kDisableSyncPasswords,
153 syncer::PASSWORDS);