| Index: webkit/fileapi/isolated_context_unittest.cc
|
| diff --git a/webkit/fileapi/isolated_context_unittest.cc b/webkit/fileapi/isolated_context_unittest.cc
|
| index a1b138b691f5cc60e130afe3285fde6f826aeec6..a031fb52bb748c521563c9f79c241625142f887d 100644
|
| --- a/webkit/fileapi/isolated_context_unittest.cc
|
| +++ b/webkit/fileapi/isolated_context_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/basictypes.h"
|
| #include "base/logging.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "webkit/fileapi/isolated_context.h"
|
|
|
| #define FPL(x) FILE_PATH_LITERAL(x)
|
|
|
| @@ -20,14 +21,18 @@
|
|
|
| namespace fileapi {
|
|
|
| +typedef IsolatedContext::FileInfo FileInfo;
|
| +
|
| namespace {
|
|
|
| const FilePath kTestPaths[] = {
|
| FilePath(DRIVE FPL("/a/b")),
|
| FilePath(DRIVE FPL("/c/d/e")),
|
| FilePath(DRIVE FPL("/h/")),
|
| + FilePath(DRIVE FPL("/")),
|
| #if defined(FILE_PATH_USES_WIN_SEPARATORS)
|
| FilePath(DRIVE FPL("\\foo\\bar")),
|
| + FilePath(DRIVE FPL("\\")),
|
| #endif
|
| };
|
|
|
| @@ -41,12 +46,19 @@ class IsolatedContextTest : public testing::Test {
|
| }
|
|
|
| void SetUp() {
|
| - id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_);
|
| + std::vector<IsolatedContext::FileInfo> files;
|
| + for (std::set<FilePath>::iterator iter = fileset_.begin();
|
| + iter != fileset_.end(); ++iter) {
|
| + files.push_back(IsolatedContext::FileInfo(
|
| + fileapi::IsolatedContext::GetNameForPath(*iter),
|
| + iter->NormalizePathSeparators()));
|
| + }
|
| + id_ = IsolatedContext::GetInstance()->RegisterFileSystem(files);
|
| ASSERT_FALSE(id_.empty());
|
| }
|
|
|
| void TearDown() {
|
| - IsolatedContext::GetInstance()->RevokeIsolatedFileSystem(id_);
|
| + IsolatedContext::GetInstance()->RevokeFileSystem(id_);
|
| }
|
|
|
| IsolatedContext* isolated_context() const {
|
| @@ -63,40 +75,41 @@ class IsolatedContextTest : public testing::Test {
|
|
|
| TEST_F(IsolatedContextTest, RegisterAndRevokeTest) {
|
| // See if the returned top-level entries match with what we registered.
|
| - std::vector<FilePath> toplevels;
|
| - ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id_, &toplevels));
|
| + std::vector<FileInfo> toplevels;
|
| + ASSERT_TRUE(isolated_context()->GetRegisteredFileInfo(id_, &toplevels));
|
| ASSERT_EQ(fileset_.size(), toplevels.size());
|
| for (size_t i = 0; i < toplevels.size(); ++i) {
|
| - ASSERT_TRUE(fileset_.find(toplevels[i]) != fileset_.end());
|
| + ASSERT_TRUE(fileset_.find(toplevels[i].path) != fileset_.end());
|
| }
|
|
|
| // See if the basename of each registered kTestPaths (that is what we
|
| - // register in SetUp() by RegisterIsolatedFileSystem) is properly cracked as
|
| + // register in SetUp() by RegisterFileSystem) is properly cracked as
|
| // a valid virtual path in the isolated filesystem.
|
| for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
|
| - FilePath virtual_path = isolated_context()->CreateVirtualPath(
|
| - id_, kTestPaths[i].BaseName());
|
| + FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_)
|
| + .AppendASCII(IsolatedContext::GetNameForPath(kTestPaths[i]));
|
| std::string cracked_id;
|
| - FilePath root_path, cracked_path;
|
| + FileInfo root_info;
|
| + FilePath cracked_path;
|
| ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
|
| - virtual_path, &cracked_id, &root_path, &cracked_path));
|
| + virtual_path, &cracked_id, &root_info, &cracked_path));
|
| ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(),
|
| cracked_path.value());
|
| - ASSERT_TRUE(fileset_.find(root_path.NormalizePathSeparators())
|
| + ASSERT_TRUE(fileset_.find(root_info.path.NormalizePathSeparators())
|
| != fileset_.end());
|
| ASSERT_EQ(id_, cracked_id);
|
| }
|
|
|
| // Revoking the current one and registering a new (empty) one.
|
| - isolated_context()->RevokeIsolatedFileSystem(id_);
|
| - std::string id2 = isolated_context()->RegisterIsolatedFileSystem(
|
| - std::set<FilePath>());
|
| + isolated_context()->RevokeFileSystem(id_);
|
| + std::string id2 = isolated_context()->RegisterFileSystem(
|
| + std::vector<FileInfo>());
|
|
|
| - // Make sure the GetTopLevelPaths returns true only for the new one.
|
| - ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id2, &toplevels));
|
| - ASSERT_FALSE(isolated_context()->GetTopLevelPaths(id_, &toplevels));
|
| + // Make sure the GetRegisteredFileInfo returns true only for the new one.
|
| + ASSERT_TRUE(isolated_context()->GetRegisteredFileInfo(id2, &toplevels));
|
| + ASSERT_FALSE(isolated_context()->GetRegisteredFileInfo(id_, &toplevels));
|
|
|
| - isolated_context()->RevokeIsolatedFileSystem(id2);
|
| + isolated_context()->RevokeFileSystem(id2);
|
| }
|
|
|
| TEST_F(IsolatedContextTest, CrackWithRelativePaths) {
|
| @@ -122,18 +135,20 @@ TEST_F(IsolatedContextTest, CrackWithRelativePaths) {
|
| for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) {
|
| SCOPED_TRACE(testing::Message() << "Testing "
|
| << kTestPaths[i].value() << " " << relatives[j].path);
|
| - FilePath virtual_path = isolated_context()->CreateVirtualPath(
|
| - id_, kTestPaths[i].BaseName().Append(relatives[j].path));
|
| + FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_)
|
| + .AppendASCII(IsolatedContext::GetNameForPath(kTestPaths[i]))
|
| + .Append(relatives[j].path);
|
| std::string cracked_id;
|
| - FilePath root_path, cracked_path;
|
| + FileInfo root_info;
|
| + FilePath cracked_path;
|
| if (!relatives[j].valid) {
|
| ASSERT_FALSE(isolated_context()->CrackIsolatedPath(
|
| - virtual_path, &cracked_id, &root_path, &cracked_path));
|
| + virtual_path, &cracked_id, &root_info, &cracked_path));
|
| continue;
|
| }
|
| ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
|
| - virtual_path, &cracked_id, &root_path, &cracked_path));
|
| - ASSERT_TRUE(fileset_.find(root_path.NormalizePathSeparators())
|
| + virtual_path, &cracked_id, &root_info, &cracked_path));
|
| + ASSERT_TRUE(fileset_.find(root_info.path.NormalizePathSeparators())
|
| != fileset_.end());
|
| ASSERT_EQ(kTestPaths[i].Append(relatives[j].path)
|
| .NormalizePathSeparators().value(),
|
| @@ -145,24 +160,23 @@ TEST_F(IsolatedContextTest, CrackWithRelativePaths) {
|
|
|
| TEST_F(IsolatedContextTest, TestWithVirtualRoot) {
|
| std::string cracked_id;
|
| - FilePath root_path, cracked_path;
|
| - const FilePath root(FPL("/"));
|
| + FilePath cracked_path;
|
|
|
| // Trying to crack virtual root "/" returns true but with empty cracked path
|
| // as "/" of the isolated filesystem is a pure virtual directory
|
| // that has no corresponding platform directory.
|
| - FilePath virtual_path = isolated_context()->CreateVirtualPath(id_, root);
|
| + FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_);
|
| ASSERT_TRUE(isolated_context()->CrackIsolatedPath(
|
| - virtual_path, &cracked_id, &root_path, &cracked_path));
|
| + virtual_path, &cracked_id, NULL, &cracked_path));
|
| ASSERT_EQ(FPL(""), cracked_path.value());
|
| ASSERT_EQ(id_, cracked_id);
|
|
|
| // Trying to crack "/foo" should fail (because "foo" is not the one
|
| // included in the kTestPaths).
|
| - virtual_path = isolated_context()->CreateVirtualPath(
|
| - id_, FilePath(FPL("foo")));
|
| + virtual_path = isolated_context()->CreateVirtualRootPath(
|
| + id_).AppendASCII("foo");
|
| ASSERT_FALSE(isolated_context()->CrackIsolatedPath(
|
| - virtual_path, &cracked_id, &root_path, &cracked_path));
|
| + virtual_path, &cracked_id, NULL, &cracked_path));
|
| }
|
|
|
| TEST_F(IsolatedContextTest, Writable) {
|
| @@ -179,7 +193,7 @@ TEST_F(IsolatedContextTest, Writable) {
|
|
|
| // Set writable again, and revoke the filesystem.
|
| ASSERT_TRUE(isolated_context()->SetWritable(id_, true));
|
| - isolated_context()->RevokeIsolatedFileSystem(id_);
|
| + isolated_context()->RevokeFileSystem(id_);
|
|
|
| // IsWritable should return false for non-registered file system.
|
| ASSERT_FALSE(isolated_context()->IsWritable(id_));
|
|
|