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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 } | 992 } |
993 EXPECT_TRUE(found); | 993 EXPECT_TRUE(found); |
994 } | 994 } |
995 | 995 |
996 std::set<GURL> diff; | 996 std::set<GURL> diff; |
997 std::set_symmetric_difference(origins_expected.begin(), | 997 std::set_symmetric_difference(origins_expected.begin(), |
998 origins_expected.end(), origins_found.begin(), origins_found.end(), | 998 origins_expected.end(), origins_found.begin(), origins_found.end(), |
999 inserter(diff, diff.begin())); | 999 inserter(diff, diff.begin())); |
1000 EXPECT_TRUE(diff.empty()); | 1000 EXPECT_TRUE(diff.empty()); |
1001 } | 1001 } |
1002 | |
1003 TEST_F(ObfuscatedFileSystemFileUtilTest, TestInconsistency) { | |
1004 const FilePath kPath1 = FilePath().AppendASCII("hoge"); | |
1005 const FilePath kPath2 = FilePath().AppendASCII("fuga"); | |
1006 | |
1007 scoped_ptr<FileSystemOperationContext> context; | |
1008 base::PlatformFile file; | |
1009 base::PlatformFileInfo file_info; | |
1010 FilePath data_path; | |
1011 bool created = false; | |
1012 | |
1013 // Create a non-empty file. | |
1014 context.reset(NewContext()); | |
1015 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1016 ofsfu()->EnsureFileExists(context.get(), kPath1, &created)); | |
1017 EXPECT_TRUE(created); | |
1018 context.reset(NewContext()); | |
1019 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1020 ofsfu()->Truncate(context.get(), kPath1, 10)); | |
1021 context.reset(NewContext()); | |
1022 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1023 ofsfu()->GetFileInfo( | |
1024 context.get(), kPath1, &file_info, &data_path)); | |
1025 EXPECT_EQ(10, file_info.size); | |
1026 | |
1027 // Destroy database to make inconsistency between database and filesystem. | |
1028 ofsfu()->DestroyDirectoryDatabase(origin_url(), type()); | |
1029 | |
1030 // Try to get file info of broken file. | |
1031 context.reset(NewContext()); | |
1032 EXPECT_FALSE(ofsfu()->PathExists(context.get(), kPath1)); | |
1033 context.reset(NewContext()); | |
1034 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1035 ofsfu()->EnsureFileExists(context.get(), kPath1, &created)); | |
1036 EXPECT_TRUE(created); | |
1037 context.reset(NewContext()); | |
1038 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1039 ofsfu()->GetFileInfo( | |
1040 context.get(), kPath1, &file_info, &data_path)); | |
1041 EXPECT_EQ(0, file_info.size); | |
1042 | |
1043 // Make another broken file to |kPath2|. | |
1044 context.reset(NewContext()); | |
1045 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1046 ofsfu()->EnsureFileExists(context.get(), kPath2, &created)); | |
1047 EXPECT_TRUE(created); | |
1048 | |
1049 // Destroy again. | |
1050 ofsfu()->DestroyDirectoryDatabase(origin_url(), type()); | |
1051 | |
1052 // Repair broken |kPath1|. | |
1053 context.reset(NewContext()); | |
1054 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1055 ofsfu()->Touch(context.get(), kPath1, base::Time::Now(), | |
1056 base::Time::Now())); | |
1057 | |
1058 // Copy from sound |kPath1| to broken |kPath2|. | |
1059 context.reset(NewContext()); | |
1060 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1061 ofsfu()->CopyOrMoveFile(context.get(), kPath1, kPath2, | |
1062 true /* copy */)); | |
1063 | |
1064 ofsfu()->DestroyDirectoryDatabase(origin_url(), type()); | |
1065 context.reset(NewContext()); | |
1066 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
1067 ofsfu()->CreateOrOpen( | |
1068 context.get(), kPath1, | |
1069 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE, | |
ericu
2011/08/10 17:28:01
I see that you changed this from WRITE to READ; do
tzik
2011/08/16 08:25:33
READ | CREATE_ALWAYS was fail-case in previous pat
| |
1070 &file, &created)); | |
1071 EXPECT_TRUE(created); | |
1072 EXPECT_TRUE(base::GetPlatformFileInfo(file, &file_info)); | |
1073 EXPECT_EQ(0, file_info.size); | |
1074 EXPECT_TRUE(base::ClosePlatformFile(file)); | |
1075 } | |
OLD | NEW |