| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/platform_thread.h" | 6 #include "base/platform_thread.h" |
| 7 #include "base/timer.h" | 7 #include "base/timer.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 CacheTestFillBuffer(buffer3->data(), kSize3, false); | 140 CacheTestFillBuffer(buffer3->data(), kSize3, false); |
| 141 | 141 |
| 142 EXPECT_EQ(0, entry1->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1)); | 142 EXPECT_EQ(0, entry1->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1)); |
| 143 base::strlcpy(buffer1->data(), "the data", kSize1); | 143 base::strlcpy(buffer1->data(), "the data", kSize1); |
| 144 int expected = 0; | 144 int expected = 0; |
| 145 int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback2, false); | 145 int ret = entry1->WriteData(0, 0, buffer1, kSize1, &callback2, false); |
| 146 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); | 146 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); |
| 147 if (net::ERR_IO_PENDING == ret) | 147 if (net::ERR_IO_PENDING == ret) |
| 148 expected++; | 148 expected++; |
| 149 | 149 |
| 150 memset(buffer2->data(), 0, kSize1); | 150 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
| 151 memset(buffer2->data(), 0, kSize2); |
| 151 ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback3); | 152 ret = entry1->ReadData(0, 0, buffer2, kSize1, &callback3); |
| 152 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); | 153 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); |
| 153 if (net::ERR_IO_PENDING == ret) | 154 if (net::ERR_IO_PENDING == ret) |
| 154 expected++; | 155 expected++; |
| 155 | 156 |
| 156 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); | 157 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
| 157 EXPECT_STREQ("the data", buffer2->data()); | 158 EXPECT_STREQ("the data", buffer2->data()); |
| 158 | 159 |
| 159 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); | 160 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); |
| 160 ret = entry1->WriteData(1, 1500, buffer2, kSize2, &callback4, true); | 161 ret = entry1->WriteData(1, 1500, buffer2, kSize2, &callback4, true); |
| 161 EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret); | 162 EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret); |
| 162 if (net::ERR_IO_PENDING == ret) | 163 if (net::ERR_IO_PENDING == ret) |
| 163 expected++; | 164 expected++; |
| 164 | 165 |
| 165 memset(buffer3->data(), 0, kSize2); | 166 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
| 167 memset(buffer3->data(), 0, kSize3); |
| 166 ret = entry1->ReadData(1, 1511, buffer3, kSize2, &callback5); | 168 ret = entry1->ReadData(1, 1511, buffer3, kSize2, &callback5); |
| 167 EXPECT_TRUE(4989 == ret || net::ERR_IO_PENDING == ret); | 169 EXPECT_TRUE(4989 == ret || net::ERR_IO_PENDING == ret); |
| 168 if (net::ERR_IO_PENDING == ret) | 170 if (net::ERR_IO_PENDING == ret) |
| 169 expected++; | 171 expected++; |
| 170 | 172 |
| 171 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); | 173 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
| 172 EXPECT_STREQ("big data goes here", buffer3->data()); | 174 EXPECT_STREQ("big data goes here", buffer3->data()); |
| 173 ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback6); | 175 ret = entry1->ReadData(1, 0, buffer2, kSize2, &callback6); |
| 174 EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret); | 176 EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret); |
| 175 if (net::ERR_IO_PENDING == ret) | 177 if (net::ERR_IO_PENDING == ret) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback9); | 189 ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback9); |
| 188 EXPECT_TRUE(6500 == ret || net::ERR_IO_PENDING == ret); | 190 EXPECT_TRUE(6500 == ret || net::ERR_IO_PENDING == ret); |
| 189 if (net::ERR_IO_PENDING == ret) | 191 if (net::ERR_IO_PENDING == ret) |
| 190 expected++; | 192 expected++; |
| 191 | 193 |
| 192 ret = entry1->WriteData(1, 0, buffer3, 8192, &callback10, true); | 194 ret = entry1->WriteData(1, 0, buffer3, 8192, &callback10, true); |
| 193 EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret); | 195 EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret); |
| 194 if (net::ERR_IO_PENDING == ret) | 196 if (net::ERR_IO_PENDING == ret) |
| 195 expected++; | 197 expected++; |
| 196 | 198 |
| 199 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
| 197 ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback11); | 200 ret = entry1->ReadData(1, 0, buffer3, kSize3, &callback11); |
| 198 EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret); | 201 EXPECT_TRUE(8192 == ret || net::ERR_IO_PENDING == ret); |
| 199 if (net::ERR_IO_PENDING == ret) | 202 if (net::ERR_IO_PENDING == ret) |
| 200 expected++; | 203 expected++; |
| 201 | 204 |
| 202 EXPECT_EQ(8192, entry1->GetDataSize(1)); | 205 EXPECT_EQ(8192, entry1->GetDataSize(1)); |
| 203 | 206 |
| 204 ret = entry1->ReadData(0, 0, buffer1, kSize1, &callback12); | 207 ret = entry1->ReadData(0, 0, buffer1, kSize1, &callback12); |
| 205 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); | 208 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); |
| 206 if (net::ERR_IO_PENDING == ret) | 209 if (net::ERR_IO_PENDING == ret) |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 entry2->Close(); | 1176 entry2->Close(); |
| 1174 | 1177 |
| 1175 // Doom the second entry after it's fully saved. | 1178 // Doom the second entry after it's fully saved. |
| 1176 EXPECT_TRUE(cache_->DoomEntry(key2)); | 1179 EXPECT_TRUE(cache_->DoomEntry(key2)); |
| 1177 | 1180 |
| 1178 // Make sure we do all needed work. This may fail for entry2 if between Close | 1181 // Make sure we do all needed work. This may fail for entry2 if between Close |
| 1179 // and DoomEntry the system decides to remove all traces of the file from the | 1182 // and DoomEntry the system decides to remove all traces of the file from the |
| 1180 // system cache so we don't see that there is pending IO. | 1183 // system cache so we don't see that there is pending IO. |
| 1181 MessageLoop::current()->RunAllPending(); | 1184 MessageLoop::current()->RunAllPending(); |
| 1182 | 1185 |
| 1183 if (memory_only_) | 1186 if (memory_only_) { |
| 1184 EXPECT_EQ(0, cache_->GetEntryCount()); | 1187 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1185 else | 1188 } else { |
| 1189 if (5 == cache_->GetEntryCount()) { |
| 1190 // Most likely we are waiting for the result of reading the sparse info |
| 1191 // (it's always async on Posix so it is easy to miss). Unfortunately we |
| 1192 // don't have any signal to watch for so we can only wait. |
| 1193 PlatformThread::Sleep(500); |
| 1194 MessageLoop::current()->RunAllPending(); |
| 1195 } |
| 1186 EXPECT_EQ(0, cache_->GetEntryCount()); | 1196 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1197 } |
| 1187 } | 1198 } |
| 1188 | 1199 |
| 1189 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { | 1200 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { |
| 1190 InitCache(); | 1201 InitCache(); |
| 1191 DoomSparseEntry(); | 1202 DoomSparseEntry(); |
| 1192 } | 1203 } |
| 1193 | 1204 |
| 1194 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyDoomSparseEntry) { | 1205 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyDoomSparseEntry) { |
| 1195 SetMemoryOnlyMode(); | 1206 SetMemoryOnlyMode(); |
| 1196 InitCache(); | 1207 InitCache(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 16384, buf1, kSize, NULL)); | 1316 EXPECT_EQ(kSize, entry->WriteSparseData(k1Meg + 16384, buf1, kSize, NULL)); |
| 1306 EXPECT_EQ(0, entry->ReadSparseData(k1Meg + 8192, buf1, kSize, NULL)); | 1317 EXPECT_EQ(0, entry->ReadSparseData(k1Meg + 8192, buf1, kSize, NULL)); |
| 1307 | 1318 |
| 1308 // We never touched this one. | 1319 // We never touched this one. |
| 1309 EXPECT_EQ(kSize, entry->ReadSparseData(8192, buf1, kSize, NULL)); | 1320 EXPECT_EQ(kSize, entry->ReadSparseData(8192, buf1, kSize, NULL)); |
| 1310 entry->Close(); | 1321 entry->Close(); |
| 1311 | 1322 |
| 1312 // We re-created one of the corrupt children. | 1323 // We re-created one of the corrupt children. |
| 1313 EXPECT_EQ(3, cache_->GetEntryCount()); | 1324 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 1314 } | 1325 } |
| OLD | NEW |