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