OLD | NEW |
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 "net/url_request/url_request_test_util.h" | 8 #include "net/url_request/url_request_test_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 // Tests that a valid HTML resource will correctly get diverted | 164 // Tests that a valid HTML resource will correctly get diverted |
165 // to the PrerenderManager. | 165 // to the PrerenderManager. |
166 TEST_F(PrerenderResourceHandlerTest, Prerender) { | 166 TEST_F(PrerenderResourceHandlerTest, Prerender) { |
167 StartPrerendering("text/html", | 167 StartPrerendering("text/html", |
168 "HTTP/1.1 200 OK\n"); | 168 "HTTP/1.1 200 OK\n"); |
169 EXPECT_EQ(default_url_, last_handled_url_); | 169 EXPECT_EQ(default_url_, last_handled_url_); |
170 } | 170 } |
171 | 171 |
172 static const int kRequestId = 1; | |
173 | |
174 // Tests that the final request in a redirect chain will | 172 // Tests that the final request in a redirect chain will |
175 // get diverted to the PrerenderManager. | 173 // get diverted to the PrerenderManager. |
176 TEST_F(PrerenderResourceHandlerTest, PrerenderRedirect) { | 174 TEST_F(PrerenderResourceHandlerTest, PrerenderRedirect) { |
| 175 int request_id = 1; |
177 GURL url_redirect("http://www.redirect.com"); | 176 GURL url_redirect("http://www.redirect.com"); |
178 bool defer = false; | 177 bool defer = false; |
179 EXPECT_TRUE(pre_handler_->OnWillStart(kRequestId, default_url_, &defer)); | 178 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer)); |
180 EXPECT_FALSE(defer); | 179 EXPECT_FALSE(defer); |
181 EXPECT_TRUE(pre_handler_->OnRequestRedirected(kRequestId, | 180 EXPECT_TRUE(pre_handler_->OnRequestRedirected(request_id, |
182 url_redirect, | 181 url_redirect, |
183 NULL, | 182 NULL, |
184 &defer)); | 183 &defer)); |
185 EXPECT_FALSE(defer); | 184 EXPECT_FALSE(defer); |
186 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 185 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
187 response->response_head.mime_type = "text/html"; | 186 response->response_head.mime_type = "text/html"; |
188 response->response_head.headers = CreateResponseHeaders( | 187 response->response_head.headers = CreateResponseHeaders( |
189 "HTTP/1.1 200 OK\n"); | 188 "HTTP/1.1 200 OK\n"); |
190 EXPECT_TRUE(pre_handler_->OnResponseStarted(kRequestId, response)); | 189 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); |
191 EXPECT_TRUE(last_handled_url_.is_empty()); | 190 EXPECT_TRUE(last_handled_url_.is_empty()); |
192 loop_.RunAllPending(); | 191 loop_.RunAllPending(); |
193 EXPECT_EQ(url_redirect, last_handled_url_); | 192 EXPECT_EQ(url_redirect, last_handled_url_); |
194 EXPECT_EQ(true, ContainsAliasURL(url_redirect)); | 193 EXPECT_EQ(true, ContainsAliasURL(url_redirect)); |
195 EXPECT_EQ(true, ContainsAliasURL(default_url_)); | 194 EXPECT_EQ(true, ContainsAliasURL(default_url_)); |
196 EXPECT_EQ(2, static_cast<int>(alias_urls_.size())); | 195 EXPECT_EQ(2, static_cast<int>(alias_urls_.size())); |
197 } | 196 } |
198 | 197 |
199 // Tests that https requests will not be prerendered. | |
200 TEST_F(PrerenderResourceHandlerTest, PrerenderHttps) { | |
201 GURL url_https("https://www.google.com"); | |
202 bool defer = false; | |
203 EXPECT_FALSE(pre_handler_->OnWillStart(kRequestId, url_https, &defer)); | |
204 EXPECT_FALSE(defer); | |
205 } | |
206 | |
207 TEST_F(PrerenderResourceHandlerTest, PrerenderRedirectToHttps) { | |
208 bool defer = false; | |
209 EXPECT_TRUE(pre_handler_->OnWillStart(kRequestId, default_url_, &defer)); | |
210 EXPECT_FALSE(defer); | |
211 GURL url_https("https://www.google.com"); | |
212 EXPECT_FALSE(pre_handler_->OnRequestRedirected(kRequestId, | |
213 url_https, | |
214 NULL, | |
215 &defer)); | |
216 EXPECT_FALSE(defer); | |
217 } | |
218 | |
219 } // namespace | 198 } // namespace |
220 | 199 |
221 } // namespace prerender | 200 } // namespace prerender |
OLD | NEW |