From 5c5291df2649a2d86c55f229a42fe3a50577a171 Mon Sep 17 00:00:00 2001 From: "mtomasz@chromium.org" Date: Fri, 27 Jun 2014 06:07:49 +0000 Subject: [PATCH] [fsp] Fix parsing a URL in case it is of an isolated type. Before, the parser class was parsing a virtual_path() member of the passed URL, which in case of an isolated file system url was of a different format. This CL resolves this issue by relying on path(), not virtual_path(). The first one is of the same format for both file system url types. TEST=unit_test: *FileSystemProvider*Parser_IsolatedURL& BUG=388963 Review URL: https://codereview.chromium.org/339713007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280248 0039d316-1c4b-4281-b951-d872f2087c98 --- .../file_system_provider/mount_path_util.cc | 12 ++--- .../mount_path_util_unittest.cc | 51 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/chrome/browser/chromeos/file_system_provider/mount_path_util.cc b/chrome/browser/chromeos/file_system_provider/mount_path_util.cc index 8ea1a40d2cc2..5ad64fa3e8d9 100644 --- a/chrome/browser/chromeos/file_system_provider/mount_path_util.cc +++ b/chrome/browser/chromeos/file_system_provider/mount_path_util.cc @@ -111,14 +111,16 @@ bool FileSystemURLParser::Parse() { if (!file_system) continue; - // Strip the mount point name from the virtual path, to extract the file - // path within the provided file system. + // Strip the mount path name from the local path, to extract the file path + // within the provided file system. file_system_ = file_system; std::vector components; - url_.virtual_path().GetComponents(&components); - DCHECK_LT(0u, components.size()); + url_.path().GetComponents(&components); + if (components.size() < 3) + return false; + file_path_ = base::FilePath::FromUTF8Unsafe("/"); - for (size_t i = 1; i < components.size(); ++i) { + for (size_t i = 3; i < components.size(); ++i) { // TODO(mtomasz): This could be optimized, to avoid unnecessary copies. file_path_ = file_path_.Append(components[i]); } diff --git a/chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc b/chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc index 433ae5cfc5c0..99c7007530cd 100644 --- a/chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc +++ b/chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc @@ -22,6 +22,7 @@ #include "extensions/browser/extension_registry.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/browser/fileapi/external_mount_points.h" +#include "webkit/browser/fileapi/isolated_context.h" namespace chromeos { namespace file_system_provider { @@ -177,9 +178,9 @@ TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { kFileSystemName, GetMountPath(profile_, kExtensionId, kFileSystemId)); - const base::FilePath file_path = base::FilePath::FromUTF8Unsafe("/hello"); + const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); const fileapi::FileSystemURL url = - CreateFileSystemURL(profile_, file_system_info, file_path); + CreateFileSystemURL(profile_, file_system_info, kFilePath); // It is impossible to create a cracked URL for a mount point which doesn't // exist, therefore is will always be invalid, and empty. EXPECT_FALSE(url.is_valid()); @@ -188,6 +189,52 @@ TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { EXPECT_FALSE(parser.Parse()); } +TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { + const bool result = file_system_provider_service_->MountFileSystem( + kExtensionId, kFileSystemId, kFileSystemName); + ASSERT_TRUE(result); + const ProvidedFileSystemInfo file_system_info = + file_system_provider_service_->GetProvidedFileSystem(kExtensionId, + kFileSystemId) + ->GetFileSystemInfo(); + + const base::FilePath kFilePath = + base::FilePath::FromUTF8Unsafe("/hello/world.txt"); + const fileapi::FileSystemURL url = + CreateFileSystemURL(profile_, file_system_info, kFilePath); + EXPECT_TRUE(url.is_valid()); + + // Create an isolated URL for the original one. + fileapi::IsolatedContext* const isolated_context = + fileapi::IsolatedContext::GetInstance(); + const std::string isolated_file_system_id = + isolated_context->RegisterFileSystemForPath( + fileapi::kFileSystemTypeProvided, + url.filesystem_id(), + url.path(), + NULL); + + const base::FilePath isolated_virtual_path = + isolated_context->CreateVirtualRootPath(isolated_file_system_id) + .Append(kFilePath.BaseName().value()); + + const fileapi::FileSystemURL isolated_url = + isolated_context->CreateCrackedFileSystemURL( + url.origin(), + fileapi::kFileSystemTypeIsolated, + isolated_virtual_path); + + EXPECT_TRUE(isolated_url.is_valid()); + + FileSystemURLParser parser(isolated_url); + EXPECT_TRUE(parser.Parse()); + + ProvidedFileSystemInterface* file_system = parser.file_system(); + ASSERT_TRUE(file_system); + EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); + EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); +} + TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { const bool result = file_system_provider_service_->MountFileSystem( kExtensionId, kFileSystemId, kFileSystemName); -- 2.11.4.GIT