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

Side by Side Diff: chrome/browser/extensions/extension_protocols_unittest.cc

Issue 1003953008: Remove prerender cookie store, part 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prerender-revert-cookie-store-3
Patch Set: rebase (just in case since this is so huge) Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 // First test a main frame request. 185 // First test a main frame request.
186 { 186 {
187 // It doesn't matter that the resource doesn't exist. If the resource 187 // It doesn't matter that the resource doesn't exist. If the resource
188 // is blocked, we should see ADDRESS_UNREACHABLE. Otherwise, the request 188 // is blocked, we should see ADDRESS_UNREACHABLE. Otherwise, the request
189 // should just fail because the file doesn't exist. 189 // should just fail because the file doesn't exist.
190 scoped_ptr<net::URLRequest> request( 190 scoped_ptr<net::URLRequest> request(
191 resource_context_.GetRequestContext()->CreateRequest( 191 resource_context_.GetRequestContext()->CreateRequest(
192 extension->GetResourceURL("404.html"), 192 extension->GetResourceURL("404.html"),
193 net::DEFAULT_PRIORITY, 193 net::DEFAULT_PRIORITY,
194 &test_delegate_, 194 &test_delegate_));
195 NULL));
196 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME); 195 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME);
197 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 196 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
198 197
199 if (cases[i].should_allow_main_frame_load) { 198 if (cases[i].should_allow_main_frame_load) {
200 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()) << 199 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()) <<
201 cases[i].name; 200 cases[i].name;
202 } else { 201 } else {
203 EXPECT_EQ(net::ERR_ADDRESS_UNREACHABLE, request->status().error()) << 202 EXPECT_EQ(net::ERR_ADDRESS_UNREACHABLE, request->status().error()) <<
204 cases[i].name; 203 cases[i].name;
205 } 204 }
206 } 205 }
207 206
208 // Now do a subframe request. 207 // Now do a subframe request.
209 { 208 {
210 scoped_ptr<net::URLRequest> request( 209 scoped_ptr<net::URLRequest> request(
211 resource_context_.GetRequestContext()->CreateRequest( 210 resource_context_.GetRequestContext()->CreateRequest(
212 extension->GetResourceURL("404.html"), 211 extension->GetResourceURL("404.html"),
213 net::DEFAULT_PRIORITY, 212 net::DEFAULT_PRIORITY,
214 &test_delegate_, 213 &test_delegate_));
215 NULL));
216 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME); 214 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
217 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 215 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
218 216
219 if (cases[i].should_allow_sub_frame_load) { 217 if (cases[i].should_allow_sub_frame_load) {
220 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()) << 218 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()) <<
221 cases[i].name; 219 cases[i].name;
222 } else { 220 } else {
223 EXPECT_EQ(net::ERR_ADDRESS_UNREACHABLE, request->status().error()) << 221 EXPECT_EQ(net::ERR_ADDRESS_UNREACHABLE, request->status().error()) <<
224 cases[i].name; 222 cases[i].name;
225 } 223 }
(...skipping 22 matching lines...) Expand all
248 base::Time::Now(), 246 base::Time::Now(),
249 false, 247 false,
250 false); 248 false);
251 249
252 // First test it with the extension enabled. 250 // First test it with the extension enabled.
253 { 251 {
254 scoped_ptr<net::URLRequest> request( 252 scoped_ptr<net::URLRequest> request(
255 resource_context_.GetRequestContext()->CreateRequest( 253 resource_context_.GetRequestContext()->CreateRequest(
256 extension->GetResourceURL("webstore_icon_16.png"), 254 extension->GetResourceURL("webstore_icon_16.png"),
257 net::DEFAULT_PRIORITY, 255 net::DEFAULT_PRIORITY,
258 &test_delegate_, 256 &test_delegate_));
259 NULL));
260 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA); 257 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA);
261 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 258 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
262 CheckForContentLengthHeader(request.get()); 259 CheckForContentLengthHeader(request.get());
263 } 260 }
264 261
265 // And then test it with the extension disabled. 262 // And then test it with the extension disabled.
266 extension_info_map_->RemoveExtension(extension->id(), 263 extension_info_map_->RemoveExtension(extension->id(),
267 UnloadedExtensionInfo::REASON_DISABLE); 264 UnloadedExtensionInfo::REASON_DISABLE);
268 { 265 {
269 scoped_ptr<net::URLRequest> request( 266 scoped_ptr<net::URLRequest> request(
270 resource_context_.GetRequestContext()->CreateRequest( 267 resource_context_.GetRequestContext()->CreateRequest(
271 extension->GetResourceURL("webstore_icon_16.png"), 268 extension->GetResourceURL("webstore_icon_16.png"),
272 net::DEFAULT_PRIORITY, 269 net::DEFAULT_PRIORITY,
273 &test_delegate_, 270 &test_delegate_));
274 NULL));
275 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA); 271 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA);
276 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 272 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
277 CheckForContentLengthHeader(request.get()); 273 CheckForContentLengthHeader(request.get());
278 } 274 }
279 } 275 }
280 276
281 // Tests that a URL request for resource from an extension returns a few 277 // Tests that a URL request for resource from an extension returns a few
282 // expected response headers. 278 // expected response headers.
283 TEST_F(ExtensionProtocolTest, ResourceRequestResponseHeaders) { 279 TEST_F(ExtensionProtocolTest, ResourceRequestResponseHeaders) {
284 // Register a non-incognito extension protocol handler. 280 // Register a non-incognito extension protocol handler.
285 SetProtocolHandler(false); 281 SetProtocolHandler(false);
286 282
287 scoped_refptr<Extension> extension = CreateTestResponseHeaderExtension(); 283 scoped_refptr<Extension> extension = CreateTestResponseHeaderExtension();
288 extension_info_map_->AddExtension(extension.get(), 284 extension_info_map_->AddExtension(extension.get(),
289 base::Time::Now(), 285 base::Time::Now(),
290 false, 286 false,
291 false); 287 false);
292 288
293 { 289 {
294 scoped_ptr<net::URLRequest> request( 290 scoped_ptr<net::URLRequest> request(
295 resource_context_.GetRequestContext()->CreateRequest( 291 resource_context_.GetRequestContext()->CreateRequest(
296 extension->GetResourceURL("test.dat"), 292 extension->GetResourceURL("test.dat"),
297 net::DEFAULT_PRIORITY, 293 net::DEFAULT_PRIORITY,
298 &test_delegate_, 294 &test_delegate_));
299 NULL));
300 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA); 295 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA);
301 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 296 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
302 297
303 // Check that cache-related headers are set. 298 // Check that cache-related headers are set.
304 std::string etag; 299 std::string etag;
305 request->GetResponseHeaderByName("ETag", &etag); 300 request->GetResponseHeaderByName("ETag", &etag);
306 EXPECT_TRUE(StartsWithASCII(etag, "\"", false)); 301 EXPECT_TRUE(StartsWithASCII(etag, "\"", false));
307 EXPECT_TRUE(EndsWith(etag, "\"", false)); 302 EXPECT_TRUE(EndsWith(etag, "\"", false));
308 303
309 std::string revalidation_header; 304 std::string revalidation_header;
(...skipping 19 matching lines...) Expand all
329 base::Time::Now(), 324 base::Time::Now(),
330 false, 325 false,
331 false); 326 false);
332 327
333 // All MAIN_FRAME and SUB_FRAME requests should succeed. 328 // All MAIN_FRAME and SUB_FRAME requests should succeed.
334 { 329 {
335 scoped_ptr<net::URLRequest> request( 330 scoped_ptr<net::URLRequest> request(
336 resource_context_.GetRequestContext()->CreateRequest( 331 resource_context_.GetRequestContext()->CreateRequest(
337 extension->GetResourceURL("test.dat"), 332 extension->GetResourceURL("test.dat"),
338 net::DEFAULT_PRIORITY, 333 net::DEFAULT_PRIORITY,
339 &test_delegate_, 334 &test_delegate_));
340 NULL));
341 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME); 335 StartRequest(request.get(), content::RESOURCE_TYPE_MAIN_FRAME);
342 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 336 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
343 } 337 }
344 { 338 {
345 scoped_ptr<net::URLRequest> request( 339 scoped_ptr<net::URLRequest> request(
346 resource_context_.GetRequestContext()->CreateRequest( 340 resource_context_.GetRequestContext()->CreateRequest(
347 extension->GetResourceURL("test.dat"), 341 extension->GetResourceURL("test.dat"),
348 net::DEFAULT_PRIORITY, 342 net::DEFAULT_PRIORITY,
349 &test_delegate_, 343 &test_delegate_));
350 NULL));
351 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME); 344 StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
352 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); 345 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
353 } 346 }
354 347
355 // And subresource types, such as media, should fail. 348 // And subresource types, such as media, should fail.
356 { 349 {
357 scoped_ptr<net::URLRequest> request( 350 scoped_ptr<net::URLRequest> request(
358 resource_context_.GetRequestContext()->CreateRequest( 351 resource_context_.GetRequestContext()->CreateRequest(
359 extension->GetResourceURL("test.dat"), 352 extension->GetResourceURL("test.dat"),
360 net::DEFAULT_PRIORITY, 353 net::DEFAULT_PRIORITY,
361 &test_delegate_, 354 &test_delegate_));
362 NULL));
363 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA); 355 StartRequest(request.get(), content::RESOURCE_TYPE_MEDIA);
364 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); 356 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
365 } 357 }
366 } 358 }
367 359
368 } // namespace extensions 360 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698