| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) | 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) |
| 6 // rather than as part of test_shell_tests because they rely on being able | 6 // rather than as part of test_shell_tests because they rely on being able |
| 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses | 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses |
| 8 // TYPE_UI, which URLRequest doesn't allow. | 8 // TYPE_UI, which URLRequest doesn't allow. |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "net/base/mime_util.h" | 30 #include "net/base/mime_util.h" |
| 31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
| 33 #include "net/http/http_request_headers.h" | 33 #include "net/http/http_request_headers.h" |
| 34 #include "net/url_request/url_request.h" | 34 #include "net/url_request/url_request.h" |
| 35 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "webkit/fileapi/file_system_context.h" | 37 #include "webkit/fileapi/file_system_context.h" |
| 38 #include "webkit/fileapi/file_system_file_util.h" | 38 #include "webkit/fileapi/file_system_file_util.h" |
| 39 #include "webkit/fileapi/file_system_operation_context.h" | 39 #include "webkit/fileapi/file_system_operation_context.h" |
| 40 #include "webkit/fileapi/file_system_path_manager.h" | 40 #include "webkit/fileapi/mock_file_system_options.h" |
| 41 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 41 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 42 #include "webkit/quota/mock_special_storage_policy.h" | 42 #include "webkit/quota/mock_special_storage_policy.h" |
| 43 | 43 |
| 44 namespace fileapi { | 44 namespace fileapi { |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // We always use the TEMPORARY FileSystem in this test. | 47 // We always use the TEMPORARY FileSystem in this test. |
| 48 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; | 48 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; |
| 49 const char kTestFileData[] = "0123456789"; | 49 const char kTestFileData[] = "0123456789"; |
| 50 | 50 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 77 | 77 |
| 78 special_storage_policy_ = new quota::MockSpecialStoragePolicy; | 78 special_storage_policy_ = new quota::MockSpecialStoragePolicy; |
| 79 // We use the main thread so that we can get the root path synchronously. | 79 // We use the main thread so that we can get the root path synchronously. |
| 80 // TODO(adamk): Run this on the FILE thread we've created as well. | 80 // TODO(adamk): Run this on the FILE thread we've created as well. |
| 81 file_system_context_ = | 81 file_system_context_ = |
| 82 new FileSystemContext( | 82 new FileSystemContext( |
| 83 base::MessageLoopProxy::current(), | 83 base::MessageLoopProxy::current(), |
| 84 base::MessageLoopProxy::current(), | 84 base::MessageLoopProxy::current(), |
| 85 special_storage_policy_, NULL, | 85 special_storage_policy_, NULL, |
| 86 FilePath(), false /* is_incognito */, true /* allow_file_access */, | 86 temp_dir_.path(), |
| 87 new FileSystemPathManager( | 87 new MockFileSystemOptions()); |
| 88 base::MessageLoopProxy::current(), | |
| 89 temp_dir_.path(), NULL, false, false)); | |
| 90 | 88 |
| 91 file_system_context_->path_manager()->ValidateFileSystemRootAndGetURL( | 89 file_system_context_->sandbox_provider()->ValidateFileSystemRootAndGetURL( |
| 92 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create | 90 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create |
| 93 base::Bind(&FileSystemURLRequestJobTest::OnGetRootPath, | 91 base::Bind(&FileSystemURLRequestJobTest::OnGetRootPath, |
| 94 weak_factory_.GetWeakPtr())); | 92 weak_factory_.GetWeakPtr())); |
| 95 MessageLoop::current()->RunAllPending(); | 93 MessageLoop::current()->RunAllPending(); |
| 96 | 94 |
| 97 net::URLRequest::Deprecated::RegisterProtocolFactory( | 95 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 98 "filesystem", &FileSystemURLRequestJobFactory); | 96 "filesystem", &FileSystemURLRequestJobFactory); |
| 99 } | 97 } |
| 100 | 98 |
| 101 virtual void TearDown() { | 99 virtual void TearDown() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 const net::HttpRequestHeaders* headers) { | 135 const net::HttpRequestHeaders* headers) { |
| 138 TestRequestHelper(url, headers, true); | 136 TestRequestHelper(url, headers, true); |
| 139 } | 137 } |
| 140 | 138 |
| 141 void TestRequestNoRun(const GURL& url) { | 139 void TestRequestNoRun(const GURL& url) { |
| 142 TestRequestHelper(url, NULL, false); | 140 TestRequestHelper(url, NULL, false); |
| 143 } | 141 } |
| 144 | 142 |
| 145 void CreateDirectory(const base::StringPiece& dir_name) { | 143 void CreateDirectory(const base::StringPiece& dir_name) { |
| 146 FilePath path = FilePath().AppendASCII(dir_name); | 144 FilePath path = FilePath().AppendASCII(dir_name); |
| 147 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> | 145 FileSystemFileUtil* file_util = file_system_context_-> |
| 148 sandbox_provider()->GetFileUtil(); | 146 sandbox_provider()->GetFileUtil(); |
| 149 FileSystemOperationContext context(file_system_context_, file_util); | 147 FileSystemOperationContext context(file_system_context_, file_util); |
| 150 context.set_src_origin_url(GURL("http://remote")); | 148 context.set_src_origin_url(GURL("http://remote")); |
| 151 context.set_src_type(fileapi::kFileSystemTypeTemporary); | 149 context.set_src_type(fileapi::kFileSystemTypeTemporary); |
| 152 context.set_allowed_bytes_growth(1024); | 150 context.set_allowed_bytes_growth(1024); |
| 153 | 151 |
| 154 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( | 152 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( |
| 155 &context, | 153 &context, |
| 156 path, | 154 path, |
| 157 false /* exclusive */, | 155 false /* exclusive */, |
| 158 false /* recursive */)); | 156 false /* recursive */)); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void WriteFile(const base::StringPiece& file_name, | 159 void WriteFile(const base::StringPiece& file_name, |
| 162 const char* buf, int buf_size) { | 160 const char* buf, int buf_size) { |
| 163 FilePath path = FilePath().AppendASCII(file_name); | 161 FilePath path = FilePath().AppendASCII(file_name); |
| 164 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> | 162 FileSystemFileUtil* file_util = file_system_context_-> |
| 165 sandbox_provider()->GetFileUtil(); | 163 sandbox_provider()->GetFileUtil(); |
| 166 FileSystemOperationContext context(file_system_context_, file_util); | 164 FileSystemOperationContext context(file_system_context_, file_util); |
| 167 context.set_src_origin_url(GURL("http://remote")); | 165 context.set_src_origin_url(GURL("http://remote")); |
| 168 context.set_src_type(fileapi::kFileSystemTypeTemporary); | 166 context.set_src_type(fileapi::kFileSystemTypeTemporary); |
| 169 context.set_allowed_bytes_growth(1024); | 167 context.set_allowed_bytes_growth(1024); |
| 170 | 168 |
| 171 base::PlatformFile handle = base::kInvalidPlatformFileValue; | 169 base::PlatformFile handle = base::kInvalidPlatformFileValue; |
| 172 bool created = false; | 170 bool created = false; |
| 173 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( | 171 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( |
| 174 &context, | 172 &context, |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 366 |
| 369 TestRequest(CreateFileSystemURL(kFilename)); | 367 TestRequest(CreateFileSystemURL(kFilename)); |
| 370 | 368 |
| 371 std::string mime_type_from_job; | 369 std::string mime_type_from_job; |
| 372 request_->GetMimeType(&mime_type_from_job); | 370 request_->GetMimeType(&mime_type_from_job); |
| 373 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 371 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
| 374 } | 372 } |
| 375 | 373 |
| 376 } // namespace (anonymous) | 374 } // namespace (anonymous) |
| 377 } // namespace fileapi | 375 } // namespace fileapi |
| OLD | NEW |