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

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: browser_tests compile 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 GURL CreateRawFileSystemURL(const std::string& origin_str,
30 const std::string& type_str,
31 const std::string& fs_id,
32 const FilePath& path) {
33 return GURL(std::string("filesystem:") + origin_str + type_str +
34 std::string("/") + fs_id + std::string("/") +
35 path.AsUTF8Unsafe());
36 }
37
38 class FileSystemContextTest : public testing::Test {
39 public:
40 FileSystemContextTest() {}
41
42 void SetUp() {
43 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
44
45 scoped_refptr<quota::SpecialStoragePolicy> storage_policy(
46 new quota::MockSpecialStoragePolicy());
47
48 mock_quota_manager_ = new quota::MockQuotaManager(
49 false /* is_incognito */,
50 data_dir_.path(),
51 base::MessageLoopProxy::current(),
52 base::MessageLoopProxy::current(),
53 storage_policy);
54
55 file_system_context_ = new FileSystemContext(
56 FileSystemTaskRunners::CreateMockTaskRunners(),
57 storage_policy,
58 mock_quota_manager_->proxy(),
59 data_dir_.path(),
60 CreateAllowFileAccessOptions());
61 }
62
63 protected:
64 FileSystemContext* file_system_context() {
65 return file_system_context_.get();
66 }
67
68 private:
69 base::ScopedTempDir data_dir_;
70 MessageLoop message_loop_;
71 scoped_refptr<quota::MockQuotaManager> mock_quota_manager_;
72 scoped_refptr<FileSystemContext> file_system_context_;
73 };
74
75 TEST_F(FileSystemContextTest, CrackFileSystemURL) {
76 // Register Isolated mount points.
77 std::string isolated_file_system_name = "root";
78 const std::string kIsolatedFileSystemID =
79 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
80 kFileSystemTypeNativeLocal,
81 FilePath(DRIVE FPL("/test/isolated/root")),
82 &isolated_file_system_name);
83 // Register system external mount point.
84 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
85 "system",
86 kFileSystemTypeDrive,
87 FilePath(DRIVE FPL("/test/sys/"))));
88 // Register system external mount point that overrides registered isolated
89 // mount point.
90 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
91 kIsolatedFileSystemID,
92 kFileSystemTypeRestrictedNativeLocal,
93 FilePath(DRIVE FPL("/test/system/isolated"))));
94
95 struct TestCase {
96 // Test case values.
97 std::string root;
98 FileSystemType type;
99 std::string type_str;
100
101 // Expected test results.
102 bool expect_is_valid;
103 bool expect_is_cracked;
104 FileSystemType expect_type;
105 const FilePath::CharType* expect_path;
106 };
107
108 const GURL kTestOrigin = GURL("http://chromium.org/");
109 const FilePath kVirtualPathNoRoot = FilePath(FPL("root/file"));
110
111 const TestCase kTestCases[] = {
112 // Following should not be handled by url crackers:
113 { "pers_mount", kFileSystemTypePersistent, "persistent",
114 true, false, kFileSystemTypePersistent, FPL("pers_mount/root/file") },
115 { "temp_mount", kFileSystemTypeTemporary, "temporary",
116 true, false, kFileSystemTypeTemporary, FPL("temp_mount/root/file") },
117 // Should be cracked by isolated mount points:
118 { kIsolatedFileSystemID, kFileSystemTypeIsolated, "isolated",
119 true, true, kFileSystemTypeNativeLocal,
120 DRIVE FPL("/test/isolated/root/file") },
121 // Should be cracked by system mount points:
122 { "system", kFileSystemTypeExternal,"external",
123 true, true, kFileSystemTypeDrive,
124 DRIVE FPL("/test/sys/root/file") },
125 { kIsolatedFileSystemID, kFileSystemTypeExternal, "external",
126 true, true, kFileSystemTypeRestrictedNativeLocal,
127 DRIVE FPL("/test/system/isolated/root/file") },
128 // Test for already cracked FielSystemURLs:
129 { "system", kFileSystemTypeExternal, "external",
130 true, true, kFileSystemTypeDrive,
131 DRIVE FPL("/test/sys/root/file") },
132 { kIsolatedFileSystemID, kFileSystemTypeIsolated, "isolated",
133 true, true, kFileSystemTypeNativeLocal,
134 DRIVE FPL("/test/isolated/root/file") },
135 { "invalid", kFileSystemTypeUnknown, "external",
136 false, false, kFileSystemTypeUnknown, FPL("") },
137 { "invalid", kFileSystemTypeUnknown, "isolated",
138 false, false, kFileSystemTypeUnknown, FPL("") },
139 };
140
141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
142 const FilePath virtual_path =
143 FilePath::FromUTF8Unsafe(kTestCases[i].root).Append(kVirtualPathNoRoot);
144 SCOPED_TRACE(
145 testing::Message() << "Testing test case " << i << ": "
146 << "virtual_path: " << virtual_path.value()
147 << " file system type: " << kTestCases[i].type_str);
148
149 FileSystemURL cracked = file_system_context()->CrackURL(
150 CreateRawFileSystemURL(kTestOrigin.spec(), kTestCases[i].type_str,
151 kTestCases[i].root, kVirtualPathNoRoot));
152
153 EXPECT_EQ(kTestCases[i].expect_is_valid, cracked.is_valid());
154 EXPECT_EQ(kTestCases[i].expect_is_cracked, cracked.is_cracked());
155
156 if (!kTestCases[i].expect_is_valid)
157 continue;
158 EXPECT_EQ(kTestOrigin, cracked.origin());
159 EXPECT_EQ(kTestCases[i].expect_type, cracked.type());
160 EXPECT_EQ(kTestCases[i].type, cracked.mount_type());
161 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
162 cracked.path());
163 // Following properties should not be set for non-cracked urls.
164 bool is_cracked = kTestCases[i].expect_is_cracked;
165 FilePath expect_virtual_path =
166 is_cracked ? virtual_path.NormalizePathSeparators() : FilePath();
167 EXPECT_EQ(expect_virtual_path, cracked.virtual_path());
168 std::string expect_filesystem_id =
169 is_cracked ? kTestCases[i].root : std::string();
170 EXPECT_EQ(expect_filesystem_id, cracked.filesystem_id());
171 }
172
173 IsolatedContext::GetInstance()->RevokeFileSystemByPath(
174 FilePath(DRIVE FPL("/test/isolated/root")));
175 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
176 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
177 kIsolatedFileSystemID);
178 }
179
180 } // namespace
181
182 } // namespace fileapi
183
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698