| OLD | NEW |
| 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_url_request_job.h" | 5 #include "webkit/browser/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 19 matching lines...) Expand all Loading... |
| 30 #include "net/http/http_request_headers.h" | 30 #include "net/http/http_request_headers.h" |
| 31 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
| 32 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
| 33 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "webkit/browser/fileapi/async_file_test_helper.h" | 35 #include "webkit/browser/fileapi/async_file_test_helper.h" |
| 36 #include "webkit/browser/fileapi/external_mount_points.h" | 36 #include "webkit/browser/fileapi/external_mount_points.h" |
| 37 #include "webkit/browser/fileapi/file_system_context.h" | 37 #include "webkit/browser/fileapi/file_system_context.h" |
| 38 #include "webkit/browser/fileapi/file_system_file_util.h" | 38 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 39 | 39 |
| 40 namespace fileapi { | 40 using fileapi::AsyncFileTestHelper; |
| 41 using fileapi::FileSystemContext; |
| 42 using fileapi::FileSystemURL; |
| 43 using fileapi::FileSystemURLRequestJob; |
| 44 |
| 45 namespace content { |
| 41 namespace { | 46 namespace { |
| 42 | 47 |
| 43 // We always use the TEMPORARY FileSystem in this test. | 48 // We always use the TEMPORARY FileSystem in this test. |
| 44 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; | 49 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; |
| 45 const char kTestFileData[] = "0123456789"; | 50 const char kTestFileData[] = "0123456789"; |
| 46 | 51 |
| 47 void FillBuffer(char* buffer, size_t len) { | 52 void FillBuffer(char* buffer, size_t len) { |
| 48 base::RandBytes(buffer, len); | 53 base::RandBytes(buffer, len); |
| 49 } | 54 } |
| 50 | 55 |
| 51 } // namespace | 56 } // namespace |
| 52 | 57 |
| 53 class FileSystemURLRequestJobTest : public testing::Test { | 58 class FileSystemURLRequestJobTest : public testing::Test { |
| 54 protected: | 59 protected: |
| 55 FileSystemURLRequestJobTest() : weak_factory_(this) { | 60 FileSystemURLRequestJobTest() : weak_factory_(this) { |
| 56 } | 61 } |
| 57 | 62 |
| 58 virtual void SetUp() OVERRIDE { | 63 virtual void SetUp() OVERRIDE { |
| 59 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 64 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 60 | 65 |
| 61 // We use the main thread so that we can get the root path synchronously. | 66 // We use the main thread so that we can get the root path synchronously. |
| 62 // TODO(adamk): Run this on the FILE thread we've created as well. | 67 // TODO(adamk): Run this on the FILE thread we've created as well. |
| 63 file_system_context_ = | 68 file_system_context_ = |
| 64 CreateFileSystemContextForTesting(NULL, temp_dir_.path()); | 69 CreateFileSystemContextForTesting(NULL, temp_dir_.path()); |
| 65 | 70 |
| 66 file_system_context_->OpenFileSystem( | 71 file_system_context_->OpenFileSystem( |
| 67 GURL("http://remote/"), kFileSystemTypeTemporary, | 72 GURL("http://remote/"), fileapi::kFileSystemTypeTemporary, |
| 68 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 73 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 69 base::Bind(&FileSystemURLRequestJobTest::OnOpenFileSystem, | 74 base::Bind(&FileSystemURLRequestJobTest::OnOpenFileSystem, |
| 70 weak_factory_.GetWeakPtr())); | 75 weak_factory_.GetWeakPtr())); |
| 71 base::RunLoop().RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
| 72 | 77 |
| 73 net::URLRequest::Deprecated::RegisterProtocolFactory( | 78 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 74 "filesystem", &FileSystemURLRequestJobFactory); | 79 "filesystem", &FileSystemURLRequestJobFactory); |
| 75 } | 80 } |
| 76 | 81 |
| 77 virtual void TearDown() OVERRIDE { | 82 virtual void TearDown() OVERRIDE { |
| 78 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); | 83 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 TestRequestHelper(url, headers, true, file_system_context_.get()); | 133 TestRequestHelper(url, headers, true, file_system_context_.get()); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void TestRequestNoRun(const GURL& url) { | 136 void TestRequestNoRun(const GURL& url) { |
| 132 TestRequestHelper(url, NULL, false, file_system_context_.get()); | 137 TestRequestHelper(url, NULL, false, file_system_context_.get()); |
| 133 } | 138 } |
| 134 | 139 |
| 135 void CreateDirectory(const base::StringPiece& dir_name) { | 140 void CreateDirectory(const base::StringPiece& dir_name) { |
| 136 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 141 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
| 137 GURL("http://remote"), | 142 GURL("http://remote"), |
| 138 kFileSystemTypeTemporary, | 143 fileapi::kFileSystemTypeTemporary, |
| 139 base::FilePath().AppendASCII(dir_name)); | 144 base::FilePath().AppendASCII(dir_name)); |
| 140 ASSERT_EQ(base::PLATFORM_FILE_OK, AsyncFileTestHelper::CreateDirectory( | 145 ASSERT_EQ(base::PLATFORM_FILE_OK, AsyncFileTestHelper::CreateDirectory( |
| 141 file_system_context_, url)); | 146 file_system_context_, url)); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void WriteFile(const base::StringPiece& file_name, | 149 void WriteFile(const base::StringPiece& file_name, |
| 145 const char* buf, int buf_size) { | 150 const char* buf, int buf_size) { |
| 146 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 151 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
| 147 GURL("http://remote"), | 152 GURL("http://remote"), |
| 148 kFileSystemTypeTemporary, | 153 fileapi::kFileSystemTypeTemporary, |
| 149 base::FilePath().AppendASCII(file_name)); | 154 base::FilePath().AppendASCII(file_name)); |
| 150 ASSERT_EQ(base::PLATFORM_FILE_OK, | 155 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 151 AsyncFileTestHelper::CreateFileWithData( | 156 AsyncFileTestHelper::CreateFileWithData( |
| 152 file_system_context_, url, buf, buf_size)); | 157 file_system_context_, url, buf, buf_size)); |
| 153 } | 158 } |
| 154 | 159 |
| 155 GURL CreateFileSystemURL(const std::string& path) { | 160 GURL CreateFileSystemURL(const std::string& path) { |
| 156 return GURL(kFileSystemURLPrefix + path); | 161 return GURL(kFileSystemURLPrefix + path); |
| 157 } | 162 } |
| 158 | 163 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 170 if (job_) { | 175 if (job_) { |
| 171 scoped_refptr<net::URLRequestJob> deleter = job_; | 176 scoped_refptr<net::URLRequestJob> deleter = job_; |
| 172 job_ = NULL; | 177 job_ = NULL; |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 | 180 |
| 176 // Put the message loop at the top, so that it's the last thing deleted. | 181 // Put the message loop at the top, so that it's the last thing deleted. |
| 177 base::MessageLoopForIO message_loop_; | 182 base::MessageLoopForIO message_loop_; |
| 178 | 183 |
| 179 base::ScopedTempDir temp_dir_; | 184 base::ScopedTempDir temp_dir_; |
| 180 scoped_refptr<FileSystemContext> file_system_context_; | 185 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 181 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; | 186 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; |
| 182 | 187 |
| 183 net::URLRequestContext empty_context_; | 188 net::URLRequestContext empty_context_; |
| 184 | 189 |
| 185 // NOTE: order matters, request must die before delegate | 190 // NOTE: order matters, request must die before delegate |
| 186 scoped_ptr<net::TestDelegate> delegate_; | 191 scoped_ptr<net::TestDelegate> delegate_; |
| 187 scoped_ptr<net::URLRequest> request_; | 192 scoped_ptr<net::URLRequest> request_; |
| 188 | 193 |
| 189 scoped_refptr<net::URLRequestJob> pending_job_; | 194 scoped_refptr<net::URLRequestJob> pending_job_; |
| 190 static net::URLRequestJob* job_; | 195 static net::URLRequestJob* job_; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); | 363 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
| 359 | 364 |
| 360 // Make sure it returns success with regular (non-incognito) context. | 365 // Make sure it returns success with regular (non-incognito) context. |
| 361 TestRequest(CreateFileSystemURL("file")); | 366 TestRequest(CreateFileSystemURL("file")); |
| 362 ASSERT_FALSE(request_->is_pending()); | 367 ASSERT_FALSE(request_->is_pending()); |
| 363 EXPECT_EQ(kTestFileData, delegate_->data_received()); | 368 EXPECT_EQ(kTestFileData, delegate_->data_received()); |
| 364 EXPECT_EQ(200, request_->GetResponseCode()); | 369 EXPECT_EQ(200, request_->GetResponseCode()); |
| 365 } | 370 } |
| 366 | 371 |
| 367 } // namespace | 372 } // namespace |
| 368 } // namespace fileapi | 373 } // namespace content |
| OLD | NEW |