OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #include "base/files/file_path.h" |
| 6 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" |
| 7 #include "storage/browser/fileapi/file_system_url.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 namespace arc { |
| 12 |
| 13 namespace { |
| 14 |
| 15 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrl) { |
| 16 std::string authority; |
| 17 std::string root_document_id; |
| 18 base::FilePath path; |
| 19 |
| 20 EXPECT_TRUE(ParseDocumentsProviderUrl( |
| 21 storage::FileSystemURL::CreateForTest( |
| 22 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 23 base::FilePath(kDocumentsProviderMountPointPath) |
| 24 .Append(FILE_PATH_LITERAL("cats/root/home/calico.jpg"))), |
| 25 &authority, &root_document_id, &path)); |
| 26 EXPECT_EQ("cats", authority); |
| 27 EXPECT_EQ("root", root_document_id); |
| 28 EXPECT_EQ(FILE_PATH_LITERAL("home/calico.jpg"), path.value()); |
| 29 } |
| 30 |
| 31 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlEmptyPath) { |
| 32 std::string authority; |
| 33 std::string root_document_id; |
| 34 // Assign a non-empty arbitrary path to make sure an empty path is |
| 35 // set in ParseDocumentsProviderUrl(). |
| 36 base::FilePath path(FILE_PATH_LITERAL("foobar")); |
| 37 |
| 38 // Should accept a path pointing to a root directory. |
| 39 EXPECT_TRUE(ParseDocumentsProviderUrl( |
| 40 storage::FileSystemURL::CreateForTest( |
| 41 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 42 base::FilePath(kDocumentsProviderMountPointPath) |
| 43 .Append(FILE_PATH_LITERAL("cats/root"))), |
| 44 &authority, &root_document_id, &path)); |
| 45 EXPECT_EQ("cats", authority); |
| 46 EXPECT_EQ("root", root_document_id); |
| 47 EXPECT_EQ(FILE_PATH_LITERAL(""), path.value()); |
| 48 } |
| 49 |
| 50 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlEmptyPathSlash) { |
| 51 std::string authority; |
| 52 std::string root_document_id; |
| 53 // Assign a non-empty arbitrary path to make sure an empty path is |
| 54 // set in ParseDocumentsProviderUrl(). |
| 55 base::FilePath path(FILE_PATH_LITERAL("foobar")); |
| 56 |
| 57 // Should accept a path pointing to a root directory. |
| 58 EXPECT_TRUE(ParseDocumentsProviderUrl( |
| 59 storage::FileSystemURL::CreateForTest( |
| 60 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 61 base::FilePath(kDocumentsProviderMountPointPath) |
| 62 .Append(FILE_PATH_LITERAL("cats/root/"))), |
| 63 &authority, &root_document_id, &path)); |
| 64 EXPECT_EQ("cats", authority); |
| 65 EXPECT_EQ("root", root_document_id); |
| 66 EXPECT_EQ(FILE_PATH_LITERAL(""), path.value()); |
| 67 } |
| 68 |
| 69 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlInvalidType) { |
| 70 std::string authority; |
| 71 std::string root_document_id; |
| 72 base::FilePath path; |
| 73 |
| 74 // Not storage::kFileSystemTypeArcDocumentsProvider. |
| 75 EXPECT_FALSE(ParseDocumentsProviderUrl( |
| 76 storage::FileSystemURL::CreateForTest( |
| 77 GURL(), storage::kFileSystemTypeArcContent, |
| 78 base::FilePath(kDocumentsProviderMountPointPath) |
| 79 .Append(FILE_PATH_LITERAL("cats/root/home/calico.jpg"))), |
| 80 &authority, &root_document_id, &path)); |
| 81 } |
| 82 |
| 83 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlInvalidPath) { |
| 84 std::string authority; |
| 85 std::string root_document_id; |
| 86 base::FilePath path; |
| 87 |
| 88 // root_document_id part is missing. |
| 89 EXPECT_FALSE(ParseDocumentsProviderUrl( |
| 90 storage::FileSystemURL::CreateForTest( |
| 91 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 92 base::FilePath(kDocumentsProviderMountPointPath) |
| 93 .Append(FILE_PATH_LITERAL("root-missing"))), |
| 94 &authority, &root_document_id, &path)); |
| 95 |
| 96 // Leading / is missing. |
| 97 EXPECT_FALSE(ParseDocumentsProviderUrl( |
| 98 storage::FileSystemURL::CreateForTest( |
| 99 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 100 base::FilePath(FILE_PATH_LITERAL( |
| 101 "special/arc-documents-provider/cats/root/home/calico.jpg"))), |
| 102 &authority, &root_document_id, &path)); |
| 103 |
| 104 // Not under /special. |
| 105 EXPECT_FALSE(ParseDocumentsProviderUrl( |
| 106 storage::FileSystemURL::CreateForTest( |
| 107 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 108 base::FilePath(FILE_PATH_LITERAL( |
| 109 "/invalid/arc-documents-provider/cats/root/home/calico.jpg"))), |
| 110 &authority, &root_document_id, &path)); |
| 111 |
| 112 // Not under /special/arc-documents-provider. |
| 113 EXPECT_FALSE(ParseDocumentsProviderUrl( |
| 114 storage::FileSystemURL::CreateForTest( |
| 115 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 116 base::FilePath(FILE_PATH_LITERAL( |
| 117 "/special/something-else/cats/root/home/calico.jpg"))), |
| 118 &authority, &root_document_id, &path)); |
| 119 } |
| 120 |
| 121 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlUtf8) { |
| 122 std::string authority; |
| 123 std::string root_document_id; |
| 124 base::FilePath path; |
| 125 |
| 126 EXPECT_TRUE(ParseDocumentsProviderUrl( |
| 127 storage::FileSystemURL::CreateForTest( |
| 128 GURL(), storage::kFileSystemTypeArcDocumentsProvider, |
| 129 base::FilePath( |
| 130 "/special/arc-documents-provider/cats/root/home/みけねこ.jpg")), |
| 131 &authority, &root_document_id, &path)); |
| 132 EXPECT_EQ("cats", authority); |
| 133 EXPECT_EQ("root", root_document_id); |
| 134 EXPECT_EQ(FILE_PATH_LITERAL("home/みけねこ.jpg"), path.value()); |
| 135 } |
| 136 |
| 137 } // namespace |
| 138 |
| 139 } // namespace arc |
OLD | NEW |