| 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 "content/browser/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | |
| 10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 11 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 12 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 13 #include "content/browser/fileapi/mock_url_request_delegate.h" | 13 #include "content/browser/fileapi/mock_url_request_delegate.h" |
| 14 #include "content/browser/quota/mock_quota_manager_proxy.h" | 14 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 15 #include "content/common/cache_storage/cache_storage_types.h" | 15 #include "content/common/cache_storage/cache_storage_types.h" |
| 16 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 19 #include "content/public/test/test_browser_context.h" | 19 #include "content/public/test/test_browser_context.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "net/url_request/url_request_job_factory_impl.h" | 23 #include "net/url_request/url_request_job_factory_impl.h" |
| 24 #include "storage/browser/blob/blob_data_builder.h" | 24 #include "storage/browser/blob/blob_data_builder.h" |
| 25 #include "storage/browser/blob/blob_data_handle.h" | 25 #include "storage/browser/blob/blob_data_handle.h" |
| 26 #include "storage/browser/blob/blob_data_snapshot.h" | 26 #include "storage/browser/blob/blob_data_snapshot.h" |
| 27 #include "storage/browser/blob/blob_storage_context.h" | 27 #include "storage/browser/blob/blob_storage_context.h" |
| 28 #include "storage/browser/blob/blob_url_request_job_factory.h" | 28 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 29 #include "storage/browser/quota/quota_manager_proxy.h" | 29 #include "storage/browser/quota/quota_manager_proxy.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 const char kTestData[] = "Hello World"; | 35 const char kTestData[] = "Hello World"; |
| 36 | 36 |
| 37 // Returns a BlobProtocolHandler that uses |blob_storage_context|. Caller owns | 37 // Returns a BlobProtocolHandler that uses |blob_storage_context|. Caller owns |
| 38 // the memory. | 38 // the memory. |
| 39 storage::BlobProtocolHandler* CreateMockBlobProtocolHandler( | 39 storage::BlobProtocolHandler* CreateMockBlobProtocolHandler( |
| 40 storage::BlobStorageContext* blob_storage_context) { | 40 storage::BlobStorageContext* blob_storage_context) { |
| 41 // The FileSystemContext and MessageLoopProxy are not actually used but a | 41 // The FileSystemContext and thread task runner are not actually used but a |
| 42 // MessageLoopProxy is needed to avoid a DCHECK in BlobURLRequestJob ctor. | 42 // task runner is needed to avoid a DCHECK in BlobURLRequestJob ctor. |
| 43 return new storage::BlobProtocolHandler( | 43 return new storage::BlobProtocolHandler( |
| 44 blob_storage_context, NULL, base::MessageLoopProxy::current().get()); | 44 blob_storage_context, NULL, base::ThreadTaskRunnerHandle::Get().get()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // A disk_cache::Backend wrapper that can delay operations. | 47 // A disk_cache::Backend wrapper that can delay operations. |
| 48 class DelayableBackend : public disk_cache::Backend { | 48 class DelayableBackend : public disk_cache::Backend { |
| 49 public: | 49 public: |
| 50 DelayableBackend(scoped_ptr<disk_cache::Backend> backend) | 50 DelayableBackend(scoped_ptr<disk_cache::Backend> backend) |
| 51 : backend_(backend.Pass()), delay_open_(false) {} | 51 : backend_(backend.Pass()), delay_open_(false) {} |
| 52 | 52 |
| 53 // disk_cache::Backend overrides | 53 // disk_cache::Backend overrides |
| 54 net::CacheType GetCacheType() const override { | 54 net::CacheType GetCacheType() const override { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 callback_closed_(false) {} | 179 callback_closed_(false) {} |
| 180 | 180 |
| 181 void SetUp() override { | 181 void SetUp() override { |
| 182 ChromeBlobStorageContext* blob_storage_context = | 182 ChromeBlobStorageContext* blob_storage_context = |
| 183 ChromeBlobStorageContext::GetFor(&browser_context_); | 183 ChromeBlobStorageContext::GetFor(&browser_context_); |
| 184 // Wait for chrome_blob_storage_context to finish initializing. | 184 // Wait for chrome_blob_storage_context to finish initializing. |
| 185 base::RunLoop().RunUntilIdle(); | 185 base::RunLoop().RunUntilIdle(); |
| 186 blob_storage_context_ = blob_storage_context->context(); | 186 blob_storage_context_ = blob_storage_context->context(); |
| 187 | 187 |
| 188 quota_manager_proxy_ = new MockQuotaManagerProxy( | 188 quota_manager_proxy_ = new MockQuotaManagerProxy( |
| 189 nullptr, base::MessageLoopProxy::current().get()); | 189 nullptr, base::ThreadTaskRunnerHandle::Get().get()); |
| 190 | 190 |
| 191 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 191 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| 192 url_request_job_factory_->SetProtocolHandler( | 192 url_request_job_factory_->SetProtocolHandler( |
| 193 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); | 193 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); |
| 194 | 194 |
| 195 net::URLRequestContext* url_request_context = | 195 net::URLRequestContext* url_request_context = |
| 196 browser_context_.GetRequestContext()->GetURLRequestContext(); | 196 browser_context_.GetRequestContext()->GetURLRequestContext(); |
| 197 | 197 |
| 198 url_request_context->set_job_factory(url_request_job_factory_.get()); | 198 url_request_context->set_job_factory(url_request_job_factory_.get()); |
| 199 | 199 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 CacheStorageError BatchOperation( | 255 CacheStorageError BatchOperation( |
| 256 const std::vector<CacheStorageBatchOperation>& operations) { | 256 const std::vector<CacheStorageBatchOperation>& operations) { |
| 257 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 257 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
| 258 | 258 |
| 259 cache_->BatchOperation( | 259 cache_->BatchOperation( |
| 260 operations, | 260 operations, |
| 261 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, | 261 base::Bind(&CacheStorageCacheTest::ErrorTypeCallback, |
| 262 base::Unretained(this), base::Unretained(loop.get()))); | 262 base::Unretained(this), base::Unretained(loop.get()))); |
| 263 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() | 263 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() |
| 264 // once the cache uses a passed in MessageLoopProxy instead of the CACHE | 264 // once the cache uses a passed in task runner instead of the CACHE thread. |
| 265 // thread. | |
| 266 loop->Run(); | 265 loop->Run(); |
| 267 | 266 |
| 268 return callback_error_; | 267 return callback_error_; |
| 269 } | 268 } |
| 270 | 269 |
| 271 bool Put(const ServiceWorkerFetchRequest& request, | 270 bool Put(const ServiceWorkerFetchRequest& request, |
| 272 const ServiceWorkerResponse& response) { | 271 const ServiceWorkerResponse& response) { |
| 273 CacheStorageBatchOperation operation; | 272 CacheStorageBatchOperation operation; |
| 274 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 273 operation.operation_type = CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
| 275 operation.request = request; | 274 operation.request = request; |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 EXPECT_EQ(1, sequence_out); | 861 EXPECT_EQ(1, sequence_out); |
| 863 close_loop2->Run(); | 862 close_loop2->Run(); |
| 864 EXPECT_EQ(2, sequence_out); | 863 EXPECT_EQ(2, sequence_out); |
| 865 } | 864 } |
| 866 | 865 |
| 867 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 866 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
| 868 CacheStorageCacheTestP, | 867 CacheStorageCacheTestP, |
| 869 ::testing::Values(false, true)); | 868 ::testing::Values(false, true)); |
| 870 | 869 |
| 871 } // namespace content | 870 } // namespace content |
| OLD | NEW |