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