Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: webkit/fileapi/file_system_file_util_unittest.cc

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased on the svn tree. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
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 FileSystemFileUtil. 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 FileSystemFileUtil 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 FileSystemFileUtilTest : public testing::Test {
58 public: 59 public:
59 FileSystemFileUtilTest() { 60 FileSystemFileUtilTest() {
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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(FileSystemFileUtilTest, 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 }
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_file_util_proxy.cc ('k') | webkit/fileapi/file_system_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698