Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job_unittest.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed copyright Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 #include "content/public/common/resource_type.h" 29 #include "content/public/common/resource_type.h"
30 #include "content/public/test/mock_resource_context.h" 30 #include "content/public/test/mock_resource_context.h"
31 #include "content/public/test/test_browser_context.h" 31 #include "content/public/test/test_browser_context.h"
32 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "net/base/io_buffer.h" 33 #include "net/base/io_buffer.h"
34 #include "net/http/http_request_headers.h" 34 #include "net/http/http_request_headers.h"
35 #include "net/http/http_response_headers.h" 35 #include "net/http/http_response_headers.h"
36 #include "net/url_request/url_request.h" 36 #include "net/url_request/url_request.h"
37 #include "net/url_request/url_request_context.h" 37 #include "net/url_request/url_request_context.h"
38 #include "net/url_request/url_request_job_factory_impl.h" 38 #include "net/url_request/url_request_job_factory_impl.h"
39 #include "storage/browser/blob/blob_data_builder.h"
39 #include "storage/browser/blob/blob_storage_context.h" 40 #include "storage/browser/blob/blob_storage_context.h"
40 #include "storage/browser/blob/blob_url_request_job.h" 41 #include "storage/browser/blob/blob_url_request_job.h"
41 #include "storage/browser/blob/blob_url_request_job_factory.h" 42 #include "storage/browser/blob/blob_url_request_job_factory.h"
42 #include "storage/common/blob/blob_data.h"
43 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
44 44
45 namespace content { 45 namespace content {
46 46
47 class ServiceWorkerURLRequestJobTest; 47 class ServiceWorkerURLRequestJobTest;
48 48
49 namespace { 49 namespace {
50 50
51 const int kProcessID = 1; 51 const int kProcessID = 1;
52 const int kProviderID = 100; 52 const int kProviderID = 100;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::BlobDataHandle> 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698