Index: chrome/browser/safe_browsing/malware_details_unittest.cc |
diff --git a/chrome/browser/safe_browsing/malware_details_unittest.cc b/chrome/browser/safe_browsing/malware_details_unittest.cc |
index ca1f6581232ffec445bea10894f1114f0aa9d09f..31f662d59c8cfe3c7e483c74972a8b9e3182a557 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; |