OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 expected_quota += test_case.data_file_size; | 1332 expected_quota += test_case.data_file_size; |
1333 } | 1333 } |
1334 } | 1334 } |
1335 EXPECT_EQ(expected_quota, SizeInUsageFile()); | 1335 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
1336 RevokeUsageCache(); | 1336 RevokeUsageCache(); |
1337 EXPECT_EQ(-1, SizeInUsageFile()); | 1337 EXPECT_EQ(-1, SizeInUsageFile()); |
1338 GetUsageFromQuotaManager(); | 1338 GetUsageFromQuotaManager(); |
1339 EXPECT_EQ(expected_quota, SizeInUsageFile()); | 1339 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
1340 EXPECT_EQ(expected_quota, usage()); | 1340 EXPECT_EQ(expected_quota, usage()); |
1341 } | 1341 } |
| 1342 |
| 1343 TEST_F(ObfuscatedFileSystemFileUtilTest, TestInconsistency) { |
| 1344 const FilePath kPath1 = FilePath().AppendASCII("hoge"); |
| 1345 const FilePath kPath2 = FilePath().AppendASCII("fuga"); |
| 1346 |
| 1347 scoped_ptr<FileSystemOperationContext> context; |
| 1348 base::PlatformFile file; |
| 1349 base::PlatformFileInfo file_info; |
| 1350 FilePath data_path; |
| 1351 bool created = false; |
| 1352 |
| 1353 // Create a non-empty file. |
| 1354 context.reset(NewContext(NULL)); |
| 1355 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1356 ofsfu()->EnsureFileExists(context.get(), kPath1, &created)); |
| 1357 EXPECT_TRUE(created); |
| 1358 context.reset(NewContext(NULL)); |
| 1359 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1360 ofsfu()->Truncate(context.get(), kPath1, 10)); |
| 1361 context.reset(NewContext(NULL)); |
| 1362 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1363 ofsfu()->GetFileInfo( |
| 1364 context.get(), kPath1, &file_info, &data_path)); |
| 1365 EXPECT_EQ(10, file_info.size); |
| 1366 |
| 1367 // Destroy database to make inconsistency between database and filesystem. |
| 1368 ofsfu()->DestroyDirectoryDatabase(origin(), type()); |
| 1369 |
| 1370 // Try to get file info of broken file. |
| 1371 context.reset(NewContext(NULL)); |
| 1372 EXPECT_FALSE(ofsfu()->PathExists(context.get(), kPath1)); |
| 1373 context.reset(NewContext(NULL)); |
| 1374 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1375 ofsfu()->EnsureFileExists(context.get(), kPath1, &created)); |
| 1376 EXPECT_TRUE(created); |
| 1377 context.reset(NewContext(NULL)); |
| 1378 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1379 ofsfu()->GetFileInfo( |
| 1380 context.get(), kPath1, &file_info, &data_path)); |
| 1381 EXPECT_EQ(0, file_info.size); |
| 1382 |
| 1383 // Make another broken file to |kPath2|. |
| 1384 context.reset(NewContext(NULL)); |
| 1385 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1386 ofsfu()->EnsureFileExists(context.get(), kPath2, &created)); |
| 1387 EXPECT_TRUE(created); |
| 1388 |
| 1389 // Destroy again. |
| 1390 ofsfu()->DestroyDirectoryDatabase(origin(), type()); |
| 1391 |
| 1392 // Repair broken |kPath1|. |
| 1393 context.reset(NewContext(NULL)); |
| 1394 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1395 ofsfu()->Touch(context.get(), kPath1, base::Time::Now(), |
| 1396 base::Time::Now())); |
| 1397 |
| 1398 // Copy from sound |kPath1| to broken |kPath2|. |
| 1399 context.reset(NewContext(NULL)); |
| 1400 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1401 ofsfu()->CopyOrMoveFile(context.get(), kPath1, kPath2, |
| 1402 true /* copy */)); |
| 1403 |
| 1404 ofsfu()->DestroyDirectoryDatabase(origin(), type()); |
| 1405 context.reset(NewContext(NULL)); |
| 1406 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1407 ofsfu()->CreateOrOpen( |
| 1408 context.get(), kPath1, |
| 1409 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE, |
| 1410 &file, &created)); |
| 1411 EXPECT_TRUE(created); |
| 1412 EXPECT_TRUE(base::GetPlatformFileInfo(file, &file_info)); |
| 1413 EXPECT_EQ(0, file_info.size); |
| 1414 EXPECT_TRUE(base::ClosePlatformFile(file)); |
| 1415 } |
OLD | NEW |