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

Unified Diff: webkit/fileapi/file_system_context_unittest.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 11 months 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_context_unittest.cc
diff --git a/webkit/fileapi/file_system_context_unittest.cc b/webkit/fileapi/file_system_context_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5bd2ab8f97252771e733e7120986f6033afe698f
--- /dev/null
+++ b/webkit/fileapi/file_system_context_unittest.cc
@@ -0,0 +1,191 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// 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_context.h"
+
+#include "base/files/scoped_temp_dir.h"
+#include "base/message_loop.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/external_mount_points.h"
+#include "webkit/fileapi/file_system_task_runners.h"
+#include "webkit/fileapi/isolated_context.h"
+#include "webkit/fileapi/mock_file_system_options.h"
+#include "webkit/quota/mock_quota_manager.h"
+#include "webkit/quota/mock_special_storage_policy.h"
+
+#define FPL(x) FILE_PATH_LITERAL(x)
+
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+#define DRIVE FPL("C:")
+#else
+#define DRIVE
+#endif
+
+namespace fileapi {
+
+namespace {
+
+class FileSystemContextTest : public testing::Test {
+ public:
+ FileSystemContextTest() {}
+
+ void SetUp() {
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
+
+ scoped_refptr<quota::SpecialStoragePolicy> storage_policy(
+ new quota::MockSpecialStoragePolicy());
+
+ mock_quota_manager_ = new quota::MockQuotaManager(
+ false /* is_incognito */,
+ data_dir_.path(),
+ base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current(),
+ storage_policy);
+
+ file_system_context_ = new FileSystemContext(
+ FileSystemTaskRunners::CreateMockTaskRunners(),
+ storage_policy,
+ mock_quota_manager_->proxy(),
+ data_dir_.path(),
+ CreateAllowFileAccessOptions());
+ }
+
+ protected:
+ FileSystemContext* file_system_context() {
+ return file_system_context_.get();
+ }
+
+ private:
+ base::ScopedTempDir data_dir_;
+ MessageLoop message_loop_;
+ scoped_refptr<quota::MockQuotaManager> mock_quota_manager_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+};
+
+TEST_F(FileSystemContextTest, CrackFileSystemURL) {
+ // Register Isolated mount points.
+ std::string isolated_file_system_name = "root";
+ const std::string kIsolatedFileSystemID =
+ IsolatedContext::GetInstance()->RegisterFileSystemForPath(
+ kFileSystemTypeNativeLocal,
+ FilePath(DRIVE FPL("/test/isolated/root")),
+ &isolated_file_system_name);
+ // Register system external mount point.
+ ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
+ "system",
+ kFileSystemTypeDrive,
+ FilePath(DRIVE FPL("/test/sys/"))));
+ // Register system external mount point that overrides registered isolated
+ // mount point.
+ ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
+ kIsolatedFileSystemID,
+ kFileSystemTypeRestrictedNativeLocal,
+ FilePath(DRIVE FPL("/test/system/isolated"))));
+
+ struct TestCase {
+ // Test case values.
+ std::string root;
+ FileSystemType type;
+ // Not NULL for test cases that test previously cracked URLs.
+ MountPoints* pre_test_cracker;
+
+ // Expected test results.
+ bool expect_is_valid;
+ bool expect_is_cracked;
+ FileSystemType expect_type;
+ const FilePath::CharType* expect_path;
+ };
+
+ // Test cracking invalid FileSystemURL ("foobar" is invalid type).
+ FileSystemURL invalid_cracked =file_system_context()->CrackFileSystemURL(
+ FileSystemURL(GURL("filesystem:http://c.org/foobar/file")));
+ EXPECT_FALSE(invalid_cracked.is_valid());
+ EXPECT_FALSE(invalid_cracked.is_cracked());
+
+ const GURL kTestOrigin = GURL("http://chromium.org/");
+ const FilePath kVirtualPathNoRoot = FilePath(FPL("root/file"));
+
+ const TestCase kTestCases[] = {
+ // Following should not be handled by url crackers:
+ { "pers_mount", kFileSystemTypePersistent, NULL,
+ true, false, kFileSystemTypePersistent, FPL("pers_mount/root/file") },
+ { "temp_mount", kFileSystemTypeTemporary, NULL,
+ true, false, kFileSystemTypeTemporary, FPL("temp_mount/root/file") },
+ { "system", kFileSystemTypeNativeLocal, NULL,
+ true, false, kFileSystemTypeNativeLocal, FPL("system/root/file") },
+ { "isolated", kFileSystemTypeNativeMedia, NULL,
+ true, false, kFileSystemTypeNativeMedia, FPL("isolated/root/file") },
+ // Should be cracked by isolated mount points:
+ { kIsolatedFileSystemID, kFileSystemTypeIsolated, NULL,
+ true, true, kFileSystemTypeNativeLocal,
+ DRIVE FPL("/test/isolated/root/file") },
+ // Should be cracked by system mount points:
+ { "system", kFileSystemTypeExternal, NULL,
+ true, true, kFileSystemTypeDrive,
+ DRIVE FPL("/test/sys/root/file") },
+ { kIsolatedFileSystemID, kFileSystemTypeExternal, NULL,
+ true, true, kFileSystemTypeRestrictedNativeLocal,
+ DRIVE FPL("/test/system/isolated/root/file") },
+ // Test for already cracked FielSystemURLs:
+ { "system", kFileSystemTypeExternal,
+ ExternalMountPoints::GetSystemInstance(),
+ true, true, kFileSystemTypeDrive,
+ DRIVE FPL("/test/sys/root/file") },
+ { kIsolatedFileSystemID, kFileSystemTypeIsolated,
+ IsolatedContext::GetInstance(),
+ true, true, kFileSystemTypeNativeLocal,
+ DRIVE FPL("/test/isolated/root/file") },
+ // In following two tests pre_test_cracker will create invalid
+ // FileSystemURL, so these test CrackFileSystem for invalid URL.
+ { "invalid", kFileSystemTypeExternal,
+ ExternalMountPoints::GetSystemInstance(),
+ false, false, kFileSystemTypeUnknown, FPL("") },
+ { "invalid", kFileSystemTypeIsolated,
+ IsolatedContext::GetInstance(),
+ false, false, kFileSystemTypeUnknown, FPL("") },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
+ const FilePath virtual_path =
+ FilePath::FromUTF8Unsafe(kTestCases[i].root).Append(kVirtualPathNoRoot);
+ SCOPED_TRACE(
+ testing::Message() << "Testing test case " << i << ": "
+ << "virtual_path: " << virtual_path.value()
+ << " file system type: " << kTestCases[i].type
+ << " cracked before test: "
+ << (kTestCases[i].pre_test_cracker != NULL));
+
+ FileSystemURL url(kTestOrigin, kTestCases[i].type, virtual_path);
+ if (kTestCases[i].pre_test_cracker)
+ url = kTestCases[i].pre_test_cracker->CrackURL(url);
+
+ FileSystemURL cracked = file_system_context()->CrackFileSystemURL(url);
+
+ EXPECT_EQ(kTestCases[i].expect_is_valid, cracked.is_valid());
+ EXPECT_EQ(kTestCases[i].expect_is_cracked, cracked.is_cracked());
+
+ if (!kTestCases[i].expect_is_valid)
+ continue;
+ EXPECT_EQ(kTestOrigin, cracked.origin());
+ EXPECT_EQ(kTestCases[i].expect_type, cracked.type());
+ EXPECT_EQ(kTestCases[i].type, cracked.mount_type());
+ EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
+ cracked.path());
+ EXPECT_EQ(virtual_path.NormalizePathSeparators(), cracked.virtual_path());
+ std::string expected_filesystem_id =
+ kTestCases[i].expect_is_cracked ? kTestCases[i].root : std::string();
+ EXPECT_EQ(expected_filesystem_id, cracked.filesystem_id());
+ }
+
+ IsolatedContext::GetInstance()->RevokeFileSystemByPath(
+ FilePath(DRIVE FPL("/test/isolated/root")));
+ ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
+ ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
+ kIsolatedFileSystemID);
+}
+
+} // namespace
+
+} // namespace fileapi
+

Powered by Google App Engine
This is Rietveld 408576698