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

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

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

Powered by Google App Engine
This is Rietveld 408576698