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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "webkit/fileapi/file_system_context.h"
6
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/fileapi/external_mount_points.h"
11 #include "webkit/fileapi/file_system_task_runners.h"
12 #include "webkit/fileapi/isolated_context.h"
13 #include "webkit/fileapi/mock_file_system_options.h"
14 #include "webkit/quota/mock_quota_manager.h"
15 #include "webkit/quota/mock_special_storage_policy.h"
16
17 #define FPL(x) FILE_PATH_LITERAL(x)
18
19 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
20 #define DRIVE FPL("C:")
21 #else
22 #define DRIVE
23 #endif
24
25 namespace fileapi {
26
27 namespace {
28
29 class FileSystemContextTest : public testing::Test {
30 public:
31 FileSystemContextTest() {}
32
33 void SetUp() {
34 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
35
36 scoped_refptr<quota::SpecialStoragePolicy> storage_policy(
37 new quota::MockSpecialStoragePolicy());
38
39 mock_quota_manager_ = new quota::MockQuotaManager(
40 false /* is_incognito */,
41 data_dir_.path(),
42 base::MessageLoopProxy::current(),
43 base::MessageLoopProxy::current(),
44 storage_policy);
45
46 file_system_context_ = new FileSystemContext(
47 FileSystemTaskRunners::CreateMockTaskRunners(),
48 storage_policy,
49 mock_quota_manager_->proxy(),
50 data_dir_.path(),
51 CreateAllowFileAccessOptions());
52 }
53
54 protected:
55 FileSystemContext* file_system_context() {
56 return file_system_context_.get();
57 }
58
59 private:
60 base::ScopedTempDir data_dir_;
61 MessageLoop message_loop_;
62 scoped_refptr<quota::MockQuotaManager> mock_quota_manager_;
63 scoped_refptr<FileSystemContext> file_system_context_;
64 };
65
66 TEST_F(FileSystemContextTest, CrackFileSystemURL) {
67 // Register Isolated mount points.
68 std::string isolated_file_system_name = "root";
69 const std::string kIsolatedFileSystemID =
70 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
71 kFileSystemTypeNativeLocal,
72 FilePath(DRIVE FPL("/test/isolated/root")),
73 &isolated_file_system_name);
74 // Register system external mount point.
75 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
76 "system",
77 kFileSystemTypeDrive,
78 FilePath(DRIVE FPL("/test/sys/"))));
79 // Register system external mount point that overrides registered isolated
80 // mount point.
81 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
82 kIsolatedFileSystemID,
83 kFileSystemTypeRestrictedNativeLocal,
84 FilePath(DRIVE FPL("/test/system/isolated"))));
85
86 struct TestCase {
87 // Test case values.
88 std::string root;
89 FileSystemType type;
90 // Not NULL for test cases that test previously cracked URLs.
91 MountPoints* pre_test_cracker;
92
93 // Expected test results.
94 bool expect_is_valid;
95 bool expect_is_cracked;
96 FileSystemType expect_type;
97 const FilePath::CharType* expect_path;
98 };
99
100 // Test cracking invalid FileSystemURL ("foobar" is invalid type).
101 FileSystemURL invalid_cracked =file_system_context()->CrackFileSystemURL(
102 FileSystemURL(GURL("filesystem:http://c.org/foobar/file")));
103 EXPECT_FALSE(invalid_cracked.is_valid());
104 EXPECT_FALSE(invalid_cracked.is_cracked());
105
106 const GURL kTestOrigin = GURL("http://chromium.org/");
107 const FilePath kVirtualPathNoRoot = FilePath(FPL("root/file"));
108
109 const TestCase kTestCases[] = {
110 // Following should not be handled by url crackers:
111 { "pers_mount", kFileSystemTypePersistent, NULL,
112 true, false, kFileSystemTypePersistent, FPL("pers_mount/root/file") },
113 { "temp_mount", kFileSystemTypeTemporary, NULL,
114 true, false, kFileSystemTypeTemporary, FPL("temp_mount/root/file") },
115 { "system", kFileSystemTypeNativeLocal, NULL,
116 true, false, kFileSystemTypeNativeLocal, FPL("system/root/file") },
117 { "isolated", kFileSystemTypeNativeMedia, NULL,
118 true, false, kFileSystemTypeNativeMedia, FPL("isolated/root/file") },
119 // Should be cracked by isolated mount points:
120 { kIsolatedFileSystemID, kFileSystemTypeIsolated, NULL,
121 true, true, kFileSystemTypeNativeLocal,
122 DRIVE FPL("/test/isolated/root/file") },
123 // Should be cracked by system mount points:
124 { "system", kFileSystemTypeExternal, NULL,
125 true, true, kFileSystemTypeDrive,
126 DRIVE FPL("/test/sys/root/file") },
127 { kIsolatedFileSystemID, kFileSystemTypeExternal, NULL,
128 true, true, kFileSystemTypeRestrictedNativeLocal,
129 DRIVE FPL("/test/system/isolated/root/file") },
130 // Test for already cracked FielSystemURLs:
131 { "system", kFileSystemTypeExternal,
132 ExternalMountPoints::GetSystemInstance(),
133 true, true, kFileSystemTypeDrive,
134 DRIVE FPL("/test/sys/root/file") },
135 { kIsolatedFileSystemID, kFileSystemTypeIsolated,
136 IsolatedContext::GetInstance(),
137 true, true, kFileSystemTypeNativeLocal,
138 DRIVE FPL("/test/isolated/root/file") },
139 // In following two tests pre_test_cracker will create invalid
140 // FileSystemURL, so these test CrackFileSystem for invalid URL.
141 { "invalid", kFileSystemTypeExternal,
142 ExternalMountPoints::GetSystemInstance(),
143 false, false, kFileSystemTypeUnknown, FPL("") },
144 { "invalid", kFileSystemTypeIsolated,
145 IsolatedContext::GetInstance(),
146 false, false, kFileSystemTypeUnknown, FPL("") },
147 };
148
149 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
150 const FilePath virtual_path =
151 FilePath::FromUTF8Unsafe(kTestCases[i].root).Append(kVirtualPathNoRoot);
152 SCOPED_TRACE(
153 testing::Message() << "Testing test case " << i << ": "
154 << "virtual_path: " << virtual_path.value()
155 << " file system type: " << kTestCases[i].type
156 << " cracked before test: "
157 << (kTestCases[i].pre_test_cracker != NULL));
158
159 FileSystemURL url(kTestOrigin, kTestCases[i].type, virtual_path);
160 if (kTestCases[i].pre_test_cracker)
161 url = kTestCases[i].pre_test_cracker->CrackURL(url);
162
163 FileSystemURL cracked = file_system_context()->CrackFileSystemURL(url);
164
165 EXPECT_EQ(kTestCases[i].expect_is_valid, cracked.is_valid());
166 EXPECT_EQ(kTestCases[i].expect_is_cracked, cracked.is_cracked());
167
168 if (!kTestCases[i].expect_is_valid)
169 continue;
170 EXPECT_EQ(kTestOrigin, cracked.origin());
171 EXPECT_EQ(kTestCases[i].expect_type, cracked.type());
172 EXPECT_EQ(kTestCases[i].type, cracked.mount_type());
173 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
174 cracked.path());
175 EXPECT_EQ(virtual_path.NormalizePathSeparators(), cracked.virtual_path());
176 std::string expected_filesystem_id =
177 kTestCases[i].expect_is_cracked ? kTestCases[i].root : std::string();
178 EXPECT_EQ(expected_filesystem_id, cracked.filesystem_id());
179 }
180
181 IsolatedContext::GetInstance()->RevokeFileSystemByPath(
182 FilePath(DRIVE FPL("/test/isolated/root")));
183 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
184 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
185 kIsolatedFileSystemID);
186 }
187
188 } // namespace
189
190 } // namespace fileapi
191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698