summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/isolated_context_unittest.cc
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-10 11:13:29 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-10 11:13:29 +0000
commita72724762650fed4e22a3e4df754a3e0ed6b9ecf (patch)
tree1e778133a9eba827c7ba0e3cb85b74beaba5e4b8 /webkit/fileapi/isolated_context_unittest.cc
parent0909220f66fc4ca6a3a107dfe6f589972e965c7a (diff)
downloadchromium_src-a72724762650fed4e22a3e4df754a3e0ed6b9ecf.zip
chromium_src-a72724762650fed4e22a3e4df754a3e0ed6b9ecf.tar.gz
chromium_src-a72724762650fed4e22a3e4df754a3e0ed6b9ecf.tar.bz2
Make isolated file system works for a device root (e.g. X:\\)
* directory drag-and-drop should work for a USB drive etc * Media device intent should work on Windows BUG=134828,135010 TEST=manually tested TEST=IsolatedContext\* Review URL: https://chromiumcodereview.appspot.com/10713007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/isolated_context_unittest.cc')
-rw-r--r--webkit/fileapi/isolated_context_unittest.cc82
1 files changed, 48 insertions, 34 deletions
diff --git a/webkit/fileapi/isolated_context_unittest.cc b/webkit/fileapi/isolated_context_unittest.cc
index 5a828f5..ee54557 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,15 +21,23 @@
namespace fileapi {
+typedef IsolatedContext::FileInfo FileInfo;
+
namespace {
const FilePath kTestPaths[] = {
- FilePath(DRIVE FPL("/a/b")),
+ FilePath(DRIVE FPL("/a/b.txt")),
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
+ // For duplicated base name test.
+ FilePath(DRIVE FPL("/")),
+ FilePath(DRIVE FPL("/f/e")),
+ FilePath(DRIVE FPL("/f/b.txt")),
};
} // namespace
@@ -41,12 +50,15 @@ class IsolatedContextTest : public testing::Test {
}
void SetUp() {
- id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_);
+ IsolatedContext::FileInfoSet files;
+ for (size_t i = 0; i < arraysize(kTestPaths); ++i)
+ names_.push_back(files.AddPath(kTestPaths[i].NormalizePathSeparators()));
+ id_ = IsolatedContext::GetInstance()->RegisterFileSystem(files);
ASSERT_FALSE(id_.empty());
}
void TearDown() {
- IsolatedContext::GetInstance()->RevokeIsolatedFileSystem(id_);
+ IsolatedContext::GetInstance()->RevokeFileSystem(id_);
}
IsolatedContext* isolated_context() const {
@@ -55,7 +67,8 @@ class IsolatedContextTest : public testing::Test {
protected:
std::string id_;
- std::set<FilePath> fileset_;
+ std::multiset<FilePath> fileset_;
+ std::vector<std::string> names_;
private:
DISALLOW_COPY_AND_ASSIGN(IsolatedContextTest);
@@ -63,40 +76,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
+ // See if the name of each registered kTestPaths (that is what we
+ // 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(names_[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(
+ IsolatedContext::FileInfoSet());
- // 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 +136,19 @@ 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(names_[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));
}
} // namespace fileapi