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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return new storage::BlobProtocolHandler( | 97 return new storage::BlobProtocolHandler( |
98 blob_storage_context, nullptr, base::MessageLoopProxy::current().get()); | 98 blob_storage_context, nullptr, base::MessageLoopProxy::current().get()); |
99 } | 99 } |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 class ServiceWorkerURLRequestJobTest : public testing::Test { | 103 class ServiceWorkerURLRequestJobTest : public testing::Test { |
104 protected: | 104 protected: |
105 ServiceWorkerURLRequestJobTest() | 105 ServiceWorkerURLRequestJobTest() |
106 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 106 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
107 blob_data_(new storage::BlobData("blob-id:myblob")) {} | 107 blob_data_(new storage::BlobDataBuilder("blob-id:myblob")) {} |
108 ~ServiceWorkerURLRequestJobTest() override {} | 108 ~ServiceWorkerURLRequestJobTest() override {} |
109 | 109 |
110 void SetUp() override { | 110 void SetUp() override { |
111 browser_context_.reset(new TestBrowserContext); | 111 browser_context_.reset(new TestBrowserContext); |
112 InitializeResourceContext(browser_context_.get()); | 112 InitializeResourceContext(browser_context_.get()); |
113 SetUpWithHelper(new EmbeddedWorkerTestHelper(kProcessID)); | 113 SetUpWithHelper(new EmbeddedWorkerTestHelper(kProcessID)); |
114 } | 114 } |
115 | 115 |
116 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper) { | 116 void SetUpWithHelper(EmbeddedWorkerTestHelper* helper) { |
117 helper_.reset(helper); | 117 helper_.reset(helper); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 scoped_ptr<TestBrowserContext> browser_context_; | 191 scoped_ptr<TestBrowserContext> browser_context_; |
192 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 192 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
193 scoped_refptr<ServiceWorkerRegistration> registration_; | 193 scoped_refptr<ServiceWorkerRegistration> registration_; |
194 scoped_refptr<ServiceWorkerVersion> version_; | 194 scoped_refptr<ServiceWorkerVersion> version_; |
195 | 195 |
196 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; | 196 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; |
197 net::URLRequestContext url_request_context_; | 197 net::URLRequestContext url_request_context_; |
198 MockURLRequestDelegate url_request_delegate_; | 198 MockURLRequestDelegate url_request_delegate_; |
199 scoped_ptr<net::URLRequest> request_; | 199 scoped_ptr<net::URLRequest> request_; |
200 | 200 |
201 scoped_refptr<storage::BlobData> blob_data_; | 201 scoped_ptr<storage::BlobDataBuilder> blob_data_; |
202 | 202 |
203 private: | 203 private: |
204 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJobTest); | 204 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJobTest); |
205 }; | 205 }; |
206 | 206 |
207 TEST_F(ServiceWorkerURLRequestJobTest, Simple) { | 207 TEST_F(ServiceWorkerURLRequestJobTest, Simple) { |
208 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 208 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
209 TestRequest(200, "OK", std::string()); | 209 TestRequest(200, "OK", std::string()); |
210 } | 210 } |
211 | 211 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 247 |
248 TEST_F(ServiceWorkerURLRequestJobTest, BlobResponse) { | 248 TEST_F(ServiceWorkerURLRequestJobTest, BlobResponse) { |
249 ChromeBlobStorageContext* blob_storage_context = | 249 ChromeBlobStorageContext* blob_storage_context = |
250 ChromeBlobStorageContext::GetFor(browser_context_.get()); | 250 ChromeBlobStorageContext::GetFor(browser_context_.get()); |
251 std::string expected_response; | 251 std::string expected_response; |
252 expected_response.reserve((sizeof(kTestData) - 1) * 1024); | 252 expected_response.reserve((sizeof(kTestData) - 1) * 1024); |
253 for (int i = 0; i < 1024; ++i) { | 253 for (int i = 0; i < 1024; ++i) { |
254 blob_data_->AppendData(kTestData); | 254 blob_data_->AppendData(kTestData); |
255 expected_response += kTestData; | 255 expected_response += kTestData; |
256 } | 256 } |
257 scoped_ptr<storage::BlobDataHandle> blob_handle = | 257 scoped_ptr<storage::BlobDataSnapshotHandle> blob_handle = |
258 blob_storage_context->context()->AddFinishedBlob(blob_data_.get()); | 258 blob_storage_context->context()->AddFinishedBlob(*blob_data_.get()); |
259 SetUpWithHelper(new BlobResponder( | 259 SetUpWithHelper(new BlobResponder( |
260 kProcessID, blob_handle->uuid(), expected_response.size())); | 260 kProcessID, blob_handle->uuid(), expected_response.size())); |
261 | 261 |
262 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 262 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
263 TestRequest(200, "OK", expected_response); | 263 TestRequest(200, "OK", expected_response); |
264 } | 264 } |
265 | 265 |
266 TEST_F(ServiceWorkerURLRequestJobTest, NonExistentBlobUUIDResponse) { | 266 TEST_F(ServiceWorkerURLRequestJobTest, NonExistentBlobUUIDResponse) { |
267 SetUpWithHelper(new BlobResponder(kProcessID, "blob-id:nothing-is-here", 0)); | 267 SetUpWithHelper(new BlobResponder(kProcessID, "blob-id:nothing-is-here", 0)); |
268 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 268 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 stream->Finalize(); | 528 stream->Finalize(); |
529 | 529 |
530 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
531 EXPECT_FALSE(request_->status().is_success()); | 531 EXPECT_FALSE(request_->status().is_success()); |
532 } | 532 } |
533 | 533 |
534 // TODO(kinuko): Add more tests with different response data and also for | 534 // TODO(kinuko): Add more tests with different response data and also for |
535 // FallbackToNetwork case. | 535 // FallbackToNetwork case. |
536 | 536 |
537 } // namespace content | 537 } // namespace content |
OLD | NEW |