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_manager.h" | 5 #include "content/browser/cache_storage/cache_storage_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/guid.h" | 14 #include "base/guid.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/sha1.h" | 17 #include "base/sha1.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "content/browser/cache_storage/cache_storage.pb.h" | 21 #include "content/browser/cache_storage/cache_storage.pb.h" |
22 #include "content/browser/cache_storage/cache_storage_quota_client.h" | 22 #include "content/browser/cache_storage/cache_storage_quota_client.h" |
23 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 23 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
24 #include "content/browser/quota/mock_quota_manager_proxy.h" | 24 #include "content/browser/quota/mock_quota_manager_proxy.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/cache_storage_usage_info.h" | 26 #include "content/public/browser/cache_storage_usage_info.h" |
27 #include "content/public/test/mock_special_storage_policy.h" | |
27 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
30 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
31 #include "net/url_request/url_request_job_factory_impl.h" | 32 #include "net/url_request/url_request_job_factory_impl.h" |
32 #include "storage/browser/blob/blob_data_builder.h" | 33 #include "storage/browser/blob/blob_data_builder.h" |
33 #include "storage/browser/blob/blob_data_handle.h" | 34 #include "storage/browser/blob/blob_data_handle.h" |
34 #include "storage/browser/blob/blob_storage_context.h" | 35 #include "storage/browser/blob/blob_storage_context.h" |
35 #include "storage/browser/blob/blob_url_request_job_factory.h" | 36 #include "storage/browser/blob/blob_url_request_job_factory.h" |
36 #include "storage/browser/quota/quota_manager_proxy.h" | 37 #include "storage/browser/quota/quota_manager_proxy.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 69 |
69 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 70 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
70 url_request_job_factory_->SetProtocolHandler( | 71 url_request_job_factory_->SetProtocolHandler( |
71 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); | 72 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); |
72 | 73 |
73 net::URLRequestContext* url_request_context = | 74 net::URLRequestContext* url_request_context = |
74 browser_context_.GetRequestContext()->GetURLRequestContext(); | 75 browser_context_.GetRequestContext()->GetURLRequestContext(); |
75 | 76 |
76 url_request_context->set_job_factory(url_request_job_factory_.get()); | 77 url_request_context->set_job_factory(url_request_job_factory_.get()); |
77 | 78 |
79 if (!MemoryOnly()) | |
80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
81 base::FilePath path = MemoryOnly() ? base::FilePath() : temp_dir_.path(); | |
82 | |
83 quota_policy_ = new MockSpecialStoragePolicy; | |
84 mock_quota_manager_ = new MockQuotaManager( | |
85 MemoryOnly() /* is incognito */, path, | |
michaeln
2016/01/26 00:16:08
not sure you really need the |path| local? temp_di
jkarlin
2016/01/26 12:08:35
Done. Also in cache_storage_cache_unittest.cc
| |
86 base::ThreadTaskRunnerHandle::Get().get(), | |
87 base::ThreadTaskRunnerHandle::Get().get(), quota_policy_.get()); | |
78 quota_manager_proxy_ = new MockQuotaManagerProxy( | 88 quota_manager_proxy_ = new MockQuotaManagerProxy( |
79 nullptr, base::ThreadTaskRunnerHandle::Get().get()); | 89 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); |
80 | 90 |
81 if (MemoryOnly()) { | 91 cache_manager_ = CacheStorageManager::Create( |
82 cache_manager_ = CacheStorageManager::Create( | 92 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), |
83 base::FilePath(), base::ThreadTaskRunnerHandle::Get(), | 93 quota_manager_proxy_); |
84 quota_manager_proxy_); | |
85 } else { | |
86 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
87 cache_manager_ = CacheStorageManager::Create( | |
88 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), | |
89 quota_manager_proxy_); | |
90 } | |
91 | 94 |
92 cache_manager_->SetBlobParametersForCache( | 95 cache_manager_->SetBlobParametersForCache( |
93 browser_context_.GetRequestContext(), | 96 browser_context_.GetRequestContext(), |
94 blob_storage_context->context()->AsWeakPtr()); | 97 blob_storage_context->context()->AsWeakPtr()); |
95 } | 98 } |
96 | 99 |
97 void TearDown() override { | 100 void TearDown() override { |
98 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 101 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
99 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
100 } | 103 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 303 |
301 protected: | 304 protected: |
302 // Temporary directory must be allocated first so as to be destroyed last. | 305 // Temporary directory must be allocated first so as to be destroyed last. |
303 base::ScopedTempDir temp_dir_; | 306 base::ScopedTempDir temp_dir_; |
304 | 307 |
305 TestBrowserContext browser_context_; | 308 TestBrowserContext browser_context_; |
306 TestBrowserThreadBundle browser_thread_bundle_; | 309 TestBrowserThreadBundle browser_thread_bundle_; |
307 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; | 310 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; |
308 storage::BlobStorageContext* blob_storage_context_; | 311 storage::BlobStorageContext* blob_storage_context_; |
309 | 312 |
313 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; | |
314 scoped_refptr<MockQuotaManager> mock_quota_manager_; | |
310 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 315 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
311 scoped_ptr<CacheStorageManager> cache_manager_; | 316 scoped_ptr<CacheStorageManager> cache_manager_; |
312 | 317 |
313 scoped_refptr<CacheStorageCache> callback_cache_; | 318 scoped_refptr<CacheStorageCache> callback_cache_; |
314 int callback_bool_; | 319 int callback_bool_; |
315 CacheStorageError callback_error_; | 320 CacheStorageError callback_error_; |
316 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; | 321 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; |
317 scoped_ptr<storage::BlobDataHandle> callback_data_handle_; | 322 scoped_ptr<storage::BlobDataHandle> callback_data_handle_; |
318 std::vector<std::string> callback_strings_; | 323 std::vector<std::string> callback_strings_; |
319 | 324 |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 | 1000 |
996 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1001 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
997 CacheStorageManagerTestP, | 1002 CacheStorageManagerTestP, |
998 ::testing::Values(false, true)); | 1003 ::testing::Values(false, true)); |
999 | 1004 |
1000 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1005 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
1001 CacheStorageQuotaClientTestP, | 1006 CacheStorageQuotaClientTestP, |
1002 ::testing::Values(false, true)); | 1007 ::testing::Values(false, true)); |
1003 | 1008 |
1004 } // namespace content | 1009 } // namespace content |
OLD | NEW |