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 |
| 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 |
487 namespace { | 511 namespace { |
488 | 512 |
489 class IOThread : public base::Thread { | 513 class IOThread : public base::Thread { |
490 public: | 514 public: |
491 explicit IOThread(const char* name) | 515 explicit IOThread(const char* name) |
492 : base::Thread(name), old_factory_(NULL), old_factory_https_(NULL) { | 516 : base::Thread(name) { |
493 } | 517 } |
494 | 518 |
495 ~IOThread() { | 519 ~IOThread() { |
496 // We cannot rely on our base class to stop the thread since we want our | 520 // We cannot rely on our base class to stop the thread since we want our |
497 // CleanUp function to run. | 521 // CleanUp function to run. |
498 Stop(); | 522 Stop(); |
499 } | 523 } |
500 | 524 |
501 const scoped_refptr<net::URLRequestContext>& request_context() { | 525 const scoped_refptr<net::URLRequestContext>& request_context() { |
502 return request_context_; | 526 return request_context_; |
503 } | 527 } |
504 | 528 |
| 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 |
505 virtual void Init() { | 535 virtual void Init() { |
506 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 536 job_factory_.reset(new net::URLRequestJobFactory); |
507 "http", MockHttpServer::JobFactory); | 537 job_factory_->SetProtocolHandler("http", new MockHttpServerJobFactory); |
508 old_factory_https_ = net::URLRequest::RegisterProtocolFactory( | 538 job_factory_->SetProtocolHandler("https", new MockHttpServerJobFactory); |
509 "https", MockHttpServer::JobFactory); | |
510 request_context_ = new TestURLRequestContext(); | 539 request_context_ = new TestURLRequestContext(); |
| 540 request_context_->set_job_factory(job_factory_.get()); |
511 } | 541 } |
512 | 542 |
513 virtual void CleanUp() { | 543 virtual void CleanUp() { |
514 net::URLRequest::RegisterProtocolFactory("http", old_factory_); | |
515 net::URLRequest::RegisterProtocolFactory("https", old_factory_https_); | |
516 request_context_ = NULL; | 544 request_context_ = NULL; |
| 545 job_factory_.reset(); |
517 } | 546 } |
518 | 547 |
519 net::URLRequest::ProtocolFactory* old_factory_; | 548 private: |
520 net::URLRequest::ProtocolFactory* old_factory_https_; | 549 scoped_ptr<net::URLRequestJobFactory> job_factory_; |
521 scoped_refptr<net::URLRequestContext> request_context_; | 550 scoped_refptr<net::URLRequestContext> request_context_; |
522 }; | 551 }; |
523 | 552 |
524 } // namespace | 553 } // namespace |
525 | 554 |
526 class AppCacheUpdateJobTest : public testing::Test, | 555 class AppCacheUpdateJobTest : public testing::Test, |
527 public AppCacheGroup::UpdateObserver { | 556 public AppCacheGroup::UpdateObserver { |
528 public: | 557 public: |
529 class MockAppCachePolicy : public AppCachePolicy { | 558 class MockAppCachePolicy : public AppCachePolicy { |
530 public: | 559 public: |
(...skipping 30 matching lines...) Expand all Loading... |
561 | 590 |
562 | 591 |
563 AppCacheUpdateJobTest() | 592 AppCacheUpdateJobTest() |
564 : do_checks_after_update_finished_(false), | 593 : do_checks_after_update_finished_(false), |
565 expect_group_obsolete_(false), | 594 expect_group_obsolete_(false), |
566 expect_group_has_cache_(false), | 595 expect_group_has_cache_(false), |
567 expect_old_cache_(NULL), | 596 expect_old_cache_(NULL), |
568 expect_newest_cache_(NULL), | 597 expect_newest_cache_(NULL), |
569 expect_non_null_update_time_(false), | 598 expect_non_null_update_time_(false), |
570 tested_manifest_(NONE), | 599 tested_manifest_(NONE), |
571 tested_manifest_path_override_(NULL), | 600 tested_manifest_path_override_(NULL) { |
572 registered_factory_(false), | 601 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); | 602 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
579 io_thread_->StartWithOptions(options); | 603 io_thread_->StartWithOptions(options); |
580 } | 604 } |
581 | 605 |
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 | 606 // Use a separate IO thread to run a test. Thread will be destroyed |
600 // when it goes out of scope. | 607 // when it goes out of scope. |
601 template <class Method> | 608 template <class Method> |
602 void RunTestOnIOThread(Method method) { | 609 void RunTestOnIOThread(Method method) { |
603 event_.reset(new base::WaitableEvent(false, false)); | 610 event_.reset(new base::WaitableEvent(false, false)); |
604 io_thread_->message_loop()->PostTask( | 611 io_thread_->message_loop()->PostTask( |
605 FROM_HERE, NewRunnableMethod(this, method)); | 612 FROM_HERE, NewRunnableMethod(this, method)); |
606 | 613 |
607 // Wait until task is done before exiting the test. | 614 // Wait until task is done before exiting the test. |
608 event_->Wait(); | 615 event_->Wait(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 MockFrontend::HostIds ids2(1, host2->host_id()); | 819 MockFrontend::HostIds ids2(1, host2->host_id()); |
813 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); | 820 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); |
814 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); | 821 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); |
815 | 822 |
816 WaitForUpdateToFinish(); | 823 WaitForUpdateToFinish(); |
817 } | 824 } |
818 | 825 |
819 void ManifestRedirectTest() { | 826 void ManifestRedirectTest() { |
820 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 827 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
821 | 828 |
822 old_factory_ = | 829 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
823 net::URLRequest::RegisterProtocolFactory("http", RedirectFactory); | 830 new_factory->SetProtocolHandler("http", new RedirectFactory); |
824 registered_factory_ = true; | 831 io_thread_->SetNewJobFactory(new_factory); |
825 | 832 |
826 MakeService(); | 833 MakeService(); |
827 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), | 834 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), |
828 service_->storage()->NewGroupId()); | 835 service_->storage()->NewGroupId()); |
829 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 836 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
830 group_->update_job_ = update; | 837 group_->update_job_ = update; |
831 | 838 |
832 MockFrontend* frontend = MakeMockFrontend(); | 839 MockFrontend* frontend = MakeMockFrontend(); |
833 AppCacheHost* host = MakeHost(1, frontend); | 840 AppCacheHost* host = MakeHost(1, frontend); |
834 update->StartUpdate(host, GURL()); | 841 update->StartUpdate(host, GURL()); |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 | 1611 |
1605 WaitForUpdateToFinish(); | 1612 WaitForUpdateToFinish(); |
1606 } | 1613 } |
1607 | 1614 |
1608 void RetryRequestTest() { | 1615 void RetryRequestTest() { |
1609 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1616 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
1610 | 1617 |
1611 // Set some large number of times to return retry. | 1618 // Set some large number of times to return retry. |
1612 // Expect 1 manifest fetch and 3 retries. | 1619 // Expect 1 manifest fetch and 3 retries. |
1613 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1620 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); |
1614 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 1621 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
1615 "http", RetryRequestTestJob::RetryFactory); | 1622 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); |
1616 registered_factory_ = true; | 1623 io_thread_->SetNewJobFactory(new_factory); |
1617 | 1624 |
1618 MakeService(); | 1625 MakeService(); |
1619 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1626 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
1620 service_->storage()->NewGroupId()); | 1627 service_->storage()->NewGroupId()); |
1621 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1628 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
1622 group_->update_job_ = update; | 1629 group_->update_job_ = update; |
1623 | 1630 |
1624 MockFrontend* frontend = MakeMockFrontend(); | 1631 MockFrontend* frontend = MakeMockFrontend(); |
1625 AppCacheHost* host = MakeHost(1, frontend); | 1632 AppCacheHost* host = MakeHost(1, frontend); |
1626 update->StartUpdate(host, GURL()); | 1633 update->StartUpdate(host, GURL()); |
1627 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1634 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
1628 | 1635 |
1629 // Set up checks for when update job finishes. | 1636 // Set up checks for when update job finishes. |
1630 do_checks_after_update_finished_ = true; | 1637 do_checks_after_update_finished_ = true; |
1631 expect_group_obsolete_ = false; | 1638 expect_group_obsolete_ = false; |
1632 expect_group_has_cache_ = false; | 1639 expect_group_has_cache_ = false; |
1633 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1640 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
1634 CHECKING_EVENT); | 1641 CHECKING_EVENT); |
1635 | 1642 |
1636 WaitForUpdateToFinish(); | 1643 WaitForUpdateToFinish(); |
1637 } | 1644 } |
1638 | 1645 |
1639 void RetryNoRetryAfterTest() { | 1646 void RetryNoRetryAfterTest() { |
1640 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1647 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
1641 | 1648 |
1642 // Set some large number of times to return retry. | 1649 // Set some large number of times to return retry. |
1643 // Expect 1 manifest fetch and 0 retries. | 1650 // Expect 1 manifest fetch and 0 retries. |
1644 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); | 1651 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); |
1645 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 1652 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
1646 "http", RetryRequestTestJob::RetryFactory); | 1653 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); |
1647 registered_factory_ = true; | 1654 io_thread_->SetNewJobFactory(new_factory); |
1648 | 1655 |
1649 MakeService(); | 1656 MakeService(); |
1650 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1657 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
1651 service_->storage()->NewGroupId()); | 1658 service_->storage()->NewGroupId()); |
1652 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1659 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
1653 group_->update_job_ = update; | 1660 group_->update_job_ = update; |
1654 | 1661 |
1655 MockFrontend* frontend = MakeMockFrontend(); | 1662 MockFrontend* frontend = MakeMockFrontend(); |
1656 AppCacheHost* host = MakeHost(1, frontend); | 1663 AppCacheHost* host = MakeHost(1, frontend); |
1657 update->StartUpdate(host, GURL()); | 1664 update->StartUpdate(host, GURL()); |
1658 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1665 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
1659 | 1666 |
1660 // Set up checks for when update job finishes. | 1667 // Set up checks for when update job finishes. |
1661 do_checks_after_update_finished_ = true; | 1668 do_checks_after_update_finished_ = true; |
1662 expect_group_obsolete_ = false; | 1669 expect_group_obsolete_ = false; |
1663 expect_group_has_cache_ = false; | 1670 expect_group_has_cache_ = false; |
1664 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1671 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
1665 CHECKING_EVENT); | 1672 CHECKING_EVENT); |
1666 | 1673 |
1667 WaitForUpdateToFinish(); | 1674 WaitForUpdateToFinish(); |
1668 } | 1675 } |
1669 | 1676 |
1670 void RetryNonzeroRetryAfterTest() { | 1677 void RetryNonzeroRetryAfterTest() { |
1671 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1678 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
1672 | 1679 |
1673 // Set some large number of times to return retry. | 1680 // Set some large number of times to return retry. |
1674 // Expect 1 request and 0 retry attempts. | 1681 // Expect 1 request and 0 retry attempts. |
1675 RetryRequestTestJob::Initialize( | 1682 RetryRequestTestJob::Initialize( |
1676 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); | 1683 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); |
1677 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 1684 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
1678 "http", RetryRequestTestJob::RetryFactory); | 1685 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); |
1679 registered_factory_ = true; | 1686 io_thread_->SetNewJobFactory(new_factory); |
1680 | 1687 |
1681 MakeService(); | 1688 MakeService(); |
1682 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1689 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
1683 service_->storage()->NewGroupId()); | 1690 service_->storage()->NewGroupId()); |
1684 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1691 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
1685 group_->update_job_ = update; | 1692 group_->update_job_ = update; |
1686 | 1693 |
1687 MockFrontend* frontend = MakeMockFrontend(); | 1694 MockFrontend* frontend = MakeMockFrontend(); |
1688 AppCacheHost* host = MakeHost(1, frontend); | 1695 AppCacheHost* host = MakeHost(1, frontend); |
1689 update->StartUpdate(host, GURL()); | 1696 update->StartUpdate(host, GURL()); |
1690 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1697 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
1691 | 1698 |
1692 // Set up checks for when update job finishes. | 1699 // Set up checks for when update job finishes. |
1693 do_checks_after_update_finished_ = true; | 1700 do_checks_after_update_finished_ = true; |
1694 expect_group_obsolete_ = false; | 1701 expect_group_obsolete_ = false; |
1695 expect_group_has_cache_ = false; | 1702 expect_group_has_cache_ = false; |
1696 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1703 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
1697 CHECKING_EVENT); | 1704 CHECKING_EVENT); |
1698 | 1705 |
1699 WaitForUpdateToFinish(); | 1706 WaitForUpdateToFinish(); |
1700 } | 1707 } |
1701 | 1708 |
1702 void RetrySuccessTest() { | 1709 void RetrySuccessTest() { |
1703 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1710 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
1704 | 1711 |
1705 // Set 2 as the retry limit (does not exceed the max). | 1712 // Set 2 as the retry limit (does not exceed the max). |
1706 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. | 1713 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. |
1707 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); | 1714 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); |
1708 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 1715 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
1709 "http", RetryRequestTestJob::RetryFactory); | 1716 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); |
1710 registered_factory_ = true; | 1717 io_thread_->SetNewJobFactory(new_factory); |
1711 | 1718 |
1712 MakeService(); | 1719 MakeService(); |
1713 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1720 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
1714 service_->storage()->NewGroupId()); | 1721 service_->storage()->NewGroupId()); |
1715 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1722 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
1716 group_->update_job_ = update; | 1723 group_->update_job_ = update; |
1717 | 1724 |
1718 MockFrontend* frontend = MakeMockFrontend(); | 1725 MockFrontend* frontend = MakeMockFrontend(); |
1719 AppCacheHost* host = MakeHost(1, frontend); | 1726 AppCacheHost* host = MakeHost(1, frontend); |
1720 update->StartUpdate(host, GURL()); | 1727 update->StartUpdate(host, GURL()); |
1721 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1728 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
1722 | 1729 |
1723 // Set up checks for when update job finishes. | 1730 // Set up checks for when update job finishes. |
1724 do_checks_after_update_finished_ = true; | 1731 do_checks_after_update_finished_ = true; |
1725 expect_group_obsolete_ = false; | 1732 expect_group_obsolete_ = false; |
1726 expect_group_has_cache_ = true; | 1733 expect_group_has_cache_ = true; |
1727 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1734 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
1728 CHECKING_EVENT); | 1735 CHECKING_EVENT); |
1729 | 1736 |
1730 WaitForUpdateToFinish(); | 1737 WaitForUpdateToFinish(); |
1731 } | 1738 } |
1732 | 1739 |
1733 void RetryUrlTest() { | 1740 void RetryUrlTest() { |
1734 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1741 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
1735 | 1742 |
1736 // Set 1 as the retry limit (does not exceed the max). | 1743 // 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. | 1744 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch. |
1738 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1745 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); |
1739 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 1746 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
1740 "http", RetryRequestTestJob::RetryFactory); | 1747 new_factory->SetProtocolHandler("http", new RetryRequestTestJobFactory); |
1741 registered_factory_ = true; | 1748 io_thread_->SetNewJobFactory(new_factory); |
1742 | 1749 |
1743 MakeService(); | 1750 MakeService(); |
1744 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), | 1751 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), |
1745 service_->storage()->NewGroupId()); | 1752 service_->storage()->NewGroupId()); |
1746 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1753 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
1747 group_->update_job_ = update; | 1754 group_->update_job_ = update; |
1748 | 1755 |
1749 MockFrontend* frontend = MakeMockFrontend(); | 1756 MockFrontend* frontend = MakeMockFrontend(); |
1750 AppCacheHost* host = MakeHost(1, frontend); | 1757 AppCacheHost* host = MakeHost(1, frontend); |
1751 update->StartUpdate(host, GURL()); | 1758 update->StartUpdate(host, GURL()); |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2570 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final | 2577 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final |
2571 frontend->AddExpectedEvent(ids1, CACHED_EVENT); | 2578 frontend->AddExpectedEvent(ids1, CACHED_EVENT); |
2572 | 2579 |
2573 // Group status will be IDLE so cannot call WaitForUpdateToFinish. | 2580 // Group status will be IDLE so cannot call WaitForUpdateToFinish. |
2574 group_->AddUpdateObserver(this); | 2581 group_->AddUpdateObserver(this); |
2575 } | 2582 } |
2576 | 2583 |
2577 void IfModifiedSinceTest() { | 2584 void IfModifiedSinceTest() { |
2578 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2585 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
2579 | 2586 |
2580 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 2587 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
2581 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2588 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2582 registered_factory_ = true; | 2589 io_thread_->SetNewJobFactory(new_factory); |
2583 | 2590 |
2584 MakeService(); | 2591 MakeService(); |
2585 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2592 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
2586 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2593 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
2587 group_->update_job_ = update; | 2594 group_->update_job_ = update; |
2588 | 2595 |
2589 // First test against a cache attempt. Will start manifest fetch | 2596 // First test against a cache attempt. Will start manifest fetch |
2590 // synchronously. | 2597 // synchronously. |
2591 HttpHeadersRequestTestJob::Initialize("", ""); | 2598 HttpHeadersRequestTestJob::Initialize("", ""); |
2592 MockFrontend mock_frontend; | 2599 MockFrontend mock_frontend; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2636 HttpHeadersRequestTestJob::Verify(); | 2643 HttpHeadersRequestTestJob::Verify(); |
2637 delete update; | 2644 delete update; |
2638 | 2645 |
2639 UpdateFinished(); | 2646 UpdateFinished(); |
2640 } | 2647 } |
2641 | 2648 |
2642 void IfModifiedSinceUpgradeTest() { | 2649 void IfModifiedSinceUpgradeTest() { |
2643 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2650 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
2644 | 2651 |
2645 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); | 2652 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); |
2646 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 2653 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
2647 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2654 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2648 registered_factory_ = true; | 2655 io_thread_->SetNewJobFactory(new_factory); |
2649 | 2656 |
2650 MakeService(); | 2657 MakeService(); |
2651 group_ = new AppCacheGroup( | 2658 group_ = new AppCacheGroup( |
2652 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2659 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
2653 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2660 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
2654 group_->update_job_ = update; | 2661 group_->update_job_ = update; |
2655 | 2662 |
2656 // Give the newest cache a manifest enry that is in storage. | 2663 // Give the newest cache a manifest enry that is in storage. |
2657 response_writer_.reset( | 2664 response_writer_.reset( |
2658 service_->storage()->CreateResponseWriter(group_->manifest_url())); | 2665 service_->storage()->CreateResponseWriter(group_->manifest_url())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2694 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2701 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
2695 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2702 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
2696 | 2703 |
2697 // Start update after data write completes asynchronously. | 2704 // Start update after data write completes asynchronously. |
2698 } | 2705 } |
2699 | 2706 |
2700 void IfNoneMatchUpgradeTest() { | 2707 void IfNoneMatchUpgradeTest() { |
2701 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2708 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
2702 | 2709 |
2703 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2710 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
2704 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 2711 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
2705 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2712 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2706 registered_factory_ = true; | 2713 io_thread_->SetNewJobFactory(new_factory); |
2707 | 2714 |
2708 MakeService(); | 2715 MakeService(); |
2709 group_ = new AppCacheGroup( | 2716 group_ = new AppCacheGroup( |
2710 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2717 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
2711 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2718 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
2712 group_->update_job_ = update; | 2719 group_->update_job_ = update; |
2713 | 2720 |
2714 // Give the newest cache a manifest enry that is in storage. | 2721 // Give the newest cache a manifest enry that is in storage. |
2715 response_writer_.reset( | 2722 response_writer_.reset( |
2716 service_->storage()->CreateResponseWriter(group_->manifest_url())); | 2723 service_->storage()->CreateResponseWriter(group_->manifest_url())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2752 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2759 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
2753 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2760 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
2754 | 2761 |
2755 // Start update after data write completes asynchronously. | 2762 // Start update after data write completes asynchronously. |
2756 } | 2763 } |
2757 | 2764 |
2758 void IfNoneMatchRefetchTest() { | 2765 void IfNoneMatchRefetchTest() { |
2759 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2766 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
2760 | 2767 |
2761 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2768 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
2762 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 2769 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
2763 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2770 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2764 registered_factory_ = true; | 2771 io_thread_->SetNewJobFactory(new_factory); |
2765 | 2772 |
2766 MakeService(); | 2773 MakeService(); |
2767 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2774 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
2768 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2775 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
2769 group_->update_job_ = update; | 2776 group_->update_job_ = update; |
2770 | 2777 |
2771 // Simulate a refetch manifest request that uses an ETag header. | 2778 // Simulate a refetch manifest request that uses an ETag header. |
2772 const char data[] = | 2779 const char data[] = |
2773 "HTTP/1.1 200 OK\0" | 2780 "HTTP/1.1 200 OK\0" |
2774 "ETag: \"LadeDade\"\0" | 2781 "ETag: \"LadeDade\"\0" |
(...skipping 12 matching lines...) Expand all Loading... |
2787 | 2794 |
2788 UpdateFinished(); | 2795 UpdateFinished(); |
2789 } | 2796 } |
2790 | 2797 |
2791 void MultipleHeadersRefetchTest() { | 2798 void MultipleHeadersRefetchTest() { |
2792 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2799 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
2793 | 2800 |
2794 // Verify that code is correct when building multiple extra headers. | 2801 // Verify that code is correct when building multiple extra headers. |
2795 HttpHeadersRequestTestJob::Initialize( | 2802 HttpHeadersRequestTestJob::Initialize( |
2796 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); | 2803 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); |
2797 old_factory_ = net::URLRequest::RegisterProtocolFactory( | 2804 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); |
2798 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2805 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2799 registered_factory_ = true; | 2806 io_thread_->SetNewJobFactory(new_factory); |
2800 | 2807 |
2801 MakeService(); | 2808 MakeService(); |
2802 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2809 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
2803 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2810 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
2804 group_->update_job_ = update; | 2811 group_->update_job_ = update; |
2805 | 2812 |
2806 // Simulate a refetch manifest request that uses an ETag header. | 2813 // Simulate a refetch manifest request that uses an ETag header. |
2807 const char data[] = | 2814 const char data[] = |
2808 "HTTP/1.1 200 OK\0" | 2815 "HTTP/1.1 200 OK\0" |
2809 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" | 2816 "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_) | 2918 if (do_checks_after_update_finished_) |
2912 VerifyExpectations(); | 2919 VerifyExpectations(); |
2913 | 2920 |
2914 // Clean up everything that was created on the IO thread. | 2921 // Clean up everything that was created on the IO thread. |
2915 protect_newest_cache_ = NULL; | 2922 protect_newest_cache_ = NULL; |
2916 group_ = NULL; | 2923 group_ = NULL; |
2917 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); | 2924 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); |
2918 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); | 2925 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); |
2919 response_infos_.clear(); | 2926 response_infos_.clear(); |
2920 service_.reset(NULL); | 2927 service_.reset(NULL); |
2921 if (registered_factory_) | |
2922 net::URLRequest::RegisterProtocolFactory("http", old_factory_); | |
2923 | 2928 |
2924 event_->Signal(); | 2929 event_->Signal(); |
2925 } | 2930 } |
2926 | 2931 |
2927 void MakeService() { | 2932 void MakeService() { |
2928 service_.reset(new MockAppCacheService()); | 2933 service_.reset(new MockAppCacheService()); |
2929 service_->set_request_context(io_thread_->request_context()); | 2934 service_->set_request_context(io_thread_->request_context()); |
2930 service_->set_appcache_policy(&policy_); | 2935 service_->set_appcache_policy(&policy_); |
2931 } | 2936 } |
2932 | 2937 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3227 // Various manifest files used in this test. | 3232 // Various manifest files used in this test. |
3228 enum TestedManifest { | 3233 enum TestedManifest { |
3229 NONE, | 3234 NONE, |
3230 MANIFEST1, | 3235 MANIFEST1, |
3231 MANIFEST_MERGED_TYPES, | 3236 MANIFEST_MERGED_TYPES, |
3232 EMPTY_MANIFEST, | 3237 EMPTY_MANIFEST, |
3233 EMPTY_FILE_MANIFEST, | 3238 EMPTY_FILE_MANIFEST, |
3234 PENDING_MASTER_NO_UPDATE, | 3239 PENDING_MASTER_NO_UPDATE, |
3235 }; | 3240 }; |
3236 | 3241 |
3237 static IOThread* io_thread_; | 3242 scoped_ptr<IOThread> io_thread_; |
3238 | 3243 |
3239 scoped_ptr<MockAppCacheService> service_; | 3244 scoped_ptr<MockAppCacheService> service_; |
3240 scoped_refptr<AppCacheGroup> group_; | 3245 scoped_refptr<AppCacheGroup> group_; |
3241 scoped_refptr<AppCache> protect_newest_cache_; | 3246 scoped_refptr<AppCache> protect_newest_cache_; |
3242 scoped_ptr<base::WaitableEvent> event_; | 3247 scoped_ptr<base::WaitableEvent> event_; |
3243 MockAppCachePolicy policy_; | 3248 MockAppCachePolicy policy_; |
3244 | 3249 |
3245 scoped_ptr<AppCacheResponseWriter> response_writer_; | 3250 scoped_ptr<AppCacheResponseWriter> response_writer_; |
3246 scoped_ptr<net::CompletionCallbackImpl<AppCacheUpdateJobTest> > | 3251 scoped_ptr<net::CompletionCallbackImpl<AppCacheUpdateJobTest> > |
3247 write_callback_; | 3252 write_callback_; |
(...skipping 11 matching lines...) Expand all Loading... |
3259 bool expect_group_obsolete_; | 3264 bool expect_group_obsolete_; |
3260 bool expect_group_has_cache_; | 3265 bool expect_group_has_cache_; |
3261 AppCache* expect_old_cache_; | 3266 AppCache* expect_old_cache_; |
3262 AppCache* expect_newest_cache_; | 3267 AppCache* expect_newest_cache_; |
3263 bool expect_non_null_update_time_; | 3268 bool expect_non_null_update_time_; |
3264 std::vector<MockFrontend*> frontends_; // to check expected events | 3269 std::vector<MockFrontend*> frontends_; // to check expected events |
3265 TestedManifest tested_manifest_; | 3270 TestedManifest tested_manifest_; |
3266 const char* tested_manifest_path_override_; | 3271 const char* tested_manifest_path_override_; |
3267 AppCache::EntryMap expect_extra_entries_; | 3272 AppCache::EntryMap expect_extra_entries_; |
3268 std::map<GURL, int64> expect_response_ids_; | 3273 std::map<GURL, int64> expect_response_ids_; |
3269 | |
3270 bool registered_factory_; | |
3271 net::URLRequest::ProtocolFactory* old_factory_; | |
3272 }; | 3274 }; |
3273 | 3275 |
3274 // static | |
3275 IOThread* AppCacheUpdateJobTest::io_thread_ = NULL; | |
3276 base::WaitableEvent* AppCacheUpdateJobTest::io_thread_shutdown_event_ = NULL; | |
3277 | |
3278 | |
3279 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { | 3276 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { |
3280 MockAppCacheService service; | 3277 MockAppCacheService service; |
3281 scoped_refptr<AppCacheGroup> group( | 3278 scoped_refptr<AppCacheGroup> group( |
3282 new AppCacheGroup(&service, GURL("http://manifesturl.com"), | 3279 new AppCacheGroup(&service, GURL("http://manifesturl.com"), |
3283 service.storage()->NewGroupId())); | 3280 service.storage()->NewGroupId())); |
3284 | 3281 |
3285 AppCacheUpdateJob update(&service, group); | 3282 AppCacheUpdateJob update(&service, group); |
3286 | 3283 |
3287 // Pretend group is in checking state. | 3284 // Pretend group is in checking state. |
3288 group->update_job_ = &update; | 3285 group->update_job_ = &update; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3549 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
3553 } | 3550 } |
3554 | 3551 |
3555 } // namespace appcache | 3552 } // namespace appcache |
3556 | 3553 |
3557 // AppCacheUpdateJobTest is expected to always live longer than the | 3554 // AppCacheUpdateJobTest is expected to always live longer than the |
3558 // runnable methods. This lets us call NewRunnableMethod on its instances. | 3555 // runnable methods. This lets us call NewRunnableMethod on its instances. |
3559 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); | 3556 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); |
3560 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 3557 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
3561 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); | 3558 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); |
OLD | NEW |