OLD | NEW |
1 // Copyright (c) 2012 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 "base/synchronization/waitable_event.h" |
11 #include "chrome/browser/sync/glue/data_type_controller.h" | 12 #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_components_factory_impl.h" |
13 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/webdata/web_data_service_factory.h" |
14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
16 #include "content/test/test_browser_thread.h" | 18 #include "content/test/test_browser_thread.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 | 20 |
19 using browser_sync::DataTypeController; | 21 using browser_sync::DataTypeController; |
20 using content::BrowserThread; | 22 using content::BrowserThread; |
21 | 23 |
22 class ProfileSyncComponentsFactoryImplTest : public testing::Test { | 24 class ProfileSyncComponentsFactoryImplTest : public testing::Test { |
23 protected: | 25 protected: |
24 ProfileSyncComponentsFactoryImplTest() | 26 ProfileSyncComponentsFactoryImplTest() |
25 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 27 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 28 db_thread_(BrowserThread::DB) {} |
26 | 29 |
27 virtual void SetUp() { | 30 virtual void SetUp() OVERRIDE { |
| 31 db_thread_.Start(); |
28 profile_.reset(new TestingProfile()); | 32 profile_.reset(new TestingProfile()); |
29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | 33 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
30 command_line_.reset(new CommandLine(program_path)); | 34 command_line_.reset(new CommandLine(program_path)); |
31 } | 35 } |
32 | 36 |
| 37 virtual void TearDown() OVERRIDE { |
| 38 profile_.reset(); |
| 39 // Schedule another task on the DB thread to notify us that it's safe to |
| 40 // carry on with the test. |
| 41 base::WaitableEvent done(false, false); |
| 42 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 43 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 44 done.Wait(); |
| 45 db_thread_.Stop(); |
| 46 } |
| 47 |
33 // Returns the collection of default datatypes. | 48 // Returns the collection of default datatypes. |
34 static std::vector<syncable::ModelType> DefaultDatatypes() { | 49 static std::vector<syncable::ModelType> DefaultDatatypes() { |
35 std::vector<syncable::ModelType> datatypes; | 50 std::vector<syncable::ModelType> datatypes; |
36 datatypes.push_back(syncable::APPS); | 51 datatypes.push_back(syncable::APPS); |
37 datatypes.push_back(syncable::APP_NOTIFICATIONS); | 52 datatypes.push_back(syncable::APP_NOTIFICATIONS); |
38 datatypes.push_back(syncable::APP_SETTINGS); | 53 datatypes.push_back(syncable::APP_SETTINGS); |
39 datatypes.push_back(syncable::AUTOFILL); | 54 datatypes.push_back(syncable::AUTOFILL); |
40 datatypes.push_back(syncable::AUTOFILL_PROFILE); | 55 datatypes.push_back(syncable::AUTOFILL_PROFILE); |
41 datatypes.push_back(syncable::BOOKMARKS); | 56 datatypes.push_back(syncable::BOOKMARKS); |
42 datatypes.push_back(syncable::EXTENSIONS); | 57 datatypes.push_back(syncable::EXTENSIONS); |
(...skipping 28 matching lines...) Expand all Loading... |
71 EXPECT_EQ(1U, map->count(*iter)) | 86 EXPECT_EQ(1U, map->count(*iter)) |
72 << *iter << " not found in datatypes map"; | 87 << *iter << " not found in datatypes map"; |
73 } | 88 } |
74 } | 89 } |
75 | 90 |
76 // Asserts that if you apply the command line switch |cmd_switch|, | 91 // Asserts that if you apply the command line switch |cmd_switch|, |
77 // all types are enabled except for |type|, which is disabled. | 92 // all types are enabled except for |type|, which is disabled. |
78 void TestSwitchDisablesType(const char* cmd_switch, | 93 void TestSwitchDisablesType(const char* cmd_switch, |
79 syncable::ModelType type) { | 94 syncable::ModelType type) { |
80 command_line_->AppendSwitch(cmd_switch); | 95 command_line_->AppendSwitch(cmd_switch); |
| 96 WebDataServiceFactory::GetInstance()->SetTestingFactory(profile_.get(), |
| 97 NULL); |
81 scoped_ptr<ProfileSyncService> pss( | 98 scoped_ptr<ProfileSyncService> pss( |
82 new ProfileSyncService( | 99 new ProfileSyncService( |
83 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 100 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
84 command_line_.get()), | 101 command_line_.get()), |
85 profile_.get(), | 102 profile_.get(), |
86 NULL, | 103 NULL, |
87 ProfileSyncService::MANUAL_START)); | 104 ProfileSyncService::MANUAL_START)); |
88 pss->factory()->RegisterDataTypes(pss.get()); | 105 pss->factory()->RegisterDataTypes(pss.get()); |
89 DataTypeController::StateMap controller_states; | 106 DataTypeController::StateMap controller_states; |
90 pss->GetDataTypeControllerStates(&controller_states); | 107 pss->GetDataTypeControllerStates(&controller_states); |
91 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); | 108 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); |
92 CheckDefaultDatatypesInMapExcept(&controller_states, type); | 109 CheckDefaultDatatypesInMapExcept(&controller_states, type); |
93 } | 110 } |
94 | 111 |
95 MessageLoop message_loop_; | 112 MessageLoop message_loop_; |
96 content::TestBrowserThread ui_thread_; | 113 content::TestBrowserThread ui_thread_; |
| 114 content::TestBrowserThread db_thread_; |
97 scoped_ptr<Profile> profile_; | 115 scoped_ptr<Profile> profile_; |
98 scoped_ptr<CommandLine> command_line_; | 116 scoped_ptr<CommandLine> command_line_; |
99 }; | 117 }; |
100 | 118 |
101 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { | 119 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDefault) { |
| 120 WebDataServiceFactory::GetInstance()->SetTestingFactory(profile_.get(), |
| 121 NULL); |
102 scoped_ptr<ProfileSyncService> pss( | 122 scoped_ptr<ProfileSyncService> pss( |
103 new ProfileSyncService( | 123 new ProfileSyncService( |
104 new ProfileSyncComponentsFactoryImpl(profile_.get(), | 124 new ProfileSyncComponentsFactoryImpl(profile_.get(), |
105 command_line_.get()), | 125 command_line_.get()), |
106 profile_.get(), | 126 profile_.get(), |
107 NULL, | 127 NULL, |
108 ProfileSyncService::MANUAL_START)); | 128 ProfileSyncService::MANUAL_START)); |
109 pss->factory()->RegisterDataTypes(pss.get()); | 129 pss->factory()->RegisterDataTypes(pss.get()); |
110 DataTypeController::StateMap controller_states; | 130 DataTypeController::StateMap controller_states; |
111 pss->GetDataTypeControllerStates(&controller_states); | 131 pss->GetDataTypeControllerStates(&controller_states); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 165 |
146 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { | 166 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisableAutofillProfile) { |
147 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, | 167 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, |
148 syncable::AUTOFILL_PROFILE); | 168 syncable::AUTOFILL_PROFILE); |
149 } | 169 } |
150 | 170 |
151 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { | 171 TEST_F(ProfileSyncComponentsFactoryImplTest, CreatePSSDisablePasswords) { |
152 TestSwitchDisablesType(switches::kDisableSyncPasswords, | 172 TestSwitchDisablesType(switches::kDisableSyncPasswords, |
153 syncable::PASSWORDS); | 173 syncable::PASSWORDS); |
154 } | 174 } |
OLD | NEW |