| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 static const int kMockProcessId = 1; | 32 static const int kMockProcessId = 1; |
| 33 | 33 |
| 34 class AppCacheRequestHandlerTest : public testing::Test { | 34 class AppCacheRequestHandlerTest : public testing::Test { |
| 35 public: | 35 public: |
| 36 class MockFrontend : public AppCacheFrontend { | 36 class MockFrontend : public AppCacheFrontend { |
| 37 public: | 37 public: |
| 38 virtual void OnCacheSelected( | 38 virtual void OnCacheSelected( |
| 39 int host_id, const AppCacheInfo& info) OVERRIDE {} | 39 int host_id, const AppCacheInfo& info) override {} |
| 40 | 40 |
| 41 virtual void OnStatusChanged(const std::vector<int>& host_ids, | 41 virtual void OnStatusChanged(const std::vector<int>& host_ids, |
| 42 AppCacheStatus status) OVERRIDE {} | 42 AppCacheStatus status) override {} |
| 43 | 43 |
| 44 virtual void OnEventRaised(const std::vector<int>& host_ids, | 44 virtual void OnEventRaised(const std::vector<int>& host_ids, |
| 45 AppCacheEventID event_id) OVERRIDE {} | 45 AppCacheEventID event_id) override {} |
| 46 | 46 |
| 47 virtual void OnErrorEventRaised( | 47 virtual void OnErrorEventRaised( |
| 48 const std::vector<int>& host_ids, | 48 const std::vector<int>& host_ids, |
| 49 const AppCacheErrorDetails& details) OVERRIDE {} | 49 const AppCacheErrorDetails& details) override {} |
| 50 | 50 |
| 51 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, | 51 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, |
| 52 const GURL& url, | 52 const GURL& url, |
| 53 int num_total, | 53 int num_total, |
| 54 int num_complete) OVERRIDE { | 54 int num_complete) override { |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void OnLogMessage(int host_id, | 57 virtual void OnLogMessage(int host_id, |
| 58 AppCacheLogLevel log_level, | 58 AppCacheLogLevel log_level, |
| 59 const std::string& message) OVERRIDE { | 59 const std::string& message) override { |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual void OnContentBlocked(int host_id, | 62 virtual void OnContentBlocked(int host_id, |
| 63 const GURL& manifest_url) OVERRIDE {} | 63 const GURL& manifest_url) override {} |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Helper callback to run a test on our io_thread. The io_thread is spun up | 66 // Helper callback to run a test on our io_thread. The io_thread is spun up |
| 67 // once and reused for all tests. | 67 // once and reused for all tests. |
| 68 template <class Method> | 68 template <class Method> |
| 69 void MethodWrapper(Method method) { | 69 void MethodWrapper(Method method) { |
| 70 SetUpTest(); | 70 SetUpTest(); |
| 71 (this->*method)(); | 71 (this->*method)(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Subclasses to simulate particular responses so test cases can | 74 // Subclasses to simulate particular responses so test cases can |
| 75 // exercise fallback code paths. | 75 // exercise fallback code paths. |
| 76 | 76 |
| 77 class MockURLRequestDelegate : public net::URLRequest::Delegate { | 77 class MockURLRequestDelegate : public net::URLRequest::Delegate { |
| 78 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {} | 78 virtual void OnResponseStarted(net::URLRequest* request) override {} |
| 79 virtual void OnReadCompleted(net::URLRequest* request, | 79 virtual void OnReadCompleted(net::URLRequest* request, |
| 80 int bytes_read) OVERRIDE { | 80 int bytes_read) override { |
| 81 } | 81 } |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 class MockURLRequestJob : public net::URLRequestJob { | 84 class MockURLRequestJob : public net::URLRequestJob { |
| 85 public: | 85 public: |
| 86 MockURLRequestJob(net::URLRequest* request, | 86 MockURLRequestJob(net::URLRequest* request, |
| 87 net::NetworkDelegate* network_delegate, | 87 net::NetworkDelegate* network_delegate, |
| 88 int response_code) | 88 int response_code) |
| 89 : net::URLRequestJob(request, network_delegate), | 89 : net::URLRequestJob(request, network_delegate), |
| 90 response_code_(response_code), | 90 response_code_(response_code), |
| 91 has_response_info_(false) {} | 91 has_response_info_(false) {} |
| 92 MockURLRequestJob(net::URLRequest* request, | 92 MockURLRequestJob(net::URLRequest* request, |
| 93 net::NetworkDelegate* network_delegate, | 93 net::NetworkDelegate* network_delegate, |
| 94 const net::HttpResponseInfo& info) | 94 const net::HttpResponseInfo& info) |
| 95 : net::URLRequestJob(request, network_delegate), | 95 : net::URLRequestJob(request, network_delegate), |
| 96 response_code_(info.headers->response_code()), | 96 response_code_(info.headers->response_code()), |
| 97 has_response_info_(true), | 97 has_response_info_(true), |
| 98 response_info_(info) {} | 98 response_info_(info) {} |
| 99 | 99 |
| 100 protected: | 100 protected: |
| 101 virtual ~MockURLRequestJob() {} | 101 virtual ~MockURLRequestJob() {} |
| 102 virtual void Start() OVERRIDE { | 102 virtual void Start() override { |
| 103 NotifyHeadersComplete(); | 103 NotifyHeadersComplete(); |
| 104 } | 104 } |
| 105 virtual int GetResponseCode() const OVERRIDE { | 105 virtual int GetResponseCode() const override { |
| 106 return response_code_; | 106 return response_code_; |
| 107 } | 107 } |
| 108 virtual void GetResponseInfo( | 108 virtual void GetResponseInfo( |
| 109 net::HttpResponseInfo* info) OVERRIDE { | 109 net::HttpResponseInfo* info) override { |
| 110 if (!has_response_info_) | 110 if (!has_response_info_) |
| 111 return; | 111 return; |
| 112 *info = response_info_; | 112 *info = response_info_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 int response_code_; | 116 int response_code_; |
| 117 bool has_response_info_; | 117 bool has_response_info_; |
| 118 net::HttpResponseInfo response_info_; | 118 net::HttpResponseInfo response_info_; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 class MockURLRequestJobFactory : public net::URLRequestJobFactory { | 121 class MockURLRequestJobFactory : public net::URLRequestJobFactory { |
| 122 public: | 122 public: |
| 123 MockURLRequestJobFactory() : job_(NULL) { | 123 MockURLRequestJobFactory() : job_(NULL) { |
| 124 } | 124 } |
| 125 | 125 |
| 126 virtual ~MockURLRequestJobFactory() { | 126 virtual ~MockURLRequestJobFactory() { |
| 127 DCHECK(!job_); | 127 DCHECK(!job_); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SetJob(net::URLRequestJob* job) { | 130 void SetJob(net::URLRequestJob* job) { |
| 131 job_ = job; | 131 job_ = job; |
| 132 } | 132 } |
| 133 | 133 |
| 134 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | 134 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 135 const std::string& scheme, | 135 const std::string& scheme, |
| 136 net::URLRequest* request, | 136 net::URLRequest* request, |
| 137 net::NetworkDelegate* network_delegate) const OVERRIDE { | 137 net::NetworkDelegate* network_delegate) const override { |
| 138 if (job_) { | 138 if (job_) { |
| 139 net::URLRequestJob* temp = job_; | 139 net::URLRequestJob* temp = job_; |
| 140 job_ = NULL; | 140 job_ = NULL; |
| 141 return temp; | 141 return temp; |
| 142 } else { | 142 } else { |
| 143 // Some of these tests trigger UpdateJobs which start URLRequests. | 143 // Some of these tests trigger UpdateJobs which start URLRequests. |
| 144 // We short circuit those be returning error jobs. | 144 // We short circuit those be returning error jobs. |
| 145 return new net::URLRequestErrorJob(request, | 145 return new net::URLRequestErrorJob(request, |
| 146 network_delegate, | 146 network_delegate, |
| 147 net::ERR_INTERNET_DISCONNECTED); | 147 net::ERR_INTERNET_DISCONNECTED); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE { | 151 virtual bool IsHandledProtocol(const std::string& scheme) const override { |
| 152 return scheme == "http"; | 152 return scheme == "http"; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 virtual bool IsHandledURL(const GURL& url) const OVERRIDE { | 155 virtual bool IsHandledURL(const GURL& url) const override { |
| 156 return url.SchemeIs("http"); | 156 return url.SchemeIs("http"); |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE { | 159 virtual bool IsSafeRedirectTarget(const GURL& location) const override { |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 private: | 163 private: |
| 164 mutable net::URLRequestJob* job_; | 164 mutable net::URLRequestJob* job_; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 static void SetUpTestCase() { | 167 static void SetUpTestCase() { |
| 168 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); | 168 io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); |
| 169 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 169 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 1002 |
| 1003 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { | 1003 TEST_F(AppCacheRequestHandlerTest, WorkerRequest) { |
| 1004 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); | 1004 RunTestOnIOThread(&AppCacheRequestHandlerTest::WorkerRequest); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { | 1007 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { |
| 1008 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); | 1008 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 } // namespace content | 1011 } // namespace content |
| OLD | NEW |