Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: chrome/browser/prerender/prerender_resource_handler_unittest.cc

Issue 6136006: Fix leak in PrerenderResourceHandlerTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prerender/prerender_resource_handler_unittest.cc
diff --git a/chrome/browser/prerender/prerender_resource_handler_unittest.cc b/chrome/browser/prerender/prerender_resource_handler_unittest.cc
index 110c4cc8522b07a56e85be50ffeee51423439e9a..5a35b98db8c6b34998dc88b396104476773cc4e8 100644
--- a/chrome/browser/prerender/prerender_resource_handler_unittest.cc
+++ b/chrome/browser/prerender/prerender_resource_handler_unittest.cc
@@ -87,19 +87,29 @@ class PrerenderResourceHandlerTest : public testing::Test {
protected:
PrerenderResourceHandlerTest()
: prerender_duration_(base::TimeDelta::FromSeconds(10)),
- mock_handler_(new MockResourceHandler()),
ALLOW_THIS_IN_INITIALIZER_LIST(
pre_handler_(new PrerenderResourceHandler(
- mock_handler_,
+ new MockResourceHandler(),
NewCallback(
this,
&PrerenderResourceHandlerTest::SetLastHandledURL)))),
ui_thread_(BrowserThread::UI, &loop_),
+ io_thread_(BrowserThread::IO, &loop_),
default_url_("http://www.prerender.com") {
pre_handler_->set_prerender_duration(prerender_duration_);
pre_handler_->set_get_current_time_function(&FixedGetCurrentTime);
}
+ virtual ~PrerenderResourceHandlerTest() {
+ // When a ResourceHandler's reference count drops to 0, it is not
+ // deleted immediately. Instead, a task is posted to the IO thread's
+ // message loop to delete it.
+ // So, drop the reference count to 0 and run the message loop once
+ // to ensure that all resources are cleaned up before the test exits.
+ pre_handler_ = NULL;
+ loop_.RunAllPending();
+ }
+
void SetLastHandledURL(const GURL& url, const std::vector<GURL>& alias_urls) {
last_handled_url_ = url;
alias_urls_ = alias_urls;
@@ -120,8 +130,7 @@ class PrerenderResourceHandlerTest : public testing::Test {
EXPECT_TRUE(last_handled_url_.is_empty());
// Start the response. If it is able to prerender, a task will
- // be posted to loop_ (masquerading as the UI thread), and
- // |SetLastHandledURL| will be called.
+ // be posted to the UI thread and |SetLastHandledURL| will be called.
EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response));
loop_.RunAllPending();
}
@@ -133,10 +142,10 @@ class PrerenderResourceHandlerTest : public testing::Test {
}
base::TimeDelta prerender_duration_;
- scoped_refptr<MockResourceHandler> mock_handler_;
scoped_refptr<PrerenderResourceHandler> pre_handler_;
MessageLoop loop_;
BrowserThread ui_thread_;
+ BrowserThread io_thread_;
GURL last_handled_url_;
GURL default_url_;
std::vector<GURL> alias_urls_;
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698