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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.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 |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 414 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
415 | 415 |
416 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, | 416 cache_->Close(base::Bind(&CacheStorageCacheTest::CloseCallback, |
417 base::Unretained(this), | 417 base::Unretained(this), |
418 base::Unretained(loop.get()))); | 418 base::Unretained(loop.get()))); |
419 loop->Run(); | 419 loop->Run(); |
420 return callback_closed_; | 420 return callback_closed_; |
421 } | 421 } |
422 | 422 |
423 int64_t Size() { | 423 int64_t Size() { |
| 424 // Storage notification happens after an operation completes. Let the any |
| 425 // notifications complete before calling Size. |
| 426 base::RunLoop().RunUntilIdle(); |
| 427 |
424 base::RunLoop run_loop; | 428 base::RunLoop run_loop; |
425 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, | 429 cache_->Size(base::Bind(&CacheStorageCacheTest::SizeCallback, |
426 base::Unretained(this), &run_loop)); | 430 base::Unretained(this), &run_loop)); |
427 run_loop.Run(); | 431 run_loop.Run(); |
428 return callback_size_; | 432 return callback_size_; |
429 } | 433 } |
430 | 434 |
431 void RequestsCallback(base::RunLoop* run_loop, | 435 void RequestsCallback(base::RunLoop* run_loop, |
432 CacheStorageError error, | 436 CacheStorageError error, |
433 scoped_ptr<CacheStorageCache::Requests> requests) { | 437 scoped_ptr<CacheStorageCache::Requests> requests) { |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 false); | 931 false); |
928 request.headers["content-type"] = "foo"; | 932 request.headers["content-type"] = "foo"; |
929 request.headers["Content-Type"] = "bar"; | 933 request.headers["Content-Type"] = "bar"; |
930 EXPECT_EQ("bar", request.headers["content-type"]); | 934 EXPECT_EQ("bar", request.headers["content-type"]); |
931 } | 935 } |
932 | 936 |
933 TEST_P(CacheStorageCacheTestP, QuotaManagerModified) { | 937 TEST_P(CacheStorageCacheTestP, QuotaManagerModified) { |
934 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_modified_count()); | 938 EXPECT_EQ(0, quota_manager_proxy_->notify_storage_modified_count()); |
935 | 939 |
936 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 940 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 941 // Storage notification happens after the operation returns, so continue the |
| 942 // event loop. |
| 943 base::RunLoop().RunUntilIdle(); |
937 EXPECT_EQ(1, quota_manager_proxy_->notify_storage_modified_count()); | 944 EXPECT_EQ(1, quota_manager_proxy_->notify_storage_modified_count()); |
938 EXPECT_LT(0, quota_manager_proxy_->last_notified_delta()); | 945 EXPECT_LT(0, quota_manager_proxy_->last_notified_delta()); |
939 int64_t sum_delta = quota_manager_proxy_->last_notified_delta(); | 946 int64_t sum_delta = quota_manager_proxy_->last_notified_delta(); |
940 | 947 |
941 EXPECT_TRUE(Put(body_request_, body_response_)); | 948 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 949 base::RunLoop().RunUntilIdle(); |
942 EXPECT_EQ(2, quota_manager_proxy_->notify_storage_modified_count()); | 950 EXPECT_EQ(2, quota_manager_proxy_->notify_storage_modified_count()); |
943 EXPECT_LT(sum_delta, quota_manager_proxy_->last_notified_delta()); | 951 EXPECT_LT(sum_delta, quota_manager_proxy_->last_notified_delta()); |
944 sum_delta += quota_manager_proxy_->last_notified_delta(); | 952 sum_delta += quota_manager_proxy_->last_notified_delta(); |
945 | 953 |
946 EXPECT_TRUE(Delete(body_request_)); | 954 EXPECT_TRUE(Delete(body_request_)); |
| 955 base::RunLoop().RunUntilIdle(); |
947 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count()); | 956 EXPECT_EQ(3, quota_manager_proxy_->notify_storage_modified_count()); |
948 sum_delta += quota_manager_proxy_->last_notified_delta(); | 957 sum_delta += quota_manager_proxy_->last_notified_delta(); |
949 | 958 |
950 EXPECT_TRUE(Delete(no_body_request_)); | 959 EXPECT_TRUE(Delete(no_body_request_)); |
| 960 base::RunLoop().RunUntilIdle(); |
951 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); | 961 EXPECT_EQ(4, quota_manager_proxy_->notify_storage_modified_count()); |
952 sum_delta += quota_manager_proxy_->last_notified_delta(); | 962 sum_delta += quota_manager_proxy_->last_notified_delta(); |
953 | 963 |
954 EXPECT_EQ(0, sum_delta); | 964 EXPECT_EQ(0, sum_delta); |
955 } | 965 } |
956 | 966 |
957 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { | 967 TEST_P(CacheStorageCacheTestP, PutObeysQuotaLimits) { |
958 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, | 968 mock_quota_manager_->SetQuota(GURL(kOrigin), storage::kStorageTypeTemporary, |
959 0); | 969 0); |
960 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); | 970 EXPECT_FALSE(Put(no_body_request_, no_body_response_)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 EXPECT_EQ(1, sequence_out); | 1045 EXPECT_EQ(1, sequence_out); |
1036 close_loop2->Run(); | 1046 close_loop2->Run(); |
1037 EXPECT_EQ(2, sequence_out); | 1047 EXPECT_EQ(2, sequence_out); |
1038 } | 1048 } |
1039 | 1049 |
1040 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 1050 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
1041 CacheStorageCacheTestP, | 1051 CacheStorageCacheTestP, |
1042 ::testing::Values(false, true)); | 1052 ::testing::Values(false, true)); |
1043 | 1053 |
1044 } // namespace content | 1054 } // namespace content |
OLD | NEW |