| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 public: | 52 public: |
| 53 MockHttpProtocolHandler( | 53 MockHttpProtocolHandler( |
| 54 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 54 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 55 base::WeakPtr<storage::BlobStorageContext> blob_storage_context) | 55 base::WeakPtr<storage::BlobStorageContext> blob_storage_context) |
| 56 : provider_host_(provider_host), | 56 : provider_host_(provider_host), |
| 57 blob_storage_context_(blob_storage_context) {} | 57 blob_storage_context_(blob_storage_context) {} |
| 58 virtual ~MockHttpProtocolHandler() {} | 58 virtual ~MockHttpProtocolHandler() {} |
| 59 | 59 |
| 60 virtual net::URLRequestJob* MaybeCreateJob( | 60 virtual net::URLRequestJob* MaybeCreateJob( |
| 61 net::URLRequest* request, | 61 net::URLRequest* request, |
| 62 net::NetworkDelegate* network_delegate) const OVERRIDE { | 62 net::NetworkDelegate* network_delegate) const override { |
| 63 ServiceWorkerURLRequestJob* job = | 63 ServiceWorkerURLRequestJob* job = |
| 64 new ServiceWorkerURLRequestJob(request, | 64 new ServiceWorkerURLRequestJob(request, |
| 65 network_delegate, | 65 network_delegate, |
| 66 provider_host_, | 66 provider_host_, |
| 67 blob_storage_context_, | 67 blob_storage_context_, |
| 68 FETCH_REQUEST_MODE_NO_CORS, | 68 FETCH_REQUEST_MODE_NO_CORS, |
| 69 FETCH_CREDENTIALS_MODE_OMIT, | 69 FETCH_CREDENTIALS_MODE_OMIT, |
| 70 REQUEST_CONTEXT_TYPE_HYPERLINK, | 70 REQUEST_CONTEXT_TYPE_HYPERLINK, |
| 71 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, | 71 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, |
| 72 scoped_refptr<ResourceRequestBody>()); | 72 scoped_refptr<ResourceRequestBody>()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 class ServiceWorkerURLRequestJobTest : public testing::Test { | 94 class ServiceWorkerURLRequestJobTest : public testing::Test { |
| 95 protected: | 95 protected: |
| 96 ServiceWorkerURLRequestJobTest() | 96 ServiceWorkerURLRequestJobTest() |
| 97 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 97 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 98 blob_data_(new storage::BlobData("blob-id:myblob")) {} | 98 blob_data_(new storage::BlobData("blob-id:myblob")) {} |
| 99 virtual ~ServiceWorkerURLRequestJobTest() {} | 99 virtual ~ServiceWorkerURLRequestJobTest() {} |
| 100 | 100 |
| 101 virtual void SetUp() OVERRIDE { | 101 virtual void SetUp() override { |
| 102 browser_context_.reset(new TestBrowserContext); | 102 browser_context_.reset(new TestBrowserContext); |
| 103 SetUpWithHelper(new EmbeddedWorkerTestHelper(kProcessID)); | 103 SetUpWithHelper(new EmbeddedWorkerTestHelper(kProcessID)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper) { | 106 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper) { |
| 107 helper_.reset(helper); | 107 helper_.reset(helper); |
| 108 | 108 |
| 109 registration_ = new ServiceWorkerRegistration( | 109 registration_ = new ServiceWorkerRegistration( |
| 110 GURL("http://example.com/"), | 110 GURL("http://example.com/"), |
| 111 1L, | 111 1L, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 "http", | 134 "http", |
| 135 new MockHttpProtocolHandler(provider_host->AsWeakPtr(), | 135 new MockHttpProtocolHandler(provider_host->AsWeakPtr(), |
| 136 blob_storage_context->AsWeakPtr())); | 136 blob_storage_context->AsWeakPtr())); |
| 137 url_request_job_factory_->SetProtocolHandler( | 137 url_request_job_factory_->SetProtocolHandler( |
| 138 "blob", CreateMockBlobProtocolHandler(blob_storage_context)); | 138 "blob", CreateMockBlobProtocolHandler(blob_storage_context)); |
| 139 url_request_context_.set_job_factory(url_request_job_factory_.get()); | 139 url_request_context_.set_job_factory(url_request_job_factory_.get()); |
| 140 | 140 |
| 141 helper_->context()->AddProviderHost(provider_host.Pass()); | 141 helper_->context()->AddProviderHost(provider_host.Pass()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 virtual void TearDown() OVERRIDE { | 144 virtual void TearDown() override { |
| 145 version_ = NULL; | 145 version_ = NULL; |
| 146 registration_ = NULL; | 146 registration_ = NULL; |
| 147 helper_.reset(); | 147 helper_.reset(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void TestRequest(int expected_status_code, | 150 void TestRequest(int expected_status_code, |
| 151 const std::string& expected_status_text, | 151 const std::string& expected_status_text, |
| 152 const std::string& expected_response) { | 152 const std::string& expected_response) { |
| 153 request_ = url_request_context_.CreateRequest( | 153 request_ = url_request_context_.CreateRequest( |
| 154 GURL("http://example.com/foo.html"), | 154 GURL("http://example.com/foo.html"), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 class BlobResponder : public EmbeddedWorkerTestHelper { | 194 class BlobResponder : public EmbeddedWorkerTestHelper { |
| 195 public: | 195 public: |
| 196 BlobResponder(int mock_render_process_id, const std::string& blob_uuid) | 196 BlobResponder(int mock_render_process_id, const std::string& blob_uuid) |
| 197 : EmbeddedWorkerTestHelper(mock_render_process_id), | 197 : EmbeddedWorkerTestHelper(mock_render_process_id), |
| 198 blob_uuid_(blob_uuid) {} | 198 blob_uuid_(blob_uuid) {} |
| 199 virtual ~BlobResponder() {} | 199 virtual ~BlobResponder() {} |
| 200 | 200 |
| 201 protected: | 201 protected: |
| 202 virtual void OnFetchEvent(int embedded_worker_id, | 202 virtual void OnFetchEvent(int embedded_worker_id, |
| 203 int request_id, | 203 int request_id, |
| 204 const ServiceWorkerFetchRequest& request) OVERRIDE { | 204 const ServiceWorkerFetchRequest& request) override { |
| 205 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( | 205 SimulateSend(new ServiceWorkerHostMsg_FetchEventFinished( |
| 206 embedded_worker_id, | 206 embedded_worker_id, |
| 207 request_id, | 207 request_id, |
| 208 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, | 208 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, |
| 209 ServiceWorkerResponse(GURL(""), | 209 ServiceWorkerResponse(GURL(""), |
| 210 200, | 210 200, |
| 211 "OK", | 211 "OK", |
| 212 blink::WebServiceWorkerResponseTypeDefault, | 212 blink::WebServiceWorkerResponseTypeDefault, |
| 213 ServiceWorkerHeaderMap(), | 213 ServiceWorkerHeaderMap(), |
| 214 blob_uuid_))); | 214 blob_uuid_))); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 239 TEST_F(ServiceWorkerURLRequestJobTest, NonExistentBlobUUIDResponse) { | 239 TEST_F(ServiceWorkerURLRequestJobTest, NonExistentBlobUUIDResponse) { |
| 240 SetUpWithHelper(new BlobResponder(kProcessID, "blob-id:nothing-is-here")); | 240 SetUpWithHelper(new BlobResponder(kProcessID, "blob-id:nothing-is-here")); |
| 241 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 241 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 242 TestRequest(500, "Service Worker Response Error", std::string()); | 242 TestRequest(500, "Service Worker Response Error", std::string()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // TODO(kinuko): Add more tests with different response data and also for | 245 // TODO(kinuko): Add more tests with different response data and also for |
| 246 // FallbackToNetwork case. | 246 // FallbackToNetwork case. |
| 247 | 247 |
| 248 } // namespace content | 248 } // namespace content |
| OLD | NEW |