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

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util_unittest.cc

Issue 2580303002: mediaview: Mount ARC documents provider file system volumes. (Closed)
Patch Set: Consistently use GetGlobalService(). Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h" 6 #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
7 #include "storage/browser/fileapi/file_system_url.h" 7 #include "storage/browser/fileapi/file_system_url.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
11 namespace arc { 11 namespace arc {
12 12
13 namespace { 13 namespace {
14 14
15 TEST(ArcDocumentsProviderUtilTest, EscapePathComponent) {
16 EXPECT_EQ("", EscapePathComponent(""));
17 EXPECT_EQ("%2E", EscapePathComponent("."));
18 EXPECT_EQ("%2E%2E", EscapePathComponent(".."));
19 EXPECT_EQ("...", EscapePathComponent("..."));
20 EXPECT_EQ("example.com", EscapePathComponent("example.com"));
21 EXPECT_EQ("%2F%2F%2F", EscapePathComponent("///"));
22 EXPECT_EQ("100%25", EscapePathComponent("100%"));
23 EXPECT_EQ("a b", EscapePathComponent("a b"));
24 EXPECT_EQ("ねこ", EscapePathComponent("ねこ"));
25 }
26
27 TEST(ArcDocumentsProviderUtilTest, UnescapePathComponent) {
28 EXPECT_EQ("", UnescapePathComponent(""));
29 EXPECT_EQ(".", UnescapePathComponent("%2E"));
30 EXPECT_EQ("..", UnescapePathComponent("%2E%2E"));
31 EXPECT_EQ("...", UnescapePathComponent("..."));
32 EXPECT_EQ("example.com", UnescapePathComponent("example.com"));
33 EXPECT_EQ("///", UnescapePathComponent("%2F%2F%2F"));
34 EXPECT_EQ("100%", UnescapePathComponent("100%25"));
35 EXPECT_EQ("a b", UnescapePathComponent("a b"));
36 EXPECT_EQ("ねこ", UnescapePathComponent("ねこ"));
37 }
38
39 TEST(ArcDocumentsProviderUtilTest, GetDocumentsProviderMountPath) {
40 EXPECT_EQ("/special/arc-documents-provider/authority/document_id",
41 GetDocumentsProviderMountPath("authority", "document_id").value());
42 EXPECT_EQ("/special/arc-documents-provider/a b/a b",
43 GetDocumentsProviderMountPath("a b", "a b").value());
44 EXPECT_EQ("/special/arc-documents-provider/a%2Fb/a%2Fb",
45 GetDocumentsProviderMountPath("a/b", "a/b").value());
46 EXPECT_EQ("/special/arc-documents-provider/%2E/%2E",
47 GetDocumentsProviderMountPath(".", ".").value());
48 EXPECT_EQ("/special/arc-documents-provider/%2E%2E/%2E%2E",
49 GetDocumentsProviderMountPath("..", "..").value());
50 EXPECT_EQ("/special/arc-documents-provider/.../...",
51 GetDocumentsProviderMountPath("...", "...").value());
52 }
53
15 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrl) { 54 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrl) {
16 std::string authority; 55 std::string authority;
17 std::string root_document_id; 56 std::string root_document_id;
18 base::FilePath path; 57 base::FilePath path;
19 58
20 EXPECT_TRUE(ParseDocumentsProviderUrl( 59 EXPECT_TRUE(ParseDocumentsProviderUrl(
21 storage::FileSystemURL::CreateForTest( 60 storage::FileSystemURL::CreateForTest(
22 GURL(), storage::kFileSystemTypeArcDocumentsProvider, 61 GURL(), storage::kFileSystemTypeArcDocumentsProvider,
23 base::FilePath(kDocumentsProviderMountPointPath) 62 base::FilePath(kDocumentsProviderMountPointPath)
24 .Append(FILE_PATH_LITERAL("cats/root/home/calico.jpg"))), 63 .Append(FILE_PATH_LITERAL("cats/root/home/calico.jpg"))),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 150
112 // Not under /special/arc-documents-provider. 151 // Not under /special/arc-documents-provider.
113 EXPECT_FALSE(ParseDocumentsProviderUrl( 152 EXPECT_FALSE(ParseDocumentsProviderUrl(
114 storage::FileSystemURL::CreateForTest( 153 storage::FileSystemURL::CreateForTest(
115 GURL(), storage::kFileSystemTypeArcDocumentsProvider, 154 GURL(), storage::kFileSystemTypeArcDocumentsProvider,
116 base::FilePath(FILE_PATH_LITERAL( 155 base::FilePath(FILE_PATH_LITERAL(
117 "/special/something-else/cats/root/home/calico.jpg"))), 156 "/special/something-else/cats/root/home/calico.jpg"))),
118 &authority, &root_document_id, &path)); 157 &authority, &root_document_id, &path));
119 } 158 }
120 159
160 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlUnescape) {
161 std::string authority;
162 std::string root_document_id;
163 base::FilePath path;
164
165 EXPECT_TRUE(ParseDocumentsProviderUrl(
166 storage::FileSystemURL::CreateForTest(
167 GURL(), storage::kFileSystemTypeArcDocumentsProvider,
168 base::FilePath(
169 "/special/arc-documents-provider/cats/ro%2Fot/home/calico.jpg")),
170 &authority, &root_document_id, &path));
171 EXPECT_EQ("cats", authority);
172 EXPECT_EQ("ro/ot", root_document_id);
173 EXPECT_EQ(FILE_PATH_LITERAL("home/calico.jpg"), path.value());
174 }
175
121 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlUtf8) { 176 TEST(ArcDocumentsProviderUtilTest, ParseDocumentsProviderUrlUtf8) {
122 std::string authority; 177 std::string authority;
123 std::string root_document_id; 178 std::string root_document_id;
124 base::FilePath path; 179 base::FilePath path;
125 180
126 EXPECT_TRUE(ParseDocumentsProviderUrl( 181 EXPECT_TRUE(ParseDocumentsProviderUrl(
127 storage::FileSystemURL::CreateForTest( 182 storage::FileSystemURL::CreateForTest(
128 GURL(), storage::kFileSystemTypeArcDocumentsProvider, 183 GURL(), storage::kFileSystemTypeArcDocumentsProvider,
129 base::FilePath( 184 base::FilePath(
130 "/special/arc-documents-provider/cats/root/home/みけねこ.jpg")), 185 "/special/arc-documents-provider/cats/root/home/みけねこ.jpg")),
131 &authority, &root_document_id, &path)); 186 &authority, &root_document_id, &path));
132 EXPECT_EQ("cats", authority); 187 EXPECT_EQ("cats", authority);
133 EXPECT_EQ("root", root_document_id); 188 EXPECT_EQ("root", root_document_id);
134 EXPECT_EQ(FILE_PATH_LITERAL("home/みけねこ.jpg"), path.value()); 189 EXPECT_EQ(FILE_PATH_LITERAL("home/みけねこ.jpg"), path.value());
135 } 190 }
136 191
137 TEST(ArcDocumentsProviderUtilTest, BuildDocumentUrl) { 192 TEST(ArcDocumentsProviderUtilTest, BuildDocumentUrl) {
138 EXPECT_EQ("content://Cat%20Provider/document/C%2B%2B", 193 EXPECT_EQ("content://authority/document/document_id",
139 BuildDocumentUrl("Cat Provider", "C++").spec()); 194 BuildDocumentUrl("authority", "document_id").spec());
195 EXPECT_EQ("content://a%20b/document/a%20b",
196 BuildDocumentUrl("a b", "a b").spec());
197 EXPECT_EQ("content://a%2Fb/document/a%2Fb",
198 BuildDocumentUrl("a/b", "a/b").spec());
199 EXPECT_EQ("content://../document/..", BuildDocumentUrl("..", "..").spec());
140 } 200 }
141 201
142 } // namespace 202 } // namespace
143 203
144 } // namespace arc 204 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698