| Index: chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
|
| 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 3447553240ffb74602d2f6e9922e00ef08520ba3..479714b65116524d9e46aa70e617c7098eb6fba0 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"
|
| @@ -192,16 +193,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.
|
| @@ -225,11 +216,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.
|
| @@ -237,18 +223,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) {
|
| @@ -263,16 +239,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,
|
| @@ -307,10 +273,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()));
|
| @@ -359,11 +323,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_;
|
| };
|
|
|
|
|
| @@ -407,7 +366,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) {
|
| // Make sure DoDisplayBlockingPage is not going to be called.
|
| EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0);
|
| cb.Run(GURL(verdict.url()), false);
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
|
| }
|
|
|
| @@ -439,7 +398,7 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) {
|
| // Make sure DoDisplayBlockingPage is not going to be called.
|
| EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0);
|
| cb.Run(GURL(verdict.url()), false);
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
|
| }
|
|
|
| @@ -474,7 +433,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);
|
| @@ -491,10 +450,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) {
|
| @@ -565,7 +520,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);
|
| @@ -582,10 +537,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,
|
| @@ -955,10 +906,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()));
|
|
|