| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/thread.h" | 8 #include "base/thread.h" |
| 9 #include "base/waitable_event.h" | 9 #include "base/waitable_event.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // There are a handful of http accessible resources that we need to conduct | 35 // There are a handful of http accessible resources that we need to conduct |
| 36 // these tests. Instead of running a seperate server to host these resources, | 36 // these tests. Instead of running a seperate server to host these resources, |
| 37 // we mock them up. | 37 // we mock them up. |
| 38 class MockHttpServer { | 38 class MockHttpServer { |
| 39 public: | 39 public: |
| 40 static GURL GetMockUrl(const std::string& path) { | 40 static GURL GetMockUrl(const std::string& path) { |
| 41 return GURL("http://mockhost/" + path); | 41 return GURL("http://mockhost/" + path); |
| 42 } | 42 } |
| 43 | 43 |
| 44 static URLRequestJob* JobFactory(URLRequest* request, | 44 static URLRequestJob* JobFactory(net::URLRequest* request, |
| 45 const std::string& scheme) { | 45 const std::string& scheme) { |
| 46 if (request->url().host() != "mockhost") | 46 if (request->url().host() != "mockhost") |
| 47 return new URLRequestErrorJob(request, -1); | 47 return new URLRequestErrorJob(request, -1); |
| 48 | 48 |
| 49 std::string headers, body; | 49 std::string headers, body; |
| 50 GetMockResponse(request->url().path(), &headers, &body); | 50 GetMockResponse(request->url().path(), &headers, &body); |
| 51 return new URLRequestTestJob(request, headers, body, true); | 51 return new URLRequestTestJob(request, headers, body, true); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 int last_progress_total_; | 280 int last_progress_total_; |
| 281 int last_progress_complete_; | 281 int last_progress_complete_; |
| 282 | 282 |
| 283 // Add ability for frontend to add master entries to an inprogress update. | 283 // Add ability for frontend to add master entries to an inprogress update. |
| 284 EventID start_update_trigger_; | 284 EventID start_update_trigger_; |
| 285 AppCacheUpdateJob* update_; | 285 AppCacheUpdateJob* update_; |
| 286 std::vector<AppCacheHost*> update_hosts_; | 286 std::vector<AppCacheHost*> update_hosts_; |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 // Helper factories to simulate redirected URL responses for tests. | 289 // Helper factories to simulate redirected URL responses for tests. |
| 290 static URLRequestJob* RedirectFactory(URLRequest* request, | 290 static URLRequestJob* RedirectFactory(net::URLRequest* request, |
| 291 const std::string& scheme) { | 291 const std::string& scheme) { |
| 292 return new URLRequestTestJob(request, | 292 return new URLRequestTestJob(request, |
| 293 URLRequestTestJob::test_redirect_headers(), | 293 URLRequestTestJob::test_redirect_headers(), |
| 294 URLRequestTestJob::test_data_1(), | 294 URLRequestTestJob::test_data_1(), |
| 295 true); | 295 true); |
| 296 } | 296 } |
| 297 | 297 |
| 298 // Helper class to simulate a URL that returns retry or success. | 298 // Helper class to simulate a URL that returns retry or success. |
| 299 class RetryRequestTestJob : public URLRequestTestJob { | 299 class RetryRequestTestJob : public URLRequestTestJob { |
| 300 public: | 300 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 315 expected_requests_ = expected_requests; | 315 expected_requests_ = expected_requests; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Verifies results at end of test and resets counters. | 318 // Verifies results at end of test and resets counters. |
| 319 static void Verify() { | 319 static void Verify() { |
| 320 EXPECT_EQ(expected_requests_, num_requests_); | 320 EXPECT_EQ(expected_requests_, num_requests_); |
| 321 num_requests_ = 0; | 321 num_requests_ = 0; |
| 322 expected_requests_ = 0; | 322 expected_requests_ = 0; |
| 323 } | 323 } |
| 324 | 324 |
| 325 static URLRequestJob* RetryFactory(URLRequest* request, | 325 static URLRequestJob* RetryFactory(net::URLRequest* request, |
| 326 const std::string& scheme) { | 326 const std::string& scheme) { |
| 327 ++num_requests_; | 327 ++num_requests_; |
| 328 if (num_retries_ > 0 && request->original_url() == kRetryUrl) { | 328 if (num_retries_ > 0 && request->original_url() == kRetryUrl) { |
| 329 --num_retries_; | 329 --num_retries_; |
| 330 return new RetryRequestTestJob( | 330 return new RetryRequestTestJob( |
| 331 request, RetryRequestTestJob::retry_headers(), 503); | 331 request, RetryRequestTestJob::retry_headers(), 503); |
| 332 } else { | 332 } else { |
| 333 return new RetryRequestTestJob( | 333 return new RetryRequestTestJob( |
| 334 request, RetryRequestTestJob::manifest_headers(), 200); | 334 request, RetryRequestTestJob::manifest_headers(), 200); |
| 335 } | 335 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 "Content-type: text/cache-manifest\0" | 370 "Content-type: text/cache-manifest\0" |
| 371 "\0"; | 371 "\0"; |
| 372 return std::string(headers, arraysize(headers)); | 372 return std::string(headers, arraysize(headers)); |
| 373 } | 373 } |
| 374 | 374 |
| 375 static std::string data() { | 375 static std::string data() { |
| 376 return std::string("CACHE MANIFEST\r" | 376 return std::string("CACHE MANIFEST\r" |
| 377 "http://retry\r"); // must be same as kRetryUrl | 377 "http://retry\r"); // must be same as kRetryUrl |
| 378 } | 378 } |
| 379 | 379 |
| 380 explicit RetryRequestTestJob(URLRequest* request, const std::string& headers, | 380 explicit RetryRequestTestJob(net::URLRequest* request, |
| 381 const std::string& headers, |
| 381 int response_code) | 382 int response_code) |
| 382 : URLRequestTestJob(request, headers, data(), true), | 383 : URLRequestTestJob(request, headers, data(), true), |
| 383 response_code_(response_code) { | 384 response_code_(response_code) { |
| 384 } | 385 } |
| 385 | 386 |
| 386 int response_code_; | 387 int response_code_; |
| 387 | 388 |
| 388 static int num_requests_; | 389 static int num_requests_; |
| 389 static int num_retries_; | 390 static int num_retries_; |
| 390 static RetryHeader retry_after_; | 391 static RetryHeader retry_after_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 416 EXPECT_TRUE(saw_if_none_match_); | 417 EXPECT_TRUE(saw_if_none_match_); |
| 417 | 418 |
| 418 // Reset. | 419 // Reset. |
| 419 expect_if_modified_since_.clear(); | 420 expect_if_modified_since_.clear(); |
| 420 saw_if_modified_since_ = false; | 421 saw_if_modified_since_ = false; |
| 421 expect_if_none_match_.clear(); | 422 expect_if_none_match_.clear(); |
| 422 saw_if_none_match_ = false; | 423 saw_if_none_match_ = false; |
| 423 already_checked_ = false; | 424 already_checked_ = false; |
| 424 } | 425 } |
| 425 | 426 |
| 426 static URLRequestJob* IfModifiedSinceFactory(URLRequest* request, | 427 static URLRequestJob* IfModifiedSinceFactory(net::URLRequest* request, |
| 427 const std::string& scheme) { | 428 const std::string& scheme) { |
| 428 if (!already_checked_) { | 429 if (!already_checked_) { |
| 429 already_checked_ = true; // only check once for a test | 430 already_checked_ = true; // only check once for a test |
| 430 const net::HttpRequestHeaders& extra_headers = | 431 const net::HttpRequestHeaders& extra_headers = |
| 431 request->extra_request_headers(); | 432 request->extra_request_headers(); |
| 432 std::string header_value; | 433 std::string header_value; |
| 433 saw_if_modified_since_ = | 434 saw_if_modified_since_ = |
| 434 extra_headers.GetHeader( | 435 extra_headers.GetHeader( |
| 435 net::HttpRequestHeaders::kIfModifiedSince, &header_value) && | 436 net::HttpRequestHeaders::kIfModifiedSince, &header_value) && |
| 436 header_value == expect_if_modified_since_; | 437 header_value == expect_if_modified_since_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // We cannot rely on our base class to stop the thread since we want our | 471 // We cannot rely on our base class to stop the thread since we want our |
| 471 // CleanUp function to run. | 472 // CleanUp function to run. |
| 472 Stop(); | 473 Stop(); |
| 473 } | 474 } |
| 474 | 475 |
| 475 const scoped_refptr<URLRequestContext>& request_context() { | 476 const scoped_refptr<URLRequestContext>& request_context() { |
| 476 return request_context_; | 477 return request_context_; |
| 477 } | 478 } |
| 478 | 479 |
| 479 virtual void Init() { | 480 virtual void Init() { |
| 480 old_factory_ = URLRequest::RegisterProtocolFactory( | 481 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 481 "http", MockHttpServer::JobFactory); | 482 "http", MockHttpServer::JobFactory); |
| 482 request_context_ = new TestURLRequestContext(); | 483 request_context_ = new TestURLRequestContext(); |
| 483 } | 484 } |
| 484 | 485 |
| 485 virtual void CleanUp() { | 486 virtual void CleanUp() { |
| 486 URLRequest::RegisterProtocolFactory("http", old_factory_); | 487 net::URLRequest::RegisterProtocolFactory("http", old_factory_); |
| 487 request_context_ = NULL; | 488 request_context_ = NULL; |
| 488 } | 489 } |
| 489 | 490 |
| 490 URLRequest::ProtocolFactory* old_factory_; | 491 net::URLRequest::ProtocolFactory* old_factory_; |
| 491 scoped_refptr<URLRequestContext> request_context_; | 492 scoped_refptr<URLRequestContext> request_context_; |
| 492 }; | 493 }; |
| 493 | 494 |
| 494 } // namespace | 495 } // namespace |
| 495 | 496 |
| 496 class AppCacheUpdateJobTest : public testing::Test, | 497 class AppCacheUpdateJobTest : public testing::Test, |
| 497 public AppCacheGroup::UpdateObserver { | 498 public AppCacheGroup::UpdateObserver { |
| 498 public: | 499 public: |
| 499 class MockAppCachePolicy : public AppCachePolicy { | 500 class MockAppCachePolicy : public AppCachePolicy { |
| 500 public: | 501 public: |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); | 784 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); |
| 784 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); | 785 frontend2->AddExpectedEvent(ids2, ERROR_EVENT); |
| 785 | 786 |
| 786 WaitForUpdateToFinish(); | 787 WaitForUpdateToFinish(); |
| 787 } | 788 } |
| 788 | 789 |
| 789 void ManifestRedirectTest() { | 790 void ManifestRedirectTest() { |
| 790 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 791 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 791 | 792 |
| 792 old_factory_ = | 793 old_factory_ = |
| 793 URLRequest::RegisterProtocolFactory("http", RedirectFactory); | 794 net::URLRequest::RegisterProtocolFactory("http", RedirectFactory); |
| 794 registered_factory_ = true; | 795 registered_factory_ = true; |
| 795 | 796 |
| 796 MakeService(); | 797 MakeService(); |
| 797 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), | 798 group_ = new AppCacheGroup(service_.get(), GURL("http://testme"), |
| 798 service_->storage()->NewGroupId()); | 799 service_->storage()->NewGroupId()); |
| 799 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 800 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 800 group_->update_job_ = update; | 801 group_->update_job_ = update; |
| 801 | 802 |
| 802 MockFrontend* frontend = MakeMockFrontend(); | 803 MockFrontend* frontend = MakeMockFrontend(); |
| 803 AppCacheHost* host = MakeHost(1, frontend); | 804 AppCacheHost* host = MakeHost(1, frontend); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 | 1575 |
| 1575 WaitForUpdateToFinish(); | 1576 WaitForUpdateToFinish(); |
| 1576 } | 1577 } |
| 1577 | 1578 |
| 1578 void RetryRequestTest() { | 1579 void RetryRequestTest() { |
| 1579 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1580 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1580 | 1581 |
| 1581 // Set some large number of times to return retry. | 1582 // Set some large number of times to return retry. |
| 1582 // Expect 1 manifest fetch and 3 retries. | 1583 // Expect 1 manifest fetch and 3 retries. |
| 1583 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1584 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4); |
| 1584 old_factory_ = URLRequest::RegisterProtocolFactory( | 1585 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1585 "http", RetryRequestTestJob::RetryFactory); | 1586 "http", RetryRequestTestJob::RetryFactory); |
| 1586 registered_factory_ = true; | 1587 registered_factory_ = true; |
| 1587 | 1588 |
| 1588 MakeService(); | 1589 MakeService(); |
| 1589 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1590 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1590 service_->storage()->NewGroupId()); | 1591 service_->storage()->NewGroupId()); |
| 1591 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1592 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1592 group_->update_job_ = update; | 1593 group_->update_job_ = update; |
| 1593 | 1594 |
| 1594 MockFrontend* frontend = MakeMockFrontend(); | 1595 MockFrontend* frontend = MakeMockFrontend(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1605 | 1606 |
| 1606 WaitForUpdateToFinish(); | 1607 WaitForUpdateToFinish(); |
| 1607 } | 1608 } |
| 1608 | 1609 |
| 1609 void RetryNoRetryAfterTest() { | 1610 void RetryNoRetryAfterTest() { |
| 1610 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1611 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1611 | 1612 |
| 1612 // Set some large number of times to return retry. | 1613 // Set some large number of times to return retry. |
| 1613 // Expect 1 manifest fetch and 0 retries. | 1614 // Expect 1 manifest fetch and 0 retries. |
| 1614 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); | 1615 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1); |
| 1615 old_factory_ = URLRequest::RegisterProtocolFactory( | 1616 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1616 "http", RetryRequestTestJob::RetryFactory); | 1617 "http", RetryRequestTestJob::RetryFactory); |
| 1617 registered_factory_ = true; | 1618 registered_factory_ = true; |
| 1618 | 1619 |
| 1619 MakeService(); | 1620 MakeService(); |
| 1620 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1621 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1621 service_->storage()->NewGroupId()); | 1622 service_->storage()->NewGroupId()); |
| 1622 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1623 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1623 group_->update_job_ = update; | 1624 group_->update_job_ = update; |
| 1624 | 1625 |
| 1625 MockFrontend* frontend = MakeMockFrontend(); | 1626 MockFrontend* frontend = MakeMockFrontend(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1637 WaitForUpdateToFinish(); | 1638 WaitForUpdateToFinish(); |
| 1638 } | 1639 } |
| 1639 | 1640 |
| 1640 void RetryNonzeroRetryAfterTest() { | 1641 void RetryNonzeroRetryAfterTest() { |
| 1641 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1642 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1642 | 1643 |
| 1643 // Set some large number of times to return retry. | 1644 // Set some large number of times to return retry. |
| 1644 // Expect 1 request and 0 retry attempts. | 1645 // Expect 1 request and 0 retry attempts. |
| 1645 RetryRequestTestJob::Initialize( | 1646 RetryRequestTestJob::Initialize( |
| 1646 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); | 1647 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1); |
| 1647 old_factory_ = URLRequest::RegisterProtocolFactory( | 1648 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1648 "http", RetryRequestTestJob::RetryFactory); | 1649 "http", RetryRequestTestJob::RetryFactory); |
| 1649 registered_factory_ = true; | 1650 registered_factory_ = true; |
| 1650 | 1651 |
| 1651 MakeService(); | 1652 MakeService(); |
| 1652 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1653 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1653 service_->storage()->NewGroupId()); | 1654 service_->storage()->NewGroupId()); |
| 1654 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1655 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1655 group_->update_job_ = update; | 1656 group_->update_job_ = update; |
| 1656 | 1657 |
| 1657 MockFrontend* frontend = MakeMockFrontend(); | 1658 MockFrontend* frontend = MakeMockFrontend(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1668 | 1669 |
| 1669 WaitForUpdateToFinish(); | 1670 WaitForUpdateToFinish(); |
| 1670 } | 1671 } |
| 1671 | 1672 |
| 1672 void RetrySuccessTest() { | 1673 void RetrySuccessTest() { |
| 1673 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1674 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1674 | 1675 |
| 1675 // Set 2 as the retry limit (does not exceed the max). | 1676 // Set 2 as the retry limit (does not exceed the max). |
| 1676 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. | 1677 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch. |
| 1677 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); | 1678 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5); |
| 1678 old_factory_ = URLRequest::RegisterProtocolFactory( | 1679 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1679 "http", RetryRequestTestJob::RetryFactory); | 1680 "http", RetryRequestTestJob::RetryFactory); |
| 1680 registered_factory_ = true; | 1681 registered_factory_ = true; |
| 1681 | 1682 |
| 1682 MakeService(); | 1683 MakeService(); |
| 1683 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, | 1684 group_ = new AppCacheGroup(service_.get(), RetryRequestTestJob::kRetryUrl, |
| 1684 service_->storage()->NewGroupId()); | 1685 service_->storage()->NewGroupId()); |
| 1685 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1686 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1686 group_->update_job_ = update; | 1687 group_->update_job_ = update; |
| 1687 | 1688 |
| 1688 MockFrontend* frontend = MakeMockFrontend(); | 1689 MockFrontend* frontend = MakeMockFrontend(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1699 | 1700 |
| 1700 WaitForUpdateToFinish(); | 1701 WaitForUpdateToFinish(); |
| 1701 } | 1702 } |
| 1702 | 1703 |
| 1703 void RetryUrlTest() { | 1704 void RetryUrlTest() { |
| 1704 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 1705 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 1705 | 1706 |
| 1706 // Set 1 as the retry limit (does not exceed the max). | 1707 // Set 1 as the retry limit (does not exceed the max). |
| 1707 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch. | 1708 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch. |
| 1708 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); | 1709 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4); |
| 1709 old_factory_ = URLRequest::RegisterProtocolFactory( | 1710 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 1710 "http", RetryRequestTestJob::RetryFactory); | 1711 "http", RetryRequestTestJob::RetryFactory); |
| 1711 registered_factory_ = true; | 1712 registered_factory_ = true; |
| 1712 | 1713 |
| 1713 MakeService(); | 1714 MakeService(); |
| 1714 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), | 1715 group_ = new AppCacheGroup(service_.get(), GURL("http://retryurl"), |
| 1715 service_->storage()->NewGroupId()); | 1716 service_->storage()->NewGroupId()); |
| 1716 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 1717 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 1717 group_->update_job_ = update; | 1718 group_->update_job_ = update; |
| 1718 | 1719 |
| 1719 MockFrontend* frontend = MakeMockFrontend(); | 1720 MockFrontend* frontend = MakeMockFrontend(); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2540 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final | 2541 frontend->AddExpectedEvent(ids1, PROGRESS_EVENT); // final |
| 2541 frontend->AddExpectedEvent(ids1, CACHED_EVENT); | 2542 frontend->AddExpectedEvent(ids1, CACHED_EVENT); |
| 2542 | 2543 |
| 2543 // Group status will be IDLE so cannot call WaitForUpdateToFinish. | 2544 // Group status will be IDLE so cannot call WaitForUpdateToFinish. |
| 2544 group_->AddUpdateObserver(this); | 2545 group_->AddUpdateObserver(this); |
| 2545 } | 2546 } |
| 2546 | 2547 |
| 2547 void IfModifiedSinceTest() { | 2548 void IfModifiedSinceTest() { |
| 2548 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2549 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2549 | 2550 |
| 2550 old_factory_ = URLRequest::RegisterProtocolFactory( | 2551 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2551 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2552 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2552 registered_factory_ = true; | 2553 registered_factory_ = true; |
| 2553 | 2554 |
| 2554 MakeService(); | 2555 MakeService(); |
| 2555 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2556 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2556 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2557 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2557 group_->update_job_ = update; | 2558 group_->update_job_ = update; |
| 2558 | 2559 |
| 2559 // First test against a cache attempt. Will start manifest fetch | 2560 // First test against a cache attempt. Will start manifest fetch |
| 2560 // synchronously. | 2561 // synchronously. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 HttpHeadersRequestTestJob::Verify(); | 2607 HttpHeadersRequestTestJob::Verify(); |
| 2607 delete update; | 2608 delete update; |
| 2608 | 2609 |
| 2609 UpdateFinished(); | 2610 UpdateFinished(); |
| 2610 } | 2611 } |
| 2611 | 2612 |
| 2612 void IfModifiedSinceUpgradeTest() { | 2613 void IfModifiedSinceUpgradeTest() { |
| 2613 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2614 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2614 | 2615 |
| 2615 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); | 2616 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", ""); |
| 2616 old_factory_ = URLRequest::RegisterProtocolFactory( | 2617 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2617 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2618 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2618 registered_factory_ = true; | 2619 registered_factory_ = true; |
| 2619 | 2620 |
| 2620 MakeService(); | 2621 MakeService(); |
| 2621 group_ = new AppCacheGroup( | 2622 group_ = new AppCacheGroup( |
| 2622 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2623 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
| 2623 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2624 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2624 group_->update_job_ = update; | 2625 group_->update_job_ = update; |
| 2625 | 2626 |
| 2626 // Give the newest cache a manifest enry that is in storage. | 2627 // Give the newest cache a manifest enry that is in storage. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2664 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2665 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
| 2665 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2666 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
| 2666 | 2667 |
| 2667 // Start update after data write completes asynchronously. | 2668 // Start update after data write completes asynchronously. |
| 2668 } | 2669 } |
| 2669 | 2670 |
| 2670 void IfNoneMatchUpgradeTest() { | 2671 void IfNoneMatchUpgradeTest() { |
| 2671 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2672 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2672 | 2673 |
| 2673 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2674 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
| 2674 old_factory_ = URLRequest::RegisterProtocolFactory( | 2675 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2675 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2676 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2676 registered_factory_ = true; | 2677 registered_factory_ = true; |
| 2677 | 2678 |
| 2678 MakeService(); | 2679 MakeService(); |
| 2679 group_ = new AppCacheGroup( | 2680 group_ = new AppCacheGroup( |
| 2680 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); | 2681 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 111); |
| 2681 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2682 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2682 group_->update_job_ = update; | 2683 group_->update_job_ = update; |
| 2683 | 2684 |
| 2684 // Give the newest cache a manifest enry that is in storage. | 2685 // Give the newest cache a manifest enry that is in storage. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); | 2723 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); |
| 2723 response_writer_->WriteInfo(io_buffer, write_callback_.get()); | 2724 response_writer_->WriteInfo(io_buffer, write_callback_.get()); |
| 2724 | 2725 |
| 2725 // Start update after data write completes asynchronously. | 2726 // Start update after data write completes asynchronously. |
| 2726 } | 2727 } |
| 2727 | 2728 |
| 2728 void IfNoneMatchRefetchTest() { | 2729 void IfNoneMatchRefetchTest() { |
| 2729 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2730 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2730 | 2731 |
| 2731 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); | 2732 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); |
| 2732 old_factory_ = URLRequest::RegisterProtocolFactory( | 2733 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2733 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2734 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2734 registered_factory_ = true; | 2735 registered_factory_ = true; |
| 2735 | 2736 |
| 2736 MakeService(); | 2737 MakeService(); |
| 2737 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2738 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2738 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2739 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2739 group_->update_job_ = update; | 2740 group_->update_job_ = update; |
| 2740 | 2741 |
| 2741 // Simulate a refetch manifest request that uses an ETag header. | 2742 // Simulate a refetch manifest request that uses an ETag header. |
| 2742 const char data[] = | 2743 const char data[] = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2757 | 2758 |
| 2758 UpdateFinished(); | 2759 UpdateFinished(); |
| 2759 } | 2760 } |
| 2760 | 2761 |
| 2761 void MultipleHeadersRefetchTest() { | 2762 void MultipleHeadersRefetchTest() { |
| 2762 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 2763 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
| 2763 | 2764 |
| 2764 // Verify that code is correct when building multiple extra headers. | 2765 // Verify that code is correct when building multiple extra headers. |
| 2765 HttpHeadersRequestTestJob::Initialize( | 2766 HttpHeadersRequestTestJob::Initialize( |
| 2766 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); | 2767 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\""); |
| 2767 old_factory_ = URLRequest::RegisterProtocolFactory( | 2768 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 2768 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); | 2769 "http", HttpHeadersRequestTestJob::IfModifiedSinceFactory); |
| 2769 registered_factory_ = true; | 2770 registered_factory_ = true; |
| 2770 | 2771 |
| 2771 MakeService(); | 2772 MakeService(); |
| 2772 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); | 2773 group_ = new AppCacheGroup(service_.get(), GURL("http://headertest"), 111); |
| 2773 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 2774 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
| 2774 group_->update_job_ = update; | 2775 group_->update_job_ = update; |
| 2775 | 2776 |
| 2776 // Simulate a refetch manifest request that uses an ETag header. | 2777 // Simulate a refetch manifest request that uses an ETag header. |
| 2777 const char data[] = | 2778 const char data[] = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2824 VerifyExpectations(); | 2825 VerifyExpectations(); |
| 2825 | 2826 |
| 2826 // Clean up everything that was created on the IO thread. | 2827 // Clean up everything that was created on the IO thread. |
| 2827 protect_newest_cache_ = NULL; | 2828 protect_newest_cache_ = NULL; |
| 2828 group_ = NULL; | 2829 group_ = NULL; |
| 2829 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); | 2830 STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); |
| 2830 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); | 2831 STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); |
| 2831 response_infos_.clear(); | 2832 response_infos_.clear(); |
| 2832 service_.reset(NULL); | 2833 service_.reset(NULL); |
| 2833 if (registered_factory_) | 2834 if (registered_factory_) |
| 2834 URLRequest::RegisterProtocolFactory("http", old_factory_); | 2835 net::URLRequest::RegisterProtocolFactory("http", old_factory_); |
| 2835 | 2836 |
| 2836 event_->Signal(); | 2837 event_->Signal(); |
| 2837 } | 2838 } |
| 2838 | 2839 |
| 2839 void MakeService() { | 2840 void MakeService() { |
| 2840 service_.reset(new MockAppCacheService()); | 2841 service_.reset(new MockAppCacheService()); |
| 2841 service_->set_request_context(io_thread_->request_context()); | 2842 service_->set_request_context(io_thread_->request_context()); |
| 2842 service_->set_appcache_policy(&policy_); | 2843 service_->set_appcache_policy(&policy_); |
| 2843 } | 2844 } |
| 2844 | 2845 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3173 AppCache* expect_old_cache_; | 3174 AppCache* expect_old_cache_; |
| 3174 AppCache* expect_newest_cache_; | 3175 AppCache* expect_newest_cache_; |
| 3175 bool expect_non_null_update_time_; | 3176 bool expect_non_null_update_time_; |
| 3176 std::vector<MockFrontend*> frontends_; // to check expected events | 3177 std::vector<MockFrontend*> frontends_; // to check expected events |
| 3177 TestedManifest tested_manifest_; | 3178 TestedManifest tested_manifest_; |
| 3178 const char* tested_manifest_path_override_; | 3179 const char* tested_manifest_path_override_; |
| 3179 AppCache::EntryMap expect_extra_entries_; | 3180 AppCache::EntryMap expect_extra_entries_; |
| 3180 std::map<GURL, int64> expect_response_ids_; | 3181 std::map<GURL, int64> expect_response_ids_; |
| 3181 | 3182 |
| 3182 bool registered_factory_; | 3183 bool registered_factory_; |
| 3183 URLRequest::ProtocolFactory* old_factory_; | 3184 net::URLRequest::ProtocolFactory* old_factory_; |
| 3184 }; | 3185 }; |
| 3185 | 3186 |
| 3186 // static | 3187 // static |
| 3187 IOThread* AppCacheUpdateJobTest::io_thread_ = NULL; | 3188 IOThread* AppCacheUpdateJobTest::io_thread_ = NULL; |
| 3188 base::WaitableEvent* AppCacheUpdateJobTest::io_thread_shutdown_event_ = NULL; | 3189 base::WaitableEvent* AppCacheUpdateJobTest::io_thread_shutdown_event_ = NULL; |
| 3189 | 3190 |
| 3190 | 3191 |
| 3191 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { | 3192 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { |
| 3192 MockAppCacheService service; | 3193 MockAppCacheService service; |
| 3193 scoped_refptr<AppCacheGroup> group( | 3194 scoped_refptr<AppCacheGroup> group( |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3456 RunTestOnIOThread(&AppCacheUpdateJobTest::MultipleHeadersRefetchTest); | 3457 RunTestOnIOThread(&AppCacheUpdateJobTest::MultipleHeadersRefetchTest); |
| 3457 } | 3458 } |
| 3458 | 3459 |
| 3459 } // namespace appcache | 3460 } // namespace appcache |
| 3460 | 3461 |
| 3461 // AppCacheUpdateJobTest is expected to always live longer than the | 3462 // AppCacheUpdateJobTest is expected to always live longer than the |
| 3462 // runnable methods. This lets us call NewRunnableMethod on its instances. | 3463 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 3463 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); | 3464 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); |
| 3464 DISABLE_RUNNABLE_METHOD_REFCOUNT( | 3465 DISABLE_RUNNABLE_METHOD_REFCOUNT( |
| 3465 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); | 3466 appcache::AppCacheUpdateJobTest::MockAppCachePolicy); |
| OLD | NEW |