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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "webkit/fileapi/file_system_context.h" | 11 #include "webkit/fileapi/file_system_context.h" |
12 #include "webkit/fileapi/file_system_operation_context.h" | 12 #include "webkit/fileapi/file_system_operation_context.h" |
13 #include "webkit/fileapi/file_system_test_helper.h" | 13 #include "webkit/fileapi/file_system_test_helper.h" |
14 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 14 #include "webkit/fileapi/native_file_util.h" |
15 #include "webkit/fileapi/obfuscated_file_util.h" | |
15 | 16 |
16 using namespace fileapi; | 17 using namespace fileapi; |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 struct CopyMoveTestCaseRecord { | 21 struct CopyMoveTestCaseRecord { |
21 bool is_directory; | 22 bool is_directory; |
22 const FilePath::CharType path[64]; | 23 const FilePath::CharType path[64]; |
23 int64 data_file_size; | 24 int64 data_file_size; |
24 }; | 25 }; |
(...skipping 14 matching lines...) Expand all Loading... | |
39 {false, FILE_PATH_LITERAL("file 3"), 0}, | 40 {false, FILE_PATH_LITERAL("file 3"), 0}, |
40 {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, | 41 {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, |
41 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, | 42 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, |
42 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, | 43 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, |
43 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, | 44 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, |
44 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, | 45 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, |
45 }; | 46 }; |
46 | 47 |
47 } // namespace (anonymous) | 48 } // namespace (anonymous) |
48 | 49 |
49 // This is not yet a full unit test for FileSystemFileUtil. TODO(ericu): Adapt | 50 // This is not yet a full unit test for NativeFileUtil. TODO(ericu): Adapt |
50 // the other subclasses' unit tests, as mentioned in the comments in | 51 // the other subclasses' unit tests, as mentioned in the comments in |
51 // ObfuscatedFileSystemFileUtil's unit test. | 52 // ObfuscatedFileUtil's unit test. |
ericu
2011/08/25 17:58:05
This file should have stayed as file_system_file_u
Dai Mikurube (NOT FULLTIME)
2011/08/26 05:10:59
Ah, sure. Done.
| |
52 // Currently this is just a test of cross-filesystem copy and move, which | 53 // Currently this is just a test of cross-filesystem copy and move, which |
53 // actually exercises subclasses of FileSystemFileUtil as well as the class | 54 // actually exercises subclasses of NativeFileUtil as well as the class |
54 // itself. We currently only test copies between obfuscated filesystems. | 55 // itself. We currently only test copies between obfuscated filesystems. |
55 // TODO(ericu): Add a test for copying between obfuscated and local filesystems, | 56 // TODO(ericu): Add a test for copying between obfuscated and local filesystems, |
56 // and between different local filesystems. | 57 // and between different local filesystems. |
57 class FileSystemFileUtilTest : public testing::Test { | 58 class NativeFileUtilTest : public testing::Test { |
58 public: | 59 public: |
59 FileSystemFileUtilTest() { | 60 NativeFileUtilTest() { |
60 } | 61 } |
61 | 62 |
62 void SetUp() { | 63 void SetUp() { |
63 } | 64 } |
64 | 65 |
65 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { | 66 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { |
66 FileSystemOperationContext* context = helper->NewOperationContext(); | 67 FileSystemOperationContext* context = helper->NewOperationContext(); |
67 // We need to allocate quota for paths for | 68 // We need to allocate quota for paths for |
68 // TestCrossFileSystemCopyMoveHelper, since it calls into OFSFU, which | 69 // TestCrossFileSystemCopyMoveHelper, since it calls into OFSFU, which |
69 // charges quota for paths. | 70 // charges quota for paths. |
70 context->set_allowed_bytes_growth(1024 * 1024); | 71 context->set_allowed_bytes_growth(1024 * 1024); |
71 return context; | 72 return context; |
72 } | 73 } |
73 | 74 |
74 void TestCrossFileSystemCopyMoveHelper( | 75 void TestCrossFileSystemCopyMoveHelper( |
75 const GURL& src_origin, fileapi::FileSystemType src_type, | 76 const GURL& src_origin, fileapi::FileSystemType src_type, |
76 const GURL& dest_origin, fileapi::FileSystemType dest_type, | 77 const GURL& dest_origin, fileapi::FileSystemType dest_type, |
77 bool copy) { | 78 bool copy) { |
78 ScopedTempDir base_dir; | 79 ScopedTempDir base_dir; |
79 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); | 80 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); |
80 scoped_refptr<ObfuscatedFileSystemFileUtil> file_util( | 81 scoped_refptr<ObfuscatedFileUtil> file_util( |
81 new ObfuscatedFileSystemFileUtil(base_dir.path(), | 82 new ObfuscatedFileUtil(base_dir.path(), new NativeFileUtil())); |
82 new FileSystemFileUtil())); | |
83 FileSystemTestOriginHelper src_helper(src_origin, src_type); | 83 FileSystemTestOriginHelper src_helper(src_origin, src_type); |
84 src_helper.SetUp(base_dir.path(), | 84 src_helper.SetUp(base_dir.path(), |
85 false, // incognito | 85 false, // incognito |
86 false, // unlimited quota | 86 false, // unlimited quota |
87 NULL, // quota::QuotaManagerProxy | 87 NULL, // quota::QuotaManagerProxy |
88 file_util.get()); | 88 file_util.get()); |
89 FileSystemTestOriginHelper dest_helper(dest_origin, dest_type); | 89 FileSystemTestOriginHelper dest_helper(dest_origin, dest_type); |
90 dest_helper.SetUp(src_helper.file_system_context(), NULL); | 90 dest_helper.SetUp(src_helper.file_system_context(), NULL); |
91 | 91 |
92 // Set up all the source data. | 92 // Set up all the source data. |
(...skipping 15 matching lines...) Expand all Loading... | |
108 context.reset(NewContext(&src_helper)); | 108 context.reset(NewContext(&src_helper)); |
109 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->Truncate( | 109 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->Truncate( |
110 context.get(), path, test_case.data_file_size)); | 110 context.get(), path, test_case.data_file_size)); |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 // Do the actual copy or move. | 114 // Do the actual copy or move. |
115 FileSystemContext* file_system_context = dest_helper.file_system_context(); | 115 FileSystemContext* file_system_context = dest_helper.file_system_context(); |
116 scoped_ptr<FileSystemOperationContext> copy_context( | 116 scoped_ptr<FileSystemOperationContext> copy_context( |
117 new FileSystemOperationContext(file_system_context, NULL)); | 117 new FileSystemOperationContext(file_system_context, NULL)); |
118 copy_context->set_src_file_system_file_util(file_util); | 118 copy_context->set_src_file_util(file_util); |
119 copy_context->set_dest_file_system_file_util(file_util); | 119 copy_context->set_dest_file_util(file_util); |
120 copy_context->set_src_origin_url(src_helper.origin()); | 120 copy_context->set_src_origin_url(src_helper.origin()); |
121 copy_context->set_dest_origin_url(dest_helper.origin()); | 121 copy_context->set_dest_origin_url(dest_helper.origin()); |
122 copy_context->set_src_type(src_helper.type()); | 122 copy_context->set_src_type(src_helper.type()); |
123 copy_context->set_dest_type(dest_helper.type()); | 123 copy_context->set_dest_type(dest_helper.type()); |
124 copy_context->set_allowed_bytes_growth(1024 * 1024); // OFSFU path quota. | 124 copy_context->set_allowed_bytes_growth(1024 * 1024); // OFSFU path quota. |
125 | 125 |
126 if (copy) | 126 if (copy) |
127 ASSERT_EQ(base::PLATFORM_FILE_OK, | 127 ASSERT_EQ(base::PLATFORM_FILE_OK, |
128 file_util->Copy(copy_context.get(), test_root, test_root)); | 128 file_util->Copy(copy_context.get(), test_root, test_root)); |
129 else | 129 else |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 expected_result = base::PLATFORM_FILE_OK; | 166 expected_result = base::PLATFORM_FILE_OK; |
167 else | 167 else |
168 expected_result = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 168 expected_result = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
169 EXPECT_EQ(expected_result, | 169 EXPECT_EQ(expected_result, |
170 file_util->GetFileInfo( | 170 file_util->GetFileInfo( |
171 context.get(), path, &src_file_info, &data_path)); | 171 context.get(), path, &src_file_info, &data_path)); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtilTest); | 176 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); |
177 }; | 177 }; |
178 | 178 |
179 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopyDifferentOrigins) { | 179 TEST_F(NativeFileUtilTest, TestCrossFileSystemCopyDifferentOrigins) { |
180 GURL src_origin("http://www.example.com"); | 180 GURL src_origin("http://www.example.com"); |
181 fileapi::FileSystemType type = kFileSystemTypePersistent; | 181 fileapi::FileSystemType type = kFileSystemTypePersistent; |
182 GURL dest_origin("http://www.not.the.same.domain.com"); | 182 GURL dest_origin("http://www.not.the.same.domain.com"); |
183 | 183 |
184 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, true); | 184 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, true); |
185 } | 185 } |
186 | 186 |
187 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopySameOrigin) { | 187 TEST_F(NativeFileUtilTest, TestCrossFileSystemCopySameOrigin) { |
188 GURL origin("http://www.example.com"); | 188 GURL origin("http://www.example.com"); |
189 fileapi::FileSystemType src_type = kFileSystemTypePersistent; | 189 fileapi::FileSystemType src_type = kFileSystemTypePersistent; |
190 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; | 190 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; |
191 | 191 |
192 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, true); | 192 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, true); |
193 } | 193 } |
194 | 194 |
195 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveDifferentOrigins) { | 195 TEST_F(NativeFileUtilTest, TestCrossFileSystemMoveDifferentOrigins) { |
196 GURL src_origin("http://www.example.com"); | 196 GURL src_origin("http://www.example.com"); |
197 fileapi::FileSystemType type = kFileSystemTypePersistent; | 197 fileapi::FileSystemType type = kFileSystemTypePersistent; |
198 GURL dest_origin("http://www.not.the.same.domain.com"); | 198 GURL dest_origin("http://www.not.the.same.domain.com"); |
199 | 199 |
200 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, false); | 200 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, false); |
201 } | 201 } |
202 | 202 |
203 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveSameOrigin) { | 203 TEST_F(NativeFileUtilTest, TestCrossFileSystemMoveSameOrigin) { |
204 GURL origin("http://www.example.com"); | 204 GURL origin("http://www.example.com"); |
205 fileapi::FileSystemType src_type = kFileSystemTypePersistent; | 205 fileapi::FileSystemType src_type = kFileSystemTypePersistent; |
206 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; | 206 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; |
207 | 207 |
208 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); | 208 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); |
209 } | 209 } |
OLD | NEW |