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

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

Issue 1751833002: Use string16 for cache_name in the back end of CacheStorage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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.
nhiroki 2016/03/02 05:43:13 Can we have a test for the case where the protobuf
horo 2016/03/02 08:35:27 Added in cache_storage_unittest.cc
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/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
21 #include "content/browser/cache_storage/cache_storage.pb.h" 22 #include "content/browser/cache_storage/cache_storage.pb.h"
22 #include "content/browser/cache_storage/cache_storage_quota_client.h" 23 #include "content/browser/cache_storage/cache_storage_quota_client.h"
23 #include "content/browser/fileapi/chrome_blob_storage_context.h" 24 #include "content/browser/fileapi/chrome_blob_storage_context.h"
24 #include "content/browser/quota/mock_quota_manager_proxy.h" 25 #include "content/browser/quota/mock_quota_manager_proxy.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/cache_storage_usage_info.h" 27 #include "content/public/browser/cache_storage_usage_info.h"
27 #include "content/public/test/mock_special_storage_policy.h" 28 #include "content/public/test/mock_special_storage_policy.h"
28 #include "content/public/test/test_browser_context.h" 29 #include "content/public/test/test_browser_context.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 void CacheAndErrorCallback(base::RunLoop* run_loop, 120 void CacheAndErrorCallback(base::RunLoop* run_loop,
120 const scoped_refptr<CacheStorageCache>& cache, 121 const scoped_refptr<CacheStorageCache>& cache,
121 CacheStorageError error) { 122 CacheStorageError error) {
122 callback_cache_ = cache; 123 callback_cache_ = cache;
123 callback_error_ = error; 124 callback_error_ = error;
124 run_loop->Quit(); 125 run_loop->Quit();
125 } 126 }
126 127
127 void StringsAndErrorCallback(base::RunLoop* run_loop, 128 void StringsAndErrorCallback(base::RunLoop* run_loop,
128 const std::vector<std::string>& strings, 129 const std::vector<base::string16>& strings,
129 CacheStorageError error) { 130 CacheStorageError error) {
130 callback_strings_ = strings; 131 callback_strings_.clear();
132 for (const auto& name : strings) {
133 callback_strings_.push_back(base::UTF16ToUTF8(name));
134 }
131 callback_error_ = error; 135 callback_error_ = error;
132 run_loop->Quit(); 136 run_loop->Quit();
133 } 137 }
134 138
135 void CachePutCallback(base::RunLoop* run_loop, CacheStorageError error) { 139 void CachePutCallback(base::RunLoop* run_loop, CacheStorageError error) {
136 callback_error_ = error; 140 callback_error_ = error;
137 run_loop->Quit(); 141 run_loop->Quit();
138 } 142 }
139 143
140 void CacheMatchCallback( 144 void CacheMatchCallback(
141 base::RunLoop* run_loop, 145 base::RunLoop* run_loop,
142 CacheStorageError error, 146 CacheStorageError error,
143 scoped_ptr<ServiceWorkerResponse> response, 147 scoped_ptr<ServiceWorkerResponse> response,
144 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 148 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
145 callback_error_ = error; 149 callback_error_ = error;
146 callback_cache_response_ = std::move(response); 150 callback_cache_response_ = std::move(response);
147 callback_data_handle_ = std::move(blob_data_handle); 151 callback_data_handle_ = std::move(blob_data_handle);
148 run_loop->Quit(); 152 run_loop->Quit();
149 } 153 }
150 154
151 bool Open(const GURL& origin, const std::string& cache_name) { 155 bool Open(const GURL& origin, const std::string& cache_name) {
152 base::RunLoop loop; 156 base::RunLoop loop;
153 cache_manager_->OpenCache( 157 cache_manager_->OpenCache(
154 origin, cache_name, 158 origin, base::UTF8ToUTF16(cache_name),
155 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback, 159 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback,
156 base::Unretained(this), base::Unretained(&loop))); 160 base::Unretained(this), base::Unretained(&loop)));
157 loop.Run(); 161 loop.Run();
158 162
159 bool error = callback_error_ != CACHE_STORAGE_OK; 163 bool error = callback_error_ != CACHE_STORAGE_OK;
160 if (error) 164 if (error)
161 EXPECT_TRUE(!callback_cache_.get()); 165 EXPECT_TRUE(!callback_cache_.get());
162 else 166 else
163 EXPECT_TRUE(callback_cache_.get()); 167 EXPECT_TRUE(callback_cache_.get());
164 return !error; 168 return !error;
165 } 169 }
166 170
167 bool Has(const GURL& origin, const std::string& cache_name) { 171 bool Has(const GURL& origin, const std::string& cache_name) {
168 base::RunLoop loop; 172 base::RunLoop loop;
169 cache_manager_->HasCache( 173 cache_manager_->HasCache(
170 origin, cache_name, 174 origin, base::UTF8ToUTF16(cache_name),
171 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback, 175 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback,
172 base::Unretained(this), base::Unretained(&loop))); 176 base::Unretained(this), base::Unretained(&loop)));
173 loop.Run(); 177 loop.Run();
174 178
175 return callback_bool_; 179 return callback_bool_;
176 } 180 }
177 181
178 bool Delete(const GURL& origin, const std::string& cache_name) { 182 bool Delete(const GURL& origin, const std::string& cache_name) {
179 base::RunLoop loop; 183 base::RunLoop loop;
180 cache_manager_->DeleteCache( 184 cache_manager_->DeleteCache(
181 origin, cache_name, 185 origin, base::UTF8ToUTF16(cache_name),
182 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback, 186 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback,
183 base::Unretained(this), base::Unretained(&loop))); 187 base::Unretained(this), base::Unretained(&loop)));
184 loop.Run(); 188 loop.Run();
185 189
186 return callback_bool_; 190 return callback_bool_;
187 } 191 }
188 192
189 bool Keys(const GURL& origin) { 193 bool Keys(const GURL& origin) {
190 base::RunLoop loop; 194 base::RunLoop loop;
191 cache_manager_->EnumerateCaches( 195 cache_manager_->EnumerateCaches(
192 origin, base::Bind(&CacheStorageManagerTest::StringsAndErrorCallback, 196 origin, base::Bind(&CacheStorageManagerTest::StringsAndErrorCallback,
193 base::Unretained(this), base::Unretained(&loop))); 197 base::Unretained(this), base::Unretained(&loop)));
194 loop.Run(); 198 loop.Run();
195 199
196 return callback_error_ == CACHE_STORAGE_OK; 200 return callback_error_ == CACHE_STORAGE_OK;
197 } 201 }
198 202
199 bool StorageMatch(const GURL& origin, 203 bool StorageMatch(const GURL& origin,
200 const std::string& cache_name, 204 const std::string& cache_name,
201 const GURL& url) { 205 const GURL& url) {
202 scoped_ptr<ServiceWorkerFetchRequest> request( 206 scoped_ptr<ServiceWorkerFetchRequest> request(
203 new ServiceWorkerFetchRequest()); 207 new ServiceWorkerFetchRequest());
204 request->url = url; 208 request->url = url;
205 base::RunLoop loop; 209 base::RunLoop loop;
206 cache_manager_->MatchCache( 210 cache_manager_->MatchCache(
207 origin, cache_name, std::move(request), 211 origin, base::UTF8ToUTF16(cache_name), std::move(request),
208 base::Bind(&CacheStorageManagerTest::CacheMatchCallback, 212 base::Bind(&CacheStorageManagerTest::CacheMatchCallback,
209 base::Unretained(this), base::Unretained(&loop))); 213 base::Unretained(this), base::Unretained(&loop)));
210 loop.Run(); 214 loop.Run();
211 215
212 return callback_error_ == CACHE_STORAGE_OK; 216 return callback_error_ == CACHE_STORAGE_OK;
213 } 217 }
214 218
215 bool StorageMatchAll(const GURL& origin, const GURL& url) { 219 bool StorageMatchAll(const GURL& origin, const GURL& url) {
216 scoped_ptr<ServiceWorkerFetchRequest> request( 220 scoped_ptr<ServiceWorkerFetchRequest> request(
217 new ServiceWorkerFetchRequest()); 221 new ServiceWorkerFetchRequest());
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 EXPECT_TRUE(callback_cache_->AsWeakPtr()); 608 EXPECT_TRUE(callback_cache_->AsWeakPtr());
605 } 609 }
606 610
607 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { 611 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) {
608 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. 612 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage.
609 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 613 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
610 cache_storage->StartAsyncOperationForTesting(); 614 cache_storage->StartAsyncOperationForTesting();
611 615
612 base::RunLoop open_loop; 616 base::RunLoop open_loop;
613 cache_manager_->OpenCache( 617 cache_manager_->OpenCache(
614 origin1_, "foo", 618 origin1_, base::UTF8ToUTF16("foo"),
615 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback, 619 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback,
616 base::Unretained(this), base::Unretained(&open_loop))); 620 base::Unretained(this), base::Unretained(&open_loop)));
617 621
618 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
619 EXPECT_FALSE(callback_cache_); 623 EXPECT_FALSE(callback_cache_);
620 624
621 cache_storage->CompleteAsyncOperationForTesting(); 625 cache_storage->CompleteAsyncOperationForTesting();
622 open_loop.Run(); 626 open_loop.Run();
623 EXPECT_TRUE(callback_cache_); 627 EXPECT_TRUE(callback_cache_);
624 } 628 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 1071
1068 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1072 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
1069 CacheStorageManagerTestP, 1073 CacheStorageManagerTestP,
1070 ::testing::Values(false, true)); 1074 ::testing::Values(false, true));
1071 1075
1072 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1076 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
1073 CacheStorageQuotaClientTestP, 1077 CacheStorageQuotaClientTestP,
1074 ::testing::Values(false, true)); 1078 ::testing::Values(false, true));
1075 1079
1076 } // namespace content 1080 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698