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. |
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 return context; | 68 return context; |
68 } | 69 } |
69 | 70 |
70 void TestCrossFileSystemCopyMoveHelper( | 71 void TestCrossFileSystemCopyMoveHelper( |
71 const GURL& src_origin, fileapi::FileSystemType src_type, | 72 const GURL& src_origin, fileapi::FileSystemType src_type, |
72 const GURL& dest_origin, fileapi::FileSystemType dest_type, | 73 const GURL& dest_origin, fileapi::FileSystemType dest_type, |
73 bool copy) { | 74 bool copy) { |
74 ScopedTempDir base_dir; | 75 ScopedTempDir base_dir; |
75 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); | 76 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); |
76 scoped_refptr<ObfuscatedFileSystemFileUtil> file_util( | 77 scoped_refptr<ObfuscatedFileUtil> file_util( |
77 new ObfuscatedFileSystemFileUtil(base_dir.path(), | 78 new ObfuscatedFileUtil(base_dir.path(), new NativeFileUtil())); |
78 new FileSystemFileUtil())); | |
79 FileSystemTestOriginHelper src_helper(src_origin, src_type); | 79 FileSystemTestOriginHelper src_helper(src_origin, src_type); |
80 src_helper.SetUp(base_dir.path(), | 80 src_helper.SetUp(base_dir.path(), |
81 false, // incognito | 81 false, // incognito |
82 false, // unlimited quota | 82 false, // unlimited quota |
83 NULL, // quota::QuotaManagerProxy | 83 NULL, // quota::QuotaManagerProxy |
84 file_util.get()); | 84 file_util.get()); |
85 FileSystemTestOriginHelper dest_helper(dest_origin, dest_type); | 85 FileSystemTestOriginHelper dest_helper(dest_origin, dest_type); |
86 dest_helper.SetUp(src_helper.file_system_context(), NULL); | 86 dest_helper.SetUp(src_helper.file_system_context(), NULL); |
87 | 87 |
88 // Set up all the source data. | 88 // Set up all the source data. |
(...skipping 15 matching lines...) Expand all Loading... |
104 context.reset(NewContext(&src_helper)); | 104 context.reset(NewContext(&src_helper)); |
105 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->Truncate( | 105 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->Truncate( |
106 context.get(), path, test_case.data_file_size)); | 106 context.get(), path, test_case.data_file_size)); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 // Do the actual copy or move. | 110 // Do the actual copy or move. |
111 FileSystemContext* file_system_context = dest_helper.file_system_context(); | 111 FileSystemContext* file_system_context = dest_helper.file_system_context(); |
112 scoped_ptr<FileSystemOperationContext> copy_context( | 112 scoped_ptr<FileSystemOperationContext> copy_context( |
113 new FileSystemOperationContext(file_system_context, NULL)); | 113 new FileSystemOperationContext(file_system_context, NULL)); |
114 copy_context->set_src_file_system_file_util(file_util); | 114 copy_context->set_src_file_util(file_util); |
115 copy_context->set_dest_file_system_file_util(file_util); | 115 copy_context->set_dest_file_util(file_util); |
116 copy_context->set_src_origin_url(src_helper.origin()); | 116 copy_context->set_src_origin_url(src_helper.origin()); |
117 copy_context->set_dest_origin_url(dest_helper.origin()); | 117 copy_context->set_dest_origin_url(dest_helper.origin()); |
118 copy_context->set_src_type(src_helper.type()); | 118 copy_context->set_src_type(src_helper.type()); |
119 copy_context->set_dest_type(dest_helper.type()); | 119 copy_context->set_dest_type(dest_helper.type()); |
120 | 120 |
121 if (copy) | 121 if (copy) |
122 ASSERT_EQ(base::PLATFORM_FILE_OK, | 122 ASSERT_EQ(base::PLATFORM_FILE_OK, |
123 file_util->Copy(copy_context.get(), test_root, test_root)); | 123 file_util->Copy(copy_context.get(), test_root, test_root)); |
124 else | 124 else |
125 ASSERT_EQ(base::PLATFORM_FILE_OK, | 125 ASSERT_EQ(base::PLATFORM_FILE_OK, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 expected_result = base::PLATFORM_FILE_OK; | 161 expected_result = base::PLATFORM_FILE_OK; |
162 else | 162 else |
163 expected_result = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 163 expected_result = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
164 EXPECT_EQ(expected_result, | 164 EXPECT_EQ(expected_result, |
165 file_util->GetFileInfo( | 165 file_util->GetFileInfo( |
166 context.get(), path, &src_file_info, &data_path)); | 166 context.get(), path, &src_file_info, &data_path)); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 private: | 170 private: |
171 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtilTest); | 171 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); |
172 }; | 172 }; |
173 | 173 |
174 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopyDifferentOrigins) { | 174 TEST_F(NativeFileUtilTest, TestCrossFileSystemCopyDifferentOrigins) { |
175 GURL src_origin("http://www.example.com"); | 175 GURL src_origin("http://www.example.com"); |
176 fileapi::FileSystemType type = kFileSystemTypePersistent; | 176 fileapi::FileSystemType type = kFileSystemTypePersistent; |
177 GURL dest_origin("http://www.not.the.same.domain.com"); | 177 GURL dest_origin("http://www.not.the.same.domain.com"); |
178 | 178 |
179 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, true); | 179 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, true); |
180 } | 180 } |
181 | 181 |
182 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopySameOrigin) { | 182 TEST_F(NativeFileUtilTest, TestCrossFileSystemCopySameOrigin) { |
183 GURL origin("http://www.example.com"); | 183 GURL origin("http://www.example.com"); |
184 fileapi::FileSystemType src_type = kFileSystemTypePersistent; | 184 fileapi::FileSystemType src_type = kFileSystemTypePersistent; |
185 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; | 185 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; |
186 | 186 |
187 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, true); | 187 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, true); |
188 } | 188 } |
189 | 189 |
190 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveDifferentOrigins) { | 190 TEST_F(NativeFileUtilTest, TestCrossFileSystemMoveDifferentOrigins) { |
191 GURL src_origin("http://www.example.com"); | 191 GURL src_origin("http://www.example.com"); |
192 fileapi::FileSystemType type = kFileSystemTypePersistent; | 192 fileapi::FileSystemType type = kFileSystemTypePersistent; |
193 GURL dest_origin("http://www.not.the.same.domain.com"); | 193 GURL dest_origin("http://www.not.the.same.domain.com"); |
194 | 194 |
195 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, false); | 195 TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, false); |
196 } | 196 } |
197 | 197 |
198 TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveSameOrigin) { | 198 TEST_F(NativeFileUtilTest, TestCrossFileSystemMoveSameOrigin) { |
199 GURL origin("http://www.example.com"); | 199 GURL origin("http://www.example.com"); |
200 fileapi::FileSystemType src_type = kFileSystemTypePersistent; | 200 fileapi::FileSystemType src_type = kFileSystemTypePersistent; |
201 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; | 201 fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; |
202 | 202 |
203 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); | 203 TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); |
204 } | 204 } |
OLD | NEW |