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

Side by Side 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: Merge with trunk 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prerender/prerender_resource_handler.h" 5 #include "chrome/browser/prerender/prerender_resource_handler.h"
6 #include "chrome/common/resource_response.h" 6 #include "chrome/common/resource_response.h"
7 #include "net/http/http_response_headers.h" 7 #include "net/http/http_response_headers.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 return new net::HttpResponseHeaders(headers); 81 return new net::HttpResponseHeaders(headers);
82 } 82 }
83 83
84 } // namespace 84 } // namespace
85 85
86 class PrerenderResourceHandlerTest : public testing::Test { 86 class PrerenderResourceHandlerTest : public testing::Test {
87 protected: 87 protected:
88 PrerenderResourceHandlerTest() 88 PrerenderResourceHandlerTest()
89 : prerender_duration_(base::TimeDelta::FromSeconds(10)), 89 : prerender_duration_(base::TimeDelta::FromSeconds(10)),
90 mock_handler_(new MockResourceHandler()),
91 ALLOW_THIS_IN_INITIALIZER_LIST( 90 ALLOW_THIS_IN_INITIALIZER_LIST(
92 pre_handler_(new PrerenderResourceHandler( 91 pre_handler_(new PrerenderResourceHandler(
93 mock_handler_, 92 new MockResourceHandler(),
94 NewCallback( 93 NewCallback(
95 this, 94 this,
96 &PrerenderResourceHandlerTest::SetLastHandledURL)))), 95 &PrerenderResourceHandlerTest::SetLastHandledURL)))),
97 ui_thread_(BrowserThread::UI, &loop_), 96 ui_thread_(BrowserThread::UI, &loop_),
97 io_thread_(BrowserThread::IO, &loop_),
98 default_url_("http://www.prerender.com") { 98 default_url_("http://www.prerender.com") {
99 pre_handler_->set_prerender_duration(prerender_duration_); 99 pre_handler_->set_prerender_duration(prerender_duration_);
100 pre_handler_->set_get_current_time_function(&FixedGetCurrentTime); 100 pre_handler_->set_get_current_time_function(&FixedGetCurrentTime);
101 } 101 }
102 102
103 virtual ~PrerenderResourceHandlerTest() {
104 // ResourceHandler's will post a task to get deleted when their
105 // reference count go to 0.
gavinp 2011/01/18 22:25:06 The grammar above confused me, especially the apos
cbentzel 2011/01/19 13:55:17 I changed the comment to be clearer.
106 pre_handler_ = NULL;
107 loop_.RunAllPending();
108 }
109
103 void SetLastHandledURL(const GURL& url) { 110 void SetLastHandledURL(const GURL& url) {
104 last_handled_url_ = url; 111 last_handled_url_ = url;
105 } 112 }
106 113
107 // Common logic shared by many of the tests 114 // Common logic shared by many of the tests
108 void StartPrerendering(const std::string& mime_type, 115 void StartPrerendering(const std::string& mime_type,
109 const char* headers) { 116 const char* headers) {
110 int request_id = 1; 117 int request_id = 1;
111 bool defer = false; 118 bool defer = false;
112 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer)); 119 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer));
113 EXPECT_FALSE(defer); 120 EXPECT_FALSE(defer);
114 scoped_refptr<ResourceResponse> response(new ResourceResponse); 121 scoped_refptr<ResourceResponse> response(new ResourceResponse);
115 response->response_head.request_time = FixedGetCurrentTime(); 122 response->response_head.request_time = FixedGetCurrentTime();
116 response->response_head.response_time = FixedGetCurrentTime(); 123 response->response_head.response_time = FixedGetCurrentTime();
117 response->response_head.mime_type = mime_type; 124 response->response_head.mime_type = mime_type;
118 response->response_head.headers = CreateResponseHeaders(headers); 125 response->response_head.headers = CreateResponseHeaders(headers);
119 EXPECT_TRUE(last_handled_url_.is_empty()); 126 EXPECT_TRUE(last_handled_url_.is_empty());
120 127
121 // Start the response. If it is able to prerender, a task will 128 // Start the response. If it is able to prerender, a task will
122 // be posted to loop_ (masquerading as the UI thread), and 129 // be posted to the UI thread and |SetLastHandledURL| will be called.
123 // |SetLastHandledURL| will be called.
124 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); 130 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response));
125 loop_.RunAllPending(); 131 loop_.RunAllPending();
126 } 132 }
127 133
128 base::TimeDelta prerender_duration_; 134 base::TimeDelta prerender_duration_;
129 scoped_refptr<MockResourceHandler> mock_handler_;
130 scoped_refptr<PrerenderResourceHandler> pre_handler_; 135 scoped_refptr<PrerenderResourceHandler> pre_handler_;
131 MessageLoop loop_; 136 MessageLoop loop_;
132 BrowserThread ui_thread_; 137 BrowserThread ui_thread_;
138 BrowserThread io_thread_;
133 GURL last_handled_url_; 139 GURL last_handled_url_;
134 GURL default_url_; 140 GURL default_url_;
135 }; 141 };
136 142
137 namespace { 143 namespace {
138 144
139 TEST_F(PrerenderResourceHandlerTest, NoOp) { 145 TEST_F(PrerenderResourceHandlerTest, NoOp) {
140 } 146 }
141 147
142 // Tests that a valid HTML resource will correctly get diverted 148 // Tests that a valid HTML resource will correctly get diverted
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 "HTTP/1.1 200 OK\n" 211 "HTTP/1.1 200 OK\n"
206 "cache-control: max-age=86400\n"); 212 "cache-control: max-age=86400\n");
207 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); 213 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response));
208 EXPECT_TRUE(last_handled_url_.is_empty()); 214 EXPECT_TRUE(last_handled_url_.is_empty());
209 loop_.RunAllPending(); 215 loop_.RunAllPending();
210 EXPECT_EQ(url_redirect, last_handled_url_); 216 EXPECT_EQ(url_redirect, last_handled_url_);
211 } 217 }
212 218
213 } 219 }
214 220
OLDNEW
« 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