summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 15:39:22 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-19 15:39:22 +0000
commited880f60fe33b447a542f787501b3ce4b396f17f (patch)
tree7600e7eeb0b9eb1099171a8bd7feef548d6146e6 /chrome/browser/prerender
parent4ae61df4c13769a3336836e904ce4291cbda1dfe (diff)
downloadchromium_src-ed880f60fe33b447a542f787501b3ce4b396f17f.zip
chromium_src-ed880f60fe33b447a542f787501b3ce4b396f17f.tar.gz
chromium_src-ed880f60fe33b447a542f787501b3ce4b396f17f.tar.bz2
Fix leak in PrerenderResouceHandlerTest.
ResourceHandler's expect to be deleted on the IO thread after their ref count goes to 0. Change the unit test to explicitly drop ref count and run the IO thread's message loop. BUG=69414 TEST=valgrind trybots Review URL: http://codereview.chromium.org/6136006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prerender')
-rw-r--r--chrome/browser/prerender/prerender_resource_handler_unittest.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/chrome/browser/prerender/prerender_resource_handler_unittest.cc b/chrome/browser/prerender/prerender_resource_handler_unittest.cc
index 110c4cc..5a35b98 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_;