OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stack> | 5 #include <stack> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 379 } |
380 | 380 |
381 void Verify_MainResource_Fallback() { | 381 void Verify_MainResource_Fallback() { |
382 EXPECT_FALSE(job_->is_waiting()); | 382 EXPECT_FALSE(job_->is_waiting()); |
383 EXPECT_TRUE(job_->is_delivering_network_response()); | 383 EXPECT_TRUE(job_->is_delivering_network_response()); |
384 | 384 |
385 // When the request is restarted, the existing job is dropped so a | 385 // When the request is restarted, the existing job is dropped so a |
386 // real network job gets created. We expect NULL here which will cause | 386 // real network job gets created. We expect NULL here which will cause |
387 // the net library to create a real job. | 387 // the net library to create a real job. |
388 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); | 388 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); |
389 EXPECT_FALSE(job_); | 389 EXPECT_FALSE(job_.get()); |
390 | 390 |
391 // Simulate an http error of the real network job. | 391 // Simulate an http error of the real network job. |
392 request_->SimulateResponseCode(500); | 392 request_->SimulateResponseCode(500); |
393 | 393 |
394 job_ = handler_->MaybeLoadFallbackForResponse( | 394 job_ = handler_->MaybeLoadFallbackForResponse( |
395 request_.get(), empty_network_delegate_); | 395 request_.get(), empty_network_delegate_); |
396 EXPECT_TRUE(job_); | 396 EXPECT_TRUE(job_.get()); |
397 EXPECT_TRUE(job_->is_delivering_appcache_response()); | 397 EXPECT_TRUE(job_->is_delivering_appcache_response()); |
398 | 398 |
399 int64 cache_id = kNoCacheId; | 399 int64 cache_id = kNoCacheId; |
400 GURL manifest_url; | 400 GURL manifest_url; |
401 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); | 401 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); |
402 EXPECT_EQ(1, cache_id); | 402 EXPECT_EQ(1, cache_id); |
403 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); | 403 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); |
404 EXPECT_TRUE(host_->main_resource_was_namespace_entry_); | 404 EXPECT_TRUE(host_->main_resource_was_namespace_entry_); |
405 EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->namespace_entry_url_); | 405 EXPECT_EQ(GURL("http://blah/fallbackurl"), host_->namespace_entry_url_); |
406 | 406 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 439 } |
440 | 440 |
441 void Verify_MainResource_FallbackOverride() { | 441 void Verify_MainResource_FallbackOverride() { |
442 EXPECT_FALSE(job_->is_waiting()); | 442 EXPECT_FALSE(job_->is_waiting()); |
443 EXPECT_TRUE(job_->is_delivering_network_response()); | 443 EXPECT_TRUE(job_->is_delivering_network_response()); |
444 | 444 |
445 // When the request is restarted, the existing job is dropped so a | 445 // When the request is restarted, the existing job is dropped so a |
446 // real network job gets created. We expect NULL here which will cause | 446 // real network job gets created. We expect NULL here which will cause |
447 // the net library to create a real job. | 447 // the net library to create a real job. |
448 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); | 448 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); |
449 EXPECT_FALSE(job_); | 449 EXPECT_FALSE(job_.get()); |
450 | 450 |
451 // Simulate an http error of the real network job, but with custom | 451 // Simulate an http error of the real network job, but with custom |
452 // headers that override the fallback behavior. | 452 // headers that override the fallback behavior. |
453 const char kOverrideHeaders[] = | 453 const char kOverrideHeaders[] = |
454 "HTTP/1.1 404 BOO HOO\0" | 454 "HTTP/1.1 404 BOO HOO\0" |
455 "x-chromium-appcache-fallback-override: disallow-fallback\0" | 455 "x-chromium-appcache-fallback-override: disallow-fallback\0" |
456 "\0"; | 456 "\0"; |
457 net::HttpResponseInfo info; | 457 net::HttpResponseInfo info; |
458 info.headers = new net::HttpResponseHeaders( | 458 info.headers = new net::HttpResponseHeaders( |
459 std::string(kOverrideHeaders, arraysize(kOverrideHeaders))); | 459 std::string(kOverrideHeaders, arraysize(kOverrideHeaders))); |
460 request_->SimulateResponseInfo(info); | 460 request_->SimulateResponseInfo(info); |
461 | 461 |
462 job_ = handler_->MaybeLoadFallbackForResponse( | 462 job_ = handler_->MaybeLoadFallbackForResponse( |
463 request_.get(), empty_network_delegate_); | 463 request_.get(), empty_network_delegate_); |
464 EXPECT_FALSE(job_); | 464 EXPECT_FALSE(job_.get()); |
465 | 465 |
466 TestFinished(); | 466 TestFinished(); |
467 } | 467 } |
468 | 468 |
469 // SubResource_Miss_WithNoCacheSelected ---------------------------------- | 469 // SubResource_Miss_WithNoCacheSelected ---------------------------------- |
470 | 470 |
471 void SubResource_Miss_WithNoCacheSelected() { | 471 void SubResource_Miss_WithNoCacheSelected() { |
472 request_.reset(new MockURLRequest( | 472 request_.reset(new MockURLRequest( |
473 GURL("http://blah/"), &empty_context_, empty_network_delegate_)); | 473 GURL("http://blah/"), &empty_context_, empty_network_delegate_)); |
474 handler_.reset(host_->CreateRequestHandler(request_.get(), | 474 handler_.reset(host_->CreateRequestHandler(request_.get(), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 request_.reset(new MockURLRequest( | 520 request_.reset(new MockURLRequest( |
521 GURL("http://blah/"), &empty_context_, empty_network_delegate_)); | 521 GURL("http://blah/"), &empty_context_, empty_network_delegate_)); |
522 handler_.reset(host_->CreateRequestHandler(request_.get(), | 522 handler_.reset(host_->CreateRequestHandler(request_.get(), |
523 ResourceType::SUB_RESOURCE)); | 523 ResourceType::SUB_RESOURCE)); |
524 EXPECT_TRUE(handler_.get()); | 524 EXPECT_TRUE(handler_.get()); |
525 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); | 525 job_ = handler_->MaybeLoadResource(request_.get(), empty_network_delegate_); |
526 EXPECT_TRUE(job_.get()); | 526 EXPECT_TRUE(job_.get()); |
527 EXPECT_TRUE(job_->is_waiting()); | 527 EXPECT_TRUE(job_->is_waiting()); |
528 | 528 |
529 host_->FinishCacheSelection(cache, NULL); | 529 host_->FinishCacheSelection(cache.get(), NULL); |
530 EXPECT_FALSE(job_->is_waiting()); | 530 EXPECT_FALSE(job_->is_waiting()); |
531 EXPECT_TRUE(job_->is_delivering_error_response()); | 531 EXPECT_TRUE(job_->is_delivering_error_response()); |
532 | 532 |
533 AppCacheURLRequestJob* fallback_job; | 533 AppCacheURLRequestJob* fallback_job; |
534 fallback_job = handler_->MaybeLoadFallbackForRedirect( | 534 fallback_job = handler_->MaybeLoadFallbackForRedirect( |
535 request_.get(), empty_network_delegate_, GURL("http://blah/redirect")); | 535 request_.get(), empty_network_delegate_, GURL("http://blah/redirect")); |
536 EXPECT_FALSE(fallback_job); | 536 EXPECT_FALSE(fallback_job); |
537 fallback_job = handler_->MaybeLoadFallbackForResponse( | 537 fallback_job = handler_->MaybeLoadFallbackForResponse( |
538 request_.get(), empty_network_delegate_); | 538 request_.get(), empty_network_delegate_); |
539 EXPECT_FALSE(fallback_job); | 539 EXPECT_FALSE(fallback_job); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 962 |
963 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 963 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
964 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 964 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
965 } | 965 } |
966 | 966 |
967 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 967 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
968 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 968 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
969 } | 969 } |
970 | 970 |
971 } // namespace appcache | 971 } // namespace appcache |
OLD | NEW |