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 /components | |
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
Diffstat (limited to 'components')
9 files changed, 78 insertions, 194 deletions
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 |