| 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/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/search_engines/search_terms_data.h" | 13 #include "chrome/browser/search_engines/search_terms_data.h" |
| 13 #include "chrome/browser/search_engines/template_url_service.h" | 14 #include "chrome/browser/search_engines/template_url_service.h" |
| 14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 16 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 18 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 using content::BrowserThread; | 23 using content::BrowserThread; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 122 |
| 121 // Wait for the delete of the request context to happen. | 123 // Wait for the delete of the request context to happen. |
| 122 if (io_thread_.IsRunning()) | 124 if (io_thread_.IsRunning()) |
| 123 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); | 125 TemplateURLServiceTestUtil::BlockTillIOThreadProcessesRequests(); |
| 124 | 126 |
| 125 // The I/O thread must be shutdown before the DB thread. | 127 // The I/O thread must be shutdown before the DB thread. |
| 126 io_thread_.Stop(); | 128 io_thread_.Stop(); |
| 127 | 129 |
| 128 // Clean up the test directory. | 130 // Clean up the test directory. |
| 129 if (service_.get()) | 131 if (service_.get()) |
| 130 service_->Shutdown(); | 132 service_ = NULL; |
| 131 // Note that we must ensure the DB thread is stopped after WDS | 133 // Note that we must ensure the DB thread is stopped after WDS |
| 132 // shutdown (so it can commit pending transactions) but before | 134 // shutdown (so it can commit pending transactions) but before |
| 133 // deleting the test profile directory, otherwise we may not be | 135 // deleting the test profile directory, otherwise we may not be |
| 134 // able to delete it due to an open transaction. | 136 // able to delete it due to an open transaction. |
| 137 // Schedule another task on the DB thread to notify us that it's safe to |
| 138 // carry on with the test. |
| 139 base::WaitableEvent done(false, false); |
| 140 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 141 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 142 done.Wait(); |
| 135 db_thread_.Stop(); | 143 db_thread_.Stop(); |
| 136 } | 144 } |
| 137 | 145 |
| 138 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() | 146 TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() |
| 139 : ui_thread_(BrowserThread::UI, &message_loop_), | 147 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 140 changed_count_(0) { | 148 changed_count_(0) { |
| 141 } | 149 } |
| 142 | 150 |
| 143 TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { | 151 TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { |
| 144 } | 152 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 model()->Load(); | 196 model()->Load(); |
| 189 BlockTillServiceProcessesRequests(); | 197 BlockTillServiceProcessesRequests(); |
| 190 EXPECT_EQ(1, GetObserverCount()); | 198 EXPECT_EQ(1, GetObserverCount()); |
| 191 ResetObserverCount(); | 199 ResetObserverCount(); |
| 192 } | 200 } |
| 193 | 201 |
| 194 void TemplateURLServiceTestUtil::ChangeModelToLoadState() { | 202 void TemplateURLServiceTestUtil::ChangeModelToLoadState() { |
| 195 model()->ChangeToLoadedState(); | 203 model()->ChangeToLoadedState(); |
| 196 // Initialize the web data service so that the database gets updated with | 204 // Initialize the web data service so that the database gets updated with |
| 197 // any changes made. | 205 // any changes made. |
| 198 model()->service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 206 model()->service_ = WebDataServiceFactory::GetForProfile( |
| 207 profile_.get(), Profile::EXPLICIT_ACCESS); |
| 199 } | 208 } |
| 200 | 209 |
| 201 void TemplateURLServiceTestUtil::ClearModel() { | 210 void TemplateURLServiceTestUtil::ClearModel() { |
| 202 TemplateURLServiceFactory::GetInstance()->SetTestingFactory( | 211 TemplateURLServiceFactory::GetInstance()->SetTestingFactory( |
| 203 profile_.get(), NULL); | 212 profile_.get(), NULL); |
| 204 } | 213 } |
| 205 | 214 |
| 206 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { | 215 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { |
| 207 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 216 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 208 profile_.get(), TestingTemplateURLService::Build); | 217 profile_.get(), TestingTemplateURLService::Build); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 234 return profile_.get(); | 243 return profile_.get(); |
| 235 } | 244 } |
| 236 | 245 |
| 237 void TemplateURLServiceTestUtil::StartIOThread() { | 246 void TemplateURLServiceTestUtil::StartIOThread() { |
| 238 profile_->StartIOThread(); | 247 profile_->StartIOThread(); |
| 239 } | 248 } |
| 240 | 249 |
| 241 void TemplateURLServiceTestUtil::PumpLoop() { | 250 void TemplateURLServiceTestUtil::PumpLoop() { |
| 242 message_loop_.RunAllPending(); | 251 message_loop_.RunAllPending(); |
| 243 } | 252 } |
| OLD | NEW |