Index: content/browser/fileapi/file_system_dir_url_request_job_unittest.cc |
diff --git a/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc b/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc |
index e17157f22ac98ccadb0891c2bfc6d3bcaeacae5f..3b4c73f5d4b3b27f25cbb1c20d35ab63d3fb28d7 100644 |
--- a/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc |
+++ b/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc |
@@ -6,15 +6,18 @@ |
#include <string> |
+#include "base/file_util.h" |
#include "base/files/file_path.h" |
#include "base/files/scoped_temp_dir.h" |
#include "base/format_macros.h" |
+#include "base/memory/scoped_vector.h" |
#include "base/memory/weak_ptr.h" |
#include "base/message_loop/message_loop.h" |
#include "base/platform_file.h" |
#include "base/run_loop.h" |
#include "base/strings/string_piece.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "content/public/test/test_file_system_backend.h" |
#include "content/public/test/test_file_system_context.h" |
#include "net/base/net_errors.h" |
#include "net/base/net_util.h" |
@@ -25,6 +28,7 @@ |
#include "net/url_request/url_request_test_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/icu/source/i18n/unicode/regex.h" |
+#include "webkit/browser/fileapi/external_mount_points.h" |
#include "webkit/browser/fileapi/file_system_context.h" |
#include "webkit/browser/fileapi/file_system_file_util.h" |
#include "webkit/browser/fileapi/file_system_operation_context.h" |
@@ -39,8 +43,34 @@ namespace content { |
namespace { |
// We always use the TEMPORARY FileSystem in this test. |
-static const char kFileSystemURLPrefix[] = |
- "filesystem:http://remote/temporary/"; |
+const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; |
+ |
+const char kValidExternalMountPoint[] = "mnt_name"; |
+ |
+// An auto mounter that will try to mount anything for |storage_domain| = |
+// "automount", but will only succeed for the mount point "mnt_name". |
+bool TestAutoMountForURLRequest( |
+ const net::URLRequest* /*url_request*/, |
+ const fileapi::FileSystemURL& filesystem_url, |
+ const std::string& storage_domain, |
+ const base::Callback<void(base::File::Error result)>& callback) { |
+ if (storage_domain != "automount") |
+ return false; |
+ |
+ std::vector<base::FilePath::StringType> components; |
+ filesystem_url.path().GetComponents(&components); |
+ std::string mount_point = base::FilePath(components[0]).AsUTF8Unsafe(); |
+ |
+ if (mount_point == kValidExternalMountPoint) { |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
+ kValidExternalMountPoint, fileapi::kFileSystemTypeTest, |
+ fileapi::FileSystemMountOption(), base::FilePath()); |
+ callback.Run(base::File::FILE_OK); |
+ } else { |
+ callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
+ } |
+ return true; |
+} |
} // namespace |
@@ -77,6 +107,21 @@ class FileSystemDirURLRequestJobTest : public testing::Test { |
ClearUnusedJob(); |
} |
+ void SetUpAutoMountContext(base::FilePath* mnt_point) { |
+ *mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir"); |
+ ASSERT_TRUE(base::CreateDirectory(*mnt_point)); |
+ |
+ ScopedVector<fileapi::FileSystemBackend> additional_providers; |
+ additional_providers.push_back(new TestFileSystemBackend( |
+ base::MessageLoopProxy::current().get(), *mnt_point)); |
+ |
+ std::vector<fileapi::URLRequestAutoMountHandler> handlers; |
+ handlers.push_back(base::Bind(&TestAutoMountForURLRequest)); |
+ |
+ file_system_context_ = CreateFileSystemContextWithAutoMountersForTesting( |
+ NULL, additional_providers.Pass(), handlers, temp_dir_.path()); |
+ } |
+ |
void OnOpenFileSystem(const GURL& root_url, |
const std::string& name, |
base::File::Error result) { |
@@ -90,7 +135,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { |
request_ = empty_context_.CreateRequest( |
url, net::DEFAULT_PRIORITY, delegate_.get(), NULL); |
job_ = new fileapi::FileSystemDirURLRequestJob( |
- request_.get(), NULL, file_system_context); |
+ request_.get(), NULL, url.GetOrigin().host(), file_system_context); |
request_->Start(); |
ASSERT_TRUE(request_->is_pending()); // verify that we're starting async |
@@ -158,6 +203,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { |
file_info, platform_file_path); |
} |
+ // If |size| is negative, the reported size is ignored. |
void VerifyListingEntry(const std::string& entry_line, |
const std::string& name, |
const std::string& url, |
@@ -178,8 +224,10 @@ class FileSystemDirURLRequestJobTest : public testing::Test { |
EXPECT_EQ(icu::UnicodeString(url.c_str()), match.group(2, status)); |
EXPECT_EQ(icu::UnicodeString(is_directory ? "1" : "0"), |
match.group(3, status)); |
- icu::UnicodeString size_string(FormatBytesUnlocalized(size).c_str()); |
- EXPECT_EQ(size_string, match.group(4, status)); |
+ if (size >= 0) { |
+ icu::UnicodeString size_string(FormatBytesUnlocalized(size).c_str()); |
+ EXPECT_EQ(size_string, match.group(4, status)); |
+ } |
base::Time date; |
icu::UnicodeString date_ustr(match.group(5, status)); |
@@ -265,6 +313,7 @@ TEST_F(FileSystemDirURLRequestJobTest, DirectoryListing) { |
EXPECT_TRUE(!!std::getline(in, line)); |
VerifyListingEntry(line, "baz", "baz", true, 0); |
+ EXPECT_FALSE(!!std::getline(in, line)); |
} |
TEST_F(FileSystemDirURLRequestJobTest, InvalidURL) { |
@@ -321,5 +370,67 @@ TEST_F(FileSystemDirURLRequestJobTest, Incognito) { |
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
} |
+TEST_F(FileSystemDirURLRequestJobTest, AutoMountDirectoryListing) { |
+ base::FilePath mnt_point; |
+ SetUpAutoMountContext(&mnt_point); |
+ ASSERT_TRUE(base::CreateDirectory(mnt_point)); |
+ ASSERT_TRUE(base::CreateDirectory(mnt_point.AppendASCII("foo"))); |
+ ASSERT_EQ(10, |
+ base::WriteFile(mnt_point.AppendASCII("bar"), "1234567890", 10)); |
+ |
+ TestRequest(GURL("filesystem:http://automount/external/mnt_name")); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ EXPECT_EQ(1, delegate_->response_started_count()); |
+ EXPECT_FALSE(delegate_->received_data_before_response()); |
+ EXPECT_GT(delegate_->bytes_received(), 0); |
+ |
+ std::istringstream in(delegate_->data_received()); |
+ std::string line; |
+ EXPECT_TRUE(!!std::getline(in, line)); // |line| contains the temp dir path. |
+ |
+ // Result order is not guaranteed, so sort the results. |
+ std::vector<std::string> listing_entries; |
+ while (!!std::getline(in, line)) |
+ listing_entries.push_back(line); |
+ |
+ ASSERT_EQ(2U, listing_entries.size()); |
+ std::sort(listing_entries.begin(), listing_entries.end()); |
+ VerifyListingEntry(listing_entries[0], "bar", "bar", false, 10); |
+ VerifyListingEntry(listing_entries[1], "foo", "foo", true, -1); |
+ |
+ ASSERT_TRUE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ kValidExternalMountPoint)); |
+} |
+ |
+TEST_F(FileSystemDirURLRequestJobTest, AutoMountInvalidRoot) { |
+ base::FilePath mnt_point; |
+ SetUpAutoMountContext(&mnt_point); |
+ TestRequest(GURL("filesystem:http://automount/external/invalid")); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ ASSERT_FALSE(request_->status().is_success()); |
+ EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
+ |
+ ASSERT_FALSE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ "invalid")); |
+} |
+ |
+TEST_F(FileSystemDirURLRequestJobTest, AutoMountNoHandler) { |
+ base::FilePath mnt_point; |
+ SetUpAutoMountContext(&mnt_point); |
+ TestRequest(GURL("filesystem:http://noauto/external/mnt_name")); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ ASSERT_FALSE(request_->status().is_success()); |
+ EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
+ |
+ ASSERT_FALSE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ kValidExternalMountPoint)); |
+} |
+ |
} // namespace (anonymous) |
} // namespace content |