| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 12 #include "net/url_request/url_request_error_job.h" | 12 #include "net/url_request/url_request_error_job.h" |
| 13 #include "net/url_request/url_request_job_factory.h" | |
| 14 #include "net/url_request/url_request_test_job.h" | 13 #include "net/url_request/url_request_test_job.h" |
| 15 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
| 16 #include "webkit/appcache/appcache_group.h" | 15 #include "webkit/appcache/appcache_group.h" |
| 17 #include "webkit/appcache/appcache_host.h" | 16 #include "webkit/appcache/appcache_host.h" |
| 18 #include "webkit/appcache/appcache_policy.h" | 17 #include "webkit/appcache/appcache_policy.h" |
| 19 #include "webkit/appcache/appcache_response.h" | 18 #include "webkit/appcache/appcache_response.h" |
| 20 #include "webkit/appcache/appcache_update_job.h" | 19 #include "webkit/appcache/appcache_update_job.h" |
| 21 #include "webkit/appcache/mock_appcache_service.h" | 20 #include "webkit/appcache/mock_appcache_service.h" |
| 22 | 21 |
| 23 namespace appcache { | 22 namespace appcache { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 } | 42 } |
| 44 | 43 |
| 45 static GURL GetMockHttpsUrl(const std::string& path) { | 44 static GURL GetMockHttpsUrl(const std::string& path) { |
| 46 return GURL("https://mockhost/" + path); | 45 return GURL("https://mockhost/" + path); |
| 47 } | 46 } |
| 48 | 47 |
| 49 static GURL GetMockCrossOriginHttpsUrl(const std::string& path) { | 48 static GURL GetMockCrossOriginHttpsUrl(const std::string& path) { |
| 50 return GURL("https://cross_origin_host/" + path); | 49 return GURL("https://cross_origin_host/" + path); |
| 51 } | 50 } |
| 52 | 51 |
| 53 static net::URLRequestJob* JobFactory(net::URLRequest* request) { | 52 static net::URLRequestJob* JobFactory(net::URLRequest* request, |
| 53 const std::string& scheme) { |
| 54 if (request->url().host() != "mockhost" && | 54 if (request->url().host() != "mockhost" && |
| 55 request->url().host() != "cross_origin_host") | 55 request->url().host() != "cross_origin_host") |
| 56 return new net::URLRequestErrorJob(request, -1); | 56 return new net::URLRequestErrorJob(request, -1); |
| 57 | 57 |
| 58 std::string headers, body; | 58 std::string headers, body; |
| 59 GetMockResponse(request->url().path(), &headers, &body); | 59 GetMockResponse(request->url().path(), &headers, &body); |
| 60 return new net::URLRequestTestJob(request, headers, body, true); | 60 return new net::URLRequestTestJob(request, headers, body, true); |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 (*headers) = std::string(no_store_headers, arraysize(no_store_headers)); | 175 (*headers) = std::string(no_store_headers, arraysize(no_store_headers)); |
| 176 (*body) = "no-store"; | 176 (*body) = "no-store"; |
| 177 } else { | 177 } else { |
| 178 (*headers) = std::string(not_found_headers, | 178 (*headers) = std::string(not_found_headers, |
| 179 arraysize(not_found_headers)); | 179 arraysize(not_found_headers)); |
| 180 (*body) = ""; | 180 (*body) = ""; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 class MockHttpServerJobFactory | |
| 186 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 187 public: | |
| 188 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | |
| 189 return MockHttpServer::JobFactory(request); | |
| 190 } | |
| 191 }; | |
| 192 | |
| 193 } // namespace | 185 } // namespace |
| 194 | 186 |
| 195 class MockFrontend : public AppCacheFrontend { | 187 class MockFrontend : public AppCacheFrontend { |
| 196 public: | 188 public: |
| 197 MockFrontend() | 189 MockFrontend() |
| 198 : ignore_progress_events_(false), verify_progress_events_(false), | 190 : ignore_progress_events_(false), verify_progress_events_(false), |
| 199 last_progress_total_(-1), last_progress_complete_(-1), | 191 last_progress_total_(-1), last_progress_complete_(-1), |
| 200 start_update_trigger_(CHECKING_EVENT), update_(NULL) { | 192 start_update_trigger_(CHECKING_EVENT), update_(NULL) { |
| 201 } | 193 } |
| 202 | 194 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 int last_progress_total_; | 304 int last_progress_total_; |
| 313 int last_progress_complete_; | 305 int last_progress_complete_; |
| 314 | 306 |
| 315 // Add ability for frontend to add master entries to an inprogress update. | 307 // Add ability for frontend to add master entries to an inprogress update. |
| 316 EventID start_update_trigger_; | 308 EventID start_update_trigger_; |
| 317 AppCacheUpdateJob* update_; | 309 AppCacheUpdateJob* update_; |
| 318 std::vector<AppCacheHost*> update_hosts_; | 310 std::vector<AppCacheHost*> update_hosts_; |
| 319 }; | 311 }; |
| 320 | 312 |
| 321 // Helper factories to simulate redirected URL responses for tests. | 313 // Helper factories to simulate redirected URL responses for tests. |
| 322 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler { | 314 static net::URLRequestJob* RedirectFactory(net::URLRequest* request, |
| 323 public: | 315 const std::string& scheme) { |
| 324 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | 316 return new net::URLRequestTestJob( |
| 325 return new net::URLRequestTestJob( | 317 request, |
| 326 request, | 318 net::URLRequestTestJob::test_redirect_headers(), |
| 327 net::URLRequestTestJob::test_redirect_headers(), | 319 net::URLRequestTestJob::test_data_1(), |
| 328 net::URLRequestTestJob::test_data_1(), | 320 true); |
| 329 true); | 321 } |
| 330 } | |
| 331 }; | |
| 332 | 322 |
| 333 // Helper class to simulate a URL that returns retry or success. | 323 // Helper class to simulate a URL that returns retry or success. |
| 334 class RetryRequestTestJob : public net::URLRequestTestJob { | 324 class RetryRequestTestJob : public net::URLRequestTestJob { |
| 335 public: | 325 public: |
| 336 enum RetryHeader { | 326 enum RetryHeader { |
| 337 NO_RETRY_AFTER, | 327 NO_RETRY_AFTER, |
| 338 NONZERO_RETRY_AFTER, | 328 NONZERO_RETRY_AFTER, |
| 339 RETRY_AFTER_0, | 329 RETRY_AFTER_0, |
| 340 }; | 330 }; |
| 341 | 331 |
| 342 static const GURL kRetryUrl; | 332 static const GURL kRetryUrl; |
| 343 | 333 |
| 344 // Call this at the start of each retry test. | 334 // Call this at the start of each retry test. |
| 345 static void Initialize(int num_retry_responses, RetryHeader header, | 335 static void Initialize(int num_retry_responses, RetryHeader header, |
| 346 int expected_requests) { | 336 int expected_requests) { |
| 347 num_requests_ = 0; | 337 num_requests_ = 0; |
| 348 num_retries_ = num_retry_responses; | 338 num_retries_ = num_retry_responses; |
| 349 retry_after_ = header; | 339 retry_after_ = header; |
| 350 expected_requests_ = expected_requests; | 340 expected_requests_ = expected_requests; |
| 351 } | 341 } |
| 352 | 342 |
| 353 // Verifies results at end of test and resets counters. | 343 // Verifies results at end of test and resets counters. |
| 354 static void Verify() { | 344 static void Verify() { |
| 355 EXPECT_EQ(expected_requests_, num_requests_); | 345 EXPECT_EQ(expected_requests_, num_requests_); |
| 356 num_requests_ = 0; | 346 num_requests_ = 0; |
| 357 expected_requests_ = 0; | 347 expected_requests_ = 0; |
| 358 } | 348 } |
| 359 | 349 |
| 360 static net::URLRequestJob* RetryFactory(net::URLRequest* request) { | 350 static net::URLRequestJob* RetryFactory(net::URLRequest* request, |
| 351 const std::string& scheme) { |
| 361 ++num_requests_; | 352 ++num_requests_; |
| 362 if (num_retries_ > 0 && request->original_url() == kRetryUrl) { | 353 if (num_retries_ > 0 && request->original_url() == kRetryUrl) { |
| 363 --num_retries_; | 354 --num_retries_; |
| 364 return new RetryRequestTestJob( | 355 return new RetryRequestTestJob( |
| 365 request, RetryRequestTestJob::retry_headers(), 503); | 356 request, RetryRequestTestJob::retry_headers(), 503); |
| 366 } else { | 357 } else { |
| 367 return new RetryRequestTestJob( | 358 return new RetryRequestTestJob( |
| 368 request, RetryRequestTestJob::manifest_headers(), 200); | 359 request, RetryRequestTestJob::manifest_headers(), 200); |
| 369 } | 360 } |
| 370 } | 361 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 410 } |
| 420 | 411 |
| 421 int response_code_; | 412 int response_code_; |
| 422 | 413 |
| 423 static int num_requests_; | 414 static int num_requests_; |
| 424 static int num_retries_; | 415 static int num_retries_; |
| 425 static RetryHeader retry_after_; | 416 static RetryHeader retry_after_; |
| 426 static int expected_requests_; | 417 static int expected_requests_; |
| 427 }; | 418 }; |
| 428 | 419 |
| 429 class RetryRequestTestJobFactory | |
| 430 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 431 public: | |
| 432 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | |
| 433 return RetryRequestTestJob::RetryFactory(request); | |
| 434 } | |
| 435 }; | |
| 436 | |
| 437 // static | 420 // static |
| 438 const GURL RetryRequestTestJob::kRetryUrl("http://retry"); | 421 const GURL RetryRequestTestJob::kRetryUrl("http://retry"); |
| 439 int RetryRequestTestJob::num_requests_ = 0; | 422 int RetryRequestTestJob::num_requests_ = 0; |
| 440 int RetryRequestTestJob::num_retries_; | 423 int RetryRequestTestJob::num_retries_; |
| 441 RetryRequestTestJob::RetryHeader RetryRequestTestJob::retry_after_; | 424 RetryRequestTestJob::RetryHeader RetryRequestTestJob::retry_after_; |
| 442 int RetryRequestTestJob::expected_requests_ = 0; | 425 int RetryRequestTestJob::expected_requests_ = 0; |
| 443 | 426 |
| 444 // Helper class to check for certain HTTP headers. | 427 // Helper class to check for certain HTTP headers. |
| 445 class HttpHeadersRequestTestJob : public net::URLRequestTestJob { | 428 class HttpHeadersRequestTestJob : public net::URLRequestTestJob { |
| 446 public: | 429 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 459 EXPECT_TRUE(saw_if_none_match_); | 442 EXPECT_TRUE(saw_if_none_match_); |
| 460 | 443 |
| 461 // Reset. | 444 // Reset. |
| 462 expect_if_modified_since_.clear(); | 445 expect_if_modified_since_.clear(); |
| 463 saw_if_modified_since_ = false; | 446 saw_if_modified_since_ = false; |
| 464 expect_if_none_match_.clear(); | 447 expect_if_none_match_.clear(); |
| 465 saw_if_none_match_ = false; | 448 saw_if_none_match_ = false; |
| 466 already_checked_ = false; | 449 already_checked_ = false; |
| 467 } | 450 } |
| 468 | 451 |
| 469 static net::URLRequestJob* IfModifiedSinceFactory(net::URLRequest* request) { | 452 static net::URLRequestJob* IfModifiedSinceFactory(net::URLRequest* request, |
| 453 const std::string& scheme) { |
| 470 if (!already_checked_) { | 454 if (!already_checked_) { |
| 471 already_checked_ = true; // only check once for a test | 455 already_checked_ = true; // only check once for a test |
| 472 const net::HttpRequestHeaders& extra_headers = | 456 const net::HttpRequestHeaders& extra_headers = |
| 473 request->extra_request_headers(); | 457 request->extra_request_headers(); |
| 474 std::string header_value; | 458 std::string header_value; |
| 475 saw_if_modified_since_ = | 459 saw_if_modified_since_ = |
| 476 extra_headers.GetHeader( | 460 extra_headers.GetHeader( |
| 477 net::HttpRequestHeaders::kIfModifiedSince, &header_value) && | 461 net::HttpRequestHeaders::kIfModifiedSince, &header_value) && |
| 478 header_value == expect_if_modified_since_; | 462 header_value == expect_if_modified_since_; |
| 479 | 463 |
| 480 saw_if_none_match_ = | 464 saw_if_none_match_ = |
| 481 extra_headers.GetHeader( | 465 extra_headers.GetHeader( |
| 482 net::HttpRequestHeaders::kIfNoneMatch, &header_value) && | 466 net::HttpRequestHeaders::kIfNoneMatch, &header_value) && |
| 483 header_value == expect_if_none_match_; | 467 header_value == expect_if_none_match_; |
| 484 } | 468 } |
| 485 return MockHttpServer::JobFactory(request); | 469 return MockHttpServer::JobFactory(request, scheme); |
| 486 } | 470 } |
| 487 | 471 |
| 488 private: | 472 private: |
| 489 static std::string expect_if_modified_since_; | 473 static std::string expect_if_modified_since_; |
| 490 static bool saw_if_modified_since_; | 474 static bool saw_if_modified_since_; |
| 491 static std::string expect_if_none_match_; | 475 static std::string expect_if_none_match_; |
| 492 static bool saw_if_none_match_; | 476 static bool saw_if_none_match_; |
| 493 static bool already_checked_; | 477 static bool already_checked_; |
| 494 }; | 478 }; |
| 495 | 479 |
| 496 // static | 480 // static |
| 497 std::string HttpHeadersRequestTestJob::expect_if_modified_since_; | 481 std::string HttpHeadersRequestTestJob::expect_if_modified_since_; |
| 498 bool HttpHeadersRequestTestJob::saw_if_modified_since_ = false; | 482 bool HttpHeadersRequestTestJob::saw_if_modified_since_ = false; |
| 499 std::string HttpHeadersRequestTestJob::expect_if_none_match_; | 483 std::string HttpHeadersRequestTestJob::expect_if_none_match_; |
| 500 bool HttpHeadersRequestTestJob::saw_if_none_match_ = false; | 484 bool HttpHeadersRequestTestJob::saw_if_none_match_ = false; |
| 501 bool HttpHeadersRequestTestJob::already_checked_ = false; | 485 bool HttpHeadersRequestTestJob::already_checked_ = false; |
| 502 | 486 |
| 503 class IfModifiedSinceJobFactory | |
| 504 : public net::URLRequestJobFactory::ProtocolHandler { | |
| 505 public: | |
| 506 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | |
| 507 return HttpHeadersRequestTestJob::IfModifiedSinceFactory(request); | |
| 508 } | |
| 509 }; | |
| 510 | |
| 511 namespace { | 487 namespace { |
| 512 | 488 |
| 513 class IOThread : public base::Thread { | 489 class IOThread : public base::Thread { |
| 514 public: | 490 public: |
| 515 explicit IOThread(const char* name) | 491 explicit IOThread(const char* name) |
| 516 : base::Thread(name) { | 492 : base::Thread(name), old_factory_(NULL), old_factory_https_(NULL) { |
| 517 } | 493 } |
| 518 | 494 |
| 519 ~IOThread() { | 495 ~IOThread() { |
| 520 // We cannot rely on our base class to stop the thread since we want our | 496 // We cannot rely on our base class to stop the thread since we want our |
| 521 // CleanUp function to run. | 497 // CleanUp function to run. |
| 522 Stop(); | 498 Stop(); |
| 523 } | 499 } |
| 524 | 500 |
| 525 const scoped_refptr<net::URLRequestContext>& request_context() { | 501 const scoped_refptr<net::URLRequestContext>& request_context() { |
| 526 return request_context_; | 502 return request_context_; |
| 527 } | 503 } |
| 528 | 504 |
| 529 void SetNewJobFactory(net::URLRequestJobFactory* job_factory) { | |
| 530 DCHECK(job_factory); | |
| 531 job_factory_.reset(job_factory); | |
| 532 request_context_->set_job_factory(job_factory_.get()); | |
| 533 } | |
| 534 | |
| 535 virtual void Init() { | 505 virtual void Init() { |
| 536 job_factory_.reset(new net::URLRequestJobFactory); | 506 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 537 job_factory_->SetProtocolHandler("http", new MockHttpServerJobFactory); | 507 "http", MockHttpServer::JobFactory); |
| 538 job_factory_->SetProtocolHandler("https", new MockHttpServerJobFactory); | 508 old_factory_https_ = net::URLRequest::RegisterProtocolFactory( |
| 509 "https", MockHttpServer::JobFactory); |
| 539 request_context_ = new TestURLRequestContext(); | 510 request_context_ = new TestURLRequestContext(); |
| 540 request_context_->set_job_factory(job_factory_.get()); | |
| 541 } | 511 } |
| 542 | 512 |
| 543 virtual void CleanUp() { | 513 virtual void CleanUp() { |
| 514 net::URLRequest::RegisterProtocolFactory("http", old_factory_); |
| 515 net::URLRequest::RegisterProtocolFactory("https", old_factory_https_); |
| 544 request_context_ = NULL; | 516 request_context_ = NULL; |
| 545 job_factory_.reset(); | |
| 546 } | 517 } |
| 547 | 518 |
| 548 private: | 519 net::URLRequest::ProtocolFactory* old_factory_; |
| 549 scoped_ptr<net::URLRequestJobFactory> job_factory_; | 520 net::URLRequest::ProtocolFactory* old_factory_https_; |
| 550 scoped_refptr<net::URLRequestContext> request_context_; | 521 scoped_refptr<net::URLRequestContext> request_context_; |
| 551 }; | 522 }; |
| 552 | 523 |
| 553 } // namespace | 524 } // namespace |
| 554 | 525 |
| 555 class AppCacheUpdateJobTest : public testing::Test, | 526 class AppCacheUpdateJobTest : public testing::Test, |
| 556 public AppCacheGroup::UpdateObserver { | 527 public AppCacheGroup::UpdateObserver { |
| 557 public: | 528 public: |
| 558 class MockAppCachePolicy : public AppCachePolicy { | 529 class MockAppCachePolicy : public AppCachePolicy { |
| 559 public: | 530 public: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 590 | 561 |
| 591 | 562 |
| 592 AppCacheUpdateJobTest() | 563 AppCacheUpdateJobTest() |
| 593 : do_checks_after_update_finished_(false), | 564 : do_checks_after_update_finished_(false), |
| 594 expect_group_obsolete_(false), | 565 expect_group_obsolete_(false), |
| 595 expect_group_has_cache_(false), | 566 expect_group_has_cache_(false), |
| 596 expect_old_cache_(NULL), | 567 expect_old_cache_(NULL), |
| 597 expect_newest_cache_(NULL), | 568 expect_newest_cache_(NULL), |
| 598 expect_non_null_update_time_(false), | 569 expect_non_null_update_time_(false), |
| 599 tested_manifest_(NONE), | 570 tested_manifest_(NONE), |
| 600 tested_manifest_path_override_(NULL) { | 571 tested_manifest_path_override_(NULL), |
| 601 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); | 572 registered_factory_(false), |
| 573 old_factory_(NULL) { |
| 574 } |
| 575 |
| 576 static void SetUpTestCase() { |
| 577 io_thread_ = new IOThread("AppCacheUpdateJob IO test thread"); |
| 602 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 578 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
| 603 io_thread_->StartWithOptions(options); | 579 io_thread_->StartWithOptions(options); |
| 604 } | 580 } |
| 605 | 581 |
| 582 static base::WaitableEvent* io_thread_shutdown_event_; |
| 583 |
| 584 // Cleanup function; must be called on the IO Thread. |
| 585 static void CleanupIOThread() { |
| 586 io_thread_shutdown_event_->Signal(); |
| 587 } |
| 588 |
| 589 static void TearDownTestCase() { |
| 590 io_thread_shutdown_event_ = new base::WaitableEvent(false, false); |
| 591 io_thread_->message_loop()->PostTask(FROM_HERE, |
| 592 NewRunnableFunction(CleanupIOThread)); |
| 593 io_thread_shutdown_event_->Wait(); |
| 594 delete io_thread_shutdown_event_; |
| 595 delete io_thread_; |
| 596 io_thread_ = NULL; |
| 597 } |
| 598 |
| 606 // Use a separate IO thread to run a test. Thread will be destroyed | 599 // Use a separate IO thread to run a test. Thread will be destroyed |
| 607 // when it goes out of scope. | 600 // when it goes out of scope. |
| 608 template <class Method> | 601 template <class Method> |
| 609 void RunTestOnIOThread(Method method) { | 602 void RunTestOnIOThread(Method method) { |
| 610 event_.reset(new base::WaitableEvent(false, false)); | 603 event_.reset(new base::WaitableEvent(false, false)); |
| 611 io_thread_->message_loop()->PostTask( | 604 io_thread_->message_loop()->PostTask( |
| 612 FROM_HERE, NewRunnableMethod(this, method)); | 605 FROM_HERE, NewRunnableMethod(this, method)); |
| 613 | 606 |
| 614 // Wait until task is done before exiting the test. | 607 // Wait until task is done before exiting the test. |
| 615 event_->Wait(); | 608 event_->Wait(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 MockFrontend::HostIds ids2(1, host2->host_id()); | 812 MockFrontend::HostIds ids2(1, host2->host_id()); |
| 820 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); | 813 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); |
| 821 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); | 814 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); |
| 822 | 815 |
| 823 WaitForUpdateToFinish(); | 816 WaitForUpdateToFinish(); |
| 824 } | 817 } |
| 825 | 818 |
| 826 void ManifestRedirectTest() { | 819 void ManifestRedirectTest() { |
| 827 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 820 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 828 | 821 |
| 829 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 822 old_factory_ = |
| 830 new_factory->SetProtocolHandler("http", new RedirectFactory); | 823 net::URLRequest::RegisterProtocolFactory("http", RedirectFactory); |
| 831 io_thread_->SetNewJobFactory(new_factory); | 824 registered_factory_ = true; |
| 832 | 825 |
| 833 MakeService(); | 826 MakeService(); |
| 834 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), | 827 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), |
| 835 service_->storage()->NewGroupId()); | 828 service_->storage()->NewGroupId()); |
| 836 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 829 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 837 group_->update_job_ = update; | 830 group_->update_job_ = update; |
| 838 | 831 |
| 839 MockFrontend* frontend = MakeMockFrontend(); | 832 MockFrontend* frontend = MakeMockFrontend(); |
| 840 AppCacheHost* host = MakeHost(1, frontend); | 833 AppCacheHost* host = MakeHost(1, frontend); |
| 841 update->StartUpdate(host, GURL()); | 834 update->StartUpdate(host, GURL()); |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 | 1604 |
| 1612 WaitForUpdateToFinish(); | 1605 WaitForUpdateToFinish(); |
| 1613 } | 1606 } |
| 1614 | 1607 |
| 1615 void RetryRequestTest() { | 1608 void RetryRequestTest() { |
| 1616 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1609 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1617 | 1610 |
| 1618 // Set some large number of times to return retry. | 1611 // Set some large number of times to return retry. |
| 1619 // Expect 1 manifest fetch and 3 retries. | 1612 // Expect 1 manifest fetch and 3 retries. |
| 1620 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1613 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); |
| 1621 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 1614 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1622 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); | 1615 "http", RetryRequestTestJob::RetryFactory); |
| 1623 io_thread_->SetNewJobFactory(new_factory); | 1616 registered_factory_ = true; |
| 1624 | 1617 |
| 1625 MakeService(); | 1618 MakeService(); |
| 1626 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1619 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1627 service_->storage()->NewGroupId()); | 1620 service_->storage()->NewGroupId()); |
| 1628 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1621 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1629 group_->update_job_ = update; | 1622 group_->update_job_ = update; |
| 1630 | 1623 |
| 1631 MockFrontend* frontend = MakeMockFrontend(); | 1624 MockFrontend* frontend = MakeMockFrontend(); |
| 1632 AppCacheHost* host = MakeHost(1, frontend); | 1625 AppCacheHost* host = MakeHost(1, frontend); |
| 1633 update->StartUpdate(host, GURL()); | 1626 update->StartUpdate(host, GURL()); |
| 1634 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1627 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
| 1635 | 1628 |
| 1636 // Set up checks for when update job finishes. | 1629 // Set up checks for when update job finishes. |
| 1637 do_checks_after_update_finished_ = true; | 1630 do_checks_after_update_finished_ = true; |
| 1638 expect_group_obsolete_ = false; | 1631 expect_group_obsolete_ = false; |
| 1639 expect_group_has_cache_ = false; | 1632 expect_group_has_cache_ = false; |
| 1640 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1633 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
| 1641 CHECKING_EVENT); | 1634 CHECKING_EVENT); |
| 1642 | 1635 |
| 1643 WaitForUpdateToFinish(); | 1636 WaitForUpdateToFinish(); |
| 1644 } | 1637 } |
| 1645 | 1638 |
| 1646 void RetryNoRetryAfterTest() { | 1639 void RetryNoRetryAfterTest() { |
| 1647 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1640 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1648 | 1641 |
| 1649 // Set some large number of times to return retry. | 1642 // Set some large number of times to return retry. |
| 1650 // Expect 1 manifest fetch and 0 retries. | 1643 // Expect 1 manifest fetch and 0 retries. |
| 1651 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); | 1644 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); |
| 1652 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 1645 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1653 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); | 1646 "http", RetryRequestTestJob::RetryFactory); |
| 1654 io_thread_->SetNewJobFactory(new_factory); | 1647 registered_factory_ = true; |
| 1655 | 1648 |
| 1656 MakeService(); | 1649 MakeService(); |
| 1657 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1650 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1658 service_->storage()->NewGroupId()); | 1651 service_->storage()->NewGroupId()); |
| 1659 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1652 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1660 group_->update_job_ = update; | 1653 group_->update_job_ = update; |
| 1661 | 1654 |
| 1662 MockFrontend* frontend = MakeMockFrontend(); | 1655 MockFrontend* frontend = MakeMockFrontend(); |
| 1663 AppCacheHost* host = MakeHost(1, frontend); | 1656 AppCacheHost* host = MakeHost(1, frontend); |
| 1664 update->StartUpdate(host, GURL()); | 1657 update->StartUpdate(host, GURL()); |
| 1665 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1658 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
| 1666 | 1659 |
| 1667 // Set up checks for when update job finishes. | 1660 // Set up checks for when update job finishes. |
| 1668 do_checks_after_update_finished_ = true; | 1661 do_checks_after_update_finished_ = true; |
| 1669 expect_group_obsolete_ = false; | 1662 expect_group_obsolete_ = false; |
| 1670 expect_group_has_cache_ = false; | 1663 expect_group_has_cache_ = false; |
| 1671 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1664 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
| 1672 CHECKING_EVENT); | 1665 CHECKING_EVENT); |
| 1673 | 1666 |
| 1674 WaitForUpdateToFinish(); | 1667 WaitForUpdateToFinish(); |
| 1675 } | 1668 } |
| 1676 | 1669 |
| 1677 void RetryNonzeroRetryAfterTest() { | 1670 void RetryNonzeroRetryAfterTest() { |
| 1678 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1671 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1679 | 1672 |
| 1680 // Set some large number of times to return retry. | 1673 // Set some large number of times to return retry. |
| 1681 // Expect 1 request and 0 retry attempts. | 1674 // Expect 1 request and 0 retry attempts. |
| 1682 RetryRequestTestJob::Initialize( | 1675 RetryRequestTestJob::Initialize( |
| 1683 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); | 1676 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); |
| 1684 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 1677 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1685 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); | 1678 "http", RetryRequestTestJob::RetryFactory); |
| 1686 io_thread_->SetNewJobFactory(new_factory); | 1679 registered_factory_ = true; |
| 1687 | 1680 |
| 1688 MakeService(); | 1681 MakeService(); |
| 1689 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1682 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1690 service_->storage()->NewGroupId()); | 1683 service_->storage()->NewGroupId()); |
| 1691 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1684 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1692 group_->update_job_ = update; | 1685 group_->update_job_ = update; |
| 1693 | 1686 |
| 1694 MockFrontend* frontend = MakeMockFrontend(); | 1687 MockFrontend* frontend = MakeMockFrontend(); |
| 1695 AppCacheHost* host = MakeHost(1, frontend); | 1688 AppCacheHost* host = MakeHost(1, frontend); |
| 1696 update->StartUpdate(host, GURL()); | 1689 update->StartUpdate(host, GURL()); |
| 1697 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1690 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
| 1698 | 1691 |
| 1699 // Set up checks for when update job finishes. | 1692 // Set up checks for when update job finishes. |
| 1700 do_checks_after_update_finished_ = true; | 1693 do_checks_after_update_finished_ = true; |
| 1701 expect_group_obsolete_ = false; | 1694 expect_group_obsolete_ = false; |
| 1702 expect_group_has_cache_ = false; | 1695 expect_group_has_cache_ = false; |
| 1703 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1696 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
| 1704 CHECKING_EVENT); | 1697 CHECKING_EVENT); |
| 1705 | 1698 |
| 1706 WaitForUpdateToFinish(); | 1699 WaitForUpdateToFinish(); |
| 1707 } | 1700 } |
| 1708 | 1701 |
| 1709 void RetrySuccessTest() { | 1702 void RetrySuccessTest() { |
| 1710 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1703 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1711 | 1704 |
| 1712 // Set 2 as the retry limit (does not exceed the max). | 1705 // Set 2 as the retry limit (does not exceed the max). |
| 1713 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. | 1706 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. |
| 1714 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); | 1707 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); |
| 1715 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 1708 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1716 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); | 1709 "http", RetryRequestTestJob::RetryFactory); |
| 1717 io_thread_->SetNewJobFactory(new_factory); | 1710 registered_factory_ = true; |
| 1718 | 1711 |
| 1719 MakeService(); | 1712 MakeService(); |
| 1720 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1713 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1721 service_->storage()->NewGroupId()); | 1714 service_->storage()->NewGroupId()); |
| 1722 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1715 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1723 group_->update_job_ = update; | 1716 group_->update_job_ = update; |
| 1724 | 1717 |
| 1725 MockFrontend* frontend = MakeMockFrontend(); | 1718 MockFrontend* frontend = MakeMockFrontend(); |
| 1726 AppCacheHost* host = MakeHost(1, frontend); | 1719 AppCacheHost* host = MakeHost(1, frontend); |
| 1727 update->StartUpdate(host, GURL()); | 1720 update->StartUpdate(host, GURL()); |
| 1728 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1721 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
| 1729 | 1722 |
| 1730 // Set up checks for when update job finishes. | 1723 // Set up checks for when update job finishes. |
| 1731 do_checks_after_update_finished_ = true; | 1724 do_checks_after_update_finished_ = true; |
| 1732 expect_group_obsolete_ = false; | 1725 expect_group_obsolete_ = false; |
| 1733 expect_group_has_cache_ = true; | 1726 expect_group_has_cache_ = true; |
| 1734 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1727 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
| 1735 CHECKING_EVENT); | 1728 CHECKING_EVENT); |
| 1736 | 1729 |
| 1737 WaitForUpdateToFinish(); | 1730 WaitForUpdateToFinish(); |
| 1738 } | 1731 } |
| 1739 | 1732 |
| 1740 void RetryUrlTest() { | 1733 void RetryUrlTest() { |
| 1741 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1734 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1742 | 1735 |
| 1743 // Set 1 as the retry limit (does not exceed the max). | 1736 // Set 1 as the retry limit (does not exceed the max). |
| 1744 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch. | 1737 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch. |
| 1745 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1738 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); |
| 1746 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 1739 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1747 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); | 1740 "http", RetryRequestTestJob::RetryFactory); |
| 1748 io_thread_->SetNewJobFactory(new_factory); | 1741 registered_factory_ = true; |
| 1749 | 1742 |
| 1750 MakeService(); | 1743 MakeService(); |
| 1751 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), | 1744 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), |
| 1752 service_->storage()->NewGroupId()); | 1745 service_->storage()->NewGroupId()); |
| 1753 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1746 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1754 group_->update_job_ = update; | 1747 group_->update_job_ = update; |
| 1755 | 1748 |
| 1756 MockFrontend* frontend = MakeMockFrontend(); | 1749 MockFrontend* frontend = MakeMockFrontend(); |
| 1757 AppCacheHost* host = MakeHost(1, frontend); | 1750 AppCacheHost* host = MakeHost(1, frontend); |
| 1758 update->StartUpdate(host, GURL()); | 1751 update->StartUpdate(host, GURL()); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2577 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final | 2570 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final |
| 2578 frontend->AddExpectedEvent(ids1, CACHED_EVENT); | 2571 frontend->AddExpectedEvent(ids1, CACHED_EVENT); |
| 2579 | 2572 |
| 2580 // Group status will be IDLE so cannot call WaitForUpdateToFinish. | 2573 // Group status will be IDLE so cannot call WaitForUpdateToFinish. |
| 2581 group_->AddUpdateObserver(this); | 2574 group_->AddUpdateObserver(this); |
| 2582 } | 2575 } |
| 2583 | 2576 |
| 2584 void IfModifiedSinceTest() { | 2577 void IfModifiedSinceTest() { |
| 2585 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2578 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2586 | 2579 |
| 2587 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 2580 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2588 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2581 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2589 io_thread_->SetNewJobFactory(new_factory); | 2582 registered_factory_ = true; |
| 2590 | 2583 |
| 2591 MakeService(); | 2584 MakeService(); |
| 2592 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2585 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2593 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2586 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2594 group_->update_job_ = update; | 2587 group_->update_job_ = update; |
| 2595 | 2588 |
| 2596 // First test against a cache attempt. Will start manifest fetch | 2589 // First test against a cache attempt. Will start manifest fetch |
| 2597 // synchronously. | 2590 // synchronously. |
| 2598 HttpHeadersRequestTestJob::Initialize("", ""); | 2591 HttpHeadersRequestTestJob::Initialize("", ""); |
| 2599 MockFrontend mock_frontend; | 2592 MockFrontend mock_frontend; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2643 HttpHeadersRequestTestJob::Verify(); | 2636 HttpHeadersRequestTestJob::Verify(); |
| 2644 delete update; | 2637 delete update; |
| 2645 | 2638 |
| 2646 UpdateFinished(); | 2639 UpdateFinished(); |
| 2647 } | 2640 } |
| 2648 | 2641 |
| 2649 void IfModifiedSinceUpgradeTest() { | 2642 void IfModifiedSinceUpgradeTest() { |
| 2650 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2643 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2651 | 2644 |
| 2652 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); | 2645 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); |
| 2653 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 2646 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2654 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2647 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2655 io_thread_->SetNewJobFactory(new_factory); | 2648 registered_factory_ = true; |
| 2656 | 2649 |
| 2657 MakeService(); | 2650 MakeService(); |
| 2658 group_ = new AppCacheGroup( | 2651 group_ = new AppCacheGroup( |
| 2659 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2652 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
| 2660 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2653 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2661 group_->update_job_ = update; | 2654 group_->update_job_ = update; |
| 2662 | 2655 |
| 2663 // Give the newest cache a manifest enry that is in storage. | 2656 // Give the newest cache a manifest enry that is in storage. |
| 2664 response_writer_.reset( | 2657 response_writer_.reset( |
| 2665 service_->storage()->CreateResponseWriter(group_->manifest_url())); | 2658 service_->storage()->CreateResponseWriter(group_->manifest_url())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2701 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2694 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
| 2702 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2695 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
| 2703 | 2696 |
| 2704 // Start update after data write completes asynchronously. | 2697 // Start update after data write completes asynchronously. |
| 2705 } | 2698 } |
| 2706 | 2699 |
| 2707 void IfNoneMatchUpgradeTest() { | 2700 void IfNoneMatchUpgradeTest() { |
| 2708 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2701 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2709 | 2702 |
| 2710 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2703 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
| 2711 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 2704 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2712 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2705 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2713 io_thread_->SetNewJobFactory(new_factory); | 2706 registered_factory_ = true; |
| 2714 | 2707 |
| 2715 MakeService(); | 2708 MakeService(); |
| 2716 group_ = new AppCacheGroup( | 2709 group_ = new AppCacheGroup( |
| 2717 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2710 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
| 2718 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2711 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2719 group_->update_job_ = update; | 2712 group_->update_job_ = update; |
| 2720 | 2713 |
| 2721 // Give the newest cache a manifest enry that is in storage. | 2714 // Give the newest cache a manifest enry that is in storage. |
| 2722 response_writer_.reset( | 2715 response_writer_.reset( |
| 2723 service_->storage()->CreateResponseWriter(group_->manifest_url())); | 2716 service_->storage()->CreateResponseWriter(group_->manifest_url())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2752 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
| 2760 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2753 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
| 2761 | 2754 |
| 2762 // Start update after data write completes asynchronously. | 2755 // Start update after data write completes asynchronously. |
| 2763 } | 2756 } |
| 2764 | 2757 |
| 2765 void IfNoneMatchRefetchTest() { | 2758 void IfNoneMatchRefetchTest() { |
| 2766 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2759 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2767 | 2760 |
| 2768 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2761 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
| 2769 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 2762 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2770 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2763 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2771 io_thread_->SetNewJobFactory(new_factory); | 2764 registered_factory_ = true; |
| 2772 | 2765 |
| 2773 MakeService(); | 2766 MakeService(); |
| 2774 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2767 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2775 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2768 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2776 group_->update_job_ = update; | 2769 group_->update_job_ = update; |
| 2777 | 2770 |
| 2778 // Simulate a refetch manifest request that uses an ETag header. | 2771 // Simulate a refetch manifest request that uses an ETag header. |
| 2779 const char data[] = | 2772 const char data[] = |
| 2780 "HTTP/1.1 200 OK\0" | 2773 "HTTP/1.1 200 OK\0" |
| 2781 "ETag: \"LadeDade\"\0" | 2774 "ETag: \"LadeDade\"\0" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2794 | 2787 |
| 2795 UpdateFinished(); | 2788 UpdateFinished(); |
| 2796 } | 2789 } |
| 2797 | 2790 |
| 2798 void MultipleHeadersRefetchTest() { | 2791 void MultipleHeadersRefetchTest() { |
| 2799 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2792 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2800 | 2793 |
| 2801 // Verify that code is correct when building multiple extra headers. | 2794 // Verify that code is correct when building multiple extra headers. |
| 2802 HttpHeadersRequestTestJob::Initialize( | 2795 HttpHeadersRequestTestJob::Initialize( |
| 2803 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); | 2796 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); |
| 2804 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); | 2797 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2805 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2798 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2806 io_thread_->SetNewJobFactory(new_factory); | 2799 registered_factory_ = true; |
| 2807 | 2800 |
| 2808 MakeService(); | 2801 MakeService(); |
| 2809 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2802 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2810 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2803 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2811 group_->update_job_ = update; | 2804 group_->update_job_ = update; |
| 2812 | 2805 |
| 2813 // Simulate a refetch manifest request that uses an ETag header. | 2806 // Simulate a refetch manifest request that uses an ETag header. |
| 2814 const char data[] = | 2807 const char data[] = |
| 2815 "HTTP/1.1 200 OK\0" | 2808 "HTTP/1.1 200 OK\0" |
| 2816 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" | 2809 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2918 if (do_checks_after_update_finished_) | 2911 if (do_checks_after_update_finished_) |
| 2919 VerifyExpectations(); | 2912 VerifyExpectations(); |
| 2920 | 2913 |
| 2921 // Clean up everything that was created on the IO thread. | 2914 // Clean up everything that was created on the IO thread. |
| 2922 protect_newest_cache_ = NULL; | 2915 protect_newest_cache_ = NULL; |
| 2923 group_ = NULL; | 2916 group_ = NULL; |
| 2924 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); | 2917 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); |
| 2925 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); | 2918 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); |
| 2926 response_infos_.clear(); | 2919 response_infos_.clear(); |
| 2927 service_.reset(NULL); | 2920 service_.reset(NULL); |
| 2921 if (registered_factory_) |
| 2922 net::URLRequest::RegisterProtocolFactory("http", old_factory_); |
| 2928 | 2923 |
| 2929 event_->Signal(); | 2924 event_->Signal(); |
| 2930 } | 2925 } |
| 2931 | 2926 |
| 2932 void MakeService() { | 2927 void MakeService() { |
| 2933 service_.reset(new MockAppCacheService()); | 2928 service_.reset(new MockAppCacheService()); |
| 2934 service_->set_request_context(io_thread_->request_context()); | 2929 service_->set_request_context(io_thread_->request_context()); |
| 2935 service_->set_appcache_policy(&policy_); | 2930 service_->set_appcache_policy(&policy_); |
| 2936 } | 2931 } |
| 2937 | 2932 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3232 // Various manifest files used in this test. | 3227 // Various manifest files used in this test. |
| 3233 enum TestedManifest { | 3228 enum TestedManifest { |
| 3234 NONE, | 3229 NONE, |
| 3235 MANIFEST1, | 3230 MANIFEST1, |
| 3236 MANIFEST_MERGED_TYPES, | 3231 MANIFEST_MERGED_TYPES, |
| 3237 EMPTY_MANIFEST, | 3232 EMPTY_MANIFEST, |
| 3238 EMPTY_FILE_MANIFEST, | 3233 EMPTY_FILE_MANIFEST, |
| 3239 PENDING_MASTER_NO_UPDATE, | 3234 PENDING_MASTER_NO_UPDATE, |
| 3240 }; | 3235 }; |
| 3241 | 3236 |
| 3242 scoped_ptr<IOThread> io_thread_; | 3237 static IOThread* io_thread_; |
| 3243 | 3238 |
| 3244 scoped_ptr<MockAppCacheService> service_; | 3239 scoped_ptr<MockAppCacheService> service_; |
| 3245 scoped_refptr<AppCacheGroup> group_; | 3240 scoped_refptr<AppCacheGroup> group_; |
| 3246 scoped_refptr<AppCache> protect_newest_cache_; | 3241 scoped_refptr<AppCache> protect_newest_cache_; |
| 3247 scoped_ptr<base::WaitableEvent> event_; | 3242 scoped_ptr<base::WaitableEvent> event_; |
| 3248 MockAppCachePolicy policy_; | 3243 MockAppCachePolicy policy_; |
| 3249 | 3244 |
| 3250 scoped_ptr<AppCacheResponseWriter> response_writer_; | 3245 scoped_ptr<AppCacheResponseWriter> response_writer_; |
| 3251 scoped_ptr<net::CompletionCallbackImpl<AppCacheUpdateJobTest> > | 3246 scoped_ptr<net::CompletionCallbackImpl<AppCacheUpdateJobTest> > |
| 3252 write_callback_; | 3247 write_callback_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3264 bool expect_group_obsolete_; | 3259 bool expect_group_obsolete_; |
| 3265 bool expect_group_has_cache_; | 3260 bool expect_group_has_cache_; |
| 3266 AppCache* expect_old_cache_; | 3261 AppCache* expect_old_cache_; |
| 3267 AppCache* expect_newest_cache_; | 3262 AppCache* expect_newest_cache_; |
| 3268 bool expect_non_null_update_time_; | 3263 bool expect_non_null_update_time_; |
| 3269 std::vector<MockFrontend*> frontends_; // to check expected events | 3264 std::vector<MockFrontend*> frontends_; // to check expected events |
| 3270 TestedManifest tested_manifest_; | 3265 TestedManifest tested_manifest_; |
| 3271 const char* tested_manifest_path_override_; | 3266 const char* tested_manifest_path_override_; |
| 3272 AppCache::EntryMap expect_extra_entries_; | 3267 AppCache::EntryMap expect_extra_entries_; |
| 3273 std::map<GURL, int64> expect_response_ids_; | 3268 std::map<GURL, int64> expect_response_ids_; |
| 3269 |
| 3270 bool registered_factory_; |
| 3271 net::URLRequest::ProtocolFactory* old_factory_; |
| 3274 }; | 3272 }; |
| 3275 | 3273 |
| 3274 // static |
| 3275 IOThread* AppCacheUpdateJobTest::io_thread_ = NULL; |
| 3276 base::WaitableEvent* AppCacheUpdateJobTest::io_thread_shutdown_event_ = NULL; |
| 3277 |
| 3278 |
| 3276 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { | 3279 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { |
| 3277 MockAppCacheService service; | 3280 MockAppCacheService service; |
| 3278 scoped_refptr<AppCacheGroup> group( | 3281 scoped_refptr<AppCacheGroup> group( |
| 3279 new AppCacheGroup(&service, GURL("http://manifesturl.com"), | 3282 new AppCacheGroup(&service, GURL("http://manifesturl.com"), |
| 3280 service.storage()->NewGroupId())); | 3283 service.storage()->NewGroupId())); |
| 3281 | 3284 |
| 3282 AppCacheUpdateJob update(&service, group); | 3285 AppCacheUpdateJob update(&service, group); |
| 3283 | 3286 |
| 3284 // Pretend group is in checking state. | 3287 // Pretend group is in checking state. |
| 3285 group->update_job_ = &update; | 3288 group->update_job_ = &update; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3549 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3552 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
| 3550 } | 3553 } |
| 3551 | 3554 |
| 3552 } // namespace appcache | 3555 } // namespace appcache |
| 3553 | 3556 |
| 3554 // AppCacheUpdateJobTest is expected to always live longer than the | 3557 // AppCacheUpdateJobTest is expected to always live longer than the |
| 3555 // runnable methods. This lets us call NewRunnableMethod on its instances. | 3558 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 3556 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); | 3559 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); |
| 3557 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 3560 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
| 3558 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); | 3561 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); |
| OLD | NEW |