This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "webkit/browser/fileapi/external_mount_points.h"
#include <string>
#include "base/files/file_path.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/file_system_url.h"
#define FPL FILE_PATH_LITERAL
#if defined(FILE_PATH_USES_DRIVE_LETTERS)
#define DRIVE FPL("C:")
#else
#define DRIVE
#endif
using fileapi::FileSystemURL;
namespace {
TEST(ExternalMountPointsTest, AddMountPoint) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
struct TestCase {
const char* const name;
const base::FilePath::CharType* const path;
bool success;
const base::FilePath::CharType* const registered_path;
};
const TestCase kTestCases[] = {
{ "test", DRIVE FPL("/foo/test"), true, DRIVE FPL("/foo/test") },
{ "bbb", DRIVE FPL("/bbb"), true, DRIVE FPL("/bbb") },
{ "test11", DRIVE FPL("/foo/test11"), true, DRIVE FPL("/foo/test11") },
{ "test1", DRIVE FPL("/foo/test1"), true, DRIVE FPL("/foo/test1") },
{ "", DRIVE FPL(""), false, NULL },
{ "", DRIVE FPL("/ddd"), false, NULL },
{ "empty_path", FPL(""), true, FPL("") },
{ "not_base_name", DRIVE FPL("/x/y/z"), true, DRIVE FPL("/x/y/z") },
{ "invalid", DRIVE FPL("../foo/invalid"), false, NULL },
{ "relative", DRIVE FPL("foo/relative"), false, NULL },
{ "path_exists", DRIVE FPL("/foo/test"), false, NULL },
{ "test", DRIVE FPL("/foo/a/test_name_exists"), false,
DRIVE FPL("/foo/test") },
{ "a1", DRIVE FPL("/foo/test/a"), false, NULL },
{ "foo1", DRIVE FPL("/foo"), false, NULL },
{ "g", DRIVE FPL("/foo/a/b/c/d/e/f/g"), true,
DRIVE FPL("/foo/a/b/c/d/e/f/g") },
{ "ff", DRIVE FPL("/foo/a/b/c/d/e/ff"), true,
DRIVE FPL("/foo/a/b/c/d/e/ff") },
{ "yyy", DRIVE FPL("/zzz/yyy"), true, DRIVE FPL("/zzz/yyy") },
{ "zzz1", DRIVE FPL("/zzz"), false, NULL },
{ "xxx1", DRIVE FPL("/zzz/yyy/xxx"), false, NULL },
{ "b", DRIVE FPL("/a/b"), true, DRIVE FPL("/a/b") },
{ "a2", DRIVE FPL("/a"), false, NULL },
{ "c1", DRIVE FPL("/a/b/c"), false, NULL },
{ "root", DRIVE FPL("/"), false, NULL },
{ "funky", DRIVE FPL("/tt/fun/../funky"), false, NULL },
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
{ "win", DRIVE FPL("\\try\\separators\\win"), true,
DRIVE FPL("\\try\\separators\\win") },
{ "win1", DRIVE FPL("\\try/separators\\win1"), true,
DRIVE FPL("\\try/separators\\win1") },
{ "win2", DRIVE FPL("\\try/separators\\win"), false, NULL },
#else
{ "win", DRIVE FPL("\\separators\\win"), false, NULL },
{ "win1", DRIVE FPL("\\try/separators\\win1"), false, NULL },
#endif
{ "win2", DRIVE FPL("try\\separators\\win2"), false, NULL },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
EXPECT_EQ(kTestCases[i].success,
mount_points->RegisterFileSystem(
kTestCases[i].name,
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(kTestCases[i].path)))
<< "Adding mount point: " << kTestCases[i].name << " with path "
<< kTestCases[i].path;
}
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
base::FilePath found_path;
EXPECT_EQ(kTestCases[i].registered_path != NULL,
mount_points->GetRegisteredPath(kTestCases[i].name, &found_path))
<< "Test case: " << i;
if (kTestCases[i].registered_path) {
base::FilePath expected_path(kTestCases[i].registered_path);
EXPECT_EQ(expected_path.NormalizePathSeparators(), found_path);
}
}
}
TEST(ExternalMountPointsTest, GetVirtualPath) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
mount_points->RegisterFileSystem("c",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c")));
mount_points->RegisterFileSystem("c(1)",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c(1)")));
mount_points->RegisterFileSystem("x",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/z/y/x")));
mount_points->RegisterFileSystem("o",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/m/n/o")));
mount_points->RegisterFileSystem("mount",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/root/foo")));
mount_points->RegisterFileSystem("empty_path",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath());
struct TestCase {
const base::FilePath::CharType* const local_path;
bool success;
const base::FilePath::CharType* const virtual_path;
};
const TestCase kTestCases[] = {
{ FPL(""), false, FPL("") },
{ DRIVE FPL("/a/b"), false, FPL("") },
{ DRIVE FPL("/z/y"), false, FPL("") },
{ DRIVE FPL("/m/n"), false, FPL("") },
{ DRIVE FPL("/foo/mount"), false, FPL("") },
{ DRIVE FPL("/a/b/c1"), false, FPL("") },
{ DRIVE FPL("a/b/c"), false, FPL("") },
{ DRIVE FPL("/a/b/d/e"), false, FPL("") },
{ DRIVE FPL("/z/y/v/u"), false, FPL("") },
{ DRIVE FPL("/m/n/p/q"), false, FPL("") },
{ DRIVE FPL("/a/b/c"), true, FPL("c") },
{ DRIVE FPL("/z/y/x"), true, FPL("x") },
{ DRIVE FPL("/m/n/o"), true, FPL("o") },
{ DRIVE FPL("/a/b/c/d/e"), true, FPL("c/d/e") },
{ DRIVE FPL("/z/y/x/v/u"), true, FPL("x/v/u") },
{ DRIVE FPL("/m/n/o/p/q"), true, FPL("o/p/q") },
{ DRIVE FPL("/root/foo/a/b/c"), true, FPL("mount/a/b/c") },
{ DRIVE FPL("/root/foo"), true, FPL("mount") },
{ DRIVE FPL("/a/b/c(1)/d/e"), true, FPL("c(1)/d/e") },
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
{ DRIVE FPL("/a\\b\\c/d"), true, FPL("c/d") },
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
base::FilePath virtual_path(DRIVE FPL("/mount"));
base::FilePath local_path(kTestCases[i].local_path);
EXPECT_EQ(kTestCases[i].success,
mount_points->GetVirtualPath(local_path, &virtual_path))
<< "Resolving " << kTestCases[i].local_path;
if (!kTestCases[i].success)
continue;
base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
<< "Resolving " << kTestCases[i].local_path;
}
}
TEST(ExternalMountPointsTest, HandlesFileSystemMountType) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
const GURL test_origin("http://chromium.org");
const base::FilePath test_path(FPL("/mount"));
EXPECT_TRUE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeExternal));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeIsolated));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeTemporary));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypePersistent));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeTest));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeNativeLocal));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeRestrictedNativeLocal));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeDrive));
EXPECT_FALSE(mount_points->HandlesFileSystemMountType(
fileapi::kFileSystemTypeSyncable));
}
TEST(ExternalMountPointsTest, CreateCrackedFileSystemURL) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
const GURL kTestOrigin("http://chromium.org");
mount_points->RegisterFileSystem("c",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c")));
mount_points->RegisterFileSystem("c(1)",
fileapi::kFileSystemTypeDrive,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c(1)")));
mount_points->RegisterFileSystem("empty_path",
fileapi::kFileSystemTypeSyncable,
fileapi::FileSystemMountOption(),
base::FilePath());
mount_points->RegisterFileSystem("mount",
fileapi::kFileSystemTypeDrive,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/root")));
FileSystemURL invalid = mount_points->CrackURL(GURL("http://chromium.og"));
EXPECT_FALSE(invalid.is_valid());
FileSystemURL isolated = mount_points->CreateCrackedFileSystemURL(
kTestOrigin, fileapi::kFileSystemTypeIsolated, base::FilePath(FPL("c")));
EXPECT_FALSE(isolated.is_valid());
FileSystemURL native_local = mount_points->CreateCrackedFileSystemURL(
kTestOrigin,
fileapi::kFileSystemTypeNativeLocal,
base::FilePath(FPL("c")));
EXPECT_FALSE(native_local.is_valid());
struct TestCase {
const base::FilePath::CharType* const path;
bool expect_valid;
fileapi::FileSystemType expect_type;
const base::FilePath::CharType* const expect_path;
const char* const expect_fs_id;
};
const TestCase kTestCases[] = {
{ FPL("c/d/e"),
true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
{ FPL("c(1)/d/e"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
{ FPL("c(1)"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
{ FPL("empty_path/a"),
true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
{ FPL("empty_path"),
true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
{ FPL("mount/a/b"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
{ FPL("mount"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
{ FPL("cc"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL(""),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL(".."),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/c/d/e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/c(1)/d/e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/empty_path"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("c/d/../e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/empty_path/a/../b"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
{ FPL("c/d\\e"),
true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
{ FPL("mount\\a\\b"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
FileSystemURL cracked = mount_points->CreateCrackedFileSystemURL(
kTestOrigin,
fileapi::kFileSystemTypeExternal,
base::FilePath(kTestCases[i].path));
EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid())
<< "Test case index: " << i;
if (!kTestCases[i].expect_valid)
continue;
EXPECT_EQ(kTestOrigin, cracked.origin())
<< "Test case index: " << i;
EXPECT_EQ(kTestCases[i].expect_type, cracked.type())
<< "Test case index: " << i;
EXPECT_EQ(base::FilePath(
kTestCases[i].expect_path).NormalizePathSeparators(), cracked.path())
<< "Test case index: " << i;
EXPECT_EQ(base::FilePath(kTestCases[i].path).NormalizePathSeparators(),
cracked.virtual_path())
<< "Test case index: " << i;
EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id())
<< "Test case index: " << i;
EXPECT_EQ(fileapi::kFileSystemTypeExternal, cracked.mount_type())
<< "Test case index: " << i;
}
}
TEST(ExternalMountPointsTest, CrackVirtualPath) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
const GURL kTestOrigin("http://chromium.org");
mount_points->RegisterFileSystem("c",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c")));
mount_points->RegisterFileSystem("c(1)",
fileapi::kFileSystemTypeDrive,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/a/b/c(1)")));
mount_points->RegisterFileSystem("empty_path",
fileapi::kFileSystemTypeSyncable,
fileapi::FileSystemMountOption(),
base::FilePath());
mount_points->RegisterFileSystem("mount",
fileapi::kFileSystemTypeDrive,
fileapi::FileSystemMountOption(),
base::FilePath(DRIVE FPL("/root")));
struct TestCase {
const base::FilePath::CharType* const path;
bool expect_valid;
fileapi::FileSystemType expect_type;
const base::FilePath::CharType* const expect_path;
const char* const expect_name;
};
const TestCase kTestCases[] = {
{ FPL("c/d/e"),
true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
{ FPL("c(1)/d/e"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
{ FPL("c(1)"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
{ FPL("empty_path/a"),
true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
{ FPL("empty_path"),
true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
{ FPL("mount/a/b"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
{ FPL("mount"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
{ FPL("cc"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL(""),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL(".."),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/c/d/e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/c(1)/d/e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/empty_path"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("c/d/../e"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
{ FPL("/empty_path/a/../b"),
false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
{ FPL("c/d\\e"),
true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
{ FPL("mount\\a\\b"),
true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
std::string cracked_name;
fileapi::FileSystemType cracked_type;
base::FilePath cracked_path;
fileapi::FileSystemMountOption cracked_option;
EXPECT_EQ(kTestCases[i].expect_valid,
mount_points->CrackVirtualPath(base::FilePath(kTestCases[i].path),
&cracked_name, &cracked_type, &cracked_path, &cracked_option))
<< "Test case index: " << i;
if (!kTestCases[i].expect_valid)
continue;
EXPECT_EQ(kTestCases[i].expect_type, cracked_type)
<< "Test case index: " << i;
EXPECT_EQ(base::FilePath(
kTestCases[i].expect_path).NormalizePathSeparators(), cracked_path)
<< "Test case index: " << i;
EXPECT_EQ(kTestCases[i].expect_name, cracked_name)
<< "Test case index: " << i;
}
}
TEST(ExternalMountPointsTest, MountOption) {
scoped_refptr<fileapi::ExternalMountPoints> mount_points(
fileapi::ExternalMountPoints::CreateRefCounted());
mount_points->RegisterFileSystem(
"nosync",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(fileapi::COPY_SYNC_OPTION_NO_SYNC),
base::FilePath(DRIVE FPL("/nosync")));
mount_points->RegisterFileSystem(
"sync",
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(fileapi::COPY_SYNC_OPTION_SYNC),
base::FilePath(DRIVE FPL("/sync")));
std::string name;
fileapi::FileSystemType type;
fileapi::FileSystemMountOption option;
base::FilePath path;
EXPECT_TRUE(mount_points->CrackVirtualPath(
base::FilePath(FPL("nosync/file")), &name, &type, &path, &option));
EXPECT_EQ(fileapi::COPY_SYNC_OPTION_NO_SYNC, option.copy_sync_option());
EXPECT_TRUE(mount_points->CrackVirtualPath(
base::FilePath(FPL("sync/file")), &name, &type, &path, &option));
EXPECT_EQ(fileapi::COPY_SYNC_OPTION_SYNC, option.copy_sync_option());
}
}