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

Side by Side Diff: content/browser/service_worker/service_worker_cache_unittest.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: memory leak fixed Created 5 years, 11 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/service_worker/service_worker_cache.h" 5 #include "content/browser/service_worker/service_worker_cache.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), 220 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"),
221 "GET", 221 "GET",
222 headers, 222 headers,
223 GURL(), 223 GURL(),
224 false); 224 false);
225 225
226 std::string expected_response; 226 std::string expected_response;
227 for (int i = 0; i < 100; ++i) 227 for (int i = 0; i < 100; ++i)
228 expected_blob_data_ += kTestData; 228 expected_blob_data_ += kTestData;
229 229
230 scoped_refptr<storage::BlobData> blob_data( 230 scoped_ptr<storage::BlobDataBuilder> blob_data(
231 new storage::BlobData("blob-id:myblob")); 231 new storage::BlobDataBuilder("blob-id:myblob"));
232 blob_data->AppendData(expected_blob_data_); 232 blob_data->AppendData(expected_blob_data_);
233 233
234 blob_handle_ = 234 blob_handle_ =
235 blob_storage_context->context()->AddFinishedBlob(blob_data.get()); 235 blob_storage_context->context()->AddFinishedBlob(*blob_data.get());
236 236
237 body_response_ = 237 body_response_ =
238 ServiceWorkerResponse(GURL("http://example.com/body.html"), 238 ServiceWorkerResponse(GURL("http://example.com/body.html"),
239 200, 239 200,
240 "OK", 240 "OK",
241 blink::WebServiceWorkerResponseTypeDefault, 241 blink::WebServiceWorkerResponseTypeDefault,
242 headers, 242 headers,
243 blob_handle_->uuid(), 243 blob_handle_->uuid(),
244 expected_blob_data_.size(), 244 expected_blob_data_.size(),
245 GURL()); 245 GURL());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 ServiceWorkerCache::ErrorType error) { 357 ServiceWorkerCache::ErrorType error) {
358 callback_error_ = error; 358 callback_error_ = error;
359 if (run_loop) 359 if (run_loop)
360 run_loop->Quit(); 360 run_loop->Quit();
361 } 361 }
362 362
363 void ResponseAndErrorCallback( 363 void ResponseAndErrorCallback(
364 base::RunLoop* run_loop, 364 base::RunLoop* run_loop,
365 ServiceWorkerCache::ErrorType error, 365 ServiceWorkerCache::ErrorType error,
366 scoped_ptr<ServiceWorkerResponse> response, 366 scoped_ptr<ServiceWorkerResponse> response,
367 scoped_ptr<storage::BlobDataHandle> body_handle) { 367 scoped_ptr<storage::BlobDataSnapshotHandle> body_handle) {
368 callback_error_ = error; 368 callback_error_ = error;
369 callback_response_ = response.Pass(); 369 callback_response_ = response.Pass();
370 callback_response_data_.reset(); 370 callback_response_data_.reset();
371 if (error == ServiceWorkerCache::ErrorTypeOK && 371 if (error == ServiceWorkerCache::ErrorTypeOK &&
372 !callback_response_->blob_uuid.empty()) { 372 !callback_response_->blob_uuid.empty()) {
373 callback_response_data_ = body_handle.Pass(); 373 callback_response_data_ = body_handle.Pass();
374 } 374 }
375 375
376 if (run_loop) 376 if (run_loop)
377 run_loop->Quit(); 377 run_loop->Quit();
378 } 378 }
379 379
380 void CloseCallback(base::RunLoop* run_loop) { 380 void CloseCallback(base::RunLoop* run_loop) {
381 EXPECT_FALSE(callback_closed_); 381 EXPECT_FALSE(callback_closed_);
382 callback_closed_ = true; 382 callback_closed_ = true;
383 if (run_loop) 383 if (run_loop)
384 run_loop->Quit(); 384 run_loop->Quit();
385 } 385 }
386 386
387 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { 387 void CopyBody(storage::BlobDataSnapshotHandle* blob_handle,
388 storage::BlobData* data = blob_handle->data(); 388 std::string* output) {
389 std::vector<storage::BlobData::Item> items = data->items(); 389 const storage::BlobDataSnapshot* data = blob_handle->data();
390 for (size_t i = 0, max = items.size(); i < max; ++i) 390 const auto& items = data->items();
391 output->append(items[i].bytes(), items[i].length()); 391 for (const auto& item : items) {
392 output->append(item->bytes(), item->length());
393 }
392 } 394 }
393 395
394 bool VerifyKeys(const std::vector<std::string>& expected_keys) { 396 bool VerifyKeys(const std::vector<std::string>& expected_keys) {
395 if (expected_keys.size() != callback_strings_.size()) 397 if (expected_keys.size() != callback_strings_.size())
396 return false; 398 return false;
397 399
398 std::set<std::string> found_set; 400 std::set<std::string> found_set;
399 for (int i = 0, max = callback_strings_.size(); i < max; ++i) 401 for (int i = 0, max = callback_strings_.size(); i < max; ++i)
400 found_set.insert(callback_strings_[i]); 402 found_set.insert(callback_strings_[i]);
401 403
(...skipping 28 matching lines...) Expand all
430 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 432 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
431 storage::BlobStorageContext* blob_storage_context_; 433 storage::BlobStorageContext* blob_storage_context_;
432 434
433 base::ScopedTempDir temp_dir_; 435 base::ScopedTempDir temp_dir_;
434 scoped_refptr<TestServiceWorkerCache> cache_; 436 scoped_refptr<TestServiceWorkerCache> cache_;
435 437
436 ServiceWorkerFetchRequest body_request_; 438 ServiceWorkerFetchRequest body_request_;
437 ServiceWorkerResponse body_response_; 439 ServiceWorkerResponse body_response_;
438 ServiceWorkerFetchRequest no_body_request_; 440 ServiceWorkerFetchRequest no_body_request_;
439 ServiceWorkerResponse no_body_response_; 441 ServiceWorkerResponse no_body_response_;
440 scoped_ptr<storage::BlobDataHandle> blob_handle_; 442 scoped_ptr<storage::BlobDataSnapshotHandle> blob_handle_;
441 std::string expected_blob_data_; 443 std::string expected_blob_data_;
442 444
443 ServiceWorkerCache::ErrorType callback_error_; 445 ServiceWorkerCache::ErrorType callback_error_;
444 scoped_ptr<ServiceWorkerResponse> callback_response_; 446 scoped_ptr<ServiceWorkerResponse> callback_response_;
445 scoped_ptr<storage::BlobDataHandle> callback_response_data_; 447 scoped_ptr<storage::BlobDataSnapshotHandle> callback_response_data_;
446 std::vector<std::string> callback_strings_; 448 std::vector<std::string> callback_strings_;
447 bool callback_closed_; 449 bool callback_closed_;
448 }; 450 };
449 451
450 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest, 452 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest,
451 public testing::WithParamInterface<bool> { 453 public testing::WithParamInterface<bool> {
452 bool MemoryOnly() override { return !GetParam(); } 454 bool MemoryOnly() override { return !GetParam(); }
453 }; 455 };
454 456
455 class ServiceWorkerCacheMemoryOnlyTest 457 class ServiceWorkerCacheMemoryOnlyTest
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 EXPECT_TRUE(callback_closed_); 908 EXPECT_TRUE(callback_closed_);
907 909
908 VerifyAllOpsFail(); 910 VerifyAllOpsFail();
909 } 911 }
910 912
911 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, 913 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest,
912 ServiceWorkerCacheTestP, 914 ServiceWorkerCacheTestP,
913 ::testing::Values(false, true)); 915 ::testing::Values(false, true));
914 916
915 } // namespace content 917 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698