diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 21:31:39 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-06 21:31:39 +0000 |
commit | ec04d3f550df0b20f6d9b6fe06b9c6d7050a9d61 (patch) | |
tree | f38e6f0b7e78cc83cb14d2e09a8f3481a4e7c462 | |
parent | afc78d2db8d7a72ccfb36a7f9a94afb2b4241458 (diff) | |
download | chromium_src-ec04d3f550df0b20f6d9b6fe06b9c6d7050a9d61.zip chromium_src-ec04d3f550df0b20f6d9b6fe06b9c6d7050a9d61.tar.gz chromium_src-ec04d3f550df0b20f6d9b6fe06b9c6d7050a9d61.tar.bz2 |
Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads.
This CL creates a new class, TestBrowserThreadBundle, that creates a TestBrowserThread for the most commonly needed BrowserThreads. It also adds this thread bundle into RenderViewHostTestHarness because most tests that use this harness need these threads in order to run. To support TestBrowserThreadBundle, BrowserThreadImpl's test construction was also modified to understand a NULL message_loop.
Aside from introducing the new class, this CL also removes:
(1) unnecessary constructors in test
(2) DISALLOW_COPY_AND_ASSIGNS in test fixtures*
(3) now redundant TestBrowserThreads from tests
(4) bad access-level changes for SetUp() and TearDown()
(5) using declarations that root off the global scope
(6) uses of MessageLoop's RunUntilIdle() and Quit()
(7) as many real threads as possible
There are also a changes to MediaCaptureDevicesDispatcher and OneClickSigninHelper that allow unittests to cut dependencies on IO thread activity. DesktopNotificationServiceTest (and a couple of others) were also made single threaded because the synchronization logic required for a non-flaky test meant the parallelism only really exercised the extra code in the test that forced the serialization.
* DISALLOW_COPY_AND_ASSIGN does not serve much purpose in GTest fixture types. However, using it removes the compile-provided default constructor which forces the fixture writer to provide an empty default constructor. Since GTest recommends the default constructor as the preferred method to do setup for a test (as opposed to the SetUp() method), it's confusing to have bunch of classes with both SetUp() and a default constructor. It's simpler and uses less code to just remove the DISALLOW_COPY_AND_ASSIGN. An alternative would be to use the default constructor for initialization, but this is not possible because of our test harnesses are inheritance based which means it is impossible for a derived fixture to perform initialization before the harness if we use the GTest preferred default constructor initialization pattern.
TBR=avi,battre,ben,benwells,brettw,dbeam,dimich,joi,joth,mad,marja,markusheintz,noelallen,phajdan,rdsmith,satorux,scherkus,sky,stevenjb,stuartmorgan,timsteele
BUG=159193
Review URL: https://chromiumcodereview.appspot.com/14197014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204603 0039d316-1c4b-4281-b951-d872f2087c98
91 files changed, 704 insertions, 1274 deletions
diff --git a/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc b/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc index 7693f7f..0356315 100644 --- a/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc +++ b/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc @@ -17,7 +17,6 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "net/base/net_errors.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -66,8 +65,7 @@ class CaptivePortalTabHelperTest : public ChromeRenderViewHostTestHarness { public: CaptivePortalTabHelperTest() : tab_helper_(NULL), - mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>), - ui_thread_(content::BrowserThread::UI, &message_loop_) { + mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>) { tab_helper_.SetTabReloaderForTest(mock_reloader_); } virtual ~CaptivePortalTabHelperTest() {} @@ -220,8 +218,6 @@ class CaptivePortalTabHelperTest : public ChromeRenderViewHostTestHarness { // Owned by |tab_helper_|. testing::StrictMock<MockCaptivePortalTabReloader>* mock_reloader_; - content::TestBrowserThread ui_thread_; - DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelperTest); }; diff --git a/chrome/browser/captive_portal/captive_portal_tab_reloader_unittest.cc b/chrome/browser/captive_portal/captive_portal_tab_reloader_unittest.cc index e09242d..522adb8 100644 --- a/chrome/browser/captive_portal/captive_portal_tab_reloader_unittest.cc +++ b/chrome/browser/captive_portal/captive_portal_tab_reloader_unittest.cc @@ -12,7 +12,6 @@ #include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/cert/cert_status_flags.h" @@ -89,16 +88,6 @@ class MockInterstitialPageDelegate : public content::InterstitialPageDelegate { class CaptivePortalTabReloaderTest : public ChromeRenderViewHostTestHarness { public: - CaptivePortalTabReloaderTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - file_user_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, - &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_) { - } - - virtual ~CaptivePortalTabReloaderTest() { - } - // testing::Test: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); @@ -118,10 +107,6 @@ class CaptivePortalTabReloaderTest : public ChromeRenderViewHostTestHarness { TestCaptivePortalTabReloader& tab_reloader() { return *tab_reloader_.get(); } private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; - scoped_ptr<TestCaptivePortalTabReloader> tab_reloader_; }; diff --git a/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc b/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc index f266d21..e2abc38 100644 --- a/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc @@ -20,15 +20,13 @@ #include "chrome/browser/google_apis/fake_drive_service.h" #include "chrome/browser/google_apis/task_util.h" #include "chrome/browser/google_apis/test_util.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/http/http_byte_range.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; - namespace drive { namespace internal { namespace { @@ -43,7 +41,8 @@ void IncrementCallback(int* num_called) { class LocalReaderProxyTest : public ::testing::Test { protected: - LocalReaderProxyTest() : io_thread_(BrowserThread::IO, &message_loop_) { + LocalReaderProxyTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual void SetUp() OVERRIDE { @@ -59,8 +58,7 @@ class LocalReaderProxyTest : public ::testing::Test { worker_thread_.reset(); } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; base::ScopedTempDir temp_dir_; base::FilePath file_path_; @@ -109,11 +107,11 @@ TEST_F(LocalReaderProxyTest, ReadWithLimit) { class NetworkReaderProxyTest : public ::testing::Test { protected: - NetworkReaderProxyTest() : io_thread_(BrowserThread::IO, &message_loop_) { + NetworkReaderProxyTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; }; TEST_F(NetworkReaderProxyTest, EmptyFile) { @@ -289,38 +287,13 @@ TEST_F(NetworkReaderProxyTest, CancelJob) { class DriveFileStreamReaderTest : public ::testing::Test { protected: DriveFileStreamReaderTest() - : ui_thread_(BrowserThread::UI), - io_thread_(BrowserThread::IO, &message_loop_) { + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual void SetUp() OVERRIDE { - ui_thread_.Start(); - worker_thread_.reset(new base::Thread("DriveFileStreamReaderTest")); ASSERT_TRUE(worker_thread_->Start()); - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&DriveFileStreamReaderTest::SetUpOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); - } - - virtual void TearDown() OVERRIDE { - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&DriveFileStreamReaderTest::TearDownOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); - - worker_thread_.reset(); - } - - void SetUpOnUIThread() { // Initialize FakeDriveService. fake_drive_service_.reset(new google_apis::FakeDriveService); fake_drive_service_->LoadResourceListForWapi( @@ -334,9 +307,11 @@ class DriveFileStreamReaderTest : public ::testing::Test { fake_file_system_->Initialize(); } - void TearDownOnUIThread() { + virtual void TearDown() OVERRIDE { fake_file_system_.reset(); fake_drive_service_.reset(); + + worker_thread_.reset(); } FileSystemInterface* GetFileSystem() { @@ -348,9 +323,7 @@ class DriveFileStreamReaderTest : public ::testing::Test { base::Unretained(this)); } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<base::Thread> worker_thread_; @@ -377,7 +350,7 @@ TEST_F(DriveFileStreamReaderTest, Read) { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_EQ(net::OK, error); ASSERT_TRUE(entry); EXPECT_TRUE(reader->IsInitialized()); @@ -404,7 +377,7 @@ TEST_F(DriveFileStreamReaderTest, Read) { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_EQ(net::OK, error); ASSERT_TRUE(entry); EXPECT_TRUE(reader->IsInitialized()); @@ -447,7 +420,7 @@ TEST_F(DriveFileStreamReaderTest, ReadRange) { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_EQ(net::OK, error); ASSERT_TRUE(entry); EXPECT_TRUE(reader->IsInitialized()); @@ -475,7 +448,7 @@ TEST_F(DriveFileStreamReaderTest, ReadRange) { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_EQ(net::OK, error); ASSERT_TRUE(entry); EXPECT_TRUE(reader->IsInitialized()); @@ -514,7 +487,7 @@ TEST_F(DriveFileStreamReaderTest, OutOfRangeError) { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE, error); EXPECT_FALSE(entry); } diff --git a/chrome/browser/chromeos/drive/drive_url_request_job_unittest.cc b/chrome/browser/chromeos/drive/drive_url_request_job_unittest.cc index c5ca7df..6479c14 100644 --- a/chrome/browser/chromeos/drive/drive_url_request_job_unittest.cc +++ b/chrome/browser/chromeos/drive/drive_url_request_job_unittest.cc @@ -18,15 +18,14 @@ #include "chrome/browser/google_apis/task_util.h" #include "chrome/browser/google_apis/test_util.h" #include "chrome/common/url_constants.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "googleurl/src/gurl.h" #include "net/base/test_completion_callback.h" #include "net/http/http_byte_range.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; - namespace drive { namespace { @@ -96,26 +95,28 @@ class TestDelegate : public net::TestDelegate { class DriveURLRequestJobTest : public testing::Test { protected: - DriveURLRequestJobTest() : ui_thread_(BrowserThread::UI), - io_thread_(BrowserThread::IO, &message_loop_) { + DriveURLRequestJobTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual ~DriveURLRequestJobTest() { } virtual void SetUp() OVERRIDE { - ui_thread_.Start(); + // Initialize FakeDriveService. + fake_drive_service_.reset(new google_apis::FakeDriveService); + ASSERT_TRUE(fake_drive_service_->LoadResourceListForWapi( + "chromeos/gdata/root_feed.json")); + ASSERT_TRUE(fake_drive_service_->LoadAccountMetadataForWapi( + "chromeos/gdata/account_metadata.json")); - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&DriveURLRequestJobTest::SetUpOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); + // Initialize FakeFileSystem. + fake_file_system_.reset( + new test_util::FakeFileSystem(fake_drive_service_.get())); + ASSERT_TRUE(fake_file_system_->InitializeForTesting()); scoped_refptr<base::SequencedWorkerPool> blocking_pool = - BrowserThread::GetBlockingPool(); + content::BrowserThread::GetBlockingPool(); test_network_delegate_.reset(new net::TestNetworkDelegate); test_url_request_job_factory_.reset(new TestURLRequestJobFactory( base::Bind(&DriveURLRequestJobTest::GetFileSystem, @@ -134,30 +135,6 @@ class DriveURLRequestJobTest : public testing::Test { test_url_request_job_factory_.reset(); test_network_delegate_.reset(); - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&DriveURLRequestJobTest::TearDownOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); - } - - void SetUpOnUIThread() { - // Initialize FakeDriveService. - fake_drive_service_.reset(new google_apis::FakeDriveService); - ASSERT_TRUE(fake_drive_service_->LoadResourceListForWapi( - "chromeos/gdata/root_feed.json")); - ASSERT_TRUE(fake_drive_service_->LoadAccountMetadataForWapi( - "chromeos/gdata/account_metadata.json")); - - // Initialize FakeFileSystem. - fake_file_system_.reset( - new test_util::FakeFileSystem(fake_drive_service_.get())); - ASSERT_TRUE(fake_file_system_->InitializeForTesting()); - } - - void TearDownOnUIThread() { fake_file_system_.reset(); fake_drive_service_.reset(); } @@ -186,7 +163,7 @@ class DriveURLRequestJobTest : public testing::Test { base::Bind(&google_apis::test_util::RunAndQuit), google_apis::test_util::CreateCopyResultCallback( &error, &entry))); - message_loop_.Run(); + base::MessageLoop::current()->Run(); if (error != net::OK || !entry) return false; @@ -202,9 +179,7 @@ class DriveURLRequestJobTest : public testing::Test { return true; } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; scoped_ptr<test_util::FakeFileSystem> fake_file_system_; diff --git a/chrome/browser/chromeos/drive/webkit_file_stream_reader_impl_unittest.cc b/chrome/browser/chromeos/drive/webkit_file_stream_reader_impl_unittest.cc index 687bd52..1d7860e 100644 --- a/chrome/browser/chromeos/drive/webkit_file_stream_reader_impl_unittest.cc +++ b/chrome/browser/chromeos/drive/webkit_file_stream_reader_impl_unittest.cc @@ -18,14 +18,12 @@ #include "chrome/browser/chromeos/drive/test_util.h" #include "chrome/browser/google_apis/fake_drive_service.h" #include "chrome/browser/google_apis/time_util.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; - namespace drive { namespace internal { @@ -34,41 +32,13 @@ class WebkitFileStreamReaderImplTest : public ::testing::Test { // Because the testee should live on IO thread, the main thread is // reused as IO thread, and UI thread will be run on background. WebkitFileStreamReaderImplTest() - : ui_thread_(BrowserThread::UI), - io_thread_(BrowserThread::IO, &message_loop_) { + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual void SetUp() OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - ui_thread_.Start(); - worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest")); ASSERT_TRUE(worker_thread_->Start()); - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&WebkitFileStreamReaderImplTest::SetUpOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); - } - - virtual void TearDown() OVERRIDE { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - BrowserThread::PostTaskAndReply( - BrowserThread::UI, - FROM_HERE, - base::Bind(&WebkitFileStreamReaderImplTest::TearDownOnUIThread, - base::Unretained(this)), - base::MessageLoop::QuitClosure()); - message_loop_.Run(); - - worker_thread_.reset(); - } - - void SetUpOnUIThread() { // Initialize FakeDriveService. fake_drive_service_.reset(new google_apis::FakeDriveService); fake_drive_service_->LoadResourceListForWapi( @@ -82,9 +52,11 @@ class WebkitFileStreamReaderImplTest : public ::testing::Test { fake_file_system_->Initialize(); } - void TearDownOnUIThread() { + virtual void TearDown() OVERRIDE { fake_file_system_.reset(); fake_drive_service_.reset(); + + worker_thread_.reset(); } FileSystemInterface* GetFileSystem() { @@ -96,9 +68,7 @@ class WebkitFileStreamReaderImplTest : public ::testing::Test { base::Unretained(this)); } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<base::Thread> worker_thread_; diff --git a/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc b/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc index be5778d..5417931 100644 --- a/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc +++ b/chrome/browser/chromeos/login/merge_session_load_page_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/run_loop.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/login/merge_session_load_page.h" #include "chrome/browser/chromeos/login/user_manager.h" @@ -11,10 +12,8 @@ #include "content/public/browser/interstitial_page.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" -using content::BrowserThread; using content::InterstitialPage; using content::WebContents; using content::WebContentsTester; @@ -48,12 +47,21 @@ class TestMergeSessionLoadPage : public MergeSessionLoadPage { }; class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { - public: - MergeSessionLoadPageTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), - io_thread_(BrowserThread::IO, base::MessageLoop::current()) { + protected: + virtual void SetUp() OVERRIDE { + ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif + } + + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + // Clean up pending tasks that might depend on the user manager. + base::RunLoop().RunUntilIdle(); + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); } void Navigate(const char* url, int page_id) { @@ -73,16 +81,10 @@ class MergeSessionLoadPageTest : public ChromeRenderViewHostTestHarness { } private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; - ScopedStubCrosEnabler stub_cros_enabler_; ScopedTestDeviceSettingsService test_device_settings_service_; ScopedTestCrosSettings test_cros_settings_; - ScopedTestUserManager test_user_manager_; - - DISALLOW_COPY_AND_ASSIGN(MergeSessionLoadPageTest); + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; }; TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { @@ -114,12 +116,12 @@ TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { ShowInterstitial(kURL2); InterstitialPage* interstitial = GetMergeSessionLoadPage(); ASSERT_TRUE(interstitial); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // Simulate merge session completion. UserManager::Get()->SetMergeSessionState( UserManager::MERGE_STATUS_DONE); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // The URL remains to be URL2. EXPECT_EQ(kURL2, web_contents()->GetURL().spec()); diff --git a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc index db56c59..52b0e7c 100644 --- a/chrome/browser/chromeos/offline/offline_load_page_unittest.cc +++ b/chrome/browser/chromeos/offline/offline_load_page_unittest.cc @@ -8,10 +8,8 @@ #include "content/public/browser/interstitial_page.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" -using content::BrowserThread; using content::InterstitialPage; using content::WebContents; using content::WebContentsTester; @@ -52,13 +50,6 @@ class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { CANCEL }; - OfflineLoadPageTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), - io_thread_(BrowserThread::IO, base::MessageLoop::current()) { - } - virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); user_response_ = PENDING; @@ -90,15 +81,12 @@ class OfflineLoadPageTest : public ChromeRenderViewHostTestHarness { UserResponse user_response() const { return user_response_; } private: + friend class TestOfflineLoadPage; + UserResponse user_response_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; // Initializes / shuts down a stub CrosLibrary. chromeos::ScopedStubCrosEnabler stub_cros_enabler_; - - DISALLOW_COPY_AND_ASSIGN(OfflineLoadPageTest); }; void TestOfflineLoadPage::NotifyBlockingPageComplete(bool proceed) { diff --git a/chrome/browser/content_settings/tab_specific_content_settings_unittest.cc b/chrome/browser/content_settings/tab_specific_content_settings_unittest.cc index 9dd833a..3d24dc8 100644 --- a/chrome/browser/content_settings/tab_specific_content_settings_unittest.cc +++ b/chrome/browser/content_settings/tab_specific_content_settings_unittest.cc @@ -38,18 +38,10 @@ class MockSiteDataObserver class TabSpecificContentSettingsTest : public ChromeRenderViewHostTestHarness { public: - TabSpecificContentSettingsTest() - : browser_thread_(BrowserThread::UI, &message_loop_) {} - virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); TabSpecificContentSettings::CreateForWebContents(web_contents()); } - - private: - content::TestBrowserThread browser_thread_; - - DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettingsTest); }; TEST_F(TabSpecificContentSettingsTest, BlockedContent) { diff --git a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc index bebfad2..afa9531 100644 --- a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc +++ b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc @@ -168,18 +168,13 @@ class ChromeDownloadManagerDelegateTest : TestingPrefServiceSyncable* pref_service_; base::ScopedTempDir test_download_dir_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; scoped_ptr<content::MockDownloadManager> download_manager_; scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; MockWebContentsDelegate web_contents_delegate_; }; ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(content::BrowserThread::UI, &message_loop_), - file_thread_(content::BrowserThread::FILE, &message_loop_), - download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { + : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { } void ChromeDownloadManagerDelegateTest::SetUp() { @@ -196,7 +191,7 @@ void ChromeDownloadManagerDelegateTest::SetUp() { } void ChromeDownloadManagerDelegateTest::TearDown() { - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); delegate_->Shutdown(); ChromeRenderViewHostTestHarness::TearDown(); } diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc index 5e9a2be..ca6a9ef 100644 --- a/chrome/browser/download/download_request_limiter_unittest.cc +++ b/chrome/browser/download/download_request_limiter_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/run_loop.h" #include "chrome/browser/download/download_request_infobar_delegate.h" #include "chrome/browser/download/download_request_limiter.h" #include "chrome/browser/infobars/infobar_service.h" @@ -11,10 +12,8 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; using content::WebContents; class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { @@ -25,13 +24,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { WAIT }; - DownloadRequestLimiterTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { - } - virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); BlockedContentTabHelper::CreateForWebContents(web_contents()); @@ -81,7 +73,7 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { "GET", // request method base::Bind(&DownloadRequestLimiterTest::ContinueDownload, base::Unretained(this))); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); } void OnUserGesture() { @@ -136,10 +128,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { // Number of times ShouldAllowDownload was invoked. int ask_allow_count_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; - private: DownloadRequestInfoBarDelegate::FakeCreateCallback fake_create_callback_; }; @@ -294,7 +282,7 @@ TEST_F(DownloadRequestLimiterTest, download_request_limiter_->GetDownloadStatus(web_contents())); AboutToNavigateRenderView(); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); ExpectAndResetCounts(0, 1, 0, __LINE__); ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, download_request_limiter_->GetDownloadStatus(web_contents())); @@ -311,7 +299,7 @@ TEST_F(DownloadRequestLimiterTest, ExpectAndResetCounts(0, 1, 1, __LINE__); AboutToNavigateRenderView(); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, download_request_limiter_->GetDownloadStatus(web_contents())); CanDownload(); diff --git a/chrome/browser/download/download_target_determiner_unittest.cc b/chrome/browser/download/download_target_determiner_unittest.cc index ced1786..2bb982a 100644 --- a/chrome/browser/download/download_target_determiner_unittest.cc +++ b/chrome/browser/download/download_target_determiner_unittest.cc @@ -180,8 +180,6 @@ class MockDownloadTargetDeterminerDelegate class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { public: - DownloadTargetDeterminerTest(); - // ::testing::Test virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; @@ -247,16 +245,8 @@ class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { NullWebContentsDelegate web_contents_delegate_; base::ScopedTempDir test_download_dir_; base::FilePath test_virtual_dir_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; }; -DownloadTargetDeterminerTest::DownloadTargetDeterminerTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(content::BrowserThread::UI, &message_loop_), - file_thread_(content::BrowserThread::FILE, &message_loop_) { -} - void DownloadTargetDeterminerTest::SetUp() { ChromeRenderViewHostTestHarness::SetUp(); CHECK(profile()); @@ -270,7 +260,6 @@ void DownloadTargetDeterminerTest::SetUp() { void DownloadTargetDeterminerTest::TearDown() { download_prefs_.reset(); - message_loop_.RunUntilIdle(); ChromeRenderViewHostTestHarness::TearDown(); } diff --git a/chrome/browser/extensions/active_tab_unittest.cc b/chrome/browser/extensions/active_tab_unittest.cc index 27ac325..505ce28 100644 --- a/chrome/browser/extensions/active_tab_unittest.cc +++ b/chrome/browser/extensions/active_tab_unittest.cc @@ -54,14 +54,12 @@ scoped_refptr<const Extension> CreateTestExtension( } class ActiveTabTest : public ChromeRenderViewHostTestHarness { - public: + protected: ActiveTabTest() : extension(CreateTestExtension("deadbeef", true)), another_extension(CreateTestExtension("feedbeef", true)), - extension_without_active_tab(CreateTestExtension("badbeef", false)), - ui_thread_(BrowserThread::UI, base::MessageLoop::current()) {} + extension_without_active_tab(CreateTestExtension("badbeef", false)) {} - protected: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); TabHelper::CreateForWebContents(web_contents()); @@ -124,9 +122,6 @@ class ActiveTabTest : public ChromeRenderViewHostTestHarness { // An extension without the activeTab permission. scoped_refptr<const Extension> extension_without_active_tab; - - private: - content::TestBrowserThread ui_thread_; }; TEST_F(ActiveTabTest, GrantToSinglePage) { diff --git a/chrome/browser/extensions/activity_log/activity_database_unittest.cc b/chrome/browser/extensions/activity_log/activity_database_unittest.cc index 1060c1e..d53e785 100644 --- a/chrome/browser/extensions/activity_log/activity_database_unittest.cc +++ b/chrome/browser/extensions/activity_log/activity_database_unittest.cc @@ -38,14 +38,12 @@ namespace extensions { class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { - public: - ActivityDatabaseTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - db_thread_(BrowserThread::DB, base::MessageLoop::current()), - file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} - + protected: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif CommandLine command_line(CommandLine::NO_PROGRAM); profile_ = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); @@ -56,10 +54,11 @@ class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { switches::kEnableExtensionActivityLogTesting); } - virtual ~ActivityDatabaseTest() { - base::MessageLoop::current()->PostTask(FROM_HERE, - base::MessageLoop::QuitClosure()); - base::MessageLoop::current()->Run(); + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); } protected: @@ -67,15 +66,11 @@ class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { Profile* profile_; private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; - content::TestBrowserThread file_thread_; - #if defined OS_CHROMEOS chromeos::ScopedStubCrosEnabler stub_cros_enabler_; chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif }; diff --git a/chrome/browser/extensions/activity_log/activity_log_unittest.cc b/chrome/browser/extensions/activity_log/activity_log_unittest.cc index a45c419..15f00a1 100644 --- a/chrome/browser/extensions/activity_log/activity_log_unittest.cc +++ b/chrome/browser/extensions/activity_log/activity_log_unittest.cc @@ -16,8 +16,7 @@ #include "chrome/common/extensions/dom_action_types.h" #include "chrome/common/extensions/extension_builder.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "sql/statement.h" #include "testing/gtest/include/gtest/gtest.h" @@ -36,17 +35,13 @@ const char kExtensionId[] = "abc"; namespace extensions { class ActivityLogTest : public testing::Test { - public: + protected: ActivityLogTest() - : message_loop_(base::MessageLoop::TYPE_IO), - ui_thread_(BrowserThread::UI, &message_loop_), - db_thread_(BrowserThread::DB, &message_loop_), - file_thread_(BrowserThread::FILE, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), saved_cmdline_(CommandLine::NO_PROGRAM) { - } - - virtual void SetUp() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif CommandLine command_line(CommandLine::NO_PROGRAM); saved_cmdline_ = *CommandLine::ForCurrentProcess(); profile_.reset(new TestingProfile()); @@ -60,15 +55,12 @@ class ActivityLogTest : public testing::Test { &command_line, base::FilePath(), false); } - virtual void TearDown() OVERRIDE { + virtual ~ActivityLogTest() { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif base::RunLoop().RunUntilIdle(); profile_.reset(NULL); - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::MessageLoop::QuitClosure(), - base::TimeDelta::FromSeconds(4)); // Don't hang on failure. - base::RunLoop().RunUntilIdle(); - // Restore the original command line and undo the affects of SetUp(). *CommandLine::ForCurrentProcess() = saved_cmdline_; ActivityLog::RecomputeLoggingIsEnabled(); @@ -101,12 +93,7 @@ class ActivityLogTest : public testing::Test { scoped_ptr<TestingProfile> profile_; ExtensionService* extension_service_; - private: - base::MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; - content::TestBrowserThread file_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; // Used to preserve a copy of the original command line. // The test framework will do this itself as well. However, by then, @@ -117,7 +104,7 @@ class ActivityLogTest : public testing::Test { #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif }; diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc index 8752da2..f5fc66c 100644 --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc @@ -22,7 +22,7 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_test_util.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/http/http_response_headers.h" #include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" @@ -71,7 +71,7 @@ namespace keys = declarative_webrequest_constants; class WebRequestActionWithThreadsTest : public testing::Test { public: WebRequestActionWithThreadsTest() - : io_thread_(content::BrowserThread::IO, &message_loop_) {} + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} protected: virtual void SetUp() OVERRIDE; @@ -99,8 +99,7 @@ class WebRequestActionWithThreadsTest : public testing::Test { scoped_refptr<ExtensionInfoMap> extension_info_map_; private: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; }; void WebRequestActionWithThreadsTest::SetUp() { diff --git a/chrome/browser/extensions/api/identity/experimental_web_auth_flow_unittest.cc b/chrome/browser/extensions/api/identity/experimental_web_auth_flow_unittest.cc index e0fc9db..7a8f0ec 100644 --- a/chrome/browser/extensions/api/identity/experimental_web_auth_flow_unittest.cc +++ b/chrome/browser/extensions/api/identity/experimental_web_auth_flow_unittest.cc @@ -7,15 +7,11 @@ #include "chrome/browser/ui/host_desktop.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; -using content::TestBrowserThread; using content::WebContents; using content::WebContentsTester; using extensions::ExperimentalWebAuthFlow; @@ -80,14 +76,6 @@ class MockExperimentalWebAuthFlow : public ExperimentalWebAuthFlow { class ExperimentalWebAuthFlowTest : public ChromeRenderViewHostTestHarness { protected: - ExperimentalWebAuthFlowTest() - : thread_(BrowserThread::UI, &message_loop_) { - } - - virtual void SetUp() { - ChromeRenderViewHostTestHarness::SetUp(); - } - virtual void TearDown() { // DetachDelegateAndDelete posts a task to clean up |flow_|, so it // has to be called before @@ -114,7 +102,6 @@ class ExperimentalWebAuthFlowTest : public ChromeRenderViewHostTestHarness { flow_base()->AfterUrlLoaded(); } - TestBrowserThread thread_; MockDelegate delegate_; scoped_ptr<MockExperimentalWebAuthFlow> flow_; }; diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc index ad4ad6b..17f4ba3 100644 --- a/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc +++ b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc @@ -29,7 +29,7 @@ #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/features/feature.h" #include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" using content::BrowserThread; @@ -79,10 +79,11 @@ class FakeLauncher : public NativeProcessLauncher { class NativeMessagingTest : public ::testing::Test, public NativeMessageProcessHost::Client, public base::SupportsWeakPtr<NativeMessagingTest> { - public: + protected: NativeMessagingTest() : current_channel_(chrome::VersionInfo::CHANNEL_DEV), - native_message_process_host_(NULL) { + native_message_process_host_(NULL), + thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual void SetUp() OVERRIDE { @@ -91,10 +92,6 @@ class NativeMessagingTest : public ::testing::Test, // directory. ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)); ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, GetTestDir())); - ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, - &message_loop_)); - io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO, - &message_loop_)); } virtual void TearDown() OVERRIDE { @@ -104,7 +101,7 @@ class NativeMessagingTest : public ::testing::Test, BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, native_message_process_host_.release()); } - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); } virtual void PostMessageFromNativeProcess( @@ -149,10 +146,8 @@ class NativeMessagingTest : public ::testing::Test, Feature::ScopedCurrentChannel current_channel_; scoped_ptr<NativeMessageProcessHost> native_message_process_host_; base::FilePath user_data_dir_; - base::MessageLoopForIO message_loop_; scoped_ptr<base::RunLoop> read_message_run_loop_; - scoped_ptr<content::TestBrowserThread> ui_thread_; - scoped_ptr<content::TestBrowserThread> io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<DictionaryValue> last_message_; }; @@ -197,10 +192,10 @@ TEST_F(NativeMessagingTest, SingleSendMessageWrite) { AsWeakPtr(), kTestNativeMessagingExtensionId, "empty_app.py", 0, launcher.Pass()); ASSERT_TRUE(native_message_process_host_.get()); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); native_message_process_host_->Send(kTestMessage); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); std::string output; base::TimeTicks start_time = base::TimeTicks::Now(); diff --git a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc index dac311d..0b4c630 100644 --- a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc @@ -37,7 +37,7 @@ #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "content/public/common/url_constants.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/auth.h" #include "net/base/capturing_net_log.h" #include "net/base/net_util.h" @@ -173,8 +173,7 @@ class TestIPCSender : public IPC::Sender { class ExtensionWebRequestTest : public testing::Test { public: ExtensionWebRequestTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), profile_manager_(TestingBrowserProcess::GetGlobal()), event_router_(new EventRouterForwarder) {} @@ -200,9 +199,7 @@ class ExtensionWebRequestTest : public testing::Test { const std::vector<char>& bytes_1, const std::vector<char>& bytes_2); - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; TestingProfileManager profile_manager_; net::TestDelegate delegate_; @@ -768,8 +765,7 @@ class ExtensionWebRequestHeaderModificationTest : public testing::TestWithParam<HeaderModificationTest> { public: ExtensionWebRequestHeaderModificationTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), profile_manager_(TestingBrowserProcess::GetGlobal()), event_router_(new EventRouterForwarder) {} @@ -791,9 +787,7 @@ class ExtensionWebRequestHeaderModificationTest context_->Init(); } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; TestingProfileManager profile_manager_; net::TestDelegate delegate_; diff --git a/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc index 5820af4..017806d 100644 --- a/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc +++ b/chrome/browser/extensions/api/web_request/web_request_permissions_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/common/extensions/extension_test_util.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/resource_request_info.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,7 +23,7 @@ using extension_test_util::LoadManifestUnchecked; class ExtensionWebRequestHelpersTestWithThreadsTest : public testing::Test { public: ExtensionWebRequestHelpersTestWithThreadsTest() - : io_thread_(content::BrowserThread::IO, &message_loop_) {} + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} protected: virtual void SetUp() OVERRIDE; @@ -38,8 +38,7 @@ class ExtensionWebRequestHelpersTestWithThreadsTest : public testing::Test { scoped_refptr<ExtensionInfoMap> extension_info_map_; private: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; }; void ExtensionWebRequestHelpersTestWithThreadsTest::SetUp() { diff --git a/chrome/browser/extensions/extension_protocols_unittest.cc b/chrome/browser/extensions/extension_protocols_unittest.cc index 6848b56..f5d9085 100644 --- a/chrome/browser/extensions/extension_protocols_unittest.cc +++ b/chrome/browser/extensions/extension_protocols_unittest.cc @@ -16,7 +16,7 @@ #include "chrome/common/url_constants.h" #include "content/public/browser/resource_request_info.h" #include "content/public/test/mock_resource_context.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "extensions/common/constants.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job_factory_impl.h" @@ -24,8 +24,6 @@ #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; - namespace extensions { scoped_refptr<Extension> CreateTestExtension(const std::string& name, @@ -88,9 +86,7 @@ scoped_refptr<Extension> CreateTestResponseHeaderExtension() { class ExtensionProtocolTest : public testing::Test { public: ExtensionProtocolTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - file_thread_(BrowserThread::FILE, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) {} + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} virtual void SetUp() OVERRIDE { testing::Test::SetUp(); @@ -127,10 +123,7 @@ class ExtensionProtocolTest : public testing::Test { } protected: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_refptr<ExtensionInfoMap> extension_info_map_; net::URLRequestJobFactoryImpl job_factory_; const net::URLRequestJobFactory* old_factory_; diff --git a/chrome/browser/extensions/page_action_controller_unittest.cc b/chrome/browser/extensions/page_action_controller_unittest.cc index f77ef6e..70358eb 100644 --- a/chrome/browser/extensions/page_action_controller_unittest.cc +++ b/chrome/browser/extensions/page_action_controller_unittest.cc @@ -28,19 +28,16 @@ #include "chrome/browser/chromeos/settings/device_settings_service.h" #endif -using content::BrowserThread; - namespace extensions { namespace { class PageActionControllerTest : public ChromeRenderViewHostTestHarness { - public: - PageActionControllerTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} - + protected: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif TabHelper::CreateForWebContents(web_contents()); // Create an ExtensionService so the PageActionController can find its // extensions. @@ -52,7 +49,13 @@ class PageActionControllerTest : public ChromeRenderViewHostTestHarness { &command_line, base::FilePath(), false); } - protected: + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); + } + int tab_id() { return SessionID::IdForTab(web_contents()); } @@ -60,13 +63,10 @@ class PageActionControllerTest : public ChromeRenderViewHostTestHarness { ExtensionService* extension_service_; private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif }; diff --git a/chrome/browser/extensions/script_badge_controller_unittest.cc b/chrome/browser/extensions/script_badge_controller_unittest.cc index 14ada07..f28f3e8 100644 --- a/chrome/browser/extensions/script_badge_controller_unittest.cc +++ b/chrome/browser/extensions/script_badge_controller_unittest.cc @@ -37,8 +37,6 @@ #include "chrome/browser/chromeos/settings/device_settings_service.h" #endif -using content::BrowserThread; - namespace extensions { namespace { @@ -46,8 +44,6 @@ class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { public: ScriptBadgeControllerTest() : feature_override_(FeatureSwitch::script_badges(), true), - ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_thread_(BrowserThread::FILE, base::MessageLoop::current()), current_channel_(chrome::VersionInfo::CHANNEL_DEV) {} virtual void SetUp() OVERRIDE { @@ -56,6 +52,10 @@ class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { // not use that for testing. ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif + Profile* profile = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); TestExtensionSystem* extension_system = @@ -72,6 +72,13 @@ class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { TabHelper::FromWebContents(web_contents())->location_bar_controller()); } + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); + } + protected: // Creates a test extension and adds it to |extension_service_|. scoped_refptr<const Extension> AddTestExtension() { @@ -98,14 +105,12 @@ class ScriptBadgeControllerTest : public ChromeRenderViewHostTestHarness { private: FeatureSwitch::ScopedOverride feature_override_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; Feature::ScopedCurrentChannel current_channel_; #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif }; diff --git a/chrome/browser/extensions/script_bubble_controller_unittest.cc b/chrome/browser/extensions/script_bubble_controller_unittest.cc index f76b65c..8f7a269 100644 --- a/chrome/browser/extensions/script_bubble_controller_unittest.cc +++ b/chrome/browser/extensions/script_bubble_controller_unittest.cc @@ -31,21 +31,20 @@ #include "chrome/browser/chromeos/settings/device_settings_service.h" #endif -using content::BrowserThread; - namespace extensions { namespace { class ScriptBubbleControllerTest : public ChromeRenderViewHostTestHarness { - public: + protected: ScriptBubbleControllerTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_thread_(BrowserThread::FILE, base::MessageLoop::current()), - enable_script_bubble_(FeatureSwitch::script_bubble(), true) { + : enable_script_bubble_(FeatureSwitch::script_bubble(), true) { } virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif CommandLine command_line(CommandLine::NO_PROGRAM); Profile* profile = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); @@ -60,7 +59,13 @@ class ScriptBubbleControllerTest : public ChromeRenderViewHostTestHarness { TabHelper::FromWebContents(web_contents())->script_bubble_controller(); } - protected: + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); + } + int tab_id() { return ExtensionTabUtil::GetTabId(web_contents()); } @@ -69,14 +74,12 @@ class ScriptBubbleControllerTest : public ChromeRenderViewHostTestHarness { ScriptBubbleController* script_bubble_controller_; private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; FeatureSwitch::ScopedOverride enable_script_bubble_; #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif }; diff --git a/chrome/browser/extensions/webstore_inline_installer_unittest.cc b/chrome/browser/extensions/webstore_inline_installer_unittest.cc index 4211993..70e4ba1 100644 --- a/chrome/browser/extensions/webstore_inline_installer_unittest.cc +++ b/chrome/browser/extensions/webstore_inline_installer_unittest.cc @@ -62,10 +62,6 @@ class WebstoreInlineInstallerTest : public ChromeRenderViewHostTestHarness { const std::vector<std::string>& verified_sites); protected: - WebstoreInlineInstallerTest() - : thread_(content::BrowserThread::UI, &message_loop_) {} - - content::TestBrowserThread thread_; scoped_ptr<content::WebContents> web_contents_; }; diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 88c0f45..4406cdf 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -26,7 +26,6 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "content/public/test/web_contents_tester.h" #include "extensions/browser/view_type_utils.h" @@ -98,11 +97,10 @@ void ClosedDelegateTracker::Clear() { // This class sets up GeolocationArbitrator. class GeolocationPermissionContextTests : public ChromeRenderViewHostTestHarness { - public: - GeolocationPermissionContextTests(); - protected: - virtual ~GeolocationPermissionContextTests(); + // ChromeRenderViewHostTestHarness: + virtual void SetUp() OVERRIDE; + virtual void TearDown() OVERRIDE; GeolocationPermissionRequestID RequestID(int bridge_id); GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id); @@ -134,28 +132,11 @@ class GeolocationPermissionContextTests ClosedDelegateTracker closed_delegate_tracker_; ScopedVector<content::WebContents> extra_tabs_; - private: - // ChromeRenderViewHostTestHarness: - virtual void SetUp() OVERRIDE; - virtual void TearDown() OVERRIDE; - - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; - // A map between renderer child id and a pair represending the bridge id and // whether the requested permission was allowed. base::hash_map<int, std::pair<int, bool> > responses_; }; -GeolocationPermissionContextTests::GeolocationPermissionContextTests() - : ChromeRenderViewHostTestHarness(), - ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), - db_thread_(content::BrowserThread::DB) { -} - -GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { -} - GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID( int bridge_id) { return GeolocationPermissionRequestID( @@ -253,7 +234,6 @@ void GeolocationPermissionContextTests::CheckTabContentsState( } void GeolocationPermissionContextTests::SetUp() { - db_thread_.Start(); ChromeRenderViewHostTestHarness::SetUp(); // Set up required helpers, and make this be as "tabby" as the code requires. @@ -270,14 +250,6 @@ void GeolocationPermissionContextTests::SetUp() { void GeolocationPermissionContextTests::TearDown() { extra_tabs_.clear(); ChromeRenderViewHostTestHarness::TearDown(); - // Schedule another task on the DB thread to notify us that it's safe to - // carry on with the test. - base::WaitableEvent done(false, false); - content::BrowserThread::PostTask( - content::BrowserThread::DB, FROM_HERE, - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); - done.Wait(); - db_thread_.Stop(); } // Tests ---------------------------------------------------------------------- diff --git a/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc b/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc index 30586cd..44a0710 100644 --- a/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc +++ b/chrome/browser/geolocation/geolocation_infobar_queue_controller_unittest.cc @@ -15,38 +15,20 @@ class GeolocationInfoBarQueueControllerTests : public ChromeRenderViewHostTestHarness { - public: - GeolocationInfoBarQueueControllerTests(); - protected: - GeolocationPermissionRequestID RequestID(int bridge_id); - - private: - // ChromeRenderViewHostTestHarness: - virtual void SetUp() OVERRIDE; - - content::TestBrowserThread ui_thread_; - - DISALLOW_COPY_AND_ASSIGN(GeolocationInfoBarQueueControllerTests); + virtual void SetUp() OVERRIDE { + ChromeRenderViewHostTestHarness::SetUp(); + InfoBarService::CreateForWebContents(web_contents()); + } + + GeolocationPermissionRequestID RequestID(int bridge_id) { + return GeolocationPermissionRequestID( + web_contents()->GetRenderProcessHost()->GetID(), + web_contents()->GetRenderViewHost()->GetRoutingID(), + bridge_id); + } }; -GeolocationInfoBarQueueControllerTests::GeolocationInfoBarQueueControllerTests() - : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()) { -} - -GeolocationPermissionRequestID - GeolocationInfoBarQueueControllerTests::RequestID(int bridge_id) { - return GeolocationPermissionRequestID( - web_contents()->GetRenderProcessHost()->GetID(), - web_contents()->GetRenderViewHost()->GetRoutingID(), - bridge_id); -} - -void GeolocationInfoBarQueueControllerTests::SetUp() { - ChromeRenderViewHostTestHarness::SetUp(); - InfoBarService::CreateForWebContents(web_contents()); -} - class ObservationCountingQueueController : public GeolocationInfoBarQueueController { public: diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc index 5fb643f..d9229b1 100644 --- a/chrome/browser/media/media_capture_devices_dispatcher.cc +++ b/chrome/browser/media/media_capture_devices_dispatcher.cc @@ -86,6 +86,7 @@ MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() : devices_enumerated_(false), + is_device_enumeration_disabled_(false), media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), audio_stream_indicator_(new AudioStreamIndicator()) {} @@ -117,7 +118,7 @@ void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) { const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!devices_enumerated_) { + if (!is_device_enumeration_disabled_ && !devices_enumerated_) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&content::EnsureMonitorCaptureDevices)); @@ -129,7 +130,7 @@ MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!devices_enumerated_) { + if (!is_device_enumeration_disabled_ && !devices_enumerated_) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&content::EnsureMonitorCaptureDevices)); @@ -304,6 +305,10 @@ void MediaCaptureDevicesDispatcher::GetRequestedDevice( } } +void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { + is_device_enumeration_disabled_ = true; +} + scoped_refptr<MediaStreamCaptureIndicator> MediaCaptureDevicesDispatcher::GetMediaStreamCaptureIndicator() { return media_stream_capture_indicator_; diff --git a/chrome/browser/media/media_capture_devices_dispatcher.h b/chrome/browser/media/media_capture_devices_dispatcher.h index c9fb31c..0a704d4 100644 --- a/chrome/browser/media/media_capture_devices_dispatcher.h +++ b/chrome/browser/media/media_capture_devices_dispatcher.h @@ -91,6 +91,11 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { bool video, content::MediaStreamDevices* devices); + // Unittests that do not require actual device enumeration should call this + // API on the singleton. It is safe to call this multiple times on the + // signleton. + void DisableDeviceEnumerationForTesting(); + // Overridden from content::MediaObserver: virtual void OnAudioCaptureDevicesChanged( const content::MediaStreamDevices& devices) OVERRIDE; @@ -150,6 +155,9 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { // Only accessed on UI thread. bool devices_enumerated_; + // Flag used by unittests to disable device enumeration. + bool is_device_enumeration_disabled_; + scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; diff --git a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc index 4118171..fe37098 100644 --- a/chrome/browser/media_galleries/media_file_system_registry_unittest.cc +++ b/chrome/browser/media_galleries/media_file_system_registry_unittest.cc @@ -280,9 +280,6 @@ class ProfileState { class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { public: - MediaFileSystemRegistryTest(); - virtual ~MediaFileSystemRegistryTest() {} - void CreateProfileState(size_t profile_count); ProfileState* GetProfileState(size_t i); @@ -370,13 +367,11 @@ class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { TestMediaFileSystemContext* test_file_system_context_; // Needed for extension service & friends to work. - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; + scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; #endif // TODO(gbillock): Eliminate windows-specific code from this test. @@ -389,8 +384,6 @@ class MediaFileSystemRegistryTest : public ChromeRenderViewHostTestHarness { MockProfileSharedRenderProcessHostFactory rph_factory_; ScopedVector<ProfileState> profile_states_; - - DISALLOW_COPY_AND_ASSIGN(MediaFileSystemRegistryTest); }; namespace { @@ -578,11 +571,6 @@ int ProfileState::GetAndClearComparisonCount() { // MediaFileSystemRegistryTest // ///////////////////////////////// -MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() - : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), - file_thread_(content::BrowserThread::FILE, base::MessageLoop::current()) { -} - void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { for (size_t i = 0; i < profile_count; ++i) { ProfileState* state = new ProfileState(&rph_factory_); @@ -739,6 +727,7 @@ size_t MediaFileSystemRegistryTest::GetExtensionGalleriesHostCount( void MediaFileSystemRegistryTest::SetUp() { + ChromeRenderViewHostTestHarness::SetUp(); #if defined(OS_WIN) test::TestPortableDeviceWatcherWin* portable_device_watcher = new test::TestPortableDeviceWatcherWin; @@ -747,28 +736,24 @@ void MediaFileSystemRegistryTest::SetUp() { portable_device_watcher->set_use_dummy_mtp_storage_info(true); monitor_.reset(new test::TestStorageMonitorWin( mount_watcher, portable_device_watcher)); - monitor_->Initialize(base::Bind(&base::DoNothing)); - // TODO(gbillock): Replace this with the correct event notification - // on the storage monitor finishing the startup scan when that exists. - base::RunLoop().RunUntilIdle(); - mount_watcher->FlushWorkerPoolForTesting(); - base::RunLoop().RunUntilIdle(); - mount_watcher->FlushWorkerPoolForTesting(); - base::RunLoop().RunUntilIdle(); #else monitor_.reset(new test::TestStorageMonitor()); - monitor_->Initialize(base::Bind(&base::DoNothing)); monitor_->MarkInitialized(); - base::RunLoop().RunUntilIdle(); #endif + base::RunLoop runloop; + monitor_->Initialize(runloop.QuitClosure()); + runloop.Run(); - ChromeRenderViewHostTestHarness::SetUp(); DeleteContents(); SetRenderProcessHostFactory(&rph_factory_); test_file_system_context_ = new TestMediaFileSystemContext( g_browser_process->media_file_system_registry()); +#if defined(OS_CHROMEOS) + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif + ASSERT_TRUE(galleries_dir_.CreateUniqueTempDir()); empty_dir_ = galleries_dir_.path().AppendASCII("empty"); ASSERT_TRUE(file_util::CreateDirectory(empty_dir_)); @@ -779,12 +764,17 @@ void MediaFileSystemRegistryTest::SetUp() { void MediaFileSystemRegistryTest::TearDown() { profile_states_.clear(); - ChromeRenderViewHostTestHarness::TearDown(); MediaFileSystemRegistry* registry = g_browser_process->media_file_system_registry(); EXPECT_EQ(0U, GetExtensionGalleriesHostCount(registry)); - BrowserThread::GetBlockingPool()->FlushForTesting(); - base::MessageLoop::current()->RunUntilIdle(); +#if defined(OS_CHROMEOS) + test_user_manager_.reset(); +#endif + +#if defined(OS_WIN) + monitor_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); } /////////// diff --git a/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc b/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc index 902d9a3..a1b394f 100644 --- a/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc +++ b/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc @@ -9,7 +9,7 @@ #include "base/message_loop.h" #include "base/run_loop.h" #include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,8 +20,7 @@ namespace pnacl_cache { class PNaClTranslationCacheTest : public testing::Test { protected: PNaClTranslationCacheTest() - : cache_thread_(BrowserThread::CACHE, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) {} + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} virtual ~PNaClTranslationCacheTest() {} virtual void SetUp() { cache_ = new PNaClTranslationCache(); } virtual void TearDown() { @@ -36,9 +35,7 @@ class PNaClTranslationCacheTest : public testing::Test { protected: PNaClTranslationCache* cache_; - base::MessageLoopForIO message_loop_; - content::TestBrowserThread cache_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; }; TEST_F(PNaClTranslationCacheTest, StoreOneInMem) { diff --git a/chrome/browser/net/chrome_network_delegate_unittest.cc b/chrome/browser/net/chrome_network_delegate_unittest.cc index 9e9d626..356b62f 100644 --- a/chrome/browser/net/chrome_network_delegate_unittest.cc +++ b/chrome/browser/net/chrome_network_delegate_unittest.cc @@ -14,7 +14,7 @@ #include "chrome/common/url_constants.h" #include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/completion_callback.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_test_util.h" @@ -91,8 +91,7 @@ TEST_F(ChromeNetworkDelegateTest, NeverThrottleLogic) { class ChromeNetworkDelegateSafeSearchTest : public testing::Test { public: ChromeNetworkDelegateSafeSearchTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), forwarder_(new extensions::EventRouterForwarder()) { } @@ -137,9 +136,7 @@ class ChromeNetworkDelegateSafeSearchTest : public testing::Test { } private: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_refptr<extensions::EventRouterForwarder> forwarder_; TestingProfile profile_; BooleanPrefMember enable_referrers_; @@ -286,8 +283,7 @@ TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearchOff) { class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { public: ChromeNetworkDelegatePrivacyModeTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), forwarder_(new extensions::EventRouterForwarder()), cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)), kBlockedSite("http://ads.thirdparty.com"), @@ -316,9 +312,7 @@ class ChromeNetworkDelegatePrivacyModeTest : public testing::Test { } protected: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_refptr<extensions::EventRouterForwarder> forwarder_; TestingProfile profile_; CookieSettings* cookie_settings_; diff --git a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc index 2f14235..9c9d8a6 100644 --- a/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc +++ b/chrome/browser/net/http_pipelining_compatibility_client_unittest.cc @@ -10,13 +10,14 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" #include "base/metrics/histogram.h" #include "base/metrics/histogram_samples.h" #include "base/metrics/statistics_recorder.h" +#include "base/run_loop.h" #include "base/stl_util.h" #include "base/stringprintf.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/test/spawned_test_server/spawned_test_server.h" @@ -81,11 +82,11 @@ using testing::StrEq; class HttpPipeliningCompatibilityClientTest : public testing::Test { public: HttpPipeliningCompatibilityClientTest() - : test_server_(net::SpawnedTestServer::TYPE_HTTP, + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), + test_server_(net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost, base::FilePath(FILE_PATH_LITERAL( - "chrome/test/data/http_pipelining"))), - io_thread_(BrowserThread::IO, &message_loop_) { + "chrome/test/data/http_pipelining"))) { } protected: @@ -109,7 +110,7 @@ class HttpPipeliningCompatibilityClientTest : public testing::Test { virtual void TearDown() OVERRIDE { BrowserThread::ReleaseSoon(BrowserThread::IO, FROM_HERE, context_); - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); STLDeleteValues(&original_samples_); } @@ -204,10 +205,9 @@ class HttpPipeliningCompatibilityClientTest : public testing::Test { } } - base::MessageLoopForIO message_loop_; + content::TestBrowserThreadBundle thread_bundle_; net::SpawnedTestServer test_server_; net::TestURLRequestContextGetter* context_; - content::TestBrowserThread io_thread_; private: scoped_ptr<HistogramSamples> GetHistogram(const char* name) { diff --git a/chrome/browser/net/sqlite_server_bound_cert_store.cc b/chrome/browser/net/sqlite_server_bound_cert_store.cc index 0ba32a4..674be57 100644 --- a/chrome/browser/net/sqlite_server_bound_cert_store.cc +++ b/chrome/browser/net/sqlite_server_bound_cert_store.cc @@ -479,7 +479,6 @@ void SQLiteServerBoundCertStore::Backend::BatchOperation( static const int kCommitIntervalMs = 30 * 1000; // Commit right away if we have more than 512 outstanding operations. static const size_t kCommitAfterBatchSize = 512; - DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); // We do a full copy of the cert here, and hopefully just here. scoped_ptr<PendingOperation> po(new PendingOperation(op, cert)); @@ -574,7 +573,6 @@ void SQLiteServerBoundCertStore::Backend::Commit() { // pending commit timer that will be holding a reference on us, but if/when // this fires we will already have been cleaned up and it will be ignored. void SQLiteServerBoundCertStore::Backend::Close() { - DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); // Must close the backend on the background thread. BrowserThread::PostTask( BrowserThread::DB, FROM_HERE, diff --git a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc b/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc index eeedf77..83db52a 100644 --- a/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc +++ b/chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc @@ -10,10 +10,10 @@ #include "base/message_loop.h" #include "base/run_loop.h" #include "base/stl_util.h" -#include "base/test/thread_test_helper.h" #include "chrome/browser/net/sqlite_server_bound_cert_store.h" #include "chrome/common/chrome_constants.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/test_data_directory.h" #include "net/test/cert_test_util.h" #include "sql/statement.h" @@ -25,8 +25,7 @@ using content::BrowserThread; class SQLiteServerBoundCertStoreTest : public testing::Test { public: SQLiteServerBoundCertStoreTest() - : db_thread_(BrowserThread::DB), - io_thread_(BrowserThread::IO, &message_loop_) {} + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} void Load( ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>* certs) { @@ -80,7 +79,6 @@ class SQLiteServerBoundCertStoreTest : public testing::Test { } virtual void SetUp() { - db_thread_.Start(); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); store_ = new SQLiteServerBoundCertStore( temp_dir_.path().Append(chrome::kOBCertFilename), NULL); @@ -97,9 +95,7 @@ class SQLiteServerBoundCertStoreTest : public testing::Test { "a", "b")); } - base::MessageLoopForIO message_loop_; - content::TestBrowserThread db_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; base::ScopedTempDir temp_dir_; scoped_refptr<SQLiteServerBoundCertStore> store_; ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> certs_; @@ -120,11 +116,8 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) { // to write its data to disk. Then we can see if after loading it again it // is still there. store_ = NULL; - scoped_refptr<base::ThreadTestHelper> helper( - new base::ThreadTestHelper( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); // Make sure we wait until the destructor has run. - ASSERT_TRUE(helper->Run()); + base::RunLoop().RunUntilIdle(); store_ = new SQLiteServerBoundCertStore( temp_dir_.path().Append(chrome::kOBCertFilename), NULL); @@ -158,7 +151,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestPersistence) { store_->DeleteServerBoundCert(*certs[1]); store_ = NULL; // Make sure we wait until the destructor has run. - ASSERT_TRUE(helper->Run()); + base::RunLoop().RunUntilIdle(); certs.clear(); store_ = new SQLiteServerBoundCertStore( temp_dir_.path().Append(chrome::kOBCertFilename), NULL); @@ -233,11 +226,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV1) { ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); store_ = NULL; - // Make sure we wait until the destructor has run. - scoped_refptr<base::ThreadTestHelper> helper( - new base::ThreadTestHelper( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); - ASSERT_TRUE(helper->Run()); + base::RunLoop().RunUntilIdle(); // Verify the database version is updated. { @@ -322,10 +311,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV2) { store_ = NULL; // Make sure we wait until the destructor has run. - scoped_refptr<base::ThreadTestHelper> helper( - new base::ThreadTestHelper( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); - ASSERT_TRUE(helper->Run()); + base::RunLoop().RunUntilIdle(); // Verify the database version is updated. { @@ -414,10 +400,7 @@ TEST_F(SQLiteServerBoundCertStoreTest, TestUpgradeV3) { store_ = NULL; // Make sure we wait until the destructor has run. - scoped_refptr<base::ThreadTestHelper> helper( - new base::ThreadTestHelper( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); - ASSERT_TRUE(helper->Run()); + base::RunLoop().RunUntilIdle(); // Verify the database version is updated. { diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc index a9626e0..f99bf20 100644 --- a/chrome/browser/notifications/desktop_notification_service_unittest.cc +++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc @@ -15,109 +15,16 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h" -using content::BrowserThread; - -namespace { - -// The HasPermission method of the DesktopNotificationService wants to be called -// on the IO thread. This class routes calls to the cache on the IO thread. -class ThreadProxy : public base::RefCountedThreadSafe<ThreadProxy> { - public: - ThreadProxy() - : io_event_(false, false), - ui_event_(false, false), - permission_(WebKit::WebNotificationPresenter::PermissionAllowed) { - // The current message loop was already initalized by the test superclass. - ui_thread_.reset( - new content::TestBrowserThread(BrowserThread::UI, - base::MessageLoop::current())); - - // Create IO thread, start its message loop. - io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); - io_thread_->Start(); - - // Calling PauseIOThread() here isn't safe, because the runnable method - // could complete before the constructor is done, deleting |this|. - } - - // Call the HasPermission method of the DesktopNotificationService on the IO - // thread and returns the permission setting. - WebKit::WebNotificationPresenter::Permission ServiceHasPermission( - DesktopNotificationService* service, - const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&ThreadProxy::ServiceHasPermissionIO, this, service, url)); - io_event_.Signal(); - ui_event_.Wait(); // Wait for IO thread to be done. - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&ThreadProxy::PauseIOThreadIO, this)); - - return permission_; - } - - void PauseIOThread() { - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&ThreadProxy::PauseIOThreadIO, this)); - } - - void DrainIOThread() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - io_event_.Signal(); - io_thread_->Stop(); - } - - private: - friend class base::RefCountedThreadSafe<ThreadProxy>; - ~ThreadProxy() { - DrainIOThread(); - } - - void PauseIOThreadIO() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - io_event_.Wait(); - } - - void ServiceHasPermissionIO(DesktopNotificationService* service, - const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - permission_ = service->HasPermission(url); - ui_event_.Signal(); - } - - base::WaitableEvent io_event_; - base::WaitableEvent ui_event_; - scoped_ptr<content::TestBrowserThread> ui_thread_; - scoped_ptr<content::TestBrowserThread> io_thread_; - - WebKit::WebNotificationPresenter::Permission permission_; -}; - -} // namespace - class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { - public: - DesktopNotificationServiceTest() { - } - + protected: virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); - proxy_ = new ThreadProxy; - proxy_->PauseIOThread(); // Creates the destop notification service. service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); } - virtual void TearDown() { - // The io thread's waiting on the io_event_ might hold a ref to |proxy_|, - // preventing its destruction. Clear that ref. - proxy_->DrainIOThread(); - ChromeRenderViewHostTestHarness::TearDown(); - } - DesktopNotificationService* service_; - scoped_refptr<ThreadProxy> proxy_; }; TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) { @@ -126,36 +33,36 @@ TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) { EXPECT_EQ(CONTENT_SETTING_ASK, service_->GetDefaultContentSetting(NULL)); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed, - proxy_->ServiceHasPermission(service_, url)); + service_->HasPermission(url)); service_->GrantPermission(url); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed, - proxy_->ServiceHasPermission(service_, url)); + service_->HasPermission(url)); service_->DenyPermission(url); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied, - proxy_->ServiceHasPermission(service_, url)); + service_->HasPermission(url)); GURL https_url("https://testurl"); GURL http_url("http://testurl"); EXPECT_EQ(CONTENT_SETTING_ASK, service_->GetDefaultContentSetting(NULL)); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed, - proxy_->ServiceHasPermission(service_, http_url)); + service_->HasPermission(http_url)); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed, - proxy_->ServiceHasPermission(service_, https_url)); + service_->HasPermission(https_url)); service_->GrantPermission(https_url); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed, - proxy_->ServiceHasPermission(service_, http_url)); + service_->HasPermission(http_url)); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed, - proxy_->ServiceHasPermission(service_, https_url)); + service_->HasPermission(https_url)); service_->DenyPermission(http_url); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied, - proxy_->ServiceHasPermission(service_, http_url)); + service_->HasPermission(http_url)); EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed, - proxy_->ServiceHasPermission(service_, https_url)); + service_->HasPermission(https_url)); } TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) { diff --git a/chrome/browser/password_manager/password_generation_manager_unittest.cc b/chrome/browser/password_manager/password_generation_manager_unittest.cc index 3f4a75e..e9fce01 100644 --- a/chrome/browser/password_manager/password_generation_manager_unittest.cc +++ b/chrome/browser/password_manager/password_generation_manager_unittest.cc @@ -42,19 +42,14 @@ class TestPasswordGenerationManager : public PasswordGenerationManager { }; class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness { - public: - PasswordGenerationManagerTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO) {} - + protected: virtual void SetUp() OVERRIDE { TestingProfile* profile = CreateProfile(); profile->CreateRequestContext(); browser_context_.reset(profile); + SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); ChromeRenderViewHostTestHarness::SetUp(); - io_thread_.StartIOThread(); password_generation_manager_.reset( new TestPasswordGenerationManager(web_contents())); @@ -72,10 +67,6 @@ class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness { password_generation_manager_->UpdateState(NULL, new_renderer); } - protected: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; - scoped_ptr<TestPasswordGenerationManager> password_generation_manager_; }; diff --git a/chrome/browser/password_manager/password_manager_unittest.cc b/chrome/browser/password_manager/password_manager_unittest.cc index 8ce8e39..3dd46df 100644 --- a/chrome/browser/password_manager/password_manager_unittest.cc +++ b/chrome/browser/password_manager/password_manager_unittest.cc @@ -23,13 +23,12 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; using content::PasswordForm; using testing::_; using testing::DoAll; -using ::testing::Exactly; -using ::testing::WithArg; -using ::testing::Return; +using testing::Exactly; +using testing::Return; +using testing::WithArg; class MockPasswordManagerDelegate : public PasswordManagerDelegate { public: @@ -48,11 +47,6 @@ ACTION_P(SaveToScopedPtr, scoped) { } class PasswordManagerTest : public ChromeRenderViewHostTestHarness { - public: - PasswordManagerTest() - : ui_thread_(BrowserThread::UI, base::MessageLoopForUI::current()) {} - virtual ~PasswordManagerTest() {} - protected: virtual void SetUp() { testing_profile_ = new TestingProfile; @@ -93,9 +87,6 @@ class PasswordManagerTest : public ChromeRenderViewHostTestHarness { return PasswordManager::FromWebContents(web_contents()); } - // We create a UI thread to satisfy PasswordStore. - content::TestBrowserThread ui_thread_; - scoped_refptr<MockPasswordStore> store_; MockPasswordManagerDelegate delegate_; // Owned by manager_. diff --git a/chrome/browser/prefs/chrome_pref_service_unittest.cc b/chrome/browser/prefs/chrome_pref_service_unittest.cc index a3cb07d..3f9a036 100644 --- a/chrome/browser/prefs/chrome_pref_service_unittest.cc +++ b/chrome/browser/prefs/chrome_pref_service_unittest.cc @@ -23,12 +23,10 @@ #include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_profile.h" #include "components/user_prefs/pref_registry_syncable.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" #include "ui/base/test/data/resource.h" #include "webkit/common/webpreferences.h" -using content::BrowserThread; using content::WebContentsTester; TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) { @@ -144,10 +142,6 @@ TEST_F(ChromePrefServiceUserFilePrefsTest, PreserveEmptyValue) { class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { protected: - ChromePrefServiceWebKitPrefs() - : ui_thread_(BrowserThread::UI, &message_loop_) { - } - virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); @@ -172,9 +166,6 @@ class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { pref_services->SetUserPref("webkit.webprefs.foo", Value::CreateStringValue("bar")); } - - private: - content::TestBrowserThread ui_thread_; }; // Tests to see that webkit preferences are properly loaded and copied over diff --git a/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc b/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc index 034cbdc..66fabfa 100644 --- a/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc +++ b/chrome/browser/safe_browsing/browser_feature_extractor_unittest.cc @@ -32,10 +32,9 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -using ::testing::Return; -using ::testing::StrictMock; -using content::BrowserThread; using content::WebContentsTester; +using testing::Return; +using testing::StrictMock; namespace safe_browsing { namespace { @@ -50,10 +49,6 @@ class MockClientSideDetectionService : public ClientSideDetectionService { class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { protected: - BrowserFeatureExtractorTest() - : ui_thread_(BrowserThread::UI, &message_loop_) { - } - virtual void SetUp() { ChromeRenderViewHostTestHarness::SetUp(); profile()->CreateHistoryService(true /* delete_file */, false /* no_db */); @@ -161,7 +156,6 @@ class BrowserFeatureExtractorTest : public ChromeRenderViewHostTestHarness { } } - content::TestBrowserThread ui_thread_; int num_pending_; scoped_ptr<BrowserFeatureExtractor> extractor_; std::map<ClientPhishingRequest*, bool> success_; diff --git a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc index 57ad568..5bbae8b 100644 --- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc +++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc @@ -5,6 +5,7 @@ #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/run_loop.h" #include "base/stringprintf.h" #include "base/synchronization/waitable_event.h" #include "chrome/browser/safe_browsing/browser_feature_extractor.h" @@ -172,13 +173,6 @@ class MockBrowserFeatureExtractor : public BrowserFeatureExtractor { ClientMalwareRequest*)); }; -// Helper function which quits the UI message loop from the IO message loop. -void QuitUIMessageLoopFromIO() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::MessageLoop::QuitClosure()); -} } // namespace class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { @@ -192,16 +186,6 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { mock_profile_ = new NiceMock<MockTestingProfile>(); browser_context_.reset(mock_profile_); - ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, - &message_loop_)); - file_user_blocking_thread_.reset( - new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING, - &message_loop_)); - // Note: we're starting a real IO thread to make sure our DCHECKs that - // verify which thread is running are actually tested. - io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); - ASSERT_TRUE(io_thread_->Start()); - ChromeRenderViewHostTestHarness::SetUp(); // Inject service classes. @@ -226,11 +210,6 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { csd_host_->malware_report_enabled_ = true; } - static void RunAllPendingOnIO(base::WaitableEvent* event) { - base::MessageLoop::current()->RunUntilIdle(); - event->Signal(); - } - virtual void TearDown() { // Delete the host object on the UI thread and release the // SafeBrowsingService. @@ -238,18 +217,8 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { csd_host_.release()); database_manager_ = NULL; ui_manager_ = NULL; - message_loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); ChromeRenderViewHostTestHarness::TearDown(); - - // Let the tasks on the IO thread run to avoid memory leaks. - base::WaitableEvent done(false, false); - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(RunAllPendingOnIO, &done)); - done.Wait(); - io_thread_.reset(); - message_loop_.RunUntilIdle(); - file_user_blocking_thread_.reset(); - ui_thread_.reset(); } void OnPhishingDetectionDone(const std::string& verdict_str) { @@ -264,16 +233,6 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { return csd_host_->browse_info_.get(); } - void FlushIOMessageLoop() { - // If there was a message posted on the IO thread to display the - // interstitial page we know that it would have been posted before - // we put the quit message there. - BrowserThread::PostTask(BrowserThread::IO, - FROM_HERE, - base::Bind(&QuitUIMessageLoopFromIO)); - base::MessageLoop::current()->Run(); - } - void ExpectPreClassificationChecks(const GURL& url, const bool* is_private, const bool* is_incognito, @@ -308,10 +267,8 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { } void WaitAndCheckPreClassificationChecks() { - // Wait for CheckCsdWhitelist to be called if at all. - FlushIOMessageLoop(); - // Checks for CheckCache() to be called if at all. - base::MessageLoop::current()->RunUntilIdle(); + // Wait for CheckCsdWhitelist and CheckCache() to be called if at all. + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); @@ -360,11 +317,6 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; MockTestingProfile* mock_profile_; // We don't own this object - - private: - scoped_ptr<content::TestBrowserThread> ui_thread_; - scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; - scoped_ptr<content::TestBrowserThread> io_thread_; }; @@ -408,7 +360,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { // Make sure DoDisplayBlockingPage is not going to be called. EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); cb.Run(GURL(verdict.url()), false); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); } @@ -440,7 +392,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { // Make sure DoDisplayBlockingPage is not going to be called. EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); cb.Run(GURL(verdict.url()), false); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); } @@ -475,7 +427,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { .WillOnce(SaveArg<0>(&resource)); cb.Run(phishing_url, true); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); EXPECT_EQ(phishing_url, resource.url); EXPECT_EQ(phishing_url, resource.original_url); @@ -492,10 +444,6 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { FROM_HERE, base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, ui_manager_, resource.callback)); - // Since the CsdClient object will be deleted on the UI thread I need - // to run the UI message loop. Post a task to stop the UI message loop - // after the client object destructor is called. - FlushIOMessageLoop(); } TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { @@ -566,7 +514,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { cb.Run(phishing_url, true); // Should have no effect. cb_other.Run(other_phishing_url, true); // Should show interstitial. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); EXPECT_EQ(other_phishing_url, resource.url); EXPECT_EQ(other_phishing_url, resource.original_url); @@ -583,10 +531,6 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { FROM_HERE, base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, ui_manager_, resource.callback)); - // Since the CsdClient object will be deleted on the UI thread I need - // to run the UI message loop. Post a task to stop the UI message loop - // after the client object destructor is called. - FlushIOMessageLoop(); } TEST_F(ClientSideDetectionHostTest, @@ -956,10 +900,8 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { .WillOnce(SaveArg<0>(&resource)); NavigateAndCommit(url); - // Wait for CheckCsdWhitelist to be called on the IO thread. - FlushIOMessageLoop(); - // Wait for CheckCache() to be called on the UI thread. - base::MessageLoop::current()->RunUntilIdle(); + // Wait for CheckCsdWhitelist and CheckCache() to be called. + base::RunLoop().RunUntilIdle(); // Now we check that all expected functions were indeed called on the two // service objects. EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc index ca1f658..31f662d 100644 --- a/chrome/browser/safe_browsing/malware_details_unittest.cc +++ b/chrome/browser/safe_browsing/malware_details_unittest.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/pickle.h" +#include "base/run_loop.h" #include "base/time.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_service.h" @@ -22,7 +23,6 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" @@ -122,13 +122,6 @@ void FillCache(net::URLRequestContextGetter* context_getter) { WriteToEntry(cache, kLandingURL, kLandingHeaders, kLandingData); } -void QuitUIMessageLoop() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::MessageLoop::QuitClosure()); -} - // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. // Also exposes the constructor. class MalwareDetailsWrap : public MalwareDetails { @@ -149,21 +142,29 @@ class MalwareDetailsWrap : public MalwareDetails { class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { public: + base::RunLoop* run_loop_; // The safe browsing UI manager does not need a service for this test. MockSafeBrowsingUIManager() - : SafeBrowsingUIManager(NULL) {} + : SafeBrowsingUIManager(NULL), run_loop_(NULL) {} // When the MalwareDetails is done, this is called. virtual void SendSerializedMalwareDetails( const std::string& serialized) OVERRIDE { DVLOG(1) << "SendSerializedMalwareDetails"; - // Notify WaitForSerializedReport. - BrowserThread::PostTask(BrowserThread::IO, - FROM_HERE, - base::Bind(&QuitUIMessageLoop)); + run_loop_->Quit(); + run_loop_ = NULL; serialized_ = serialized; } + // Used to synchronize SendSerializedMalwareDetails() with + // WaitForSerializedReport(). RunLoop::RunUntilIdle() is not sufficient + // because the MessageLoop task queue completely drains at some point + // between the send and the wait. + void SetRunLoopToQuit(base::RunLoop* run_loop) { + DCHECK(run_loop_ == NULL); + run_loop_ = run_loop; + } + const std::string& GetSerialized() { return serialized_; } @@ -182,23 +183,17 @@ class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; MalwareDetailsTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - io_thread_(BrowserThread::IO), - ui_manager_(new MockSafeBrowsingUIManager()) { + : ui_manager_(new MockSafeBrowsingUIManager()) { } - virtual void SetUp() { + virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); - // The URLFetcher checks that the messageloop type is IO. - ASSERT_TRUE(io_thread_.StartIOThread()); - profile()->CreateHistoryService(true /* delete_file */, false /* no_db */); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { profile()->DestroyHistoryService(); ChromeRenderViewHostTestHarness::TearDown(); - io_thread_.Stop(); } static bool ResourceLessThan( @@ -214,7 +209,9 @@ class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { base::Bind(&MalwareDetails::FinishCollection, report)); // Wait for the callback (SendSerializedMalwareDetails). DVLOG(1) << "Waiting for SendSerializedMalwareDetails"; - base::MessageLoop::current()->Run(); + base::RunLoop run_loop; + ui_manager_->SetRunLoopToQuit(&run_loop); + run_loop.Run(); return ui_manager_->GetSerialized(); } @@ -319,8 +316,6 @@ class MalwareDetailsTest : public ChromeRenderViewHostTestHarness { false); } - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; }; @@ -421,8 +416,6 @@ TEST_F(MalwareDetailsTest, MalwareDOMDetails) { params.push_back(parent_node); report->OnReceivedMalwareDOMDetails(params); - base::MessageLoop::current()->RunUntilIdle(); - std::string serialized = WaitForSerializedReport(report.get()); ClientMalwareReportRequest actual; actual.ParseFromString(serialized); @@ -552,8 +545,8 @@ TEST_F(MalwareDetailsTest, HTTPCache) { std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; report->OnReceivedMalwareDOMDetails(params); - // Let the cache callbacks complete - base::MessageLoop::current()->RunUntilIdle(); + // Let the cache callbacks complete. + base::RunLoop().RunUntilIdle(); DVLOG(1) << "Getting serialized report"; std::string serialized = WaitForSerializedReport(report.get()); @@ -623,8 +616,8 @@ TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; report->OnReceivedMalwareDOMDetails(params); - // Let the cache callbacks complete - base::MessageLoop::current()->RunUntilIdle(); + // Let the cache callbacks complete. + base::RunLoop().RunUntilIdle(); DVLOG(1) << "Getting serialized report"; std::string serialized = WaitForSerializedReport(report.get()); @@ -673,7 +666,7 @@ TEST_F(MalwareDetailsTest, HistoryServiceUrls) { report->OnReceivedMalwareDOMDetails(params); // Let the redirects callbacks complete. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); std::string serialized = WaitForSerializedReport(report.get()); ClientMalwareReportRequest actual; diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc index 5a057ea..5ed1bf9 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/prefs/pref_service.h" +#include "base/run_loop.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/safe_browsing/malware_details.h" #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" @@ -15,10 +16,8 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" -using content::BrowserThread; using content::InterstitialPage; using content::NavigationEntry; using content::WebContents; @@ -119,11 +118,7 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { CANCEL }; - SafeBrowsingBlockingPageTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), - io_thread_(BrowserThread::IO, base::MessageLoop::current()) { + SafeBrowsingBlockingPageTest() { ResetUserResponse(); // The safe browsing UI manager does not need a service for this test. ui_manager_ = new TestSafeBrowsingUIManager(NULL); @@ -196,14 +191,14 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { SafeBrowsingBlockingPage* sb_interstitial) { sb_interstitial->interstitial_page_->Proceed(); // Proceed() posts a task to update the SafeBrowsingService::Client. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); } static void DontProceedThroughInterstitial( SafeBrowsingBlockingPage* sb_interstitial) { sb_interstitial->interstitial_page_->DontProceed(); // DontProceed() posts a task to update the SafeBrowsingService::Client. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); } void DontProceedThroughSubresourceInterstitial( @@ -212,7 +207,7 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { // subresource interstitials. GoBack(false); // DontProceed() posts a task to update the SafeBrowsingService::Client. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); } scoped_refptr<TestSafeBrowsingUIManager> ui_manager_; @@ -235,9 +230,6 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness { UserResponse user_response_; TestSafeBrowsingBlockingPageFactory factory_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; }; // Tests showing a blocking page for a malware page and not proceeding. @@ -257,7 +249,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); ASSERT_TRUE(sb_interstitial); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // Simulate the user clicking "don't proceed". DontProceedThroughInterstitial(sb_interstitial); @@ -586,7 +578,7 @@ TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); ASSERT_TRUE(sb_interstitial); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // Simulate the user clicking "proceed" then "don't proceed" (before the // interstitial is shown). @@ -594,7 +586,7 @@ TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { sb_interstitial->interstitial_page_->DontProceed(); // Proceed() and DontProceed() post a task to update the // SafeBrowsingService::Client. - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // The interstitial should be gone. EXPECT_EQ(OK, user_response()); @@ -621,7 +613,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); ASSERT_TRUE(sb_interstitial); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); // Simulate the user clicking "don't proceed". DontProceedThroughInterstitial(sb_interstitial); @@ -654,7 +646,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); ASSERT_TRUE(sb_interstitial); - base::MessageLoop::current()->RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_FALSE(profile->GetPrefs()->GetBoolean( prefs::kSafeBrowsingReportingEnabled)); diff --git a/chrome/browser/safe_browsing/two_phase_uploader_unittest.cc b/chrome/browser/safe_browsing/two_phase_uploader_unittest.cc index 11fda28..e2464c34 100644 --- a/chrome/browser/safe_browsing/two_phase_uploader_unittest.cc +++ b/chrome/browser/safe_browsing/two_phase_uploader_unittest.cc @@ -7,7 +7,7 @@ #include "base/files/file_path.h" #include "base/message_loop.h" #include "chrome/browser/safe_browsing/local_two_phase_testserver.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" #include "net/base/net_errors.h" #include "net/url_request/url_fetcher.h" @@ -59,20 +59,13 @@ base::FilePath GetTestFilePath() { class TwoPhaseUploaderTest : public testing::Test { public: TwoPhaseUploaderTest() - : db_thread_(BrowserThread::DB), - io_thread_(BrowserThread::IO, &message_loop_), + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), url_request_context_getter_(new net::TestURLRequestContextGetter( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { } - virtual void SetUp() { - db_thread_.Start(); - } - protected: - base::MessageLoopForIO message_loop_; - content::TestBrowserThread db_thread_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; }; diff --git a/chrome/browser/sessions/persistent_tab_restore_service_browsertest.cc b/chrome/browser/sessions/persistent_tab_restore_service_browsertest.cc index 399b35a..c433623 100644 --- a/chrome/browser/sessions/persistent_tab_restore_service_browsertest.cc +++ b/chrome/browser/sessions/persistent_tab_restore_service_browsertest.cc @@ -5,6 +5,7 @@ #include "chrome/browser/sessions/persistent_tab_restore_service.h" #include "base/compiler_specific.h" +#include "base/run_loop.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" @@ -28,7 +29,6 @@ #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" #include "content/public/test/render_view_test.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" #include "content/public/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" @@ -61,12 +61,12 @@ class PersistentTabRestoreTimeFactory : public TabRestoreService::TimeFactory { class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { public: PersistentTabRestoreServiceTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_) { - url1_ = GURL("http://1"); - url2_ = GURL("http://2"); - url3_ = GURL("http://3"); - user_agent_override_ = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19" - " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19"; + : url1_("http://1"), + url2_("http://2"), + url3_("http://3"), + user_agent_override_( + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19" + " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19") { } virtual ~PersistentTabRestoreServiceTest() { @@ -121,7 +121,7 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { service_->Shutdown(); service_.reset(); service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); } // Adds a window with one tab and url to the profile's session service. @@ -159,6 +159,12 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { profile()->set_last_session_exited_cleanly(false); } + void SynchronousLoadTabsFromLastSession() { + // Ensures that the load is complete before continuing. + service_->LoadTabsFromLastSession(); + base::RunLoop().RunUntilIdle(); + } + GURL url1_; GURL url2_; GURL url3_; @@ -167,7 +173,6 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { PersistentTabRestoreTimeFactory* time_factory_; content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; - content::TestBrowserThread ui_thread_; }; namespace { @@ -387,7 +392,7 @@ TEST_F(PersistentTabRestoreServiceTest, DontLoadTwice) { // Recreate the service and have it load the tabs. RecreateService(); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); // There should only be one entry. ASSERT_EQ(1U, service_->entries().size()); @@ -404,7 +409,7 @@ TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSession) { TestTabRestoreServiceObserver observer; service_->AddObserver(&observer); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); EXPECT_TRUE(observer.got_loaded()); service_->RemoveObserver(&observer); @@ -432,7 +437,7 @@ TEST_F(PersistentTabRestoreServiceTest, DontLoadAfterRestore) { profile()->set_restored_last_session(true); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); // Because we restored a session PersistentTabRestoreService shouldn't load // the tabs. @@ -448,7 +453,7 @@ TEST_F(PersistentTabRestoreServiceTest, DontLoadAfterCleanExit) { profile()->set_last_session_exited_cleanly(true); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); ASSERT_EQ(0U, service_->entries().size()); } @@ -726,7 +731,7 @@ TEST_F(PersistentTabRestoreServiceTest, PruneIsCalled) { EXPECT_EQ(max_entries, service_->entries().size()); // This should not crash. - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); EXPECT_EQ(max_entries, service_->entries().size()); } @@ -744,7 +749,7 @@ TEST_F(PersistentTabRestoreServiceTest, GoToLoadedWhenHaveMaxEntries) { TestTabRestoreServiceObserver observer; service_->AddObserver(&observer); EXPECT_EQ(max_entries, service_->entries().size()); - service_->LoadTabsFromLastSession(); + SynchronousLoadTabsFromLastSession(); EXPECT_TRUE(observer.got_loaded()); EXPECT_TRUE(service_->IsLoaded()); service_->RemoveObserver(&observer); diff --git a/chrome/browser/storage_monitor/volume_mount_watcher_win.cc b/chrome/browser/storage_monitor/volume_mount_watcher_win.cc index 8cd3998..13ed0ff 100644 --- a/chrome/browser/storage_monitor/volume_mount_watcher_win.cc +++ b/chrome/browser/storage_monitor/volume_mount_watcher_win.cc @@ -428,10 +428,10 @@ bool VolumeMountWatcherWin::GetDeviceInfo(const base::FilePath& device_path, DCHECK(info); base::FilePath path(device_path); MountPointDeviceMetadataMap::const_iterator iter = - device_metadata_.find(path.value()); + device_metadata_.find(path); while (iter == device_metadata_.end() && path.DirName() != path) { path = path.DirName(); - iter = device_metadata_.find(path.value()); + iter = device_metadata_.find(path); } if (iter == device_metadata_.end()) @@ -486,7 +486,7 @@ void VolumeMountWatcherWin::HandleDeviceAttachEventOnUIThread( const StorageInfo& info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - device_metadata_[device_path.value()] = info; + device_metadata_[device_path] = info; DeviceCheckComplete(device_path); @@ -503,7 +503,7 @@ void VolumeMountWatcherWin::HandleDeviceDetachEventOnUIThread( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); MountPointDeviceMetadataMap::const_iterator device_info = - device_metadata_.find(device_location); + device_metadata_.find(base::FilePath(device_location)); // If the device isn't type removable (like a CD), it won't be there. if (device_info == device_metadata_.end()) return; @@ -522,7 +522,7 @@ void VolumeMountWatcherWin::EjectDevice( callback.Run(StorageMonitor::EJECT_FAILURE); return; } - if (device_metadata_.erase(device.value()) == 0) { + if (device_metadata_.erase(device) == 0) { callback.Run(StorageMonitor::EJECT_FAILURE); return; } diff --git a/chrome/browser/storage_monitor/volume_mount_watcher_win.h b/chrome/browser/storage_monitor/volume_mount_watcher_win.h index 15cdfbf..8ed0e61 100644 --- a/chrome/browser/storage_monitor/volume_mount_watcher_win.h +++ b/chrome/browser/storage_monitor/volume_mount_watcher_win.h @@ -100,7 +100,7 @@ class VolumeMountWatcherWin { // Key: Mass storage device mount point. // Value: Mass storage device metadata. - typedef std::map<base::string16, StorageInfo> MountPointDeviceMetadataMap; + typedef std::map<base::FilePath, StorageInfo> MountPointDeviceMetadataMap; // Maintain a set of device attribute check calls in-flight. Only accessed // on the UI thread. This is to try and prevent the same device from diff --git a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc index bb3f511..aa6f4b7 100644 --- a/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/browser_thread_model_worker_unittest.cc @@ -11,7 +11,7 @@ #include "base/threading/thread.h" #include "base/timer.h" #include "chrome/browser/sync/glue/browser_thread_model_worker.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" using base::OneShotTimer; @@ -27,8 +27,8 @@ class SyncBrowserThreadModelWorkerTest : public testing::Test { public: SyncBrowserThreadModelWorkerTest() : did_do_work_(false), - db_thread_(BrowserThread::DB), - io_thread_(BrowserThread::IO, &io_loop_), + thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP | + content::TestBrowserThreadBundle::REAL_DB_THREAD), weak_factory_(this) {} bool did_do_work() { return did_do_work_; } @@ -73,13 +73,11 @@ class SyncBrowserThreadModelWorkerTest : public testing::Test { protected: virtual void SetUp() { - db_thread_.Start(); worker_ = new DatabaseModelWorker(NULL); } virtual void Teardown() { worker_ = NULL; - db_thread_.Stop(); } private: @@ -87,9 +85,7 @@ class SyncBrowserThreadModelWorkerTest : public testing::Test { scoped_refptr<BrowserThreadModelWorker> worker_; OneShotTimer<SyncBrowserThreadModelWorkerTest> timer_; - content::TestBrowserThread db_thread_; - base::MessageLoopForIO io_loop_; - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest> weak_factory_; }; diff --git a/chrome/browser/tab_contents/render_view_context_menu_unittest.cc b/chrome/browser/tab_contents/render_view_context_menu_unittest.cc index d1ba6cd..661a4db 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_unittest.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_unittest.cc @@ -12,9 +12,7 @@ #include "chrome/browser/tab_contents/render_view_context_menu_test_util.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "extensions/common/url_pattern.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -24,9 +22,6 @@ using extensions::MenuItem; using extensions::URLPatternSet; class RenderViewContextMenuTest : public testing::Test { - public: - RenderViewContextMenuTest() { } - protected: // Proxy defined here to minimize friend classes in RenderViewContextMenu static bool ExtensionContextAndPatternMatch( @@ -36,9 +31,6 @@ class RenderViewContextMenuTest : public testing::Test { return RenderViewContextMenu::ExtensionContextAndPatternMatch(params, contexts, patterns); } - - private: - DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuTest); }; // Generates a ContextMenuParams that matches the specified contexts. @@ -250,9 +242,15 @@ TEST_F(RenderViewContextMenuTest, TargetIgnoredForSelectionOnImage) { class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness { public: - RenderViewContextMenuPrefsTest() - : browser_thread_(content::BrowserThread::UI, &message_loop_), - registry_(profile(), NULL) {} + virtual void SetUp() OVERRIDE { + ChromeRenderViewHostTestHarness::SetUp(); + registry_.reset(new ProtocolHandlerRegistry(profile(), NULL)); + } + + virtual void TearDown() OVERRIDE { + registry_.reset(); + ChromeRenderViewHostTestHarness::TearDown(); + } TestRenderViewContextMenu* CreateContextMenu() { content::ContextMenuParams params = CreateParams(MenuItem::LINK); @@ -262,16 +260,13 @@ class RenderViewContextMenuPrefsTest : public ChromeRenderViewHostTestHarness { wc, params); // TestingProfile (returned by profile()) does not provide a protocol // registry. - menu->protocol_handler_registry_ = ®istry_; + menu->protocol_handler_registry_ = registry_.get(); menu->Init(); return menu; } private: - content::TestBrowserThread browser_thread_; - ProtocolHandlerRegistry registry_; - - DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuPrefsTest); + scoped_ptr<ProtocolHandlerRegistry> registry_; }; // Verifies when Incognito Mode is not available (disabled by policy), diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 33471ee..2eedcf0 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -45,7 +45,6 @@ #include "content/public/test/mock_notification_observer.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/render_view_test.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "grit/generated_resources.h" #include "ipc/ipc_test_sink.h" @@ -55,7 +54,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" #include "third_party/cld/languages/public/languages.h" -using content::BrowserThread; using content::NavigationController; using content::RenderViewHostTester; using content::WebContents; @@ -99,8 +97,7 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, TranslateManagerBrowserTest() : pref_callback_( base::Bind(&TranslateManagerBrowserTest::OnPreferenceChanged, - base::Unretained(this))), - ui_thread_(BrowserThread::UI, &message_loop_) { + base::Unretained(this))) { } // Simulates navigating to a page and getting the page contents and language @@ -314,7 +311,6 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, private: content::NotificationRegistrar notification_registrar_; net::TestURLFetcherFactory url_fetcher_factory_; - content::TestBrowserThread ui_thread_; content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; diff --git a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc index 30f0869..eedb1e6 100644 --- a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc +++ b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc @@ -19,7 +19,6 @@ #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/aura/client/activation_change_observer.h" @@ -133,10 +132,6 @@ class TabHelperTabStripModelDelegate : public TestTabStripModelDelegate { class LauncherItemControllerPerAppTest : public ChromeRenderViewHostTestHarness { public: - LauncherItemControllerPerAppTest() - : browser_thread_(content::BrowserThread::UI, &message_loop_) { - } - virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); @@ -241,11 +236,6 @@ class LauncherItemControllerPerAppTest AppIconLoaderImpl* app_icon_loader_; scoped_ptr<aura::test::TestActivationClient> activation_client_; - - private: - content::TestBrowserThread browser_thread_; - - DISALLOW_COPY_AND_ASSIGN(LauncherItemControllerPerAppTest); }; // Verify that the launcher item positions are persisted and restored. @@ -318,8 +308,6 @@ class BrowserLauncherItemControllerTest virtual void TearDown() OVERRIDE { LauncherItemControllerPerAppTest::TearDown(); } - - DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemControllerTest); }; // Verifies a new launcher item is added for TYPE_TABBED. diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc index 2b79598..8066568 100644 --- a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc +++ b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc @@ -39,8 +39,7 @@ class LauncherContextMenuTest : public ash::test::AshTestBase { } LauncherContextMenuTest() - : ash::test::AshTestBase(), - profile_(new TestingProfile()), + : profile_(new TestingProfile()), browser_thread_(content::BrowserThread::UI, message_loop()) {} virtual void SetUp() OVERRIDE { diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 53d410f..6fbcefa 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/prefs/pref_service.h" +#include "base/run_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" #include "chrome/browser/ui/autofill/autofill_dialog_view.h" @@ -27,7 +28,7 @@ #include "components/autofill/common/autofill_switches.h" #include "components/autofill/common/form_data.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/web_contents_tester.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -69,8 +70,6 @@ const char* kFieldsFromPage[] = }; const char kSettingsOrigin[] = "Chrome settings"; -using content::BrowserThread; - void SetOutputValue(const DetailInputs& inputs, DetailOutputMap* outputs, AutofillFieldType type, @@ -301,20 +300,11 @@ class TestAutofillDialogController }; class AutofillDialogControllerTest : public testing::Test { - public: + protected: AutofillDialogControllerTest() - : ui_thread_(BrowserThread::UI, &loop_), - file_thread_(BrowserThread::FILE), - file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), - io_thread_(BrowserThread::IO), - form_structure_(NULL) { - file_thread_.Start(); - file_blocking_thread_.Start(); - io_thread_.StartIOThread(); + : form_structure_(NULL) { } - virtual ~AutofillDialogControllerTest() {} - // testing::Test implementation: virtual void SetUp() OVERRIDE { profile()->CreateRequestContext(); @@ -413,18 +403,14 @@ class AutofillDialogControllerTest : public testing::Test { EXPECT_TRUE(controller()->AutocheckoutIsRunning()); } + // Must be first member to ensure TestBrowserThreads outlive other objects. + content::TestBrowserThreadBundle thread_bundle_; + #if defined(OS_WIN) // http://crbug.com/227221 ui::ScopedOleInitializer ole_initializer_; #endif - // A bunch of threads are necessary for classes like TestWebContents and - // URLRequestContextGetter not to fall over. - base::MessageLoopForUI loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - content::TestBrowserThread file_blocking_thread_; - content::TestBrowserThread io_thread_; TestingProfile profile_; // The controller owns itself. @@ -437,8 +423,6 @@ class AutofillDialogControllerTest : public testing::Test { // Returned when the dialog closes successfully. const FormStructure* form_structure_; - - DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); }; } // namespace diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm index 37079c0..f7f1a43 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm @@ -8,20 +8,18 @@ #include "base/mac/scoped_nsautorelease_pool.h" #include "base/memory/scoped_nsobject.h" +#include "chrome/browser/media/media_capture_devices_dispatcher.h" #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" #include "chrome/common/content_settings_types.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" #include "content/public/common/media_stream_request.h" -#include "content/public/test/test_browser_thread.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest_mac.h" #include "ui/base/l10n/l10n_util.h" -using content::BrowserThread; - namespace { class DummyContentSettingBubbleModel : public ContentSettingBubbleModel { @@ -45,10 +43,6 @@ class DummyContentSettingBubbleModel : public ContentSettingBubbleModel { class ContentSettingBubbleControllerTest : public ChromeRenderViewHostTestHarness { - public: - ContentSettingBubbleControllerTest(); - virtual ~ContentSettingBubbleControllerTest(); - protected: // Helper function to create the bubble controller. ContentSettingBubbleController* CreateBubbleController( @@ -57,19 +51,9 @@ class ContentSettingBubbleControllerTest scoped_nsobject<NSWindow> parent_; private: - content::TestBrowserThread browser_thread_; - base::mac::ScopedNSAutoreleasePool pool_; }; -ContentSettingBubbleControllerTest::ContentSettingBubbleControllerTest() - : ChromeRenderViewHostTestHarness(), - browser_thread_(BrowserThread::UI, &message_loop_) { -} - -ContentSettingBubbleControllerTest::~ContentSettingBubbleControllerTest() { -} - ContentSettingBubbleController* ContentSettingBubbleControllerTest::CreateBubbleController( ContentSettingsType settingsType) { @@ -119,6 +103,8 @@ TEST_F(ContentSettingBubbleControllerTest, Init) { // Check that the bubble works for CONTENT_SETTINGS_TYPE_MEDIASTREAM. TEST_F(ContentSettingBubbleControllerTest, MediaStreamBubble) { + MediaCaptureDevicesDispatcher::GetInstance()-> + DisableDeviceEnumerationForTesting(); ContentSettingBubbleController* controller = CreateBubbleController(CONTENT_SETTINGS_TYPE_MEDIASTREAM); content_setting_bubble::MediaMenuPartsMap* mediaMenus = diff --git a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm index d290879..0c8f809 100644 --- a/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm @@ -14,9 +14,6 @@ #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/test_browser_window.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" - -using content::BrowserThread; // Subclass balloon controller and mock out the initialization of the RVH. @interface TestBalloonController : BalloonController { @@ -58,15 +55,7 @@ class MockBalloonCollection : public BalloonCollection { }; class BalloonControllerTest : public ChromeRenderViewHostTestHarness { - public: - BalloonControllerTest() : - ui_thread_(BrowserThread::UI, base::MessageLoop::current()), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, base::MessageLoop::current()), - io_thread_(BrowserThread::IO, base::MessageLoop::current()) { - } - - virtual void SetUp() { + virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); CocoaTest::BootstrapCocoa(); profile()->CreateRequestContext(); @@ -77,17 +66,13 @@ class BalloonControllerTest : public ChromeRenderViewHostTestHarness { collection_.reset(new MockBalloonCollection()); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { collection_.reset(); browser_.reset(); - base::MessageLoop::current()->RunUntilIdle(); ChromeRenderViewHostTestHarness::TearDown(); } protected: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_user_blocking_thread_; - content::TestBrowserThread io_thread_; scoped_ptr<Browser> browser_; scoped_ptr<BalloonCollection> collection_; }; diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc index ec0a725..d3a3345 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/infobars/infobar_service.h" +#include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" #include "chrome/common/chrome_switches.h" @@ -17,18 +18,13 @@ #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; using content::WebContentsTester; class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness { protected: - ContentSettingBubbleModelTest() - : ui_thread_(BrowserThread::UI, base::MessageLoop::current()) {} - virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); TabSpecificContentSettings::CreateForWebContents(web_contents()); @@ -53,8 +49,6 @@ class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness { EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); EXPECT_FALSE(bubble_content.manage_link.empty()); } - - content::TestBrowserThread ui_thread_; }; TEST_F(ContentSettingBubbleModelTest, ImageRadios) { @@ -116,6 +110,10 @@ TEST_F(ContentSettingBubbleModelTest, Cookies) { } TEST_F(ContentSettingBubbleModelTest, Mediastream) { + // Required to break dependency on BrowserMainLoop. + MediaCaptureDevicesDispatcher::GetInstance()-> + DisableDeviceEnumerationForTesting(); + scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( ContentSettingBubbleModel::CreateContentSettingBubbleModel( NULL, web_contents(), profile(), @@ -132,6 +130,10 @@ TEST_F(ContentSettingBubbleModelTest, Mediastream) { } TEST_F(ContentSettingBubbleModelTest, BlockedMediastream) { + // Required to break dependency on BrowserMainLoop. + MediaCaptureDevicesDispatcher::GetInstance()-> + DisableDeviceEnumerationForTesting(); + WebContentsTester::For(web_contents())-> NavigateAndCommit(GURL("https://www.example.com")); GURL url = web_contents()->GetURL(); diff --git a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc index bafce3b..97256a3 100644 --- a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc +++ b/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc @@ -14,7 +14,6 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "net/cookies/cookie_options.h" #include "testing/gtest/include/gtest/gtest.h" @@ -54,14 +53,6 @@ class NotificationForwarder : public content::NotificationObserver { }; class ContentSettingImageModelTest : public ChromeRenderViewHostTestHarness { - public: - ContentSettingImageModelTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_) {} - - private: - content::TestBrowserThread ui_thread_; - - DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModelTest); }; TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { diff --git a/chrome/browser/ui/find_bar/find_backend_unittest.cc b/chrome/browser/ui/find_bar/find_backend_unittest.cc index 277e31d..8244933 100644 --- a/chrome/browser/ui/find_bar/find_backend_unittest.cc +++ b/chrome/browser/ui/find_bar/find_backend_unittest.cc @@ -12,26 +12,17 @@ #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" -using content::BrowserThread; using content::WebContents; using content::WebContentsTester; class FindBackendTest : public ChromeRenderViewHostTestHarness { - public: - FindBackendTest() - : ChromeRenderViewHostTestHarness(), - browser_thread_(BrowserThread::UI, &message_loop_) {} - - private: + protected: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); FindTabHelper::CreateForWebContents(web_contents()); } - - content::TestBrowserThread browser_thread_; }; namespace { diff --git a/chrome/browser/ui/sync/one_click_signin_helper.cc b/chrome/browser/ui/sync/one_click_signin_helper.cc index 37c3595..c4c4eb2 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper.cc @@ -496,7 +496,8 @@ OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) switched_to_advanced_(false), original_source_(SyncPromoUI::SOURCE_UNKNOWN), untrusted_navigations_since_signin_visit_(0), - untrusted_confirmation_required_(false) { + untrusted_confirmation_required_(false), + do_not_clear_pending_email_(false) { } OneClickSigninHelper::~OneClickSigninHelper() { @@ -948,12 +949,14 @@ void OneClickSigninHelper::CleanTransientState() { error_message_.clear(); // Post to IO thread to clear pending email. - Profile* profile = - Profile::FromBrowserContext(web_contents()->GetBrowserContext()); - content::BrowserThread::PostTask( - content::BrowserThread::IO, FROM_HERE, - base::Bind(&ClearPendingEmailOnIOThread, - base::Unretained(profile->GetResourceContext()))); + if (!do_not_clear_pending_email_) { + Profile* profile = + Profile::FromBrowserContext(web_contents()->GetBrowserContext()); + content::BrowserThread::PostTask( + content::BrowserThread::IO, FROM_HERE, + base::Bind(&ClearPendingEmailOnIOThread, + base::Unretained(profile->GetResourceContext()))); + } } bool OneClickSigninHelper::OnMessageReceived(const IPC::Message& message) { @@ -981,6 +984,10 @@ bool OneClickSigninHelper::OnFormSubmitted(const content::PasswordForm& form) { return true; } +void OneClickSigninHelper::SetDoNotClearPendingEmailForTesting() { + do_not_clear_pending_email_ = true; +} + void OneClickSigninHelper::NavigateToPendingEntry( const GURL& url, content::NavigationController::ReloadType reload_type) { diff --git a/chrome/browser/ui/sync/one_click_signin_helper.h b/chrome/browser/ui/sync/one_click_signin_helper.h index 0d3e96e..8bd48c0 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper.h +++ b/chrome/browser/ui/sync/one_click_signin_helper.h @@ -196,6 +196,12 @@ class OneClickSigninHelper // Clear all data member of the helper, except for the error. void CleanTransientState(); + // Unitests that use a TestingProfile should call this. + // Otherwise, clearing the pending e-mail crashes because the code expects + // a real ResourceContext rather than the MockResourceContext a + // TestingProfile provides. + void SetDoNotClearPendingEmailForTesting(); + // Grab Gaia password if available. bool OnFormSubmitted(const content::PasswordForm& form); @@ -242,6 +248,10 @@ class OneClickSigninHelper // This is set to true if at least one such URL is detected. bool untrusted_confirmation_required_; + // Allows unittests to avoid accessing the ResourceContext for clearing a + // pending e-mail. + bool do_not_clear_pending_email_; + DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); }; diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc index 2d1537d..8088bc3 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc @@ -30,7 +30,6 @@ #include "content/public/common/password_form.h" #include "content/public/common/url_constants.h" #include "content/public/test/mock_render_process_host.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -227,9 +226,6 @@ class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { TestingProfile* profile_; private: - // Members to fake that we are on the UI thread. - content::TestBrowserThread ui_thread_; - // The ID of the signin process the test will assume to be trusted. // By default, set to the test RenderProcessHost's process ID, but // overridden by SetTrustedSigninProcessID. @@ -240,7 +236,6 @@ class OneClickSigninHelperTest : public content::RenderViewHostTestHarness { OneClickSigninHelperTest::OneClickSigninHelperTest() : profile_(NULL), - ui_thread_(content::BrowserThread::UI, &message_loop_), trusted_signin_process_id_(-1) { } @@ -334,7 +329,6 @@ void OneClickSigninHelperTest::SubmitGAIAPassword( class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { public: OneClickSigninHelperIOTest(); - virtual ~OneClickSigninHelperIOTest(); virtual void SetUp() OVERRIDE; @@ -346,23 +340,13 @@ class OneClickSigninHelperIOTest : public OneClickSigninHelperTest { const GURL valid_gaia_url_; private: - content::TestBrowserThread db_thread_; - content::TestBrowserThread fub_thread_; - content::TestBrowserThread io_thread_; - DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelperIOTest); }; OneClickSigninHelperIOTest::OneClickSigninHelperIOTest() : testing_profile_manager_( TestingBrowserProcess::GetGlobal()), - valid_gaia_url_("https://accounts.google.com/"), - db_thread_(content::BrowserThread::DB, &message_loop_), - fub_thread_(content::BrowserThread::FILE_USER_BLOCKING, &message_loop_), - io_thread_(content::BrowserThread::IO, &message_loop_) { -} - -OneClickSigninHelperIOTest::~OneClickSigninHelperIOTest() { + valid_gaia_url_("https://accounts.google.com/") { } void OneClickSigninHelperIOTest::SetUp() { @@ -667,6 +651,7 @@ TEST_F(OneClickSigninHelperTest, SigninFromWebstoreWithConfigSyncfirst) { OneClickSigninHelper::CreateForWebContents(contents); OneClickSigninHelper* helper = OneClickSigninHelper::FromWebContents(contents); + helper->SetDoNotClearPendingEmailForTesting(); GURL continueUrl("https://chrome.google.com/webstore?source=5"); OneClickSigninHelper::ShowInfoBarUIThread( diff --git a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc index d6befc4..de42f87 100644 --- a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc @@ -36,10 +36,8 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; using content::SiteInstance; using content::WebContents; using extensions::Extension; @@ -117,9 +115,6 @@ class TabStripModelTestIDUserData : public base::SupportsUserData::Data { class TabStripModelTest : public ChromeRenderViewHostTestHarness { public: - TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) { - } - WebContents* CreateWebContents() { return WebContents::Create(WebContents::CreateParams(profile())); } @@ -206,9 +201,6 @@ class TabStripModelTest : public ChromeRenderViewHostTestHarness { selection_model.set_active(selection_model.selected_indices()[0]); model->SetSelectionFromModel(selection_model); } - - private: - content::TestBrowserThread browser_thread_; }; class MockTabStripModelObserver : public TabStripModelObserver { diff --git a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc index 357dc82..8985dae 100644 --- a/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc +++ b/chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc @@ -23,13 +23,11 @@ #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/png_codec.h" -using content::BrowserThread; using content::WebContentsTester; namespace { @@ -64,10 +62,6 @@ class FaviconDelegate : public ui::MenuModelDelegate { class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness { public: - BackFwdMenuModelTest() - : ui_thread_(BrowserThread::UI, &message_loop_) { - } - void ValidateModel(BackForwardMenuModel* model, int history_items, int chapter_stops) { int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items); @@ -108,8 +102,6 @@ class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness { controller().GoForward(); WebContentsTester::For(web_contents())->CommitPendingNavigation(); } - - content::TestBrowserThread ui_thread_; }; TEST_F(BackFwdMenuModelTest, BasicCase) { diff --git a/chrome/browser/ui/website_settings/website_settings_unittest.cc b/chrome/browser/ui/website_settings/website_settings_unittest.cc index ef08744..7e85670 100644 --- a/chrome/browser/ui/website_settings/website_settings_unittest.cc +++ b/chrome/browser/ui/website_settings/website_settings_unittest.cc @@ -21,7 +21,6 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/cert_store.h" #include "content/public/common/ssl_status.h" -#include "content/public/test/test_browser_thread.h" #include "net/cert/cert_status_flags.h" #include "net/cert/x509_certificate.h" #include "net/ssl/ssl_connection_status_flags.h" @@ -30,7 +29,10 @@ #include "testing/gtest/include/gtest/gtest.h" using content::SSLStatus; -using namespace testing; +using testing::_; +using testing::AnyNumber; +using testing::Return; +using testing::SetArgPointee; namespace { @@ -76,7 +78,6 @@ class WebsiteSettingsTest : public ChromeRenderViewHostTestHarness { : website_settings_(NULL), mock_ui_(NULL), cert_id_(0), - browser_thread_(content::BrowserThread::UI, &message_loop_), url_("http://www.example.com") { } @@ -153,7 +154,6 @@ class WebsiteSettingsTest : public ChromeRenderViewHostTestHarness { scoped_ptr<MockWebsiteSettingsUI> mock_ui_; int cert_id_; scoped_refptr<net::X509Certificate> cert_; - content::TestBrowserThread browser_thread_; MockCertStore cert_store_; GURL url_; }; diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc index 2c49a02..279c7e2 100644 --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc @@ -15,7 +15,6 @@ #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/navigation_details.h" #include "content/public/common/frame_navigate_params.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -27,9 +26,6 @@ class TestZoomObserver : public ZoomObserver { class ZoomControllerTest : public ChromeRenderViewHostTestHarness { public: - ZoomControllerTest() - : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()) {} - virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); zoom_controller_.reset(new ZoomController(web_contents())); @@ -44,10 +40,6 @@ class ZoomControllerTest : public ChromeRenderViewHostTestHarness { protected: scoped_ptr<ZoomController> zoom_controller_; TestZoomObserver zoom_observer_; - - private: - content::TestBrowserThread ui_thread_; - DISALLOW_COPY_AND_ASSIGN(ZoomControllerTest); }; TEST_F(ZoomControllerTest, DidNavigateMainFrame) { diff --git a/chrome/browser/web_applications/web_app_unittest.cc b/chrome/browser/web_applications/web_app_unittest.cc index 149f62b..a8a760c 100644 --- a/chrome/browser/web_applications/web_app_unittest.cc +++ b/chrome/browser/web_applications/web_app_unittest.cc @@ -12,26 +12,18 @@ #include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/common/extensions/extension_messages.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; using content::RenderViewHostTester; class WebApplicationTest : public ChromeRenderViewHostTestHarness { - public: - WebApplicationTest() : ui_thread_(BrowserThread::UI, &message_loop_) { - } - - private: + protected: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); extensions::TabHelper::CreateForWebContents(web_contents()); FaviconTabHelper::CreateForWebContents(web_contents()); } - - content::TestBrowserThread ui_thread_; }; #if defined(OS_MACOSX) diff --git a/chrome/test/base/chrome_render_view_host_test_harness.cc b/chrome/test/base/chrome_render_view_host_test_harness.cc index 62e39f7..3ae5c54 100644 --- a/chrome/test/base/chrome_render_view_host_test_harness.cc +++ b/chrome/test/base/chrome_render_view_host_test_harness.cc @@ -21,8 +21,7 @@ using content::RenderViewHostTester; using content::RenderViewHostTestHarness; -ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() - : RenderViewHostTestHarness() { +ChromeRenderViewHostTestHarness::ChromeRenderViewHostTestHarness() { } ChromeRenderViewHostTestHarness::~ChromeRenderViewHostTestHarness() { diff --git a/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc b/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc index ea7c920..4fc3e6e 100644 --- a/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc +++ b/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc @@ -9,7 +9,7 @@ #include "components/autofill/browser/autocheckout/whitelist_manager.h" #include "components/autofill/browser/autofill_metrics.h" #include "components/autofill/common/autofill_switches.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/http/http_status_code.h" @@ -90,16 +90,15 @@ class TestWhitelistManager : public WhitelistManager { class WhitelistManagerTest : public testing::Test { public: - WhitelistManagerTest() : io_thread_(content::BrowserThread::IO) {} + WhitelistManagerTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} virtual void SetUp() { - io_thread_.StartIOThread(); profile_.CreateRequestContext(); } virtual void TearDown() { profile_.ResetRequestContext(); - io_thread_.Stop(); } protected: @@ -146,9 +145,7 @@ class WhitelistManagerTest : public testing::Test { scoped_ptr<TestWhitelistManager> whitelist_manager_; private: - base::MessageLoopForIO message_loop_; - // The profile's request context must be released on the IO thread. - content::TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; }; TEST_F(WhitelistManagerTest, DownloadWhitelist) { diff --git a/components/autofill/browser/autocheckout_manager_unittest.cc b/components/autofill/browser/autocheckout_manager_unittest.cc index 14990ee..530e351 100644 --- a/components/autofill/browser/autocheckout_manager_unittest.cc +++ b/components/autofill/browser/autocheckout_manager_unittest.cc @@ -22,7 +22,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" - using content::BrowserThread; namespace autofill { @@ -334,11 +333,25 @@ class TestAutocheckoutManager: public AutocheckoutManager { } // namespace class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { - public: - AutocheckoutManagerTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(BrowserThread::UI, &message_loop_), - io_thread_(BrowserThread::IO) { + protected: + virtual void SetUp() OVERRIDE { + SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); + ChromeRenderViewHostTestHarness::SetUp(); + profile()->CreateRequestContext(); + autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); + autofill_manager_.reset(new TestAutofillManager( + web_contents(), + autofill_manager_delegate_.get())); + autocheckout_manager_.reset( + new TestAutocheckoutManager(autofill_manager_.get())); + } + + virtual void TearDown() OVERRIDE { + autocheckout_manager_.reset(); + autofill_manager_delegate_.reset(); + autofill_manager_.reset(); + profile()->ResetRequestContext(); + ChromeRenderViewHostTestHarness::TearDown(); } std::vector<FormData> ReadFilledForms() { @@ -401,35 +414,9 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { } protected: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; scoped_ptr<TestAutofillManager> autofill_manager_; scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; - - private: - virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); - io_thread_.StartIOThread(); - profile()->CreateRequestContext(); - autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); - autofill_manager_.reset(new TestAutofillManager( - web_contents(), - autofill_manager_delegate_.get())); - autocheckout_manager_.reset( - new TestAutocheckoutManager(autofill_manager_.get())); - } - - virtual void TearDown() OVERRIDE { - autocheckout_manager_.reset(); - autofill_manager_delegate_.reset(); - autofill_manager_.reset(); - profile()->ResetRequestContext(); - ChromeRenderViewHostTestHarness::TearDown(); - io_thread_.Stop(); - } - - DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); }; TEST_F(AutocheckoutManagerTest, TestFillForms) { diff --git a/components/autofill/browser/autocomplete_history_manager_unittest.cc b/components/autofill/browser/autocomplete_history_manager_unittest.cc index b8b144e..5294593 100644 --- a/components/autofill/browser/autocomplete_history_manager_unittest.cc +++ b/components/autofill/browser/autocomplete_history_manager_unittest.cc @@ -6,6 +6,7 @@ #include "base/memory/ref_counted.h" #include "base/prefs/testing_pref_service.h" +#include "base/run_loop.h" #include "base/string16.h" #include "base/synchronization/waitable_event.h" #include "base/utf_string_conversions.h" @@ -26,7 +27,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/rect.h" -using content::BrowserThread; using content::WebContents; using testing::_; @@ -94,13 +94,7 @@ class MockAutofillManagerDelegate class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { protected: - AutocompleteHistoryManagerTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - db_thread_(BrowserThread::DB) { - } - virtual void SetUp() OVERRIDE { - db_thread_.Start(); ChromeRenderViewHostTestHarness::SetUp(); web_data_service_ = new MockWebDataService(); WebDataServiceFactory::GetInstance()->SetTestingFactory( @@ -112,13 +106,8 @@ class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { autocomplete_manager_.reset(); web_data_service_ = NULL; ChromeRenderViewHostTestHarness::TearDown(); - content::RunAllPendingInMessageLoop(BrowserThread::DB); - message_loop_.RunUntilIdle(); - } - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; scoped_refptr<MockWebDataService> web_data_service_; scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; MockAutofillManagerDelegate manager_delegate; diff --git a/components/autofill/browser/autofill_external_delegate_unittest.cc b/components/autofill/browser/autofill_external_delegate_unittest.cc index 331daac..4554844 100644 --- a/components/autofill/browser/autofill_external_delegate_unittest.cc +++ b/components/autofill/browser/autofill_external_delegate_unittest.cc @@ -15,13 +15,11 @@ #include "components/autofill/common/form_data.h" #include "components/autofill/common/form_field_data.h" #include "components/autofill/common/password_form_fill_data.h" -#include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" #include "ui/gfx/rect.h" -using content::BrowserThread; using testing::_; using WebKit::WebAutofillClient; @@ -92,29 +90,7 @@ class MockAutofillManager : public AutofillManager { class AutofillExternalDelegateUnitTest : public ChromeRenderViewHostTestHarness { - public: - AutofillExternalDelegateUnitTest() - : ui_thread_(BrowserThread::UI, &message_loop_) {} - virtual ~AutofillExternalDelegateUnitTest() {} - protected: - // Issue an OnQuery call with the given |query_id|. - void IssueOnQuery(int query_id) { - const FormData form; - FormFieldData field; - field.is_focusable = true; - field.should_autocomplete = true; - const gfx::RectF element_bounds; - - external_delegate_->OnQuery(query_id, form, field, element_bounds, false); - } - - MockAutofillManagerDelegate manager_delegate_; - scoped_ptr<MockAutofillManager> autofill_manager_; - scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > - external_delegate_; - - private: virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); autofill_manager_.reset( @@ -135,9 +111,21 @@ class AutofillExternalDelegateUnitTest ChromeRenderViewHostTestHarness::TearDown(); } - content::TestBrowserThread ui_thread_; + // Issue an OnQuery call with the given |query_id|. + void IssueOnQuery(int query_id) { + const FormData form; + FormFieldData field; + field.is_focusable = true; + field.should_autocomplete = true; + const gfx::RectF element_bounds; + + external_delegate_->OnQuery(query_id, form, field, element_bounds, false); + } - DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest); + MockAutofillManagerDelegate manager_delegate_; + scoped_ptr<MockAutofillManager> autofill_manager_; + scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > + external_delegate_; }; // Test that our external delegate called the virtual methods at the right time. diff --git a/components/autofill/browser/autofill_manager_unittest.cc b/components/autofill/browser/autofill_manager_unittest.cc index 4b81964..eb3c782 100644 --- a/components/autofill/browser/autofill_manager_unittest.cc +++ b/components/autofill/browser/autofill_manager_unittest.cc @@ -43,7 +43,6 @@ #include "components/user_prefs/user_prefs.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" #include "googleurl/src/gurl.h" #include "grit/component_resources.h" @@ -55,7 +54,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/rect.h" -using content::BrowserThread; using content::WebContents; using testing::_; using WebKit::WebFormElement; @@ -556,7 +554,7 @@ class TestAutofillManager : public AutofillManager { const gfx::RectF& bounding_box) OVERRIDE { AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box); // Needed for AutocheckoutManager to post task on IO thread. - content::RunAllPendingInMessageLoop(BrowserThread::IO); + content::RunAllPendingInMessageLoop(content::BrowserThread::IO); } // Resets the MessageLoopRunner so that it can wait for an asynchronous form @@ -650,16 +648,6 @@ class TestAutofillManager : public AutofillManager { class AutofillManagerTest : public ChromeRenderViewHostTestHarness { public: - AutofillManagerTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(BrowserThread::UI, &message_loop_), - file_thread_(BrowserThread::FILE), - io_thread_(BrowserThread::IO) { - } - - virtual ~AutofillManagerTest() { - } - virtual void SetUp() OVERRIDE { TestingProfile* profile = CreateProfile(); profile->CreateRequestContext(); @@ -668,7 +656,6 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { profile, TestPersonalDataManager::Build); ChromeRenderViewHostTestHarness::SetUp(); - io_thread_.StartIOThread(); autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); @@ -677,8 +664,6 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { web_contents(), autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), &personal_data_)); - - file_thread_.Start(); } virtual void TearDown() OVERRIDE { @@ -687,9 +672,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { // AutofillManager is tied to the lifetime of the WebContents, so it must // be destroyed at the destruction of the WebContents. autofill_manager_.reset(); - file_thread_.Stop(); ChromeRenderViewHostTestHarness::TearDown(); - io_thread_.Stop(); // Remove the BrowserContext so TestPersonalDataManager does not need to // care about removing self as an observer in destruction. @@ -806,19 +789,12 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { } protected: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - content::TestBrowserThread io_thread_; - scoped_ptr<TestAutofillManager> autofill_manager_; TestPersonalDataManager personal_data_; // Used when we want an off the record profile. This will store the original // profile from which the off the record profile is derived. scoped_ptr<Profile> other_browser_context_; - - private: - DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); }; class TestFormStructure : public FormStructure { diff --git a/components/autofill/browser/autofill_metrics_unittest.cc b/components/autofill/browser/autofill_metrics_unittest.cc index c2beac7..d1f2ef8 100644 --- a/components/autofill/browser/autofill_metrics_unittest.cc +++ b/components/autofill/browser/autofill_metrics_unittest.cc @@ -24,19 +24,17 @@ #include "components/autofill/common/form_field_data.h" #include "components/autofill/common/forms_seen_state.h" #include "components/webdata/common/web_data_results.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" #include "googleurl/src/gurl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/rect.h" -using content::BrowserThread; -using ::testing::_; -using ::testing::AnyNumber; -using ::testing::Mock; -using base::TimeTicks; using base::TimeDelta; +using base::TimeTicks; +using testing::_; +using testing::AnyNumber; +using testing::Mock; namespace autofill { @@ -259,7 +257,6 @@ class TestAutofillManager : public AutofillManager { class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { public: - AutofillMetricsTest(); virtual ~AutofillMetricsTest(); virtual void SetUp() OVERRIDE; @@ -269,24 +266,10 @@ class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( MockAutofillMetrics* metric_logger); - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - content::TestBrowserThread io_thread_; - scoped_ptr<TestAutofillManager> autofill_manager_; scoped_ptr<TestPersonalDataManager> personal_data_; - - private: - DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); }; -AutofillMetricsTest::AutofillMetricsTest() - : ChromeRenderViewHostTestHarness(), - ui_thread_(BrowserThread::UI, &message_loop_), - file_thread_(BrowserThread::FILE), - io_thread_(BrowserThread::IO) { -} - AutofillMetricsTest::~AutofillMetricsTest() { // Order of destruction is important as AutofillManager relies on // PersonalDataManager to be around when it gets destroyed. @@ -304,7 +287,6 @@ void AutofillMetricsTest::SetUp() { PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); ChromeRenderViewHostTestHarness::SetUp(); - io_thread_.StartIOThread(); TabAutofillManagerDelegate::CreateForWebContents(web_contents()); personal_data_.reset(new TestPersonalDataManager()); @@ -313,8 +295,6 @@ void AutofillMetricsTest::SetUp() { web_contents(), TabAutofillManagerDelegate::FromWebContents(web_contents()), personal_data_.get())); - - file_thread_.Start(); } void AutofillMetricsTest::TearDown() { @@ -325,9 +305,7 @@ void AutofillMetricsTest::TearDown() { autofill_manager_.reset(); personal_data_.reset(); profile()->ResetRequestContext(); - file_thread_.Stop(); ChromeRenderViewHostTestHarness::TearDown(); - io_thread_.Stop(); } scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( diff --git a/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc b/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc index fd02cc7..0db3dda 100644 --- a/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc +++ b/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc @@ -6,9 +6,11 @@ #include "base/bind_helpers.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" +#include "base/run_loop.h" #include "base/synchronization/waitable_event.h" #include "components/navigation_interception/intercept_navigation_resource_throttle.h" #include "components/navigation_interception/navigation_params.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/resource_controller.h" @@ -20,7 +22,6 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/common/page_transition_types.h" #include "content/public/test/mock_resource_context.h" -#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "net/url_request/url_request.h" #include "testing/gmock/include/gmock/gmock.h" @@ -39,11 +40,6 @@ namespace { const char kTestUrl[] = "http://www.test.com/"; const char kUnsafeTestUrl[] = "about:crash"; -void ContinueTestCase() { - content::BrowserThread::PostTask( - content::BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); -} - // The MS C++ compiler complains about not being able to resolve which url() // method (const or non-const) to use if we use the Property matcher to check // the return value of the NavigationParams::url() method. @@ -91,7 +87,6 @@ class MockResourceController : public content::ResourceController { } virtual void CancelAndIgnore() OVERRIDE { status_ = CANCELLED; - ContinueTestCase(); } virtual void CancelWithError(int error_code) OVERRIDE { NOTREACHED(); @@ -99,7 +94,6 @@ class MockResourceController : public content::ResourceController { virtual void Resume() OVERRIDE { DCHECK(status_ == UNKNOWN); status_ = RESUMED; - ContinueTestCase(); } private: @@ -162,15 +156,11 @@ class InterceptNavigationResourceThrottleTest public: InterceptNavigationResourceThrottleTest() : mock_callback_receiver_(new MockInterceptCallbackReceiver()), - ui_thread_(content::BrowserThread::UI, &message_loop_), - io_thread_(content::BrowserThread::IO), io_thread_state_(NULL) { } virtual void SetUp() OVERRIDE { RenderViewHostTestHarness::SetUp(); - - io_thread_.StartIOThread(); } virtual void TearDown() OVERRIDE { @@ -202,10 +192,6 @@ class InterceptNavigationResourceThrottleTest SetIOThreadState(io_thread_state); io_thread_state->ThrottleWillStartRequest(defer); - - if (!*defer) { - ContinueTestCase(); - } } protected: @@ -214,7 +200,7 @@ class InterceptNavigationResourceThrottleTest DontIgnoreNavigation }; - void SetUpWebContentsDelegateAndRunMessageLoop( + void SetUpWebContentsDelegateAndDrainRunLoop( ShouldIgnoreNavigationCallbackAction callback_action, bool* defer) { @@ -238,7 +224,7 @@ class InterceptNavigationResourceThrottleTest base::Unretained(defer))); // Wait for the request to finish processing. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); } void WaitForPreviouslyScheduledIoThreadWork() { @@ -253,15 +239,13 @@ class InterceptNavigationResourceThrottleTest } scoped_ptr<MockInterceptCallbackReceiver> mock_callback_receiver_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread io_thread_; TestIOThreadState* io_thread_state_; }; TEST_F(InterceptNavigationResourceThrottleTest, RequestDeferredAndResumedIfNavigationNotIgnored) { bool defer = false; - SetUpWebContentsDelegateAndRunMessageLoop(DontIgnoreNavigation, &defer); + SetUpWebContentsDelegateAndDrainRunLoop(DontIgnoreNavigation, &defer); EXPECT_TRUE(defer); EXPECT_TRUE(io_thread_state_); @@ -271,7 +255,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, TEST_F(InterceptNavigationResourceThrottleTest, RequestDeferredAndCancelledIfNavigationIgnored) { bool defer = false; - SetUpWebContentsDelegateAndRunMessageLoop(IgnoreNavigation, &defer); + SetUpWebContentsDelegateAndDrainRunLoop(IgnoreNavigation, &defer); EXPECT_TRUE(defer); EXPECT_TRUE(io_thread_state_); @@ -284,14 +268,8 @@ TEST_F(InterceptNavigationResourceThrottleTest, // The tested scenario is when the WebContents is deleted after the // ResourceThrottle has finished processing on the IO thread but before the - // UI thread callback has been processed. - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind( - &RenderViewHostTestHarness::DeleteContents, - base::Unretained(this))); - + // UI thread callback has been processed. Since both threads in this test + // are serviced by one message loop, the post order is the execution order. EXPECT_CALL(*mock_callback_receiver_, ShouldIgnoreNavigation(_, _)) .Times(0); @@ -309,11 +287,16 @@ TEST_F(InterceptNavigationResourceThrottleTest, web_contents()->GetRenderViewHost()->GetRoutingID(), base::Unretained(&defer))); - WaitForPreviouslyScheduledIoThreadWork(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind( + &RenderViewHostTestHarness::DeleteContents, + base::Unretained(this))); // The WebContents will now be deleted and only after that will the UI-thread // callback posted by the ResourceThrottle be executed. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); EXPECT_TRUE(defer); EXPECT_TRUE(io_thread_state_); @@ -338,7 +321,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, base::Unretained(&defer))); // Wait for the request to finish processing. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); EXPECT_FALSE(defer); } @@ -368,7 +351,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, base::Unretained(&defer))); // Wait for the request to finish processing. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); } TEST_F(InterceptNavigationResourceThrottleTest, @@ -395,7 +378,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, base::Unretained(&defer))); // Wait for the request to finish processing. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); } TEST_F(InterceptNavigationResourceThrottleTest, @@ -422,7 +405,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, base::Unretained(&defer))); // Wait for the request to finish processing. - message_loop_.Run(); + base::RunLoop().RunUntilIdle(); } } // namespace navigation_interception diff --git a/components/visitedlink/test/visitedlink_unittest.cc b/components/visitedlink/test/visitedlink_unittest.cc index b53f8a9..cf0f14d 100644 --- a/components/visitedlink/test/visitedlink_unittest.cc +++ b/components/visitedlink/test/visitedlink_unittest.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/run_loop.h" #include "base/shared_memory.h" #include "base/string_util.h" #include "base/time.h" @@ -18,11 +19,12 @@ #include "components/visitedlink/browser/visitedlink_master.h" #include "components/visitedlink/common/visitedlink_messages.h" #include "components/visitedlink/renderer/visitedlink_slave.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_context.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_renderer_host.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -135,9 +137,6 @@ class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener { class VisitedLinkTest : public testing::Test { protected: - VisitedLinkTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - file_thread_(BrowserThread::FILE, &message_loop_) {} // Initializes the visited link objects. Pass in the size that you want a // freshly created table to be. 0 means use the default. // @@ -222,16 +221,13 @@ class VisitedLinkTest : public testing::Test { base::ScopedTempDir temp_dir_; - base::MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - // Filenames for the services; base::FilePath history_dir_; base::FilePath visited_file_; scoped_ptr<VisitedLinkMaster> master_; TestVisitedLinkDelegate delegate_; + content::TestBrowserThreadBundle thread_bundle_; }; // This test creates and reads some databases to make sure the data is @@ -438,8 +434,9 @@ TEST_F(VisitedLinkTest, Rebuild) { // complete before we set the task because the rebuild completion message // is posted to the message loop; until we Run() it, rebuild can not // complete. - master_->set_rebuild_complete_task(base::MessageLoop::QuitClosure()); - base::MessageLoop::current()->Run(); + base::RunLoop run_loop; + master_->set_rebuild_complete_task(run_loop.QuitClosure()); + run_loop.Run(); // Test that all URLs were written to the database properly. Reload(); @@ -458,8 +455,9 @@ TEST_F(VisitedLinkTest, BigImport) { master_->AddURL(TestURL(i)); // Wait for the rebuild to complete. - master_->set_rebuild_complete_task(base::MessageLoop::QuitClosure()); - base::MessageLoop::current()->Run(); + base::RunLoop run_loop; + master_->set_rebuild_complete_task(run_loop.QuitClosure()); + run_loop.Run(); // Ensure that the right number of URLs are present int used_count = master_->GetUsedCount(); @@ -592,10 +590,6 @@ class VisitedLinkRenderProcessHostFactory class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { public: - VisitedLinkEventsTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - file_thread_(BrowserThread::FILE, &message_loop_) {} - virtual ~VisitedLinkEventsTest() {} virtual void SetUp() { browser_context_.reset(new VisitCountingContext()); master_.reset(new VisitedLinkMaster(context(), &delegate_, true)); @@ -614,11 +608,14 @@ class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { void WaitForCoalescense() { // Let the timer fire. + // + // TODO(ajwong): This is horrid! What is the right synchronization method? + base::RunLoop run_loop; base::MessageLoop::current()->PostDelayedTask( FROM_HERE, - base::MessageLoop::QuitClosure(), + run_loop.QuitClosure(), base::TimeDelta::FromMilliseconds(110)); - base::MessageLoop::current()->Run(); + run_loop.Run(); } protected: @@ -627,10 +624,6 @@ class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { private: TestVisitedLinkDelegate delegate_; scoped_ptr<VisitedLinkMaster> master_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; - - DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest); }; TEST_F(VisitedLinkEventsTest, Coalescense) { diff --git a/components/web_modal/web_contents_modal_dialog_manager_unittest.cc b/components/web_modal/web_contents_modal_dialog_manager_unittest.cc index 613182b..1268896 100644 --- a/components/web_modal/web_contents_modal_dialog_manager_unittest.cc +++ b/components/web_modal/web_contents_modal_dialog_manager_unittest.cc @@ -4,7 +4,7 @@ #include "components/web_modal/native_web_contents_modal_dialog_manager.h" #include "components/web_modal/web_contents_modal_dialog_manager.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/test_renderer_host.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,17 +15,10 @@ namespace web_modal { class WebContentsModalDialogManagerTest : public content::RenderViewHostTestHarness { public: - WebContentsModalDialogManagerTest() - : ui_thread_(BrowserThread::UI, &message_loop_) { - } - virtual void SetUp() { content::RenderViewHostTestHarness::SetUp(); WebContentsModalDialogManager::CreateForWebContents(web_contents()); } - - private: - content::TestBrowserThread ui_thread_; }; class NativeWebContentsModalDialogManagerCloseTest diff --git a/content/browser/browser_thread_impl.h b/content/browser/browser_thread_impl.h index b4ca49b..1726345 100644 --- a/content/browser/browser_thread_impl.h +++ b/content/browser/browser_thread_impl.h @@ -18,8 +18,9 @@ class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread, // to construct a BrowserThreadImpl that already exists. explicit BrowserThreadImpl(BrowserThread::ID identifier); - // Special constructor for the main (UI) thread and unittests. We use a dummy - // thread here since the main thread already exists. + // Special constructor for the main (UI) thread and unittests. If a + // |message_loop| is provied, we use a dummy thread here since the main + // thread already exists. BrowserThreadImpl(BrowserThread::ID identifier, base::MessageLoop* message_loop); virtual ~BrowserThreadImpl(); diff --git a/content/browser/devtools/devtools_manager_unittest.cc b/content/browser/devtools/devtools_manager_unittest.cc index 944850d..0167a15 100644 --- a/content/browser/devtools/devtools_manager_unittest.cc +++ b/content/browser/devtools/devtools_manager_unittest.cc @@ -106,10 +106,6 @@ class DevToolsManagerTestBrowserClient : public TestContentBrowserClient { } // namespace class DevToolsManagerTest : public RenderViewHostImplTestHarness { - public: - DevToolsManagerTest() { - } - protected: virtual void SetUp() OVERRIDE { original_browser_client_ = SetBrowserClientForTesting(&browser_client_); diff --git a/content/browser/download/save_package_unittest.cc b/content/browser/download/save_package_unittest.cc index e40af08..bb5852b 100644 --- a/content/browser/download/save_package_unittest.cc +++ b/content/browser/download/save_package_unittest.cc @@ -9,7 +9,6 @@ #include "base/path_service.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "content/browser/browser_thread_impl.h" #include "content/browser/download/save_package.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/test/net/url_request_mock_http_job.h" @@ -68,9 +67,6 @@ bool HasOrdinalNumber(const base::FilePath::StringType& filename) { class SavePackageTest : public RenderViewHostImplTestHarness { public: - SavePackageTest() : browser_thread_(BrowserThread::UI, &message_loop_) { - } - bool GetGeneratedFilename(bool need_success_generate_filename, const std::string& disposition, const std::string& url, @@ -123,16 +119,12 @@ class SavePackageTest : public RenderViewHostImplTestHarness { } private: - BrowserThreadImpl browser_thread_; - // SavePackage for successfully generating file name. scoped_refptr<SavePackage> save_package_success_; // SavePackage for failed generating file name. scoped_refptr<SavePackage> save_package_fail_; base::ScopedTempDir temp_dir_; - - DISALLOW_COPY_AND_ASSIGN(SavePackageTest); }; static const struct { diff --git a/content/browser/gpu/shader_disk_cache_unittest.cc b/content/browser/gpu/shader_disk_cache_unittest.cc index 93ed979..9c7061b 100644 --- a/content/browser/gpu/shader_disk_cache_unittest.cc +++ b/content/browser/gpu/shader_disk_cache_unittest.cc @@ -6,7 +6,7 @@ #include "base/threading/thread.h" #include "content/browser/browser_thread_impl.h" #include "content/browser/gpu/shader_disk_cache.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" @@ -22,8 +22,7 @@ const char kCacheValue[] = "cached value"; class ShaderDiskCacheTest : public testing::Test { public: ShaderDiskCacheTest() - : cache_thread_(BrowserThread::CACHE, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual ~ShaderDiskCacheTest() {} @@ -42,9 +41,7 @@ class ShaderDiskCacheTest : public testing::Test { } base::ScopedTempDir temp_dir_; - base::MessageLoopForIO message_loop_; - TestBrowserThread cache_thread_; - TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheTest); }; diff --git a/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc b/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc index 52bca58..4c7e4d9 100644 --- a/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc +++ b/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc @@ -22,7 +22,7 @@ #include "content/public/browser/notification_types.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_context.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" #include "content/test/test_web_contents.h" #include "media/base/video_util.h" @@ -417,8 +417,8 @@ class StubConsumer : public media::VideoCaptureDevice::EventHandler { // Test harness that sets up a minimal environment with necessary stubs. class WebContentsVideoCaptureDeviceTest : public testing::Test { public: - WebContentsVideoCaptureDeviceTest() {} - + // This is public because C++ method pointer scoping rules are silly and make + // this hard to use with Bind(). void ResetWebContents() { web_contents_.reset(); } @@ -433,10 +433,6 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test { // custom RenderViewHostFactory, or else we implant some kind of delegated // CopyFromBackingStore functionality into TestRenderViewHost itself. - // The main thread will serve as the UI thread as well as the test thread. - // We'll manually pump the run loop at appropriate times in the test. - ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); - render_process_host_factory_.reset(new MockRenderProcessHostFactory()); // Create our (self-registering) RVH factory, so that when we create a // WebContents, it in turn creates CaptureTestRenderViewHosts. @@ -463,7 +459,7 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test { device_.reset(WebContentsVideoCaptureDevice::Create(device_id)); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); } virtual void TearDown() { @@ -477,13 +473,13 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test { device_.reset(); } - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); // Destroy the browser objects. web_contents_.reset(); browser_context_.reset(); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); SiteInstanceImpl::set_render_process_host_factory(NULL); render_view_host_factory_.reset(); @@ -519,11 +515,6 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test { // The controller controls which pixel patterns to produce. CaptureTestSourceController controller_; - // We run the UI message loop on the main thread. The capture device - // will also spin up its own threads. - base::MessageLoopForUI message_loop_; - scoped_ptr<TestBrowserThread> ui_thread_; - // Self-registering RenderProcessHostFactory. scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory_; @@ -538,7 +529,7 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test { // Finally, the WebContentsVideoCaptureDevice under test. scoped_ptr<media::VideoCaptureDevice> device_; - DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDeviceTest); + TestBrowserThreadBundle thread_bundle_; }; TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) { @@ -564,7 +555,7 @@ TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) { SimulateDrawEvent(); ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); // Post a task to close the tab. We should see an error reported to the // consumer. @@ -588,7 +579,7 @@ TEST_F(WebContentsVideoCaptureDeviceTest, // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message // loop. These should both succeed without crashing, and the machine should // wind up in the idle state. - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); } TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { @@ -599,7 +590,8 @@ TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { consumer()); device()->Start(); // Make a point of not running the UI messageloop here. - content::RunAllPendingInMessageLoop(); + // TODO(ajwong): Why do we care? + base::RunLoop().RunUntilIdle(); for (int i = 0; i < 10; ++i) SimulateDrawEvent(); @@ -611,14 +603,14 @@ TEST_F(WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { // loop. These should both succeed without crashing, and the machine should // wind up in the idle state. ASSERT_FALSE(consumer()->HasError()); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); ASSERT_FALSE(consumer()->HasError()); } TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { device()->Allocate(kTestWidth, kTestHeight, kTestFramesPerSecond, consumer()); device()->Start(); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); source()->SetSolidColor(SK_ColorRED); SimulateDrawEvent(); SimulateDrawEvent(); @@ -633,7 +625,7 @@ TEST_F(WebContentsVideoCaptureDeviceTest, DeviceRestart) { // Device is stopped, but content can still be animating. SimulateDrawEvent(); SimulateDrawEvent(); - content::RunAllPendingInMessageLoop(); + base::RunLoop().RunUntilIdle(); device()->Start(); source()->SetSolidColor(SK_ColorBLUE); diff --git a/content/browser/storage_partition_impl_unittest.cc b/content/browser/storage_partition_impl_unittest.cc index 631ac7b..0298513 100644 --- a/content/browser/storage_partition_impl_unittest.cc +++ b/content/browser/storage_partition_impl_unittest.cc @@ -10,7 +10,7 @@ #include "content/browser/gpu/shader_disk_cache.h" #include "content/browser/storage_partition_impl.h" #include "content/public/browser/storage_partition.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/test_completion_callback.h" #include "testing/gtest/include/gtest/gtest.h" @@ -50,10 +50,8 @@ const char kCacheValue[] = "cached value"; class StoragePartitionShaderClearTest : public testing::Test { public: - StoragePartitionShaderClearTest() : - ui_thread_(BrowserThread::UI, &message_loop_), - cache_thread_(BrowserThread::CACHE, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { + StoragePartitionShaderClearTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { } virtual ~StoragePartitionShaderClearTest() {} @@ -85,8 +83,6 @@ class StoragePartitionShaderClearTest : public testing::Test { size_t Size() { return cache_->Size(); } - base::MessageLoop* message_loop() { return &message_loop_; } - private: virtual void TearDown() OVERRIDE { cache_ = NULL; @@ -94,10 +90,7 @@ class StoragePartitionShaderClearTest : public testing::Test { } base::ScopedTempDir temp_dir_; - base::MessageLoopForIO message_loop_; - TestBrowserThread ui_thread_; - TestBrowserThread cache_thread_; - TestBrowserThread io_thread_; + content::TestBrowserThreadBundle thread_bundle_; scoped_refptr<ShaderDiskCache> cache_; }; @@ -115,8 +108,9 @@ TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { TestClosureCallback clear_cb; StoragePartitionImpl sp(cache_path(), NULL, NULL, NULL, NULL, NULL, NULL); - message_loop()->PostTask(FROM_HERE, - base::Bind(&ClearData, &sp, clear_cb.callback())); + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ClearData, &sp, clear_cb.callback())); clear_cb.WaitForResult(); EXPECT_EQ(0u, Size()); } diff --git a/content/browser/web_contents/render_view_host_manager_unittest.cc b/content/browser/web_contents/render_view_host_manager_unittest.cc index 6223e4f..0acfadc 100644 --- a/content/browser/web_contents/render_view_host_manager_unittest.cc +++ b/content/browser/web_contents/render_view_host_manager_unittest.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "base/utf_string_conversions.h" -#include "content/browser/browser_thread_impl.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance_impl.h" #include "content/browser/web_contents/navigation_controller_impl.h" @@ -21,7 +20,6 @@ #include "content/public/common/url_constants.h" #include "content/public/common/url_utils.h" #include "content/public/test/mock_render_process_host.h" -#include "content/public/test/test_browser_context.h" #include "content/public/test/test_notification_tracker.h" #include "content/test/test_content_browser_client.h" #include "content/test/test_content_client.h" @@ -130,7 +128,6 @@ class RenderViewHostManagerTest // a regression test for bug 9364. TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { set_should_create_webui(true); - BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); const GURL kChromeUrl("chrome://foo"); const GURL kDestUrl("http://www.google.com/"); @@ -195,7 +192,6 @@ TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { // for synchronous messages, which cannot be ignored without leaving the // renderer in a stuck state. See http://crbug.com/93427. TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { - BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); const GURL kChromeURL("chrome://foo"); const GURL kDestUrl("http://www.google.com/"); @@ -272,7 +268,6 @@ TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) { // EnableViewSourceMode message is sent on every navigation regardless // RenderView is being newly created or reused. TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { - BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); const GURL kChromeUrl("chrome://foo"); const GURL kUrl("view-source:http://foo"); @@ -591,7 +586,6 @@ TEST_F(RenderViewHostManagerTest, NavigateWithEarlyReNavigation) { // Tests WebUI creation. TEST_F(RenderViewHostManagerTest, WebUI) { set_should_create_webui(true); - BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); SiteInstance* instance = SiteInstance::Create(browser_context()); scoped_ptr<TestWebContents> web_contents( diff --git a/content/browser/web_contents/web_contents_delegate_unittest.cc b/content/browser/web_contents/web_contents_delegate_unittest.cc index 9c5e0e7..e5bb679 100644 --- a/content/browser/web_contents/web_contents_delegate_unittest.cc +++ b/content/browser/web_contents/web_contents_delegate_unittest.cc @@ -7,30 +7,16 @@ #include "base/message_loop.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/renderer_host/test_render_view_host.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/test/test_browser_context.h" -#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { class MockWebContentsDelegate : public WebContentsDelegate { - public: - virtual ~MockWebContentsDelegate() {} }; class WebContentsDelegateTest : public RenderViewHostImplTestHarness { - public: - WebContentsDelegateTest() - : file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { - } - - private: - TestBrowserThread file_user_blocking_thread_; - TestBrowserThread io_thread_; }; TEST_F(WebContentsDelegateTest, UnregisterInDestructor) { diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index 3d5dbed..f854d7a 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -235,28 +235,18 @@ class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { class WebContentsImplTest : public RenderViewHostImplTestHarness { public: - WebContentsImplTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - file_user_blocking_thread_( - BrowserThread::FILE_USER_BLOCKING, &message_loop_), - io_thread_(BrowserThread::IO, &message_loop_) { - } - virtual void SetUp() { RenderViewHostImplTestHarness::SetUp(); WebUIControllerFactory::RegisterFactory(&factory_); } virtual void TearDown() { - RenderViewHostImplTestHarness::TearDown(); WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); + RenderViewHostImplTestHarness::TearDown(); } private: WebContentsImplTestWebUIControllerFactory factory_; - TestBrowserThread ui_thread_; - TestBrowserThread file_user_blocking_thread_; - TestBrowserThread io_thread_; }; class TestWebContentsObserver : public WebContentsObserver { diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 43f2751..0ef8458 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -24,9 +24,9 @@ '..', ], 'sources': [ - 'public/test/browser_test.h', 'public/test/browser_test_base.cc', 'public/test/browser_test_base.h', + 'public/test/browser_test.h', 'public/test/browser_test_utils.cc', 'public/test/browser_test_utils.h', 'public/test/content_test_suite_base.cc', @@ -57,6 +57,8 @@ 'public/test/render_widget_test.h', 'public/test/test_browser_context.cc', 'public/test/test_browser_context.h', + 'public/test/test_browser_thread_bundle.cc', + 'public/test/test_browser_thread_bundle.h', 'public/test/test_browser_thread.cc', 'public/test/test_browser_thread.h', 'public/test/test_content_client_initializer.cc', diff --git a/content/public/test/test_browser_thread_bundle.cc b/content/public/test/test_browser_thread_bundle.cc new file mode 100644 index 0000000..a9a1c19 --- /dev/null +++ b/content/public/test/test_browser_thread_bundle.cc @@ -0,0 +1,98 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/test/test_browser_thread_bundle.h" + +#include "base/message_loop.h" +#include "base/run_loop.h" +#include "content/public/test/test_browser_thread.h" + +namespace content { + +TestBrowserThreadBundle::TestBrowserThreadBundle() { + Init(DEFAULT); +} + +TestBrowserThreadBundle::TestBrowserThreadBundle(int options) { + Init(options); +} + +TestBrowserThreadBundle::~TestBrowserThreadBundle() { + base::RunLoop().RunUntilIdle(); +} + +void TestBrowserThreadBundle::Init(int options) { + if (options & IO_MAINLOOP) { + message_loop_.reset(new base::MessageLoopForIO()); + } else { + message_loop_.reset(new base::MessageLoopForUI()); + } + + ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, + message_loop_.get())); + + if (options & REAL_DB_THREAD) { + db_thread_.reset(new TestBrowserThread(BrowserThread::DB)); + db_thread_->Start(); + } else { + db_thread_.reset(new TestBrowserThread(BrowserThread::DB, + message_loop_.get())); + } + + if (options & REAL_WEBKIT_DEPRECATED_THREAD) { + webkit_deprecated_thread_.reset( + new TestBrowserThread(BrowserThread::WEBKIT_DEPRECATED)); + webkit_deprecated_thread_->Start(); + } else { + webkit_deprecated_thread_.reset( + new TestBrowserThread(BrowserThread::WEBKIT_DEPRECATED, + message_loop_.get())); + } + + if (options & REAL_FILE_THREAD) { + file_thread_.reset(new TestBrowserThread(BrowserThread::FILE)); + file_thread_->Start(); + } else { + file_thread_.reset(new TestBrowserThread(BrowserThread::FILE, + message_loop_.get())); + } + + if (options & REAL_FILE_USER_BLOCKING_THREAD) { + file_user_blocking_thread_.reset( + new TestBrowserThread(BrowserThread::FILE_USER_BLOCKING)); + file_user_blocking_thread_->Start(); + } else { + file_user_blocking_thread_.reset( + new TestBrowserThread(BrowserThread::FILE_USER_BLOCKING, + message_loop_.get())); + } + + if (options & REAL_PROCESS_LAUNCHER_THREAD) { + process_launcher_thread_.reset( + new TestBrowserThread(BrowserThread::PROCESS_LAUNCHER)); + process_launcher_thread_->Start(); + } else { + process_launcher_thread_.reset( + new TestBrowserThread(BrowserThread::PROCESS_LAUNCHER, + message_loop_.get())); + } + + if (options & REAL_CACHE_THREAD) { + cache_thread_.reset(new TestBrowserThread(BrowserThread::CACHE)); + cache_thread_->Start(); + } else { + cache_thread_.reset(new TestBrowserThread(BrowserThread::CACHE, + message_loop_.get())); + } + + if (options & REAL_IO_THREAD) { + io_thread_.reset(new TestBrowserThread(BrowserThread::IO)); + io_thread_->StartIOThread(); + } else { + io_thread_.reset( + new TestBrowserThread(BrowserThread::IO, message_loop_.get())); + } +} + +} // namespace content diff --git a/content/public/test/test_browser_thread_bundle.h b/content/public/test/test_browser_thread_bundle.h new file mode 100644 index 0000000..8adc61b --- /dev/null +++ b/content/public/test/test_browser_thread_bundle.h @@ -0,0 +1,78 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TestBrowserThreadBundle is a convenience class for creating a set of +// TestBrowserThreads in unit tests. For most tests, it is sufficient to +// just instantiate the TestBrowserThreadBundle as a member variable. +// +// By default, all of the created TestBrowserThreads will be backed by a single +// shared MessageLoop. If a test truly needs separate threads, it can do +// so by passing the appropriate combination of RealThreadsMask values during +// the TestBrowserThreadBundle construction. +// +// The TestBrowserThreadBundle will attempt to drain the MessageLoop on +// destruction. Sometimes a test needs to drain currently enqueued tasks +// mid-test. Browser tests should call content::RunAllPendingInMessageLoop(). +// Unit tests should use base::RunLoop (e.g., base::RunLoop().RunUntilIdle()). +// TODO(phajdan.jr): Revise this comment after switch to Aura. +// +// Some tests using the IO thread expect a MessageLoopForIO. Passing +// IO_MAINLOOP will use a MessageLoopForIO for the main MessageLoop. +// Most of the time, this avoids needing to use a REAL_IO_THREAD. + +#ifndef CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ +#define CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ + +#include "base/memory/scoped_ptr.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { +class MessageLoop; +} // namespace base + +namespace content { + +class TestBrowserThread; + +class TestBrowserThreadBundle { + public: + // Used to specify the type of MessageLoop that backs the UI thread, and + // which of the named BrowserThreads should be backed by a real + // threads. The UI thread is always the main thread in a unit test. + enum Options { + DEFAULT = 0x00, + IO_MAINLOOP = 0x01, + REAL_DB_THREAD = 0x02, + REAL_WEBKIT_DEPRECATED_THREAD = 0x04, + REAL_FILE_THREAD = 0x08, + REAL_FILE_USER_BLOCKING_THREAD = 0x10, + REAL_PROCESS_LAUNCHER_THREAD = 0x20, + REAL_CACHE_THREAD = 0x40, + REAL_IO_THREAD = 0x80, + }; + + TestBrowserThreadBundle(); + explicit TestBrowserThreadBundle(int options); + + ~TestBrowserThreadBundle(); + + private: + void Init(int options); + + scoped_ptr<base::MessageLoop> message_loop_; + scoped_ptr<TestBrowserThread> ui_thread_; + scoped_ptr<TestBrowserThread> db_thread_; + scoped_ptr<TestBrowserThread> webkit_deprecated_thread_; + scoped_ptr<TestBrowserThread> file_thread_; + scoped_ptr<TestBrowserThread> file_user_blocking_thread_; + scoped_ptr<TestBrowserThread> process_launcher_thread_; + scoped_ptr<TestBrowserThread> cache_thread_; + scoped_ptr<TestBrowserThread> io_thread_; + + DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle); +}; + +} // namespace content + +#endif /* CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ */ diff --git a/content/public/test/test_renderer_host.cc b/content/public/test/test_renderer_host.cc index 9a1cc85..cea76c5 100644 --- a/content/public/test/test_renderer_host.cc +++ b/content/public/test/test_renderer_host.cc @@ -10,6 +10,7 @@ #include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance_impl.h" #include "content/browser/web_contents/navigation_entry_impl.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_context.h" @@ -72,7 +73,9 @@ RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { // RenderViewHostTestHarness -------------------------------------------------- -RenderViewHostTestHarness::RenderViewHostTestHarness() : contents_(NULL) { +RenderViewHostTestHarness::RenderViewHostTestHarness() + : contents_(NULL), + thread_bundle_options_(TestBrowserThreadBundle::DEFAULT) { } RenderViewHostTestHarness::~RenderViewHostTestHarness() { @@ -155,11 +158,14 @@ void RenderViewHostTestHarness::FailedReload() { } void RenderViewHostTestHarness::SetUp() { + thread_bundle_.reset(new TestBrowserThreadBundle(thread_bundle_options_)); + #if defined(OS_WIN) ole_initializer_.reset(new ui::ScopedOleInitializer()); #endif #if defined(USE_AURA) - aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); + aura_test_helper_.reset( + new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); aura_test_helper_->SetUp(); #endif SetContents(CreateTestWebContents()); @@ -174,17 +180,22 @@ void RenderViewHostTestHarness::TearDown() { // before we destroy the browser context. base::RunLoop().RunUntilIdle(); +#if defined(OS_WIN) + ole_initializer_.reset(); +#endif + // Delete any RenderProcessHosts before the BrowserContext goes away. if (rvh_test_enabler_.rph_factory_) rvh_test_enabler_.rph_factory_.reset(); - // Release the browser context on the UI thread. - message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); - base::RunLoop().RunUntilIdle(); - -#if defined(OS_WIN) - ole_initializer_.reset(); -#endif + // Release the browser context by posting itself on the end of the task + // queue. This is preferable to immediate deletion because it will behave + // properly if the |rph_factory_| reset above enqueued any tasks which + // depend on |browser_context_|. + BrowserThread::DeleteSoon(content::BrowserThread::UI, + FROM_HERE, + browser_context_.release()); + thread_bundle_.reset(); } void RenderViewHostTestHarness::SetRenderProcessHostFactory( diff --git a/content/public/test/test_renderer_host.h b/content/public/test/test_renderer_host.h index 44b5ff8..7b0bfae 100644 --- a/content/public/test/test_renderer_host.h +++ b/content/public/test/test_renderer_host.h @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "content/public/browser/render_view_host.h" #include "content/public/common/page_transition_types.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(USE_AURA) @@ -155,6 +156,15 @@ class RenderViewHostTestHarness : public testing::Test { virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; + // Configures which TestBrowserThreads inside |thread_bundle| are backed by + // real threads. Must be called before SetUp(). + void SetThreadBundleOptions(int options) { + DCHECK(thread_bundle_.get() == NULL); + thread_bundle_options_ = options; + } + + TestBrowserThreadBundle* thread_bundle() { return thread_bundle_.get(); } + #if defined(USE_AURA) aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } #endif @@ -168,8 +178,6 @@ class RenderViewHostTestHarness : public testing::Test { // SetUp(). scoped_ptr<BrowserContext> browser_context_; - base::MessageLoopForUI message_loop_; - private: // It is important not to use this directly in the implementation as // web_contents() and SetContents() are virtual and may be @@ -183,6 +191,9 @@ class RenderViewHostTestHarness : public testing::Test { #endif RenderViewHostTestEnabler rvh_test_enabler_; + int thread_bundle_options_; + scoped_ptr<TestBrowserThreadBundle> thread_bundle_; + DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); }; diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 4522315..fe41a6c 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -228,10 +228,6 @@ URLRequest::URLRequest(const GURL& url, DCHECK(base::MessageLoop::current()) << "The current base::MessageLoop must exist"; - DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)) - << "" - "The current base::MessageLoop must be TYPE_IO"; - CHECK(context); context->url_requests()->insert(this); @@ -268,10 +264,6 @@ URLRequest::URLRequest(const GURL& url, DCHECK(base::MessageLoop::current()) << "The current base::MessageLoop must exist"; - DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)) - << "" - "The current base::MessageLoop must be TYPE_IO"; - CHECK(context); context->url_requests()->insert(this); diff --git a/webkit/browser/appcache/appcache_storage_impl.cc b/webkit/browser/appcache/appcache_storage_impl.cc index 23ee4bc..259d310 100644 --- a/webkit/browser/appcache/appcache_storage_impl.cc +++ b/webkit/browser/appcache/appcache_storage_impl.cc @@ -186,7 +186,8 @@ void AppCacheStorageImpl::DatabaseTask::Schedule() { base::Bind(&DatabaseTask::CallRun, this, base::TimeTicks::Now()))) { storage_->scheduled_database_tasks_.push_back(this); } else { - NOTREACHED() << "The database thread is not running."; + NOTREACHED() << "Thread for database tasks is not running. " + << "This is not always the DB thread."; } } |