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

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

Issue 6864040: Fixed file/directory url resolution for external mount point provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/file_util.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_temp_dir.h" 10 #include "base/memory/scoped_temp_dir.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/fileapi/file_system_callback_dispatcher.h" 13 #include "webkit/fileapi/file_system_callback_dispatcher.h"
14 #include "webkit/fileapi/file_system_context.h"
13 #include "webkit/fileapi/file_system_file_util.h" 15 #include "webkit/fileapi/file_system_file_util.h"
16 #include "webkit/fileapi/file_system_mount_point_provider.h"
14 #include "webkit/fileapi/file_system_operation.h" 17 #include "webkit/fileapi/file_system_operation.h"
18 #include "webkit/fileapi/file_system_path_manager.h"
19 #include "webkit/fileapi/file_system_util.h"
15 20
16 namespace fileapi { 21 namespace fileapi {
17 22
18 const int kFileOperationStatusNotSet = 1; 23 const int kFileOperationStatusNotSet = 1;
19 const int kFileOperationSucceeded = 0; 24 const int kFileOperationSucceeded = 0;
20 25
21 static bool FileExists(FilePath path) { 26 static bool FileExists(FilePath path) {
22 return file_util::PathExists(path) && !file_util::DirectoryExists(path); 27 return file_util::PathExists(path) && !file_util::DirectoryExists(path);
23 } 28 }
24 29
25 class MockDispatcher; 30 class MockDispatcher;
26 31
27 // Test class for FileSystemOperation. Note that this just tests low-level 32 // Test class for FileSystemOperation. Note that this just tests low-level
28 // operations but doesn't test OpenFileSystem or any additional checks 33 // operations but doesn't test OpenFileSystem or any additional checks
29 // that require FileSystemContext (e.g. sandboxed paths, unlimited_storage 34 // that require FileSystemContext (e.g. sandboxed paths, unlimited_storage
30 // quota handling etc). 35 // quota handling etc).
31 // See SimpleFileSystem for more complete test environment for sandboxed 36 // See SimpleFileSystem for more complete test environment for sandboxed
32 // FileSystem. 37 // FileSystem.
33 class FileSystemOperationTest : public testing::Test { 38 class FileSystemOperationTest : public testing::Test {
34 public: 39 public:
35 FileSystemOperationTest() 40 FileSystemOperationTest()
36 : status_(kFileOperationStatusNotSet) { 41 : status_(kFileOperationStatusNotSet) {
37 EXPECT_TRUE(base_.CreateUniqueTempDir()); 42 EXPECT_TRUE(base_.CreateUniqueTempDir());
38 } 43 }
39 44
40 FileSystemOperation* operation(); 45 FileSystemOperation* operation();
41 46
47 void set_local_path(const FilePath& path) { local_path_ = path; }
48 const FilePath& local_path() const { return local_path_; }
42 void set_status(int status) { status_ = status; } 49 void set_status(int status) { status_ = status; }
43 int status() const { return status_; } 50 int status() const { return status_; }
44 void set_info(const base::PlatformFileInfo& info) { info_ = info; } 51 void set_info(const base::PlatformFileInfo& info) { info_ = info; }
45 const base::PlatformFileInfo& info() const { return info_; } 52 const base::PlatformFileInfo& info() const { return info_; }
46 void set_path(const FilePath& path) { path_ = path; } 53 void set_path(const FilePath& path) { path_ = path; }
47 const FilePath& path() const { return path_; } 54 const FilePath& path() const { return path_; }
48 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { 55 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) {
49 entries_ = entries; 56 entries_ = entries;
50 } 57 }
51 const std::vector<base::FileUtilProxy::Entry>& entries() const { 58 const std::vector<base::FileUtilProxy::Entry>& entries() const {
52 return entries_; 59 return entries_;
53 } 60 }
54 61
55 protected: 62 protected:
56 // Common temp base for nondestructive uses. 63 // Common temp base for nondestructive uses.
57 ScopedTempDir base_; 64 ScopedTempDir base_;
58 65
59 GURL URLForRelativePath(const std::string& path) const { 66 GURL URLForRelativePath(const std::string& path) const {
60 // Only the path will actually get used. 67 // Only the path will actually get used.
61 return GURL("file://").Resolve(base_.path().value()).Resolve(path); 68 return GURL("file://").Resolve(base_.path().value()).Resolve(path);
62 } 69 }
63 70
64 GURL URLForPath(const FilePath& path) const { 71 GURL URLForPath(const FilePath& path) const {
65 // Only the path will actually get used. 72 // Only the path will actually get used.
66 return GURL("file://").Resolve(path.value()); 73 return GURL("file://").Resolve(path.value());
67 } 74 }
68 75
76 GURL TestLocalPath(const FilePath& path) const {
77 return GURL(std::string("chrome://test") + path.value());
ericu 2011/04/20 02:23:46 This looks unlikely to work on Windows, where path
zel 2011/04/20 02:49:57 Done.
78 }
79
80 GURL TestURLForPath(const FilePath& path) const {
81 return GURL(std::string("filesystem:") + TestLocalPath(path).spec());
ericu 2011/04/20 02:23:46 Likewise here, can you use one of the above functi
zel 2011/04/20 02:49:57 Yes, I've been already bitten by angry bbots on th
82 }
83
69 // For post-operation status. 84 // For post-operation status.
70 int status_; 85 int status_;
71 base::PlatformFileInfo info_; 86 base::PlatformFileInfo info_;
72 FilePath path_; 87 FilePath path_;
88 FilePath local_path_;
73 std::vector<base::FileUtilProxy::Entry> entries_; 89 std::vector<base::FileUtilProxy::Entry> entries_;
74 90
75 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); 91 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
76 }; 92 };
77 93
78 class MockDispatcher : public FileSystemCallbackDispatcher { 94 class MockDispatcher : public FileSystemCallbackDispatcher {
79 public: 95 public:
80 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } 96 MockDispatcher(FileSystemOperationTest* test) : test_(test) { }
81 97
82 virtual void DidFail(base::PlatformFileError status) { 98 virtual void DidFail(base::PlatformFileError status) {
83 test_->set_status(status); 99 test_->set_status(status);
84 } 100 }
85 101
86 virtual void DidSucceed() { 102 virtual void DidSucceed() {
87 test_->set_status(kFileOperationSucceeded); 103 test_->set_status(kFileOperationSucceeded);
88 } 104 }
89 105
106 virtual void DidGetLocalPath(const FilePath& local_path) {
107 test_->set_local_path(local_path);
108 test_->set_status(kFileOperationSucceeded);
109 }
110
90 virtual void DidReadMetadata( 111 virtual void DidReadMetadata(
91 const base::PlatformFileInfo& info, 112 const base::PlatformFileInfo& info,
92 const FilePath& platform_path) { 113 const FilePath& platform_path) {
93 test_->set_info(info); 114 test_->set_info(info);
94 test_->set_path(platform_path); 115 test_->set_path(platform_path);
95 test_->set_status(kFileOperationSucceeded); 116 test_->set_status(kFileOperationSucceeded);
96 } 117 }
97 118
98 virtual void DidReadDirectory( 119 virtual void DidReadDirectory(
99 const std::vector<base::FileUtilProxy::Entry>& entries, 120 const std::vector<base::FileUtilProxy::Entry>& entries,
(...skipping 19 matching lines...) Expand all
119 base::MessageLoopProxy::CreateForCurrentThread(), 140 base::MessageLoopProxy::CreateForCurrentThread(),
120 NULL, 141 NULL,
121 FileSystemFileUtil::GetInstance()); 142 FileSystemFileUtil::GetInstance());
122 operation->file_system_operation_context()->set_src_type( 143 operation->file_system_operation_context()->set_src_type(
123 kFileSystemTypeTemporary); 144 kFileSystemTypeTemporary);
124 operation->file_system_operation_context()->set_dest_type( 145 operation->file_system_operation_context()->set_dest_type(
125 kFileSystemTypeTemporary); 146 kFileSystemTypeTemporary);
126 GURL origin_url("fake://fake.foo/"); 147 GURL origin_url("fake://fake.foo/");
127 operation->file_system_operation_context()->set_src_origin_url(origin_url); 148 operation->file_system_operation_context()->set_src_origin_url(origin_url);
128 operation->file_system_operation_context()->set_dest_origin_url(origin_url); 149 operation->file_system_operation_context()->set_dest_origin_url(origin_url);
150
129 return operation; 151 return operation;
130 } 152 }
131 153
132 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { 154 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
133 GURL src(URLForRelativePath("a")); 155 GURL src(URLForRelativePath("a"));
134 GURL dest(URLForRelativePath("b")); 156 GURL dest(URLForRelativePath("b"));
135 operation()->Move(src, dest); 157 operation()->Move(src, dest);
136 MessageLoop::current()->RunAllPending(); 158 MessageLoop::current()->RunAllPending();
137 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 159 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
138 } 160 }
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 MessageLoop::current()->RunAllPending(); 625 MessageLoop::current()->RunAllPending();
604 EXPECT_EQ(kFileOperationSucceeded, status()); 626 EXPECT_EQ(kFileOperationSucceeded, status());
605 627
606 operation()->GetMetadata(URLForPath(file)); 628 operation()->GetMetadata(URLForPath(file));
607 MessageLoop::current()->RunAllPending(); 629 MessageLoop::current()->RunAllPending();
608 EXPECT_EQ(kFileOperationSucceeded, status()); 630 EXPECT_EQ(kFileOperationSucceeded, status());
609 EXPECT_FALSE(info().is_directory); 631 EXPECT_FALSE(info().is_directory);
610 EXPECT_EQ(file, path()); 632 EXPECT_EQ(file, path());
611 } 633 }
612 634
635 TEST_F(FileSystemOperationTest, TestGetLocalFilePathSuccess) {
636 ScopedTempDir dir;
637 ASSERT_TRUE(dir.CreateUniqueTempDir());
638 operation()->GetLocalPath(TestURLForPath(dir.path()));
639 MessageLoop::current()->RunAllPending();
640 EXPECT_EQ(kFileOperationSucceeded, status());
641 EXPECT_EQ(local_path().value(), TestLocalPath(dir.path()).spec());
642
643 FilePath file;
644 file_util::CreateTemporaryFileInDir(dir.path(), &file);
645 operation()->GetLocalPath(TestURLForPath(file));
646 MessageLoop::current()->RunAllPending();
647 EXPECT_EQ(kFileOperationSucceeded, status());
648 EXPECT_EQ(local_path().value(), TestLocalPath(file).spec());
649 }
650
613 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { 651 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
614 ScopedTempDir dir; 652 ScopedTempDir dir;
615 ASSERT_TRUE(dir.CreateUniqueTempDir()); 653 ASSERT_TRUE(dir.CreateUniqueTempDir());
616 operation()->FileExists(URLForPath(dir.path())); 654 operation()->FileExists(URLForPath(dir.path()));
617 MessageLoop::current()->RunAllPending(); 655 MessageLoop::current()->RunAllPending();
618 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 656 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
619 657
620 FilePath file; 658 FilePath file;
621 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file)); 659 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file));
622 operation()->DirectoryExists(URLForPath(file)); 660 operation()->DirectoryExists(URLForPath(file));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 817
780 // Check that its length is now 3 and that it contains only bits of test data. 818 // Check that its length is now 3 and that it contains only bits of test data.
781 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); 819 EXPECT_TRUE(file_util::GetFileInfo(file, &info));
782 EXPECT_EQ(length, info.size); 820 EXPECT_EQ(length, info.size);
783 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); 821 EXPECT_EQ(length, file_util::ReadFile(file, data, length));
784 for (int i = 0; i < length; ++i) 822 for (int i = 0; i < length; ++i)
785 EXPECT_EQ(test_data[i], data[i]); 823 EXPECT_EQ(test_data[i], data[i]);
786 } 824 }
787 825
788 } // namespace fileapi 826 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698