summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_util_unittest.cc
diff options
context:
space:
mode:
authoradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 03:29:35 +0000
committeradamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 03:29:35 +0000
commit8fbe7994047c3ec60182b4b2540d825c95e9f6ef (patch)
treeaf6dfd9cb03fa40c22ffad2b8a739f425f6d8626 /webkit/fileapi/file_system_util_unittest.cc
parent6aa800f9d7af07c758cacd2c7d0425c706e4f057 (diff)
downloadchromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.zip
chromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.tar.gz
chromium_src-8fbe7994047c3ec60182b4b2540d825c95e9f6ef.tar.bz2
First crack at FileSystemURLRequestJob for handling filesystem: URLs.
Disabled behind a switch, "--enable-filesystem-url-scheme". Review URL: http://codereview.chromium.org/6262015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_util_unittest.cc')
-rw-r--r--webkit/fileapi/file_system_util_unittest.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/webkit/fileapi/file_system_util_unittest.cc b/webkit/fileapi/file_system_util_unittest.cc
new file mode 100644
index 0000000..7cb4c59
--- /dev/null
+++ b/webkit/fileapi/file_system_util_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2011 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_util.h"
+
+#include "base/file_path.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_types.h"
+
+namespace fileapi {
+namespace {
+
+class FileSystemUtilTest : public testing::Test {
+ protected:
+ bool CrackFileSystemURL(const char* url) {
+ return fileapi::CrackFileSystemURL(
+ GURL(url), &origin_url_, &type_, &file_path_);
+ }
+
+ GURL origin_url_;
+ FileSystemType type_;
+ FilePath file_path_;
+};
+
+TEST_F(FileSystemUtilTest, ParsePersistent) {
+ ASSERT_TRUE(CrackFileSystemURL(
+ "filesystem:http://chromium.org/persistent/directory/file"));
+ EXPECT_EQ("http://chromium.org/", origin_url_.spec());
+ EXPECT_EQ(kFileSystemTypePersistent, type_);
+ EXPECT_EQ(FILE_PATH_LITERAL("directory/file"), file_path_.value());
+}
+
+TEST_F(FileSystemUtilTest, ParseTemporary) {
+ ASSERT_TRUE(CrackFileSystemURL(
+ "filesystem:http://chromium.org/temporary/directory/file"));
+ EXPECT_EQ("http://chromium.org/", origin_url_.spec());
+ EXPECT_EQ(kFileSystemTypeTemporary, type_);
+ EXPECT_EQ(FILE_PATH_LITERAL("directory/file"), file_path_.value());
+}
+
+TEST_F(FileSystemUtilTest, EnsureFilePathIsRelative) {
+ ASSERT_TRUE(CrackFileSystemURL(
+ "filesystem:http://chromium.org/temporary/////directory/file"));
+ EXPECT_EQ("http://chromium.org/", origin_url_.spec());
+ EXPECT_EQ(kFileSystemTypeTemporary, type_);
+ EXPECT_EQ(FILE_PATH_LITERAL("directory/file"), file_path_.value());
+ EXPECT_FALSE(file_path_.IsAbsolute());
+}
+
+TEST_F(FileSystemUtilTest, RejectBadSchemes) {
+ EXPECT_FALSE(CrackFileSystemURL("http://chromium.org/"));
+ EXPECT_FALSE(CrackFileSystemURL("https://chromium.org/"));
+ EXPECT_FALSE(CrackFileSystemURL("file:///foo/bar"));
+ EXPECT_FALSE(CrackFileSystemURL("foobar:///foo/bar"));
+}
+
+TEST_F(FileSystemUtilTest, UnescapePath) {
+ ASSERT_TRUE(CrackFileSystemURL(
+ "filesystem:http://chromium.org/persistent/%7Echromium/space%20bar"));
+ EXPECT_EQ(FILE_PATH_LITERAL("~chromium/space bar"), file_path_.value());
+}
+
+TEST_F(FileSystemUtilTest, RejectBadType) {
+ EXPECT_FALSE(CrackFileSystemURL("filesystem:http://c.org/foobar/file"));
+}
+
+TEST_F(FileSystemUtilTest, RejectMalformedURL) {
+ EXPECT_FALSE(CrackFileSystemURL("filesystem:///foobar/file"));
+ EXPECT_FALSE(CrackFileSystemURL("filesystem:foobar/file"));
+}
+
+} // namespace (anonymous)
+} // namespace fileapi