Experimental push messaging api reference docs.
[chromium-blink-merge.git] / webkit / fileapi / file_system_url_unittest.cc
blob260af770226b89e5d9ab438b12a7456fe58d3663
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "webkit/fileapi/file_system_url.h"
7 #include "base/file_path.h"
8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/fileapi/file_system_types.h"
11 #include "webkit/fileapi/file_system_util.h"
13 namespace fileapi {
14 namespace {
15 FileSystemURL CreateFileSystemURL(const char* url) {
16 return FileSystemURL(GURL(url));
18 } // namespace
20 TEST(FileSystemURLTest, ParsePersistent) {
21 FileSystemURL url = CreateFileSystemURL(
22 "filesystem:http://chromium.org/persistent/directory/file");
23 ASSERT_TRUE(url.is_valid());
24 EXPECT_EQ("http://chromium.org/", url.origin().spec());
25 EXPECT_EQ(kFileSystemTypePersistent, url.type());
26 EXPECT_EQ(FILE_PATH_LITERAL("file"),
27 VirtualPath::BaseName(url.path()).value());
28 EXPECT_EQ(FILE_PATH_LITERAL("directory"), url.path().DirName().value());
31 TEST(FileSystemURLTest, ParseTemporary) {
32 FileSystemURL url = CreateFileSystemURL(
33 "filesystem:http://chromium.org/temporary/directory/file");
34 ASSERT_TRUE(url.is_valid());
35 EXPECT_EQ("http://chromium.org/", url.origin().spec());
36 EXPECT_EQ(kFileSystemTypeTemporary, url.type());
37 EXPECT_EQ(FILE_PATH_LITERAL("file"),
38 VirtualPath::BaseName(url.path()).value());
39 EXPECT_EQ(FILE_PATH_LITERAL("directory"), url.path().DirName().value());
42 TEST(FileSystemURLTest, EnsureFilePathIsRelative) {
43 FileSystemURL url = CreateFileSystemURL(
44 "filesystem:http://chromium.org/temporary/////directory/file");
45 ASSERT_TRUE(url.is_valid());
46 EXPECT_EQ("http://chromium.org/", url.origin().spec());
47 EXPECT_EQ(kFileSystemTypeTemporary, url.type());
48 EXPECT_EQ(FILE_PATH_LITERAL("file"),
49 VirtualPath::BaseName(url.path()).value());
50 EXPECT_EQ(FILE_PATH_LITERAL("directory"), url.path().DirName().value());
51 EXPECT_FALSE(url.path().IsAbsolute());
54 TEST(FileSystemURLTest, RejectBadSchemes) {
55 EXPECT_FALSE(CreateFileSystemURL("http://chromium.org/").is_valid());
56 EXPECT_FALSE(CreateFileSystemURL("https://chromium.org/").is_valid());
57 EXPECT_FALSE(CreateFileSystemURL("file:///foo/bar").is_valid());
58 EXPECT_FALSE(CreateFileSystemURL("foobar:///foo/bar").is_valid());
61 TEST(FileSystemURLTest, UnescapePath) {
62 FileSystemURL url = CreateFileSystemURL(
63 "filesystem:http://chromium.org/persistent/%7Echromium/space%20bar");
64 ASSERT_TRUE(url.is_valid());
65 EXPECT_EQ(FILE_PATH_LITERAL("space bar"),
66 VirtualPath::BaseName(url.path()).value());
67 EXPECT_EQ(FILE_PATH_LITERAL("~chromium"), url.path().DirName().value());
70 TEST(FileSystemURLTest, RejectBadType) {
71 EXPECT_FALSE(CreateFileSystemURL(
72 "filesystem:http://c.org/foobar/file").is_valid());
75 TEST(FileSystemURLTest, RejectMalformedURL) {
76 EXPECT_FALSE(CreateFileSystemURL("filesystem:///foobar/file").is_valid());
77 EXPECT_FALSE(CreateFileSystemURL("filesystem:foobar/file").is_valid());
80 TEST(FileSystemURLTest, CompareURLs) {
81 const GURL urls[] = {
82 GURL("filesystem:http://chromium.org/temporary/dir a/file a"),
83 GURL("filesystem:http://chromium.org/temporary/dir a/file a"),
84 GURL("filesystem:http://chromium.org/temporary/dir a/file b"),
85 GURL("filesystem:http://chromium.org/temporary/dir a/file aa"),
86 GURL("filesystem:http://chromium.org/temporary/dir b/file a"),
87 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"),
88 GURL("filesystem:http://chromium.com/temporary/dir a/file a"),
89 GURL("filesystem:https://chromium.org/temporary/dir a/file a")
92 FileSystemURL::Comparator compare;
93 for (size_t i = 0; i < arraysize(urls); ++i) {
94 for (size_t j = 0; j < arraysize(urls); ++j) {
95 SCOPED_TRACE(testing::Message() << i << " < " << j);
96 EXPECT_EQ(urls[i] < urls[j],
97 compare(FileSystemURL(urls[i]), FileSystemURL(urls[j])));
101 FileSystemURL a = CreateFileSystemURL(
102 "filesystem:http://chromium.org/temporary/dir a/file a");
103 FileSystemURL b = CreateFileSystemURL(
104 "filesystem:http://chromium.org/persistent/dir a/file a");
105 EXPECT_EQ(a.type() < b.type(), compare(a, b));
106 EXPECT_EQ(b.type() < a.type(), compare(b, a));
109 } // namespace fileapi