diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 13:04:40 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 13:04:40 +0000 |
commit | 24210ecbd8ed89268c5f67ecb02440c5fadf98a9 (patch) | |
tree | 029692c1ca490c3d2b8223d83ec7b5b1a9b7fe0e | |
parent | 4926b7d95ed4783c0c1d6aa5e8043fff5b6d6c47 (diff) | |
download | chromium_src-24210ecbd8ed89268c5f67ecb02440c5fadf98a9.zip chromium_src-24210ecbd8ed89268c5f67ecb02440c5fadf98a9.tar.gz chromium_src-24210ecbd8ed89268c5f67ecb02440c5fadf98a9.tar.bz2 |
Switch to composition for TestBrowserThread.
This avoids exposing BrowserThreadImpl internals outside of content/,
and goes most of the way to not exposing the fact that underneath, it
is a base::Thread. There are only three test files that use the
TestBrowserThread::DeprecatedGetThreadObject method.
TBR=owners
BUG=98716
Review URL: http://codereview.chromium.org/8440039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108452 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 124 insertions, 77 deletions
diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc index b90ce98..c8919cc 100644 --- a/chrome/browser/autofill/autofill_download_unittest.cc +++ b/chrome/browser/autofill/autofill_download_unittest.cc @@ -71,9 +71,7 @@ class AutofillDownloadTest : public AutofillDownloadManager::Observer, } virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); profile_.CreateRequestContext(); } @@ -135,8 +133,7 @@ class AutofillDownloadTest : public AutofillDownloadManager::Observer, AutofillDownloadManager download_manager_; private: - // |request_context_getter_| must be released on the IO thread. - MessageLoop* io_thread_loop() { return io_thread_.message_loop(); } + // The profile's request context must be released on the IO thread. content::TestBrowserThread io_thread_; }; diff --git a/chrome/browser/component_updater/component_updater_service_unittest.cc b/chrome/browser/component_updater/component_updater_service_unittest.cc index 3bbac3d..b080cca 100644 --- a/chrome/browser/component_updater/component_updater_service_unittest.cc +++ b/chrome/browser/component_updater/component_updater_service_unittest.cc @@ -232,7 +232,7 @@ TEST_F(ComponentUpdaterTest, CheckCrxSleep) { content::TestBrowserThread file_thread(BrowserThread::FILE); content::TestBrowserThread io_thread(BrowserThread::IO); - io_thread.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); + io_thread.StartIOThread(); file_thread.Start(); scoped_refptr<ComponentUpdateInterceptor> @@ -316,7 +316,7 @@ TEST_F(ComponentUpdaterTest, InstallCrx) { content::TestBrowserThread file_thread(BrowserThread::FILE); content::TestBrowserThread io_thread(BrowserThread::IO); - io_thread.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); + io_thread.StartIOThread(); file_thread.Start(); scoped_refptr<ComponentUpdateInterceptor> @@ -382,7 +382,7 @@ TEST_F(ComponentUpdaterTest, ProdVersionCheck) { content::TestBrowserThread file_thread(BrowserThread::FILE); content::TestBrowserThread io_thread(BrowserThread::IO); - io_thread.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); + io_thread.StartIOThread(); file_thread.Start(); scoped_refptr<ComponentUpdateInterceptor> diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc index 72eac2a..2db0f1e 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc @@ -233,13 +233,10 @@ class ProtocolHandlerRegistryTest : public testing::Test { ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, MessageLoop::current())); io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_->StartWithOptions(options); + io_thread_->StartIOThread(); file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE)); - options.message_loop_type = MessageLoop::TYPE_DEFAULT; - file_thread_->StartWithOptions(options); + file_thread_->Start(); profile_.reset(new TestingProfile()); profile_->SetPrefService(new TestingPrefService()); diff --git a/chrome/browser/download/download_item_unittest.cc b/chrome/browser/download/download_item_unittest.cc index 694f584..c2757e9 100644 --- a/chrome/browser/download/download_item_unittest.cc +++ b/chrome/browser/download/download_item_unittest.cc @@ -68,7 +68,7 @@ class DownloadItemTest : public testing::Test { // to ensure that all resources are cleaned up before the test exits. download_manager_ = NULL; profile_.reset(NULL); - ui_thread_.message_loop()->RunAllPending(); + ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunAllPending(); } DownloadItem* CreateDownloadItem(DownloadItem::DownloadState state) { diff --git a/chrome/browser/external_protocol/external_protocol_handler_unittest.cc b/chrome/browser/external_protocol/external_protocol_handler_unittest.cc index 51d5ff2..74bb856 100644 --- a/chrome/browser/external_protocol/external_protocol_handler_unittest.cc +++ b/chrome/browser/external_protocol/external_protocol_handler_unittest.cc @@ -99,9 +99,7 @@ class ExternalProtocolHandlerTest : public testing::Test { file_thread_(BrowserThread::FILE) {} virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_DEFAULT; - file_thread_.StartWithOptions(options); + file_thread_.Start(); } void DoTest(ExternalProtocolHandler::BlockState block_state, diff --git a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc index b92a202..fcb60e3 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc @@ -189,17 +189,19 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) { temp_dir_.path().Append(chrome::kCookieFilename)); // Posting a blocking task to db_thread_ makes sure that the DB thread waits // until both Load and LoadCookiesForKey have been posted to its task queue. - db_thread_.PostTask(BrowserThread::DB, FROM_HERE, - base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, - base::Unretained(this))); + BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, + base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, + base::Unretained(this))); store_->Load(base::Bind(&SQLitePersistentCookieStoreTest::OnLoaded, base::Unretained(this))); store_->LoadCookiesForKey("aaa.com", base::Bind(&SQLitePersistentCookieStoreTest::OnKeyLoaded, base::Unretained(this))); - db_thread_.PostTask(BrowserThread::DB, FROM_HERE, - base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, - base::Unretained(this))); + BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, + base::Bind(&SQLitePersistentCookieStoreTest::WaitOnDBEvent, + base::Unretained(this))); // Now the DB-thread queue contains: // (active:) diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc index d6e253f..024fe9c 100644 --- a/chrome/browser/safe_browsing/malware_details_unittest.cc +++ b/chrome/browser/safe_browsing/malware_details_unittest.cc @@ -177,8 +177,7 @@ class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); // The URLFetcher checks that the messageloop type is IO. - ASSERT_TRUE(io_thread_.StartWithOptions( - base::Thread::Options(MessageLoop::TYPE_IO, 0))); + ASSERT_TRUE(io_thread_.StartIOThread()); profile()->CreateHistoryService(true /* delete_file */, false /* no_db */); } diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc index 7d33f56..a7a3390 100644 --- a/chrome/browser/search_engines/template_url_service_test_util.cc +++ b/chrome/browser/search_engines/template_url_service_test_util.cc @@ -65,9 +65,7 @@ class TemplateURLServiceTestingProfile : public TestingProfile { // Starts the I/O thread. This isn't done automatically because not every test // needs this. void StartIOThread() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); } virtual WebDataService* GetWebDataService(ServiceAccessType access) { diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc index a38dae2..56f2e9c 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.cc +++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc @@ -105,9 +105,7 @@ AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {} void AbstractProfileSyncServiceTest::SetUp() { db_thread_.Start(); - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); } void AbstractProfileSyncServiceTest::TearDown() { diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc index 27c545e..290661e 100644 --- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc @@ -116,7 +116,8 @@ class AutofillDataTypeControllerTest : public testing::Test { virtual void SetUp() { db_thread_.Start(); - db_notification_service_ = new ThreadNotificationService(&db_thread_); + db_notification_service_ = new ThreadNotificationService( + db_thread_.DeprecatedGetThreadObject()); db_notification_service_->Init(); web_data_service_ = new WebDataServiceFake(); EXPECT_CALL(profile_, GetProfileSyncService()).WillRepeatedly( @@ -162,7 +163,8 @@ TEST_F(AutofillDataTypeControllerTest, StartWDSNotReady) { autofill_dtc_->set_state(DataTypeController::MODEL_STARTING); EXPECT_FALSE(autofill_dtc_->StartModels()); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&ui_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + ui_thread_.DeprecatedGetThreadObject())); autofill_dtc_->Observe( chrome::NOTIFICATION_WEB_DATABASE_LOADED, content::Source<WebDataService>(web_data_service_.get()), diff --git a/chrome/browser/sync/glue/http_bridge_unittest.cc b/chrome/browser/sync/glue/http_bridge_unittest.cc index deb60de..0c5e3b4 100644 --- a/chrome/browser/sync/glue/http_bridge_unittest.cc +++ b/chrome/browser/sync/glue/http_bridge_unittest.cc @@ -29,13 +29,11 @@ class HttpBridgeTest : public testing::Test { } virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); } virtual void TearDown() { - io_thread_loop()->ReleaseSoon(FROM_HERE, + GetIOThreadLoop()->ReleaseSoon(FROM_HERE, fake_default_request_context_getter_); io_thread_.Stop(); fake_default_request_context_getter_ = NULL; @@ -70,7 +68,9 @@ class HttpBridgeTest : public testing::Test { main_message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask); } - MessageLoop* io_thread_loop() { return io_thread_.message_loop(); } + MessageLoop* GetIOThreadLoop() { + return io_thread_.DeprecatedGetThreadObject()->message_loop(); + } // Note this is lazy created, so don't call this before your bridge. TestURLRequestContextGetter* GetTestRequestContextGetter() { @@ -102,20 +102,20 @@ class ShuntedHttpBridge : public HttpBridge { test_(test), never_finishes_(never_finishes) { } protected: virtual void MakeAsynchronousPost() { - ASSERT_TRUE(MessageLoop::current() == test_->io_thread_loop()); + ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop()); if (never_finishes_) return; // We don't actually want to make a request for this test, so just callback // as if it completed. - test_->io_thread_loop()->PostTask(FROM_HERE, + test_->GetIOThreadLoop()->PostTask(FROM_HERE, NewRunnableMethod(this, &ShuntedHttpBridge::CallOnURLFetchComplete)); } private: ~ShuntedHttpBridge() {} void CallOnURLFetchComplete() { - ASSERT_TRUE(MessageLoop::current() == test_->io_thread_loop()); + ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop()); // We return no cookies and a dummy content response. net::ResponseCookies cookies; diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc index b8812ff..cea326a 100644 --- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc +++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc @@ -59,9 +59,7 @@ class SyncBackendHostTest : public testing::Test { virtual ~SyncBackendHostTest() {} virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); } virtual void TearDown() { diff --git a/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc index 90e21a4..1d934ca 100644 --- a/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc +++ b/chrome/browser/sync/notifier/non_blocking_invalidation_notifier_unittest.cc @@ -35,7 +35,7 @@ class NonBlockingInvalidationNotifierTest : public testing::Test { virtual void SetUp() { base::Thread::Options options; options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); request_context_getter_ = new TestURLRequestContextGetter; notifier::NotifierOptions notifier_options; notifier_options.request_context_getter = request_context_getter_; diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 464c382..3535570 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -354,7 +354,8 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest { WillRepeatedly(Return(web_data_service_.get())); personal_data_manager_->Init(&profile_); - notification_service_ = new ThreadNotificationService(&db_thread_); + notification_service_ = new ThreadNotificationService( + db_thread_.DeprecatedGetThreadObject()); notification_service_->Init(); // Note: This must be called *after* the notification service is created. @@ -943,7 +944,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + db_thread_.DeprecatedGetThreadObject())); notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, content::Source<WebDataService>(web_data_service_.get()), content::Details<AutofillChangeList>(&changes)); @@ -972,7 +974,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { AutofillProfileChange change(AutofillProfileChange::ADD, added_profile.guid(), &added_profile); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + db_thread_.DeprecatedGetThreadObject())); notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, content::Source<WebDataService>(web_data_service_.get()), content::Details<AutofillProfileChange>(&change)); @@ -1005,7 +1008,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::UPDATE, updated_entry.key())); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + db_thread_.DeprecatedGetThreadObject())); notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, content::Source<WebDataService>(web_data_service_.get()), content::Details<AutofillChangeList>(&changes)); @@ -1034,7 +1038,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { AutofillChangeList changes; changes.push_back(AutofillChange(AutofillChange::REMOVE, original_entry.key())); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + db_thread_.DeprecatedGetThreadObject())); notifier->Notify(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, content::Source<WebDataService>(web_data_service_.get()), content::Details<AutofillChangeList>(&changes)); @@ -1072,7 +1077,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { AutofillProfileChange change(AutofillProfileChange::REMOVE, sync_profile.guid(), NULL); - scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier(&db_thread_)); + scoped_refptr<ThreadNotifier> notifier(new ThreadNotifier( + db_thread_.DeprecatedGetThreadObject())); notifier->Notify(chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, content::Source<WebDataService>(web_data_service_.get()), content::Details<AutofillProfileChange>(&change)); diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc index cd59234..50dfed69 100644 --- a/chrome/browser/sync/profile_sync_service_password_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc @@ -162,7 +162,8 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { profile_.CreateRequestContext(); password_store_ = new MockPasswordStore(); - notification_service_ = new ThreadNotificationService(&db_thread_); + notification_service_ = new ThreadNotificationService( + db_thread_.DeprecatedGetThreadObject()); notification_service_->Init(); registrar_.Add(&observer_, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc index ed25ad0..f5aac7b 100644 --- a/chrome/browser/sync/profile_sync_service_session_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc @@ -166,9 +166,7 @@ class ProfileSyncServiceSessionTest virtual void SetUp() { // BrowserWithTestWindowTest implementation. BrowserWithTestWindowTest::SetUp(); - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); profile()->CreateRequestContext(); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); SessionService* session_service = new SessionService(temp_dir_.path()); diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc index 674c423..400ffcc 100644 --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc @@ -44,9 +44,7 @@ class ProfileSyncServiceStartupTest : public testing::Test { } virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); profile_->CreateRequestContext(); CreateSyncService(); service_->AddObserver(&observer_); diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc index 376687f..470ba48 100644 --- a/chrome/browser/sync/profile_sync_service_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_unittest.cc @@ -49,9 +49,7 @@ class ProfileSyncServiceTest : public testing::Test { virtual ~ProfileSyncServiceTest() {} virtual void SetUp() { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - io_thread_.StartWithOptions(options); + io_thread_.StartIOThread(); profile_.reset(new TestingProfile()); profile_->CreateRequestContext(); diff --git a/chrome/browser/sync/util/extensions_activity_monitor_unittest.cc b/chrome/browser/sync/util/extensions_activity_monitor_unittest.cc index b719f37..3bd0694 100644 --- a/chrome/browser/sync/util/extensions_activity_monitor_unittest.cc +++ b/chrome/browser/sync/util/extensions_activity_monitor_unittest.cc @@ -115,18 +115,16 @@ class ExtensionsActivityMonitorTest : public testing::Test { virtual void SetUp() { ui_thread_.Start(); base::WaitableEvent service_created(false, false); - ui_thread_.message_loop()->PostTask(FROM_HERE, + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, new DoUIThreadSetupTask(&service_, &service_created)); service_created.Wait(); } virtual void TearDown() { - ui_thread_.message_loop()->DeleteSoon(FROM_HERE, service_); + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, service_); ui_thread_.Stop(); } - MessageLoop* ui_loop() { return ui_thread_.message_loop(); } - static std::string GetExtensionIdForPath( const FilePath::StringType& extension_path) { std::string error; @@ -182,7 +180,7 @@ TEST_F(ExtensionsActivityMonitorTest, Basic) { EXPECT_EQ(writes_by_extension1, results[id1].bookmark_write_count); EXPECT_EQ(writes_by_extension2, results[id2].bookmark_write_count); - ui_loop()->DeleteSoon(FROM_HERE, monitor); + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, monitor); } TEST_F(ExtensionsActivityMonitorTest, Put) { @@ -219,7 +217,7 @@ TEST_F(ExtensionsActivityMonitorTest, Put) { EXPECT_EQ(id2, new_records[id2].extension_id); EXPECT_EQ(5U, new_records[id1].bookmark_write_count); EXPECT_EQ(8U + 2U, new_records[id2].bookmark_write_count); - ui_loop()->DeleteSoon(FROM_HERE, monitor); + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, monitor); } TEST_F(ExtensionsActivityMonitorTest, MultiGet) { @@ -246,5 +244,5 @@ TEST_F(ExtensionsActivityMonitorTest, MultiGet) { EXPECT_EQ(1U, results.size()); EXPECT_EQ(3U, results[id1].bookmark_write_count); - ui_loop()->DeleteSoon(FROM_HERE, monitor); + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, monitor); } diff --git a/content/test/test_browser_thread.cc b/content/test/test_browser_thread.cc index ca90930..f3e6cc8 100644 --- a/content/test/test_browser_thread.cc +++ b/content/test/test_browser_thread.cc @@ -4,18 +4,44 @@ #include "content/test/test_browser_thread.h" +#include "base/threading/thread.h" +#include "content/browser/browser_thread_impl.h" + namespace content { -TestBrowserThread::TestBrowserThread(ID identifier) - : BrowserThreadImpl(identifier) { +TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier) + : impl(new BrowserThreadImpl(identifier)) { } -TestBrowserThread::TestBrowserThread(ID identifier, MessageLoop* message_loop) - : BrowserThreadImpl(identifier, message_loop) { +TestBrowserThread::TestBrowserThread(BrowserThread::ID identifier, + MessageLoop* message_loop) + : impl(new BrowserThreadImpl(identifier, message_loop)) { } TestBrowserThread::~TestBrowserThread() { Stop(); } +bool TestBrowserThread::Start() { + return impl->Start(); +} + +bool TestBrowserThread::StartIOThread() { + base::Thread::Options options; + options.message_loop_type = MessageLoop::TYPE_IO; + return impl->StartWithOptions(options); +} + +void TestBrowserThread::Stop() { + impl->Stop(); +} + +bool TestBrowserThread::IsRunning() { + return impl->IsRunning(); +} + +base::Thread* TestBrowserThread::DeprecatedGetThreadObject() { + return impl.get(); +} + } // namespace content diff --git a/content/test/test_browser_thread.h b/content/test/test_browser_thread.h index 1067f9e..06e632f 100644 --- a/content/test/test_browser_thread.h +++ b/content/test/test_browser_thread.h @@ -6,17 +6,50 @@ #define CONTENT_TEST_TEST_BROWSER_BROWSER_THREAD_H_ #pragma once -#include "content/browser/browser_thread_impl.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_thread.h" + +class MessageLoop; + +namespace base { +class Thread; +} namespace content { +class BrowserThreadImpl; + // A BrowserThread for unit tests; this lets unit tests in chrome/ // create BrowserThread instances. -class TestBrowserThread : public BrowserThreadImpl { +class TestBrowserThread { public: - explicit TestBrowserThread(ID identifier); - TestBrowserThread(ID identifier, MessageLoop* message_loop); - virtual ~TestBrowserThread(); + explicit TestBrowserThread(BrowserThread::ID identifier); + TestBrowserThread(BrowserThread::ID identifier, MessageLoop* message_loop); + ~TestBrowserThread(); + + // We provide a subset of the capabilities of the Thread interface + // to enable certain unit tests. To avoid a stronger dependency of + // the internals of BrowserThread, we do not provide the full Thread + // interface. + + // Starts the thread with a generic message loop. + bool Start(); + + // Starts the thread with an IOThread message loop. + bool StartIOThread(); + + // Stops the thread. + void Stop(); + + // Returns true if the thread is running. + bool IsRunning(); + + // Returns a Thread pointer for the thread. This should not be used + // in new tests. + base::Thread* DeprecatedGetThreadObject(); + + private: + scoped_ptr<BrowserThreadImpl> impl; }; } // namespace content |