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 |
172 // Tests that the final request in a redirect chain will | 174 // Tests that the final request in a redirect chain will |
173 // get diverted to the PrerenderManager. | 175 // get diverted to the PrerenderManager. |
174 TEST_F(PrerenderResourceHandlerTest, PrerenderRedirect) { | 176 TEST_F(PrerenderResourceHandlerTest, PrerenderRedirect) { |
175 int request_id = 1; | |
176 GURL url_redirect("http://www.redirect.com"); | 177 GURL url_redirect("http://www.redirect.com"); |
177 bool defer = false; | 178 bool defer = false; |
178 EXPECT_TRUE(pre_handler_->OnWillStart(request_id, default_url_, &defer)); | 179 EXPECT_TRUE(pre_handler_->OnWillStart(kRequestId, default_url_, &defer)); |
179 EXPECT_FALSE(defer); | 180 EXPECT_FALSE(defer); |
180 EXPECT_TRUE(pre_handler_->OnRequestRedirected(request_id, | 181 EXPECT_TRUE(pre_handler_->OnRequestRedirected(kRequestId, |
181 url_redirect, | 182 url_redirect, |
182 NULL, | 183 NULL, |
183 &defer)); | 184 &defer)); |
184 EXPECT_FALSE(defer); | 185 EXPECT_FALSE(defer); |
185 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 186 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
186 response->response_head.mime_type = "text/html"; | 187 response->response_head.mime_type = "text/html"; |
187 response->response_head.headers = CreateResponseHeaders( | 188 response->response_head.headers = CreateResponseHeaders( |
188 "HTTP/1.1 200 OK\n"); | 189 "HTTP/1.1 200 OK\n"); |
189 EXPECT_TRUE(pre_handler_->OnResponseStarted(request_id, response)); | 190 EXPECT_TRUE(pre_handler_->OnResponseStarted(kRequestId, response)); |
190 EXPECT_TRUE(last_handled_url_.is_empty()); | 191 EXPECT_TRUE(last_handled_url_.is_empty()); |
191 loop_.RunAllPending(); | 192 loop_.RunAllPending(); |
192 EXPECT_EQ(url_redirect, last_handled_url_); | 193 EXPECT_EQ(url_redirect, last_handled_url_); |
193 EXPECT_EQ(true, ContainsAliasURL(url_redirect)); | 194 EXPECT_EQ(true, ContainsAliasURL(url_redirect)); |
194 EXPECT_EQ(true, ContainsAliasURL(default_url_)); | 195 EXPECT_EQ(true, ContainsAliasURL(default_url_)); |
195 EXPECT_EQ(2, static_cast<int>(alias_urls_.size())); | 196 EXPECT_EQ(2, static_cast<int>(alias_urls_.size())); |
196 } | 197 } |
197 | 198 |
| 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 |
198 } // namespace | 219 } // namespace |
199 | 220 |
200 } // namespace prerender | 221 } // namespace prerender |
OLD | NEW |