| 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 <stack> | 5 #include <stack> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 AppCacheRequestHandlerTest* test_; | 67 AppCacheRequestHandlerTest* test_; |
| 68 Method method_; | 68 Method method_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // Subclasses to simulate particular response codes so test cases can | 71 // Subclasses to simulate particular response codes so test cases can |
| 72 // exercise fallback code paths. | 72 // exercise fallback code paths. |
| 73 | 73 |
| 74 class MockURLRequestJob : public URLRequestJob { | 74 class MockURLRequestJob : public net::URLRequestJob { |
| 75 public: | 75 public: |
| 76 MockURLRequestJob(net::URLRequest* request, int response_code) | 76 MockURLRequestJob(net::URLRequest* request, int response_code) |
| 77 : URLRequestJob(request), response_code_(response_code) {} | 77 : net::URLRequestJob(request), response_code_(response_code) {} |
| 78 virtual void Start() {} | 78 virtual void Start() {} |
| 79 virtual int GetResponseCode() const { return response_code_; } | 79 virtual int GetResponseCode() const { return response_code_; } |
| 80 int response_code_; | 80 int response_code_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 class MockURLRequest : public net::URLRequest { | 83 class MockURLRequest : public net::URLRequest { |
| 84 public: | 84 public: |
| 85 explicit MockURLRequest(const GURL& url) : net::URLRequest(url, NULL) {} | 85 explicit MockURLRequest(const GURL& url) : net::URLRequest(url, NULL) {} |
| 86 | 86 |
| 87 void SimulateResponseCode(int http_response_code) { | 87 void SimulateResponseCode(int http_response_code) { |
| 88 mock_factory_job_ = new MockURLRequestJob(this, http_response_code); | 88 mock_factory_job_ = new MockURLRequestJob(this, http_response_code); |
| 89 Start(); | 89 Start(); |
| 90 DCHECK(!mock_factory_job_); | 90 DCHECK(!mock_factory_job_); |
| 91 // All our simulation need to do satisfy are the following two DCHECKs | 91 // All our simulation need to do satisfy are the following two DCHECKs |
| 92 DCHECK(status().is_success()); | 92 DCHECK(status().is_success()); |
| 93 DCHECK_EQ(http_response_code, GetResponseCode()); | 93 DCHECK_EQ(http_response_code, GetResponseCode()); |
| 94 } | 94 } |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 static URLRequestJob* MockHttpJobFactory(net::URLRequest* request, | 97 static net::URLRequestJob* MockHttpJobFactory(net::URLRequest* request, |
| 98 const std::string& scheme) { | 98 const std::string& scheme) { |
| 99 if (mock_factory_job_) { | 99 if (mock_factory_job_) { |
| 100 URLRequestJob* temp = mock_factory_job_; | 100 net::URLRequestJob* temp = mock_factory_job_; |
| 101 mock_factory_job_ = NULL; | 101 mock_factory_job_ = NULL; |
| 102 return temp; | 102 return temp; |
| 103 } else { | 103 } else { |
| 104 // Some of these tests trigger UpdateJobs which start URLRequests. | 104 // Some of these tests trigger UpdateJobs which start URLRequests. |
| 105 // We short circuit those be returning error jobs. | 105 // We short circuit those be returning error jobs. |
| 106 return new URLRequestErrorJob(request, net::ERR_INTERNET_DISCONNECTED); | 106 return new URLRequestErrorJob(request, net::ERR_INTERNET_DISCONNECTED); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 static void SetUpTestCase() { | 110 static void SetUpTestCase() { |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 scoped_ptr<MockAppCacheService> mock_service_; | 661 scoped_ptr<MockAppCacheService> mock_service_; |
| 662 scoped_ptr<AppCacheBackendImpl> backend_impl_; | 662 scoped_ptr<AppCacheBackendImpl> backend_impl_; |
| 663 scoped_ptr<MockFrontend> mock_frontend_; | 663 scoped_ptr<MockFrontend> mock_frontend_; |
| 664 AppCacheHost* host_; | 664 AppCacheHost* host_; |
| 665 scoped_ptr<MockURLRequest> request_; | 665 scoped_ptr<MockURLRequest> request_; |
| 666 scoped_ptr<AppCacheRequestHandler> handler_; | 666 scoped_ptr<AppCacheRequestHandler> handler_; |
| 667 scoped_refptr<AppCacheURLRequestJob> job_; | 667 scoped_refptr<AppCacheURLRequestJob> job_; |
| 668 net::URLRequest::ProtocolFactory* orig_http_factory_; | 668 net::URLRequest::ProtocolFactory* orig_http_factory_; |
| 669 | 669 |
| 670 static scoped_ptr<base::Thread> io_thread_; | 670 static scoped_ptr<base::Thread> io_thread_; |
| 671 static URLRequestJob* mock_factory_job_; | 671 static net::URLRequestJob* mock_factory_job_; |
| 672 }; | 672 }; |
| 673 | 673 |
| 674 // static | 674 // static |
| 675 scoped_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; | 675 scoped_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; |
| 676 URLRequestJob* AppCacheRequestHandlerTest::mock_factory_job_ = NULL; | 676 net::URLRequestJob* AppCacheRequestHandlerTest::mock_factory_job_ = NULL; |
| 677 | 677 |
| 678 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { | 678 TEST_F(AppCacheRequestHandlerTest, MainResource_Miss) { |
| 679 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Miss); | 679 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Miss); |
| 680 } | 680 } |
| 681 | 681 |
| 682 TEST_F(AppCacheRequestHandlerTest, MainResource_Hit) { | 682 TEST_F(AppCacheRequestHandlerTest, MainResource_Hit) { |
| 683 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Hit); | 683 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Hit); |
| 684 } | 684 } |
| 685 | 685 |
| 686 TEST_F(AppCacheRequestHandlerTest, MainResource_Fallback) { | 686 TEST_F(AppCacheRequestHandlerTest, MainResource_Fallback) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 | 738 |
| 739 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 739 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 740 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 740 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 741 } | 741 } |
| 742 | 742 |
| 743 } // namespace appcache | 743 } // namespace appcache |
| 744 | 744 |
| 745 // AppCacheRequestHandlerTest is expected to always live longer than the | 745 // AppCacheRequestHandlerTest is expected to always live longer than the |
| 746 // runnable methods. This lets us call NewRunnableMethod on its instances. | 746 // runnable methods. This lets us call NewRunnableMethod on its instances. |
| 747 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheRequestHandlerTest); | 747 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheRequestHandlerTest); |
| OLD | NEW |