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

Side by Side Diff: chrome/browser/prerender/prerender_resource_handler_unittest.cc

Issue 6171007: For prerendering, keep track of all the intermediate redirects, and hook into... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 | « chrome/browser/prerender/prerender_resource_handler.cc ('k') | no next file » | 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 mock_handler_, 93 mock_handler_,
94 NewCallback( 94 NewCallback(
95 this, 95 this,
96 &PrerenderResourceHandlerTest::SetLastHandledURL)))), 96 &PrerenderResourceHandlerTest::SetLastHandledURL)))),
97 ui_thread_(BrowserThread::UI, &loop_), 97 ui_thread_(BrowserThread::UI, &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 void SetLastHandledURL(const GURL& url) { 103 void SetLastHandledURL(const GURL& url, const std::vector<GURL>& alias_urls) {
104 last_handled_url_ = url; 104 last_handled_url_ = url;
105 alias_urls_ = alias_urls;
105 } 106 }
106 107
107 // Common logic shared by many of the tests 108 // Common logic shared by many of the tests
108 void StartPrerendering(const std::string& mime_type, 109 void StartPrerendering(const std::string& mime_type,
109 const char* headers) { 110 const char* headers) {
110 int request_id = 1; 111 int request_id = 1;
111 bool defer = false; 112 bool defer = false;
112 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer)); 113 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer));
113 EXPECT_FALSE(defer); 114 EXPECT_FALSE(defer);
114 scoped_refptr<ResourceResponse> response(new ResourceResponse); 115 scoped_refptr<ResourceResponse> response(new ResourceResponse);
115 response->response_head.request_time = FixedGetCurrentTime(); 116 response->response_head.request_time = FixedGetCurrentTime();
116 response->response_head.response_time = FixedGetCurrentTime(); 117 response->response_head.response_time = FixedGetCurrentTime();
117 response->response_head.mime_type = mime_type; 118 response->response_head.mime_type = mime_type;
118 response->response_head.headers = CreateResponseHeaders(headers); 119 response->response_head.headers = CreateResponseHeaders(headers);
119 EXPECT_TRUE(last_handled_url_.is_empty()); 120 EXPECT_TRUE(last_handled_url_.is_empty());
120 121
121 // Start the response. If it is able to prerender, a task will 122 // Start the response. If it is able to prerender, a task will
122 // be posted to loop_ (masquerading as the UI thread), and 123 // be posted to loop_ (masquerading as the UI thread), and
123 // |SetLastHandledURL| will be called. 124 // |SetLastHandledURL| will be called.
124 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); 125 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response));
125 loop_.RunAllPending(); 126 loop_.RunAllPending();
126 } 127 }
127 128
129 // Test whether a given URL is part of alias_urls_.
130 bool ContainsAliasURL(const GURL& url) {
131 return std::find(alias_urls_.begin(), alias_urls_.end(), url)
132 != alias_urls_.end();
133 }
134
128 base::TimeDelta prerender_duration_; 135 base::TimeDelta prerender_duration_;
129 scoped_refptr<MockResourceHandler> mock_handler_; 136 scoped_refptr<MockResourceHandler> mock_handler_;
130 scoped_refptr<PrerenderResourceHandler> pre_handler_; 137 scoped_refptr<PrerenderResourceHandler> pre_handler_;
131 MessageLoop loop_; 138 MessageLoop loop_;
132 BrowserThread ui_thread_; 139 BrowserThread ui_thread_;
133 GURL last_handled_url_; 140 GURL last_handled_url_;
134 GURL default_url_; 141 GURL default_url_;
142 std::vector<GURL> alias_urls_;
135 }; 143 };
136 144
137 namespace { 145 namespace {
138 146
139 TEST_F(PrerenderResourceHandlerTest, NoOp) { 147 TEST_F(PrerenderResourceHandlerTest, NoOp) {
140 } 148 }
141 149
142 // Tests that a valid HTML resource will correctly get diverted 150 // Tests that a valid HTML resource will correctly get diverted
143 // to the PrerenderManager. 151 // to the PrerenderManager.
144 TEST_F(PrerenderResourceHandlerTest, Prerender) { 152 TEST_F(PrerenderResourceHandlerTest, Prerender) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 response->response_head.mime_type = "text/html"; 209 response->response_head.mime_type = "text/html";
202 response->response_head.request_time = FixedGetCurrentTime(); 210 response->response_head.request_time = FixedGetCurrentTime();
203 response->response_head.response_time = FixedGetCurrentTime(); 211 response->response_head.response_time = FixedGetCurrentTime();
204 response->response_head.headers = CreateResponseHeaders( 212 response->response_head.headers = CreateResponseHeaders(
205 "HTTP/1.1 200 OK\n" 213 "HTTP/1.1 200 OK\n"
206 "cache-control: max-age=86400\n"); 214 "cache-control: max-age=86400\n");
207 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); 215 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response));
208 EXPECT_TRUE(last_handled_url_.is_empty()); 216 EXPECT_TRUE(last_handled_url_.is_empty());
209 loop_.RunAllPending(); 217 loop_.RunAllPending();
210 EXPECT_EQ(url_redirect, last_handled_url_); 218 EXPECT_EQ(url_redirect, last_handled_url_);
219 EXPECT_EQ(true, ContainsAliasURL(url_redirect));
220 EXPECT_EQ(true, ContainsAliasURL(default_url_));
221 EXPECT_EQ(2, static_cast<int>(alias_urls_.size()));
211 } 222 }
212 223
213 } 224 }
214
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_resource_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698