| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 // Note that this file only tests the basic behavior of the cache counter, as in | 5 // Note that this file only tests the basic behavior of the cache counter, as in |
| 6 // when it counts and when not, when result is nonzero and when not. It does not | 6 // when it counts and when not, when result is nonzero and when not. It does not |
| 7 // test whether the result of the counting is correct. This is the | 7 // test whether the result of the counting is correct. This is the |
| 8 // responsibility of a lower layer, and is tested in | 8 // responsibility of a lower layer, and is tested in |
| 9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests. | 9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests. |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 std::string data = "entry data"; | 75 std::string data = "entry data"; |
| 76 scoped_refptr<net::StringIOBuffer> buffer = | 76 scoped_refptr<net::StringIOBuffer> buffer = |
| 77 new net::StringIOBuffer(data); | 77 new net::StringIOBuffer(data); |
| 78 return_value = | 78 return_value = |
| 79 entry_->WriteData(0, 0, buffer.get(), data.size(), callback, true); | 79 entry_->WriteData(0, 0, buffer.get(), data.size(), callback, true); |
| 80 break; | 80 break; |
| 81 } | 81 } |
| 82 | 82 |
| 83 case DONE: { | 83 case DONE: { |
| 84 entry_->Close(); | 84 entry_->Close(); |
| 85 BrowserThread::PostTask( | 85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 86 BrowserThread::UI, FROM_HERE, | 86 base::BindOnce(&CacheCounterTest::Callback, |
| 87 base::Bind(&CacheCounterTest::Callback, | 87 base::Unretained(this))); |
| 88 base::Unretained(this))); | |
| 89 return; | 88 return; |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 | 91 |
| 93 if (return_value >= 0) { | 92 if (return_value >= 0) { |
| 94 // Success. | 93 // Success. |
| 95 CreateCacheEntryStep(net::OK); | 94 CreateCacheEntryStep(net::OK); |
| 96 } else if (return_value == net::ERR_IO_PENDING) { | 95 } else if (return_value == net::ERR_IO_PENDING) { |
| 97 // The callback will trigger the next step. | 96 // The callback will trigger the next step. |
| 98 } else { | 97 } else { |
| 99 // Error. | 98 // Error. |
| 100 NOTREACHED(); | 99 NOTREACHED(); |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 | 102 |
| 104 // Create a cache entry on the IO thread. | 103 // Create a cache entry on the IO thread. |
| 105 void CreateCacheEntry() { | 104 void CreateCacheEntry() { |
| 106 storage_partition_ = | 105 storage_partition_ = |
| 107 BrowserContext::GetDefaultStoragePartition(browser()->profile()); | 106 BrowserContext::GetDefaultStoragePartition(browser()->profile()); |
| 108 next_step_ = GET_CACHE; | 107 next_step_ = GET_CACHE; |
| 109 | 108 |
| 110 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 111 BrowserThread::IO, FROM_HERE, | 110 BrowserThread::IO, FROM_HERE, |
| 112 base::Bind(&CacheCounterTest::CreateCacheEntryStep, | 111 base::BindOnce(&CacheCounterTest::CreateCacheEntryStep, |
| 113 base::Unretained(this), | 112 base::Unretained(this), net::OK)); |
| 114 net::OK)); | |
| 115 WaitForIOThread(); | 113 WaitForIOThread(); |
| 116 } | 114 } |
| 117 | 115 |
| 118 // Wait for IO thread operations, such as cache creation, counting, writing, | 116 // Wait for IO thread operations, such as cache creation, counting, writing, |
| 119 // deletion etc. | 117 // deletion etc. |
| 120 void WaitForIOThread() { | 118 void WaitForIOThread() { |
| 121 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 122 run_loop_.reset(new base::RunLoop()); | 120 run_loop_.reset(new base::RunLoop()); |
| 123 run_loop_->Run(); | 121 run_loop_->Run(); |
| 124 } | 122 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 WaitForIOThread(); | 265 WaitForIOThread(); |
| 268 EXPECT_EQ(result, GetResult()); | 266 EXPECT_EQ(result, GetResult()); |
| 269 | 267 |
| 270 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); | 268 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
| 271 WaitForIOThread(); | 269 WaitForIOThread(); |
| 272 EXPECT_EQ(result, GetResult()); | 270 EXPECT_EQ(result, GetResult()); |
| 273 EXPECT_FALSE(IsUpperLimit()); | 271 EXPECT_FALSE(IsUpperLimit()); |
| 274 } | 272 } |
| 275 | 273 |
| 276 } // namespace | 274 } // namespace |
| OLD | NEW |