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/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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 scoped_ptr<ServiceWorkerResponse> callback_response_; | 293 scoped_ptr<ServiceWorkerResponse> callback_response_; |
294 scoped_ptr<storage::BlobDataHandle> callback_response_data_; | 294 scoped_ptr<storage::BlobDataHandle> callback_response_data_; |
295 std::vector<std::string> callback_strings_; | 295 std::vector<std::string> callback_strings_; |
296 }; | 296 }; |
297 | 297 |
298 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest, | 298 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest, |
299 public testing::WithParamInterface<bool> { | 299 public testing::WithParamInterface<bool> { |
300 bool MemoryOnly() override { return !GetParam(); } | 300 bool MemoryOnly() override { return !GetParam(); } |
301 }; | 301 }; |
302 | 302 |
| 303 class ServiceWorkerCacheMemoryOnlyTest |
| 304 : public ServiceWorkerCacheTest, |
| 305 public testing::WithParamInterface<bool> { |
| 306 bool MemoryOnly() override { return true; } |
| 307 }; |
| 308 |
303 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { | 309 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { |
304 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 310 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
305 EXPECT_TRUE(callback_response_); | 311 EXPECT_TRUE(callback_response_); |
306 EXPECT_STREQ(no_body_response_.url.spec().c_str(), | 312 EXPECT_STREQ(no_body_response_.url.spec().c_str(), |
307 callback_response_->url.spec().c_str()); | 313 callback_response_->url.spec().c_str()); |
308 EXPECT_FALSE(callback_response_data_); | 314 EXPECT_FALSE(callback_response_data_); |
309 EXPECT_STREQ("", callback_response_->blob_uuid.c_str()); | 315 EXPECT_STREQ("", callback_response_->blob_uuid.c_str()); |
310 EXPECT_EQ(0u, callback_response_->blob_size); | 316 EXPECT_EQ(0u, callback_response_->blob_size); |
311 } | 317 } |
312 | 318 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count()); | 564 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count()); |
559 sum_delta += quota_manager_proxy_->last_notified_delta(); | 565 sum_delta += quota_manager_proxy_->last_notified_delta(); |
560 | 566 |
561 EXPECT_TRUE(Delete(no_body_request_)); | 567 EXPECT_TRUE(Delete(no_body_request_)); |
562 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); | 568 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); |
563 sum_delta += quota_manager_proxy_->last_notified_delta(); | 569 sum_delta += quota_manager_proxy_->last_notified_delta(); |
564 | 570 |
565 EXPECT_EQ(0, sum_delta); | 571 EXPECT_EQ(0, sum_delta); |
566 } | 572 } |
567 | 573 |
| 574 TEST_F(ServiceWorkerCacheMemoryOnlyTest, MemoryBackedSize) { |
| 575 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 576 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 577 EXPECT_LT(0, cache_->MemoryBackedSize()); |
| 578 int64 no_body_size = cache_->MemoryBackedSize(); |
| 579 |
| 580 EXPECT_TRUE(Delete(no_body_request_)); |
| 581 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 582 |
| 583 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 584 EXPECT_LT(no_body_size, cache_->MemoryBackedSize()); |
| 585 |
| 586 EXPECT_TRUE(Delete(body_request_)); |
| 587 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 588 } |
| 589 |
| 590 TEST_F(ServiceWorkerCacheTest, MemoryBackedSizePersistent) { |
| 591 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 592 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 593 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 594 } |
| 595 |
568 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 596 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
569 ServiceWorkerCacheTestP, | 597 ServiceWorkerCacheTestP, |
570 ::testing::Values(false, true)); | 598 ::testing::Values(false, true)); |
571 | 599 |
572 } // namespace content | 600 } // namespace content |
OLD | NEW |