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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 21 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
22 #include "content/browser/fileapi/mock_url_request_delegate.h" | 22 #include "content/browser/fileapi/mock_url_request_delegate.h" |
23 #include "content/browser/quota/mock_quota_manager_proxy.h" | 23 #include "content/browser/quota/mock_quota_manager_proxy.h" |
24 #include "content/common/cache_storage/cache_storage_types.h" | 24 #include "content/common/cache_storage/cache_storage_types.h" |
25 #include "content/common/service_worker/service_worker_types.h" | 25 #include "content/common/service_worker/service_worker_types.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/storage_partition.h" | |
28 #include "content/public/common/referrer.h" | 27 #include "content/public/common/referrer.h" |
29 #include "content/public/test/mock_special_storage_policy.h" | 28 #include "content/public/test/mock_special_storage_policy.h" |
30 #include "content/public/test/test_browser_context.h" | 29 #include "content/public/test/test_browser_context.h" |
31 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
32 #include "net/base/test_completion_callback.h" | 31 #include "net/base/test_completion_callback.h" |
33 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
34 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
35 #include "net/url_request/url_request_job_factory_impl.h" | 34 #include "net/url_request/url_request_job_factory_impl.h" |
36 #include "storage/browser/blob/blob_data_builder.h" | 35 #include "storage/browser/blob/blob_data_builder.h" |
37 #include "storage/browser/blob/blob_data_handle.h" | 36 #include "storage/browser/blob/blob_data_handle.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 1024 * 1024 * 100); | 298 1024 * 1024 * 100); |
300 | 299 |
301 quota_manager_proxy_ = new MockQuotaManagerProxy( | 300 quota_manager_proxy_ = new MockQuotaManagerProxy( |
302 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); | 301 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); |
303 | 302 |
304 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 303 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
305 url_request_job_factory_->SetProtocolHandler( | 304 url_request_job_factory_->SetProtocolHandler( |
306 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); | 305 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); |
307 | 306 |
308 net::URLRequestContext* url_request_context = | 307 net::URLRequestContext* url_request_context = |
309 BrowserContext::GetDefaultStoragePartition(&browser_context_)-> | 308 browser_context_.GetRequestContext()->GetURLRequestContext(); |
310 GetURLRequestContext()->GetURLRequestContext(); | |
311 | 309 |
312 url_request_context->set_job_factory(url_request_job_factory_.get()); | 310 url_request_context->set_job_factory(url_request_job_factory_.get()); |
313 | 311 |
314 CreateRequests(blob_storage_context); | 312 CreateRequests(blob_storage_context); |
315 | 313 |
316 cache_ = make_scoped_refptr(new TestCacheStorageCache( | 314 cache_ = make_scoped_refptr(new TestCacheStorageCache( |
317 GURL(kOrigin), kCacheName, temp_dir_.path(), | 315 GURL(kOrigin), kCacheName, temp_dir_.path(), |
318 BrowserContext::GetDefaultStoragePartition(&browser_context_)-> | 316 browser_context_.GetRequestContext(), quota_manager_proxy_, |
319 GetURLRequestContext(), | 317 blob_storage_context->context()->AsWeakPtr())); |
320 quota_manager_proxy_, blob_storage_context->context()->AsWeakPtr())); | |
321 } | 318 } |
322 | 319 |
323 void TearDown() override { | 320 void TearDown() override { |
324 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 321 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
325 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
326 } | 323 } |
327 | 324 |
328 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { | 325 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { |
329 ServiceWorkerHeaderMap headers; | 326 ServiceWorkerHeaderMap headers; |
330 headers.insert(std::make_pair("a", "a")); | 327 headers.insert(std::make_pair("a", "a")); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); | 590 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); |
594 EXPECT_FALSE(Match(no_body_request_)); | 591 EXPECT_FALSE(Match(no_body_request_)); |
595 EXPECT_FALSE(Delete(body_request_)); | 592 EXPECT_FALSE(Delete(body_request_)); |
596 EXPECT_FALSE(Keys()); | 593 EXPECT_FALSE(Keys()); |
597 } | 594 } |
598 | 595 |
599 virtual bool MemoryOnly() { return false; } | 596 virtual bool MemoryOnly() { return false; } |
600 | 597 |
601 protected: | 598 protected: |
602 base::ScopedTempDir temp_dir_; | 599 base::ScopedTempDir temp_dir_; |
| 600 TestBrowserContext browser_context_; |
603 TestBrowserThreadBundle browser_thread_bundle_; | 601 TestBrowserThreadBundle browser_thread_bundle_; |
604 TestBrowserContext browser_context_; | |
605 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; | 602 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; |
606 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; | 603 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; |
607 scoped_refptr<MockQuotaManager> mock_quota_manager_; | 604 scoped_refptr<MockQuotaManager> mock_quota_manager_; |
608 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 605 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
609 storage::BlobStorageContext* blob_storage_context_; | 606 storage::BlobStorageContext* blob_storage_context_; |
610 | 607 |
611 scoped_refptr<TestCacheStorageCache> cache_; | 608 scoped_refptr<TestCacheStorageCache> cache_; |
612 | 609 |
613 ServiceWorkerFetchRequest body_request_; | 610 ServiceWorkerFetchRequest body_request_; |
614 ServiceWorkerResponse body_response_; | 611 ServiceWorkerResponse body_response_; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 EXPECT_EQ(1, sequence_out); | 1209 EXPECT_EQ(1, sequence_out); |
1213 close_loop2->Run(); | 1210 close_loop2->Run(); |
1214 EXPECT_EQ(2, sequence_out); | 1211 EXPECT_EQ(2, sequence_out); |
1215 } | 1212 } |
1216 | 1213 |
1217 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1214 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1218 CacheStorageCacheTestP, | 1215 CacheStorageCacheTestP, |
1219 ::testing::Values(false, true)); | 1216 ::testing::Values(false, true)); |
1220 | 1217 |
1221 } // namespace content | 1218 } // namespace content |
OLD | NEW |