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

Unified Diff: content/browser/fileapi/file_system_dir_url_request_job_unittest.cc

Issue 195923002: Add mechanism to auto mount file systems in response to a URL request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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 46b4bb163f8219e52e4b89e17320f27b1c637450..73a102a5f6f948c0f5158b7f96aee99595892595 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,6 +6,7 @@
#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"
@@ -25,6 +26,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"
@@ -42,6 +44,38 @@ namespace {
static const char kFileSystemURLPrefix[] =
"filesystem:http://remote/temporary/";
+static const char kValidExternalMountPoint[] = "mnt_name";
kinuko 2014/03/13 04:19:20 nit: no need of static inside anon namespace? (And
vandebo (ex-Chrome) 2014/03/13 20:19:32 Done.
+
+// 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 base::FilePath& path,
+ 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);
+#if defined(OS_POSIX)
+ std::string mount_point = components[0];
+#elif defined(OS_WIN)
+ std::string mount_point = base::WideToUTF8(components[0]);
kinuko 2014/03/13 04:19:20 FilePath(components[0]).AsUTF8Unsafe() would work
vandebo (ex-Chrome) 2014/03/13 20:19:32 Yea, but then you make an unnecessary object... I
+#endif // OS_WIN
+
+ if (mount_point == kValidExternalMountPoint) {
+ fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
+ kValidExternalMountPoint, fileapi::kFileSystemTypeNativeLocal,
+ fileapi::FileSystemMountOption(), path);
+ callback.Run(base::File::FILE_OK);
+ } else {
+ callback.Run(base::File::FILE_ERROR_NOT_FOUND);
+ }
+ return true;
+}
+
} // namespace
class FileSystemDirURLRequestJobTest : public testing::Test {
@@ -90,7 +124,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
request_ = empty_context_.CreateRequest(
url, net::DEFAULT_PRIORITY, delegate_.get());
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
@@ -265,6 +299,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 +356,84 @@ TEST_F(FileSystemDirURLRequestJobTest, Incognito) {
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
}
+TEST_F(FileSystemDirURLRequestJobTest, AutoMountDirectoryListing) {
+ base::FilePath mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir");
+ 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));
+
+ std::vector<fileapi::URLRequestAutoMountHandler> handlers;
+ handlers.push_back(base::Bind(&TestAutoMountForURLRequest, mnt_point));
+ scoped_refptr<FileSystemContext> file_system_context =
+ CreateFileSystemContextWithAutoMountersForTesting(NULL, handlers,
+ temp_dir_.path());
+
+ TestRequestWithContext(GURL("filesystem:http://automount/external/mnt_name"),
+ file_system_context);
+
+ 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.
+
+ EXPECT_TRUE(!!std::getline(in, line));
+ VerifyListingEntry(line, "bar", "bar", false, 10);
+
+ EXPECT_TRUE(!!std::getline(in, line));
+ VerifyListingEntry(line, "foo", "foo", true, 4096);
+ EXPECT_FALSE(!!std::getline(in, line));
+
+ ASSERT_TRUE(
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
+ kValidExternalMountPoint));
+}
+
+TEST_F(FileSystemDirURLRequestJobTest, AutoMountInvalidRoot) {
+ base::FilePath mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir");
+ ASSERT_TRUE(base::CreateDirectory(mnt_point));
+
+ std::vector<fileapi::URLRequestAutoMountHandler> handlers;
+ handlers.push_back(base::Bind(&TestAutoMountForURLRequest, mnt_point));
+ scoped_refptr<FileSystemContext> file_system_context =
+ CreateFileSystemContextWithAutoMountersForTesting(NULL, handlers,
+ temp_dir_.path());
+
+ TestRequestWithContext(GURL("filesystem:http://automount/external/invalid"),
+ file_system_context);
+ 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 = temp_dir_.path().AppendASCII("auto_mount_dir");
+ ASSERT_TRUE(base::CreateDirectory(mnt_point));
+
+ std::vector<fileapi::URLRequestAutoMountHandler> handlers;
+ handlers.push_back(base::Bind(&TestAutoMountForURLRequest, mnt_point));
+ scoped_refptr<FileSystemContext> file_system_context =
+ CreateFileSystemContextWithAutoMountersForTesting(NULL, handlers,
+ temp_dir_.path());
+
+ TestRequestWithContext(GURL("filesystem:http://noauto/external/mnt_name"),
+ file_system_context);
+ 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

Powered by Google App Engine
This is Rietveld 408576698