Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Unified Diff: webkit/fileapi/file_system_mount_point_provider_unittest.cc

Issue 9004019: Cleanup: Removing FileSystemPathManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/file_system_mount_point_provider_unittest.cc
diff --git a/webkit/fileapi/file_system_path_manager_unittest.cc b/webkit/fileapi/file_system_mount_point_provider_unittest.cc
similarity index 78%
rename from webkit/fileapi/file_system_path_manager_unittest.cc
rename to webkit/fileapi/file_system_mount_point_provider_unittest.cc
index f99824db4d8f3ef685237cb773f1376fbd651d9f..21647ca2f630a9409bceb3030f00b8ab05fe46e4 100644
--- a/webkit/fileapi/file_system_path_manager_unittest.cc
+++ b/webkit/fileapi/file_system_mount_point_provider_unittest.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "webkit/fileapi/file_system_path_manager.h"
-
#include <set>
#include <string>
@@ -20,11 +18,18 @@
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_util.h"
+#include "webkit/fileapi/mock_file_system_options.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/mock_special_storage_policy.h"
+#if defined(OS_CHROMEOS)
+#include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
+#endif
+
namespace fileapi {
+
namespace {
// PS stands for path separator.
@@ -196,21 +201,25 @@ const struct IsRestrictedNameTest {
{ FILE_PATH_LITERAL(".b"), false, },
};
-FilePath UTF8ToFilePath(const std::string& str) {
- FilePath::StringType result;
-#if defined(OS_POSIX)
- result = base::SysWideToNativeMB(UTF8ToWide(str));
-#elif defined(OS_WIN)
- result = UTF8ToUTF16(str);
-#endif
- return FilePath(result);
-}
+// Mock FileSystem options for testing incognito mode.
+class IncognitoOptions : public FileSystemOptions {
+ public:
+ virtual bool is_incognito() const OVERRIDE { return true; }
+ virtual bool allow_file_access_from_files() const OVERRIDE { return false; }
+};
+
+// Mock FileSystem options that disallows file:// access.
+class DisallowFileAccessOptions : public FileSystemOptions {
+ public:
+ virtual bool is_incognito() const OVERRIDE { return false; }
+ virtual bool allow_file_access_from_files() const OVERRIDE { return false; }
+};
} // namespace
-class FileSystemPathManagerTest : public testing::Test {
+class FileSystemMountPointProviderTest : public testing::Test {
public:
- FileSystemPathManagerTest()
+ FileSystemMountPointProviderTest()
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
@@ -219,25 +228,29 @@ class FileSystemPathManagerTest : public testing::Test {
root_path_callback_status_ = false;
root_path_.clear();
file_system_name_.clear();
+ special_storage_policy_ = new quota::MockSpecialStoragePolicy;
}
protected:
- FileSystemPathManager* NewPathManager(
- bool incognito,
- bool allow_file_access) {
- FileSystemPathManager* manager = new FileSystemPathManager(
+ void SetupNewContext(FileSystemOptions* options) {
+ ASSERT_TRUE(options != NULL);
+ file_system_context_ = new FileSystemContext(
base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current(),
+ special_storage_policy_,
+ NULL,
data_dir_.path(),
- scoped_refptr<quota::SpecialStoragePolicy>(
- new quota::MockSpecialStoragePolicy),
- incognito,
- allow_file_access);
+ options);
#if defined(OS_CHROMEOS)
fileapi::ExternalFileSystemMountPointProvider* ext_provider =
- manager->external_provider();
+ file_system_context_->external_provider();
ext_provider->AddMountPoint(FilePath("/tmp/testing"));
#endif
- return manager;
+ }
+
+ FileSystemMountPointProvider* provider(FileSystemType type) {
+ DCHECK(file_system_context_);
+ return file_system_context_->GetMountPointProvider(type);
}
void OnGetRootPath(bool success,
@@ -248,14 +261,13 @@ class FileSystemPathManagerTest : public testing::Test {
file_system_name_ = name;
}
- bool GetRootPath(FileSystemPathManager* manager,
- const GURL& origin_url,
+ bool GetRootPath(const GURL& origin_url,
fileapi::FileSystemType type,
bool create,
FilePath* root_path) {
- manager->ValidateFileSystemRootAndGetURL(
+ provider(type)->ValidateFileSystemRootAndGetURL(
origin_url, type, create,
- base::Bind(&FileSystemPathManagerTest::OnGetRootPath,
+ base::Bind(&FileSystemMountPointProviderTest::OnGetRootPath,
weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
if (root_path)
@@ -269,27 +281,30 @@ class FileSystemPathManagerTest : public testing::Test {
SandboxMountPointProvider::kNewFileSystemDirectory);
}
FilePath external_file_system_path() {
- return UTF8ToFilePath(std::string(fileapi::kExternalDir));
+ return FilePath::FromUTF8Unsafe(std::string(fileapi::kExternalDir));
tzik 2011/12/21 02:52:33 maybe we can omit std::string
kinuko 2011/12/21 13:00:50 Done.
}
FilePath external_file_path_root() {
- return UTF8ToFilePath(std::string("/tmp"));
+ return FilePath::FromUTF8Unsafe(std::string("/tmp"));
tzik 2011/12/21 02:52:33 ditto
kinuko 2011/12/21 13:00:50 Done.
}
private:
ScopedTempDir data_dir_;
- base::WeakPtrFactory<FileSystemPathManagerTest> weak_factory_;
+ base::WeakPtrFactory<FileSystemMountPointProviderTest> weak_factory_;
bool root_path_callback_status_;
FilePath root_path_;
std::string file_system_name_;
- DISALLOW_COPY_AND_ASSIGN(FileSystemPathManagerTest);
+ scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSystemMountPointProviderTest);
};
-TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) {
+TEST_F(FileSystemMountPointProviderTest, GetRootPathCreateAndExamine) {
std::vector<FilePath> returned_root_path(
ARRAYSIZE_UNSAFE(kRootPathTestCases));
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+ SetupNewContext(new DisallowFileAccessOptions());
// Create a new root directory.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
@@ -297,8 +312,7 @@ TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) {
<< kRootPathTestCases[i].expected_path);
FilePath root_path;
- EXPECT_TRUE(GetRootPath(manager.get(),
- GURL(kRootPathTestCases[i].origin_url),
+ EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url),
kRootPathTestCases[i].type,
true /* create */, &root_path));
@@ -324,8 +338,7 @@ TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) {
<< kRootPathTestCases[i].expected_path);
FilePath root_path;
- EXPECT_TRUE(GetRootPath(manager.get(),
- GURL(kRootPathTestCases[i].origin_url),
+ EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url),
kRootPathTestCases[i].type,
false /* create */, &root_path));
ASSERT_TRUE(returned_root_path.size() > i);
@@ -333,75 +346,70 @@ TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) {
}
}
-TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamineWithNewManager) {
+TEST_F(FileSystemMountPointProviderTest,
+ GetRootPathCreateAndExamineWithNewProvider) {
std::vector<FilePath> returned_root_path(
ARRAYSIZE_UNSAFE(kRootPathTestCases));
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+ SetupNewContext(new DisallowFileAccessOptions());
GURL origin_url("http://foo.com:1/");
FilePath root_path1;
- EXPECT_TRUE(GetRootPath(manager.get(), origin_url,
+ EXPECT_TRUE(GetRootPath(origin_url,
kFileSystemTypeTemporary, true, &root_path1));
- manager.reset(NewPathManager(false, false));
+ SetupNewContext(new DisallowFileAccessOptions());
FilePath root_path2;
- EXPECT_TRUE(GetRootPath(manager.get(), origin_url,
+ EXPECT_TRUE(GetRootPath(origin_url,
kFileSystemTypeTemporary, false, &root_path2));
EXPECT_EQ(root_path1.value(), root_path2.value());
}
-TEST_F(FileSystemPathManagerTest, GetRootPathGetWithoutCreate) {
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+TEST_F(FileSystemMountPointProviderTest, GetRootPathGetWithoutCreate) {
+ SetupNewContext(new DisallowFileAccessOptions());
// Try to get a root directory without creating.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " "
<< kRootPathTestCases[i].expected_path);
- EXPECT_FALSE(GetRootPath(manager.get(),
- GURL(kRootPathTestCases[i].origin_url),
+ EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url),
kRootPathTestCases[i].type,
false /* create */, NULL));
}
}
-TEST_F(FileSystemPathManagerTest, GetRootPathInIncognito) {
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(
- true /* incognito */, false));
+TEST_F(FileSystemMountPointProviderTest, GetRootPathInIncognito) {
+ SetupNewContext(new IncognitoOptions());
// Try to get a root directory.
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " "
<< kRootPathTestCases[i].expected_path);
- EXPECT_FALSE(GetRootPath(manager.get(),
- GURL(kRootPathTestCases[i].origin_url),
+ EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url),
kRootPathTestCases[i].type,
true /* create */, NULL));
}
}
-TEST_F(FileSystemPathManagerTest, GetRootPathFileURI) {
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+TEST_F(FileSystemMountPointProviderTest, GetRootPathFileURI) {
+ SetupNewContext(new DisallowFileAccessOptions());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) {
SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #"
<< i << " " << kRootPathFileURITestCases[i].expected_path);
- EXPECT_FALSE(GetRootPath(manager.get(),
- GURL(kRootPathFileURITestCases[i].origin_url),
+ EXPECT_FALSE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url),
kRootPathFileURITestCases[i].type,
true /* create */, NULL));
}
}
-TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) {
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(
- false, true /* allow_file_access_from_files */));
+TEST_F(FileSystemMountPointProviderTest, GetRootPathFileURIWithAllowFlag) {
+ SetupNewContext(new MockFileSystemOptions());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) {
SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #"
<< i << " " << kRootPathFileURITestCases[i].expected_path);
FilePath root_path;
- EXPECT_TRUE(GetRootPath(manager.get(),
- GURL(kRootPathFileURITestCases[i].origin_url),
+ EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url),
kRootPathFileURITestCases[i].type,
true /* create */, &root_path));
if (kRootPathFileURITestCases[i].type != fileapi::kFileSystemTypeExternal) {
@@ -415,14 +423,14 @@ TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) {
}
}
-TEST_F(FileSystemPathManagerTest, IsRestrictedName) {
- scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
+TEST_F(FileSystemMountPointProviderTest, IsRestrictedName) {
+ SetupNewContext(new DisallowFileAccessOptions());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
<< kIsRestrictedNameTestCases[i].name);
FilePath name(kIsRestrictedNameTestCases[i].name);
EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
- manager->IsRestrictedFileName(kFileSystemTypeTemporary, name));
+ provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name));
}
}

Powered by Google App Engine
This is Rietveld 408576698