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 "chrome/browser/search_engines/template_url_service_test_util.h" | 5 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "chrome/browser/search_engines/search_terms_data.h" | 12 #include "chrome/browser/search_engines/search_terms_data.h" |
13 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "chrome/browser/webdata/web_data_service_factory.h" | |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 121 |
121 // Wait for the delete of the request context to happen. | 122 // Wait for the delete of the request context to happen. |
122 if (io_thread_.IsRunning()) | 123 if (io_thread_.IsRunning()) |
123 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 124 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
124 | 125 |
125 // The I/O thread must be shutdown before the DB thread. | 126 // The I/O thread must be shutdown before the DB thread. |
126 io_thread_.Stop(); | 127 io_thread_.Stop(); |
127 | 128 |
128 // Clean up the test directory. | 129 // Clean up the test directory. |
129 if (service_.get()) | 130 if (service_.get()) |
130 service_->Shutdown(); | 131 service_ = NULL; |
131 // Note that we must ensure the DB thread is stopped after WDS | 132 // Note that we must ensure the DB thread is stopped after WDS |
132 // shutdown (so it can commit pending transactions) but before | 133 // shutdown (so it can commit pending transactions) but before |
133 // deleting the test profile directory, otherwise we may not be | 134 // deleting the test profile directory, otherwise we may not be |
134 // able to delete it due to an open transaction. | 135 // able to delete it due to an open transaction. |
135 db_thread_.Stop(); | 136 db_thread_.Stop(); |
136 } | 137 } |
137 | 138 |
138 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() | 139 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() |
139 : ui_thread_(BrowserThread::UI, &message_loop_), | 140 : ui_thread_(BrowserThread::UI, &message_loop_), |
140 changed_count_(0) { | 141 changed_count_(0) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 model()->Load(); | 189 model()->Load(); |
189 BlockTillServiceProcessesRequests(); | 190 BlockTillServiceProcessesRequests(); |
190 EXPECT_EQ(1, GetObserverCount()); | 191 EXPECT_EQ(1, GetObserverCount()); |
191 ResetObserverCount(); | 192 ResetObserverCount(); |
192 } | 193 } |
193 | 194 |
194 void TemplateURLServiceTestUtil::ChangeModelToLoadState() { | 195 void TemplateURLServiceTestUtil::ChangeModelToLoadState() { |
195 model()->ChangeToLoadedState(); | 196 model()->ChangeToLoadedState(); |
196 // Initialize the web data service so that the database gets updated with | 197 // Initialize the web data service so that the database gets updated with |
197 // any changes made. | 198 // any changes made. |
198 model()->service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 199 model()->service_ = |
Peter Kasting
2012/03/27 18:18:25
Nit: Another way would be
model()->service_ = W
GeorgeY
2012/03/30 19:20:12
Done.
| |
200 WebDataServiceFactory::GetForProfile(profile_.get(), | |
201 Profile::EXPLICIT_ACCESS); | |
199 } | 202 } |
200 | 203 |
201 void TemplateURLServiceTestUtil::ClearModel() { | 204 void TemplateURLServiceTestUtil::ClearModel() { |
202 TemplateURLServiceFactory::GetInstance()->SetTestingFactory( | 205 TemplateURLServiceFactory::GetInstance()->SetTestingFactory( |
203 profile_.get(), NULL); | 206 profile_.get(), NULL); |
204 } | 207 } |
205 | 208 |
206 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { | 209 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { |
207 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 210 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
208 profile_.get(), TestingTemplateURLService::Build); | 211 profile_.get(), TestingTemplateURLService::Build); |
(...skipping 25 matching lines...) Expand all Loading... | |
234 return profile_.get(); | 237 return profile_.get(); |
235 } | 238 } |
236 | 239 |
237 void TemplateURLServiceTestUtil::StartIOThread() { | 240 void TemplateURLServiceTestUtil::StartIOThread() { |
238 profile_->StartIOThread(); | 241 profile_->StartIOThread(); |
239 } | 242 } |
240 | 243 |
241 void TemplateURLServiceTestUtil::PumpLoop() { | 244 void TemplateURLServiceTestUtil::PumpLoop() { |
242 message_loop_.RunAllPending(); | 245 message_loop_.RunAllPending(); |
243 } | 246 } |
OLD | NEW |