Index: content/browser/fileapi/file_system_url_request_job_unittest.cc |
diff --git a/content/browser/fileapi/file_system_url_request_job_unittest.cc b/content/browser/fileapi/file_system_url_request_job_unittest.cc |
index 7fe55f600053c56b08ee296d8e423f3a187a8501..9b7eb8c4e525e9ad994b82c315fcd3e5cf2b32a3 100644 |
--- a/content/browser/fileapi/file_system_url_request_job_unittest.cc |
+++ b/content/browser/fileapi/file_system_url_request_job_unittest.cc |
@@ -53,6 +53,37 @@ void FillBuffer(char* buffer, size_t len) { |
base::RandBytes(buffer, len); |
} |
+static 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 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
ditto, AsUTF8Unsafe() should work?
vandebo (ex-Chrome)
2014/03/13 20:19:32
Done.
|
+#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 FileSystemURLRequestJobTest : public testing::Test { |
@@ -110,7 +141,7 @@ class FileSystemURLRequestJobTest : public testing::Test { |
request_->SetExtraRequestHeaders(*headers); |
ASSERT_TRUE(!job_); |
job_ = new FileSystemURLRequestJob( |
- request_.get(), NULL, file_system_context); |
+ request_.get(), NULL, url.GetOrigin().host(), file_system_context); |
pending_job_ = job_; |
request_->Start(); |
@@ -260,7 +291,6 @@ TEST_F(FileSystemURLRequestJobTest, FileTestHalfSpecifiedRange) { |
EXPECT_TRUE(partial_buffer_string == delegate_->data_received()); |
} |
- |
TEST_F(FileSystemURLRequestJobTest, FileTestMultipleRangesNotSupported) { |
WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1); |
net::HttpRequestHeaders headers; |
@@ -369,5 +399,85 @@ TEST_F(FileSystemURLRequestJobTest, Incognito) { |
EXPECT_EQ(200, request_->GetResponseCode()); |
} |
+TEST_F(FileSystemURLRequestJobTest, AutoMountFileTest) { |
+ base::FilePath mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir"); |
+ ASSERT_TRUE(base::CreateDirectory(mnt_point)); |
+ ASSERT_EQ(static_cast<int>(sizeof(kTestFileData)) - 1, |
+ base::WriteFile(mnt_point.AppendASCII("foo"), kTestFileData, |
+ sizeof(kTestFileData) - 1)); |
+ |
+ 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/foo"), |
+ file_system_context); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ EXPECT_EQ(1, delegate_->response_started_count()); |
+ EXPECT_FALSE(delegate_->received_data_before_response()); |
+ EXPECT_EQ(kTestFileData, delegate_->data_received()); |
+ EXPECT_EQ(200, request_->GetResponseCode()); |
+ std::string cache_control; |
+ request_->GetResponseHeaderByName("cache-control", &cache_control); |
+ EXPECT_EQ("no-cache", cache_control); |
+ |
+ ASSERT_TRUE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ kValidExternalMountPoint)); |
+} |
+ |
+TEST_F(FileSystemURLRequestJobTest, AutoMountInvalidRoot) { |
+ base::FilePath mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir"); |
+ ASSERT_TRUE(base::CreateDirectory(mnt_point)); |
+ ASSERT_EQ(static_cast<int>(sizeof(kTestFileData)) - 1, |
+ base::WriteFile(mnt_point.AppendASCII("foo"), kTestFileData, |
+ sizeof(kTestFileData) - 1)); |
+ |
+ 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/foo"), |
+ file_system_context); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ EXPECT_TRUE(delegate_->request_failed()); |
+ EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
+ |
+ ASSERT_FALSE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ "invalid")); |
+} |
+ |
+TEST_F(FileSystemURLRequestJobTest, AutoMountNoHandler) { |
+ base::FilePath mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir"); |
+ ASSERT_TRUE(base::CreateDirectory(mnt_point)); |
+ ASSERT_EQ(static_cast<int>(sizeof(kTestFileData)) - 1, |
+ base::WriteFile(mnt_point.AppendASCII("foo"), kTestFileData, |
+ sizeof(kTestFileData) - 1)); |
+ |
+ 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/foo"), |
+ file_system_context); |
+ |
+ ASSERT_FALSE(request_->is_pending()); |
+ EXPECT_TRUE(delegate_->request_failed()); |
+ EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
+ |
+ ASSERT_FALSE( |
+ fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
+ kValidExternalMountPoint)); |
+} |
+ |
} // namespace |
} // namespace content |