| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fileapi/file_system_url_request_job.h" | 5 #include "webkit/fileapi/file_system_url_request_job.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 23 #include "net/base/mime_util.h" | 23 #include "net/base/mime_util.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 26 #include "net/http/http_request_headers.h" | 26 #include "net/http/http_request_headers.h" |
| 27 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 28 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 29 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "webkit/fileapi/external_mount_points.h" | |
| 32 #include "webkit/fileapi/file_system_context.h" | 31 #include "webkit/fileapi/file_system_context.h" |
| 33 #include "webkit/fileapi/file_system_file_util.h" | 32 #include "webkit/fileapi/file_system_file_util.h" |
| 34 #include "webkit/fileapi/file_system_operation_context.h" | 33 #include "webkit/fileapi/file_system_operation_context.h" |
| 35 #include "webkit/fileapi/file_system_task_runners.h" | 34 #include "webkit/fileapi/mock_file_system_context.h" |
| 36 #include "webkit/fileapi/mock_file_system_options.h" | |
| 37 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 35 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 38 #include "webkit/quota/mock_special_storage_policy.h" | |
| 39 | 36 |
| 40 namespace fileapi { | 37 namespace fileapi { |
| 41 namespace { | 38 namespace { |
| 42 | 39 |
| 43 // We always use the TEMPORARY FileSystem in this test. | 40 // We always use the TEMPORARY FileSystem in this test. |
| 44 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; | 41 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; |
| 45 const char kTestFileData[] = "0123456789"; | 42 const char kTestFileData[] = "0123456789"; |
| 46 | 43 |
| 47 void FillBuffer(char* buffer, size_t len) { | 44 void FillBuffer(char* buffer, size_t len) { |
| 48 base::RandBytes(buffer, len); | 45 base::RandBytes(buffer, len); |
| 49 } | 46 } |
| 50 | 47 |
| 51 } // namespace | 48 } // namespace |
| 52 | 49 |
| 53 class FileSystemURLRequestJobTest : public testing::Test { | 50 class FileSystemURLRequestJobTest : public testing::Test { |
| 54 protected: | 51 protected: |
| 55 FileSystemURLRequestJobTest() | 52 FileSystemURLRequestJobTest() |
| 56 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread | 53 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread |
| 57 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 54 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 58 } | 55 } |
| 59 | 56 |
| 60 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
| 61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 62 | 59 |
| 63 special_storage_policy_ = new quota::MockSpecialStoragePolicy; | |
| 64 // We use the main thread so that we can get the root path synchronously. | 60 // We use the main thread so that we can get the root path synchronously. |
| 65 // TODO(adamk): Run this on the FILE thread we've created as well. | 61 // TODO(adamk): Run this on the FILE thread we've created as well. |
| 66 file_system_context_ = | 62 file_system_context_ = |
| 67 new FileSystemContext( | 63 CreateFileSystemContextForTesting(NULL, temp_dir_.path()); |
| 68 FileSystemTaskRunners::CreateMockTaskRunners(), | |
| 69 ExternalMountPoints::CreateRefCounted().get(), | |
| 70 special_storage_policy_, NULL, | |
| 71 temp_dir_.path(), | |
| 72 CreateDisallowFileAccessOptions()); | |
| 73 | 64 |
| 74 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( | 65 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( |
| 75 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create | 66 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create |
| 76 base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem, | 67 base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem, |
| 77 weak_factory_.GetWeakPtr())); | 68 weak_factory_.GetWeakPtr())); |
| 78 MessageLoop::current()->RunUntilIdle(); | 69 MessageLoop::current()->RunUntilIdle(); |
| 79 | 70 |
| 80 net::URLRequest::Deprecated::RegisterProtocolFactory( | 71 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 81 "filesystem", &FileSystemURLRequestJobFactory); | 72 "filesystem", &FileSystemURLRequestJobFactory); |
| 82 } | 73 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (job_) { | 184 if (job_) { |
| 194 scoped_refptr<net::URLRequestJob> deleter = job_; | 185 scoped_refptr<net::URLRequestJob> deleter = job_; |
| 195 job_ = NULL; | 186 job_ = NULL; |
| 196 } | 187 } |
| 197 } | 188 } |
| 198 | 189 |
| 199 // Put the message loop at the top, so that it's the last thing deleted. | 190 // Put the message loop at the top, so that it's the last thing deleted. |
| 200 MessageLoop message_loop_; | 191 MessageLoop message_loop_; |
| 201 | 192 |
| 202 base::ScopedTempDir temp_dir_; | 193 base::ScopedTempDir temp_dir_; |
| 203 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; | |
| 204 scoped_refptr<FileSystemContext> file_system_context_; | 194 scoped_refptr<FileSystemContext> file_system_context_; |
| 205 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; | 195 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; |
| 206 | 196 |
| 207 net::URLRequestContext empty_context_; | 197 net::URLRequestContext empty_context_; |
| 208 | 198 |
| 209 // NOTE: order matters, request must die before delegate | 199 // NOTE: order matters, request must die before delegate |
| 210 scoped_ptr<net::TestDelegate> delegate_; | 200 scoped_ptr<net::TestDelegate> delegate_; |
| 211 scoped_ptr<net::URLRequest> request_; | 201 scoped_ptr<net::URLRequest> request_; |
| 212 | 202 |
| 213 scoped_refptr<net::URLRequestJob> pending_job_; | 203 scoped_refptr<net::URLRequestJob> pending_job_; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 350 |
| 361 TestRequest(CreateFileSystemURL(kFilename)); | 351 TestRequest(CreateFileSystemURL(kFilename)); |
| 362 | 352 |
| 363 std::string mime_type_from_job; | 353 std::string mime_type_from_job; |
| 364 request_->GetMimeType(&mime_type_from_job); | 354 request_->GetMimeType(&mime_type_from_job); |
| 365 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 355 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
| 366 } | 356 } |
| 367 | 357 |
| 368 } // namespace | 358 } // namespace |
| 369 } // namespace fileapi | 359 } // namespace fileapi |
| OLD | NEW |