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

Side by Side Diff: content/browser/cache_storage/cache_storage_manager_unittest.cc

Issue 1864583006: Simplify BrowserContext by removing redundant methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 8 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 "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 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/sha1.h" 19 #include "base/sha1.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
23 #include "content/browser/cache_storage/cache_storage.pb.h" 23 #include "content/browser/cache_storage/cache_storage.pb.h"
24 #include "content/browser/cache_storage/cache_storage_quota_client.h" 24 #include "content/browser/cache_storage/cache_storage_quota_client.h"
25 #include "content/browser/fileapi/chrome_blob_storage_context.h" 25 #include "content/browser/fileapi/chrome_blob_storage_context.h"
26 #include "content/browser/quota/mock_quota_manager_proxy.h" 26 #include "content/browser/quota/mock_quota_manager_proxy.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/cache_storage_usage_info.h" 28 #include "content/public/browser/cache_storage_usage_info.h"
29 #include "content/public/browser/storage_partition.h"
29 #include "content/public/test/mock_special_storage_policy.h" 30 #include "content/public/test/mock_special_storage_policy.h"
30 #include "content/public/test/test_browser_context.h" 31 #include "content/public/test/test_browser_context.h"
31 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
34 #include "net/url_request/url_request_job_factory_impl.h" 35 #include "net/url_request/url_request_job_factory_impl.h"
35 #include "storage/browser/blob/blob_data_builder.h" 36 #include "storage/browser/blob/blob_data_builder.h"
36 #include "storage/browser/blob/blob_data_handle.h" 37 #include "storage/browser/blob/blob_data_handle.h"
37 #include "storage/browser/blob/blob_storage_context.h" 38 #include "storage/browser/blob/blob_storage_context.h"
38 #include "storage/browser/blob/blob_url_request_job_factory.h" 39 #include "storage/browser/blob/blob_url_request_job_factory.h"
(...skipping 28 matching lines...) Expand all
67 // Wait for ChromeBlobStorageContext to finish initializing. 68 // Wait for ChromeBlobStorageContext to finish initializing.
68 base::RunLoop().RunUntilIdle(); 69 base::RunLoop().RunUntilIdle();
69 70
70 blob_storage_context_ = blob_storage_context->context(); 71 blob_storage_context_ = blob_storage_context->context();
71 72
72 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); 73 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl);
73 url_request_job_factory_->SetProtocolHandler( 74 url_request_job_factory_->SetProtocolHandler(
74 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); 75 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context()));
75 76
76 net::URLRequestContext* url_request_context = 77 net::URLRequestContext* url_request_context =
77 browser_context_.GetRequestContext()->GetURLRequestContext(); 78 BrowserContext::GetDefaultStoragePartition(&browser_context_)->
79 GetURLRequestContext()->GetURLRequestContext();
78 80
79 url_request_context->set_job_factory(url_request_job_factory_.get()); 81 url_request_context->set_job_factory(url_request_job_factory_.get());
80 82
81 if (!MemoryOnly()) 83 if (!MemoryOnly())
82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 84 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
83 85
84 quota_policy_ = new MockSpecialStoragePolicy; 86 quota_policy_ = new MockSpecialStoragePolicy;
85 mock_quota_manager_ = new MockQuotaManager( 87 mock_quota_manager_ = new MockQuotaManager(
86 MemoryOnly() /* is incognito */, temp_dir_.path(), 88 MemoryOnly() /* is incognito */, temp_dir_.path(),
87 base::ThreadTaskRunnerHandle::Get().get(), 89 base::ThreadTaskRunnerHandle::Get().get(),
88 base::ThreadTaskRunnerHandle::Get().get(), quota_policy_.get()); 90 base::ThreadTaskRunnerHandle::Get().get(), quota_policy_.get());
89 mock_quota_manager_->SetQuota( 91 mock_quota_manager_->SetQuota(
90 GURL(origin1_), storage::kStorageTypeTemporary, 1024 * 1024 * 100); 92 GURL(origin1_), storage::kStorageTypeTemporary, 1024 * 1024 * 100);
91 mock_quota_manager_->SetQuota( 93 mock_quota_manager_->SetQuota(
92 GURL(origin2_), storage::kStorageTypeTemporary, 1024 * 1024 * 100); 94 GURL(origin2_), storage::kStorageTypeTemporary, 1024 * 1024 * 100);
93 95
94 quota_manager_proxy_ = new MockQuotaManagerProxy( 96 quota_manager_proxy_ = new MockQuotaManagerProxy(
95 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); 97 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get());
96 98
97 cache_manager_ = CacheStorageManager::Create( 99 cache_manager_ = CacheStorageManager::Create(
98 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), 100 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(),
99 quota_manager_proxy_); 101 quota_manager_proxy_);
100 102
101 cache_manager_->SetBlobParametersForCache( 103 cache_manager_->SetBlobParametersForCache(
102 browser_context_.GetRequestContext(), 104 BrowserContext::GetDefaultStoragePartition(&browser_context_)->
105 GetURLRequestContext(),
103 blob_storage_context->context()->AsWeakPtr()); 106 blob_storage_context->context()->AsWeakPtr());
104 } 107 }
105 108
106 void TearDown() override { 109 void TearDown() override {
107 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 110 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
108 base::RunLoop().RunUntilIdle(); 111 base::RunLoop().RunUntilIdle();
109 } 112 }
110 113
111 virtual bool MemoryOnly() { return false; } 114 virtual bool MemoryOnly() { return false; }
112 115
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 cache_storage->Size(base::Bind(&CacheStorageManagerTest::UsageCallback, 332 cache_storage->Size(base::Bind(&CacheStorageManagerTest::UsageCallback,
330 base::Unretained(this), &loop)); 333 base::Unretained(this), &loop));
331 loop.Run(); 334 loop.Run();
332 return callback_usage_; 335 return callback_usage_;
333 } 336 }
334 337
335 protected: 338 protected:
336 // Temporary directory must be allocated first so as to be destroyed last. 339 // Temporary directory must be allocated first so as to be destroyed last.
337 base::ScopedTempDir temp_dir_; 340 base::ScopedTempDir temp_dir_;
338 341
342 TestBrowserThreadBundle browser_thread_bundle_;
339 TestBrowserContext browser_context_; 343 TestBrowserContext browser_context_;
340 TestBrowserThreadBundle browser_thread_bundle_;
341 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; 344 std::unique_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_;
342 storage::BlobStorageContext* blob_storage_context_; 345 storage::BlobStorageContext* blob_storage_context_;
343 346
344 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; 347 scoped_refptr<MockSpecialStoragePolicy> quota_policy_;
345 scoped_refptr<MockQuotaManager> mock_quota_manager_; 348 scoped_refptr<MockQuotaManager> mock_quota_manager_;
346 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 349 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
347 std::unique_ptr<CacheStorageManager> cache_manager_; 350 std::unique_ptr<CacheStorageManager> cache_manager_;
348 351
349 scoped_refptr<CacheStorageCache> callback_cache_; 352 scoped_refptr<CacheStorageCache> callback_cache_;
350 int callback_bool_; 353 int callback_bool_;
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1146
1144 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1147 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
1145 CacheStorageManagerTestP, 1148 CacheStorageManagerTestP,
1146 ::testing::Values(false, true)); 1149 ::testing::Values(false, true));
1147 1150
1148 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1151 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
1149 CacheStorageQuotaClientTestP, 1152 CacheStorageQuotaClientTestP,
1150 ::testing::Values(false, true)); 1153 ::testing::Values(false, true));
1151 1154
1152 } // namespace content 1155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698