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

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

Issue 9232011: sync: Make ProfileSyncService a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 11 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/sync/glue/data_type_controller.h" 11 #include "chrome/browser/sync/glue/data_type_controller.h"
12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 12 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
13 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
16 #include "content/test/test_browser_thread.h" 16 #include "content/test/test_browser_thread.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using browser_sync::DataTypeController; 19 using browser_sync::DataTypeController;
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 class ProfileSyncComponentsFactoryImplTest : public testing::Test { 22 class ProfileSyncComponentsFactoryImplTest : public testing::Test {
23 protected: 23 protected:
24 ProfileSyncComponentsFactoryImplTest() 24 ProfileSyncComponentsFactoryImplTest()
25 : ui_thread_(BrowserThread::UI, &message_loop_) {} 25 : ui_thread_(BrowserThread::UI, &message_loop_) {}
26 26
27 virtual void SetUp() { 27 virtual void SetUp() {
28 profile_.reset(new TestingProfile()); 28 profile_.reset(new TestingProfile());
29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); 29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe"));
30 command_line_.reset(new CommandLine(program_path)); 30 command_line_.reset(new CommandLine(program_path));
31 profile_sync_service_factory_.reset(
32 new ProfileSyncComponentsFactoryImpl(profile_.get(),
33 command_line_.get()));
34 } 31 }
35 32
36 // Returns the collection of default datatypes. 33 // Returns the collection of default datatypes.
37 static std::vector<syncable::ModelType> DefaultDatatypes() { 34 static std::vector<syncable::ModelType> DefaultDatatypes() {
38 std::vector<syncable::ModelType> datatypes; 35 std::vector<syncable::ModelType> datatypes;
39 datatypes.push_back(syncable::BOOKMARKS); 36 datatypes.push_back(syncable::BOOKMARKS);
40 datatypes.push_back(syncable::PREFERENCES); 37 datatypes.push_back(syncable::PREFERENCES);
41 datatypes.push_back(syncable::AUTOFILL); 38 datatypes.push_back(syncable::AUTOFILL);
42 datatypes.push_back(syncable::THEMES); 39 datatypes.push_back(syncable::THEMES);
43 datatypes.push_back(syncable::EXTENSIONS); 40 datatypes.push_back(syncable::EXTENSIONS);
(...skipping 28 matching lines...) Expand all
72 << *iter << " not found in datatypes map"; 69 << *iter << " not found in datatypes map";
73 } 70 }
74 } 71 }
75 72
76 // Asserts that if you apply the command line switch |cmd_switch|, 73 // Asserts that if you apply the command line switch |cmd_switch|,
77 // all types are enabled except for |type|, which is disabled. 74 // all types are enabled except for |type|, which is disabled.
78 void TestSwitchDisablesType(const char* cmd_switch, 75 void TestSwitchDisablesType(const char* cmd_switch,
79 syncable::ModelType type) { 76 syncable::ModelType type) {
80 command_line_->AppendSwitch(cmd_switch); 77 command_line_->AppendSwitch(cmd_switch);
81 scoped_ptr<ProfileSyncService> pss( 78 scoped_ptr<ProfileSyncService> pss(
82 profile_sync_service_factory_->CreateProfileSyncService()); 79 new ProfileSyncService(
83 profile_sync_service_factory_->RegisterDataTypes(pss.get()); 80 new ProfileSyncComponentsFactoryImpl(profile_.get(),
81 command_line_.get()),
82 profile_.get(),
83 NULL,
84 ProfileSyncService::MANUAL_START));
85 pss->factory()->RegisterDataTypes(pss.get());
84 DataTypeController::StateMap controller_states; 86 DataTypeController::StateMap controller_states;
85 pss->GetDataTypeControllerStates(&controller_states); 87 pss->GetDataTypeControllerStates(&controller_states);
86 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); 88 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size());
87 CheckDefaultDatatypesInMapExcept(&controller_states, type); 89 CheckDefaultDatatypesInMapExcept(&controller_states, type);
88 } 90 }
89 91
90 MessageLoop message_loop_; 92 MessageLoop message_loop_;
91 content::TestBrowserThread ui_thread_; 93 content::TestBrowserThread ui_thread_;
92 scoped_ptr<Profile> profile_; 94 scoped_ptr<Profile> profile_;
93 scoped_ptr<CommandLine> command_line_; 95 scoped_ptr<CommandLine> command_line_;
94 scoped_ptr<ProfileSyncComponentsFactoryImpl> profile_sync_service_factory_;
95 }; 96 };
96 97
97 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { 98 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) {
98 scoped_ptr<ProfileSyncService> pss( 99 scoped_ptr<ProfileSyncService> pss(
99 profile_sync_service_factory_->CreateProfileSyncService()); 100 new ProfileSyncService(
100 profile_sync_service_factory_->RegisterDataTypes(pss.get()); 101 new ProfileSyncComponentsFactoryImpl(profile_.get(),
102 command_line_.get()),
103 profile_.get(),
104 NULL,
105 ProfileSyncService::MANUAL_START));
106 pss->factory()->RegisterDataTypes(pss.get());
101 DataTypeController::StateMap controller_states; 107 DataTypeController::StateMap controller_states;
102 pss->GetDataTypeControllerStates(&controller_states); 108 pss->GetDataTypeControllerStates(&controller_states);
103 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); 109 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size());
104 CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED); 110 CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED);
105 } 111 }
106 112
107 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) { 113 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofill) {
108 TestSwitchDisablesType(switches::kDisableSyncAutofill, 114 TestSwitchDisablesType(switches::kDisableSyncAutofill,
109 syncable::AUTOFILL); 115 syncable::AUTOFILL);
110 } 116 }
(...skipping 25 matching lines...) Expand all
136 142
137 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { 143 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) {
138 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, 144 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile,
139 syncable::AUTOFILL_PROFILE); 145 syncable::AUTOFILL_PROFILE);
140 } 146 }
141 147
142 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { 148 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) {
143 TestSwitchDisablesType(switches::kDisableSyncPasswords, 149 TestSwitchDisablesType(switches::kDisableSyncPasswords,
144 syncable::PASSWORDS); 150 syncable::PASSWORDS);
145 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698