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

Side by Side Diff: content/browser/fileapi/file_system_dir_url_request_job_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "webkit/browser/fileapi/file_system_dir_url_request_job.h" 5 #include "storage/browser/fileapi/file_system_dir_url_request_job.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "content/public/test/mock_special_storage_policy.h" 19 #include "content/public/test/mock_special_storage_policy.h"
20 #include "content/public/test/test_file_system_backend.h" 20 #include "content/public/test/test_file_system_backend.h"
21 #include "content/public/test/test_file_system_context.h" 21 #include "content/public/test/test_file_system_context.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
24 #include "net/base/request_priority.h" 24 #include "net/base/request_priority.h"
25 #include "net/http/http_request_headers.h" 25 #include "net/http/http_request_headers.h"
26 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
27 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
28 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "third_party/icu/source/i18n/unicode/regex.h" 30 #include "third_party/icu/source/i18n/unicode/regex.h"
31 #include "webkit/browser/fileapi/external_mount_points.h" 31 #include "storage/browser/fileapi/external_mount_points.h"
32 #include "webkit/browser/fileapi/file_system_context.h" 32 #include "storage/browser/fileapi/file_system_context.h"
33 #include "webkit/browser/fileapi/file_system_file_util.h" 33 #include "storage/browser/fileapi/file_system_file_util.h"
34 #include "webkit/browser/fileapi/file_system_operation_context.h" 34 #include "storage/browser/fileapi/file_system_operation_context.h"
35 #include "webkit/browser/fileapi/file_system_url.h" 35 #include "storage/browser/fileapi/file_system_url.h"
36 36
37 using fileapi::FileSystemContext; 37 using storage::FileSystemContext;
38 using fileapi::FileSystemOperationContext; 38 using storage::FileSystemOperationContext;
39 using fileapi::FileSystemURL; 39 using storage::FileSystemURL;
40 40
41 namespace content { 41 namespace content {
42 namespace { 42 namespace {
43 43
44 // We always use the TEMPORARY FileSystem in this test. 44 // We always use the TEMPORARY FileSystem in this test.
45 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; 45 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/";
46 46
47 const char kValidExternalMountPoint[] = "mnt_name"; 47 const char kValidExternalMountPoint[] = "mnt_name";
48 48
49 // An auto mounter that will try to mount anything for |storage_domain| = 49 // An auto mounter that will try to mount anything for |storage_domain| =
50 // "automount", but will only succeed for the mount point "mnt_name". 50 // "automount", but will only succeed for the mount point "mnt_name".
51 bool TestAutoMountForURLRequest( 51 bool TestAutoMountForURLRequest(
52 const net::URLRequest* /*url_request*/, 52 const net::URLRequest* /*url_request*/,
53 const fileapi::FileSystemURL& filesystem_url, 53 const storage::FileSystemURL& filesystem_url,
54 const std::string& storage_domain, 54 const std::string& storage_domain,
55 const base::Callback<void(base::File::Error result)>& callback) { 55 const base::Callback<void(base::File::Error result)>& callback) {
56 if (storage_domain != "automount") 56 if (storage_domain != "automount")
57 return false; 57 return false;
58 58
59 std::vector<base::FilePath::StringType> components; 59 std::vector<base::FilePath::StringType> components;
60 filesystem_url.path().GetComponents(&components); 60 filesystem_url.path().GetComponents(&components);
61 std::string mount_point = base::FilePath(components[0]).AsUTF8Unsafe(); 61 std::string mount_point = base::FilePath(components[0]).AsUTF8Unsafe();
62 62
63 if (mount_point == kValidExternalMountPoint) { 63 if (mount_point == kValidExternalMountPoint) {
64 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 64 storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
65 kValidExternalMountPoint, fileapi::kFileSystemTypeTest, 65 kValidExternalMountPoint,
66 fileapi::FileSystemMountOption(), base::FilePath()); 66 storage::kFileSystemTypeTest,
67 storage::FileSystemMountOption(),
68 base::FilePath());
67 callback.Run(base::File::FILE_OK); 69 callback.Run(base::File::FILE_OK);
68 } else { 70 } else {
69 callback.Run(base::File::FILE_ERROR_NOT_FOUND); 71 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
70 } 72 }
71 return true; 73 return true;
72 } 74 }
73 75
74 class FileSystemDirURLRequestJobFactory : public net::URLRequestJobFactory { 76 class FileSystemDirURLRequestJobFactory : public net::URLRequestJobFactory {
75 public: 77 public:
76 FileSystemDirURLRequestJobFactory(const std::string& storage_domain, 78 FileSystemDirURLRequestJobFactory(const std::string& storage_domain,
77 FileSystemContext* context) 79 FileSystemContext* context)
78 : storage_domain_(storage_domain), file_system_context_(context) { 80 : storage_domain_(storage_domain), file_system_context_(context) {
79 } 81 }
80 82
81 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 83 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
82 const std::string& scheme, 84 const std::string& scheme,
83 net::URLRequest* request, 85 net::URLRequest* request,
84 net::NetworkDelegate* network_delegate) const OVERRIDE { 86 net::NetworkDelegate* network_delegate) const OVERRIDE {
85 return new fileapi::FileSystemDirURLRequestJob( 87 return new storage::FileSystemDirURLRequestJob(
86 request, network_delegate, storage_domain_, file_system_context_); 88 request, network_delegate, storage_domain_, file_system_context_);
87 } 89 }
88 90
89 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE { 91 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE {
90 return true; 92 return true;
91 } 93 }
92 94
93 virtual bool IsHandledURL(const GURL& url) const OVERRIDE { 95 virtual bool IsHandledURL(const GURL& url) const OVERRIDE {
94 return true; 96 return true;
95 } 97 }
(...skipping 17 matching lines...) Expand all
113 } 115 }
114 116
115 virtual void SetUp() OVERRIDE { 117 virtual void SetUp() OVERRIDE {
116 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 118 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
117 119
118 special_storage_policy_ = new MockSpecialStoragePolicy; 120 special_storage_policy_ = new MockSpecialStoragePolicy;
119 file_system_context_ = CreateFileSystemContextForTesting( 121 file_system_context_ = CreateFileSystemContextForTesting(
120 NULL, temp_dir_.path()); 122 NULL, temp_dir_.path());
121 123
122 file_system_context_->OpenFileSystem( 124 file_system_context_->OpenFileSystem(
123 GURL("http://remote/"), fileapi::kFileSystemTypeTemporary, 125 GURL("http://remote/"),
124 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 126 storage::kFileSystemTypeTemporary,
127 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
125 base::Bind(&FileSystemDirURLRequestJobTest::OnOpenFileSystem, 128 base::Bind(&FileSystemDirURLRequestJobTest::OnOpenFileSystem,
126 weak_factory_.GetWeakPtr())); 129 weak_factory_.GetWeakPtr()));
127 base::RunLoop().RunUntilIdle(); 130 base::RunLoop().RunUntilIdle();
128 } 131 }
129 132
130 virtual void TearDown() OVERRIDE { 133 virtual void TearDown() OVERRIDE {
131 // NOTE: order matters, request must die before delegate 134 // NOTE: order matters, request must die before delegate
132 request_.reset(NULL); 135 request_.reset(NULL);
133 delegate_.reset(NULL); 136 delegate_.reset(NULL);
134 } 137 }
135 138
136 void SetUpAutoMountContext(base::FilePath* mnt_point) { 139 void SetUpAutoMountContext(base::FilePath* mnt_point) {
137 *mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir"); 140 *mnt_point = temp_dir_.path().AppendASCII("auto_mount_dir");
138 ASSERT_TRUE(base::CreateDirectory(*mnt_point)); 141 ASSERT_TRUE(base::CreateDirectory(*mnt_point));
139 142
140 ScopedVector<fileapi::FileSystemBackend> additional_providers; 143 ScopedVector<storage::FileSystemBackend> additional_providers;
141 additional_providers.push_back(new TestFileSystemBackend( 144 additional_providers.push_back(new TestFileSystemBackend(
142 base::MessageLoopProxy::current().get(), *mnt_point)); 145 base::MessageLoopProxy::current().get(), *mnt_point));
143 146
144 std::vector<fileapi::URLRequestAutoMountHandler> handlers; 147 std::vector<storage::URLRequestAutoMountHandler> handlers;
145 handlers.push_back(base::Bind(&TestAutoMountForURLRequest)); 148 handlers.push_back(base::Bind(&TestAutoMountForURLRequest));
146 149
147 file_system_context_ = CreateFileSystemContextWithAutoMountersForTesting( 150 file_system_context_ = CreateFileSystemContextWithAutoMountersForTesting(
148 NULL, additional_providers.Pass(), handlers, temp_dir_.path()); 151 NULL, additional_providers.Pass(), handlers, temp_dir_.path());
149 } 152 }
150 153
151 void OnOpenFileSystem(const GURL& root_url, 154 void OnOpenFileSystem(const GURL& root_url,
152 const std::string& name, 155 const std::string& name,
153 base::File::Error result) { 156 base::File::Error result) {
154 ASSERT_EQ(base::File::FILE_OK, result); 157 ASSERT_EQ(base::File::FILE_OK, result);
(...skipping 23 matching lines...) Expand all
178 FileSystemContext* file_system_context) { 181 FileSystemContext* file_system_context) {
179 TestRequestHelper(url, true, file_system_context); 182 TestRequestHelper(url, true, file_system_context);
180 } 183 }
181 184
182 void TestRequestNoRun(const GURL& url) { 185 void TestRequestNoRun(const GURL& url) {
183 TestRequestHelper(url, false, file_system_context_.get()); 186 TestRequestHelper(url, false, file_system_context_.get());
184 } 187 }
185 188
186 FileSystemURL CreateURL(const base::FilePath& file_path) { 189 FileSystemURL CreateURL(const base::FilePath& file_path) {
187 return file_system_context_->CreateCrackedFileSystemURL( 190 return file_system_context_->CreateCrackedFileSystemURL(
188 GURL("http://remote"), 191 GURL("http://remote"), storage::kFileSystemTypeTemporary, file_path);
189 fileapi::kFileSystemTypeTemporary,
190 file_path);
191 } 192 }
192 193
193 FileSystemOperationContext* NewOperationContext() { 194 FileSystemOperationContext* NewOperationContext() {
194 FileSystemOperationContext* context( 195 FileSystemOperationContext* context(
195 new FileSystemOperationContext(file_system_context_.get())); 196 new FileSystemOperationContext(file_system_context_.get()));
196 context->set_allowed_bytes_growth(1024); 197 context->set_allowed_bytes_growth(1024);
197 return context; 198 return context;
198 } 199 }
199 200
200 void CreateDirectory(const base::StringPiece& dir_name) { 201 void CreateDirectory(const base::StringPiece& dir_name) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 std::string date_str; 262 std::string date_str;
262 base::UTF16ToUTF8(date_ustr.getBuffer(), date_ustr.length(), &date_str); 263 base::UTF16ToUTF8(date_ustr.getBuffer(), date_ustr.length(), &date_str);
263 EXPECT_TRUE(base::Time::FromString(date_str.c_str(), &date)); 264 EXPECT_TRUE(base::Time::FromString(date_str.c_str(), &date));
264 EXPECT_FALSE(date.is_null()); 265 EXPECT_FALSE(date.is_null());
265 } 266 }
266 267
267 GURL CreateFileSystemURL(const std::string path) { 268 GURL CreateFileSystemURL(const std::string path) {
268 return GURL(kFileSystemURLPrefix + path); 269 return GURL(kFileSystemURLPrefix + path);
269 } 270 }
270 271
271 fileapi::FileSystemFileUtil* file_util() { 272 storage::FileSystemFileUtil* file_util() {
272 return file_system_context_->sandbox_delegate()->sync_file_util(); 273 return file_system_context_->sandbox_delegate()->sync_file_util();
273 } 274 }
274 275
275 // Put the message loop at the top, so that it's the last thing deleted. 276 // Put the message loop at the top, so that it's the last thing deleted.
276 // Delete all MessageLoopProxy objects before the MessageLoop, to help prevent 277 // Delete all MessageLoopProxy objects before the MessageLoop, to help prevent
277 // leaks caused by tasks posted during shutdown. 278 // leaks caused by tasks posted during shutdown.
278 base::MessageLoopForIO message_loop_; 279 base::MessageLoopForIO message_loop_;
279 280
280 base::ScopedTempDir temp_dir_; 281 base::ScopedTempDir temp_dir_;
281 net::URLRequestContext empty_context_; 282 net::URLRequestContext empty_context_;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 std::vector<std::string> listing_entries; 400 std::vector<std::string> listing_entries;
400 while (!!std::getline(in, line)) 401 while (!!std::getline(in, line))
401 listing_entries.push_back(line); 402 listing_entries.push_back(line);
402 403
403 ASSERT_EQ(2U, listing_entries.size()); 404 ASSERT_EQ(2U, listing_entries.size());
404 std::sort(listing_entries.begin(), listing_entries.end()); 405 std::sort(listing_entries.begin(), listing_entries.end());
405 VerifyListingEntry(listing_entries[0], "bar", "bar", false, 10); 406 VerifyListingEntry(listing_entries[0], "bar", "bar", false, 10);
406 VerifyListingEntry(listing_entries[1], "foo", "foo", true, -1); 407 VerifyListingEntry(listing_entries[1], "foo", "foo", true, -1);
407 408
408 ASSERT_TRUE( 409 ASSERT_TRUE(
409 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 410 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
410 kValidExternalMountPoint)); 411 kValidExternalMountPoint));
411 } 412 }
412 413
413 TEST_F(FileSystemDirURLRequestJobTest, AutoMountInvalidRoot) { 414 TEST_F(FileSystemDirURLRequestJobTest, AutoMountInvalidRoot) {
414 base::FilePath mnt_point; 415 base::FilePath mnt_point;
415 SetUpAutoMountContext(&mnt_point); 416 SetUpAutoMountContext(&mnt_point);
416 TestRequest(GURL("filesystem:http://automount/external/invalid")); 417 TestRequest(GURL("filesystem:http://automount/external/invalid"));
417 418
418 ASSERT_FALSE(request_->is_pending()); 419 ASSERT_FALSE(request_->is_pending());
419 ASSERT_FALSE(request_->status().is_success()); 420 ASSERT_FALSE(request_->status().is_success());
420 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); 421 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
421 422
422 ASSERT_FALSE( 423 ASSERT_FALSE(
423 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 424 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
424 "invalid")); 425 "invalid"));
425 } 426 }
426 427
427 TEST_F(FileSystemDirURLRequestJobTest, AutoMountNoHandler) { 428 TEST_F(FileSystemDirURLRequestJobTest, AutoMountNoHandler) {
428 base::FilePath mnt_point; 429 base::FilePath mnt_point;
429 SetUpAutoMountContext(&mnt_point); 430 SetUpAutoMountContext(&mnt_point);
430 TestRequest(GURL("filesystem:http://noauto/external/mnt_name")); 431 TestRequest(GURL("filesystem:http://noauto/external/mnt_name"));
431 432
432 ASSERT_FALSE(request_->is_pending()); 433 ASSERT_FALSE(request_->is_pending());
433 ASSERT_FALSE(request_->status().is_success()); 434 ASSERT_FALSE(request_->status().is_success());
434 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); 435 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
435 436
436 ASSERT_FALSE( 437 ASSERT_FALSE(
437 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 438 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
438 kValidExternalMountPoint)); 439 kValidExternalMountPoint));
439 } 440 }
440 441
441 } // namespace (anonymous) 442 } // namespace (anonymous)
442 } // namespace content 443 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698