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

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

Issue 307433002: Remove ProtocolFactory use from file_writer_delegate_unittest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "content/public/test/async_file_test_helper.h" 14 #include "content/public/test/async_file_test_helper.h"
15 #include "content/public/test/test_file_system_context.h" 15 #include "content/public/test/test_file_system_context.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/request_priority.h" 17 #include "net/base/request_priority.h"
18 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_job.h" 20 #include "net/url_request/url_request_job.h"
21 #include "net/url_request/url_request_job_factory.h"
21 #include "net/url_request/url_request_status.h" 22 #include "net/url_request/url_request_status.h"
22 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 #include "webkit/browser/fileapi/file_system_context.h" 25 #include "webkit/browser/fileapi/file_system_context.h"
25 #include "webkit/browser/fileapi/file_system_quota_util.h" 26 #include "webkit/browser/fileapi/file_system_quota_util.h"
26 #include "webkit/browser/fileapi/file_writer_delegate.h" 27 #include "webkit/browser/fileapi/file_writer_delegate.h"
27 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" 28 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h"
28 29
29 using content::AsyncFileTestHelper; 30 using content::AsyncFileTestHelper;
30 using fileapi::FileSystemURL; 31 using fileapi::FileSystemURL;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 68 }
68 } 69 }
69 70
70 private: 71 private:
71 // For post-operation status. 72 // For post-operation status.
72 base::File::Error status_; 73 base::File::Error status_;
73 int64 bytes_written_; 74 int64 bytes_written_;
74 FileWriterDelegate::WriteProgressStatus write_status_; 75 FileWriterDelegate::WriteProgressStatus write_status_;
75 }; 76 };
76 77
78 class BlobURLRequestJobFactory;
79
77 } // namespace (anonymous) 80 } // namespace (anonymous)
78 81
79 class FileWriterDelegateTest : public PlatformTest { 82 class FileWriterDelegateTest : public PlatformTest {
80 public: 83 public:
81 FileWriterDelegateTest() {} 84 FileWriterDelegateTest() {}
82 85
83 protected: 86 protected:
84 virtual void SetUp() OVERRIDE; 87 virtual void SetUp() OVERRIDE;
85 virtual void TearDown() OVERRIDE; 88 virtual void TearDown() OVERRIDE;
86 89
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void PrepareForWrite(const char* test_file_path, 137 void PrepareForWrite(const char* test_file_path,
135 const GURL& blob_url, 138 const GURL& blob_url,
136 int64 offset, 139 int64 offset,
137 int64 allowed_growth) { 140 int64 allowed_growth) {
138 file_writer_delegate_.reset( 141 file_writer_delegate_.reset(
139 CreateWriterDelegate(test_file_path, offset, allowed_growth)); 142 CreateWriterDelegate(test_file_path, offset, allowed_growth));
140 request_ = empty_context_.CreateRequest( 143 request_ = empty_context_.CreateRequest(
141 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get(), NULL); 144 blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get(), NULL);
142 } 145 }
143 146
144 static net::URLRequest::ProtocolFactory Factory;
145
146 // This should be alive until the very end of this instance. 147 // This should be alive until the very end of this instance.
147 base::MessageLoopForIO loop_; 148 base::MessageLoopForIO loop_;
148 149
149 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 150 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
150 151
151 net::URLRequestContext empty_context_; 152 net::URLRequestContext empty_context_;
152 scoped_ptr<FileWriterDelegate> file_writer_delegate_; 153 scoped_ptr<FileWriterDelegate> file_writer_delegate_;
153 scoped_ptr<net::URLRequest> request_; 154 scoped_ptr<net::URLRequest> request_;
155 scoped_ptr<BlobURLRequestJobFactory> job_factory_;
154 156
155 base::ScopedTempDir dir_; 157 base::ScopedTempDir dir_;
156 158
157 static const char* content_; 159 static const char* content_;
158 }; 160 };
159 161
160 const char* FileWriterDelegateTest::content_ = NULL; 162 const char* FileWriterDelegateTest::content_ = NULL;
161 163
162 namespace { 164 namespace {
163 165
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 203
202 protected: 204 protected:
203 virtual ~FileWriterDelegateTestJob() {} 205 virtual ~FileWriterDelegateTestJob() {}
204 206
205 private: 207 private:
206 std::string content_; 208 std::string content_;
207 int remaining_bytes_; 209 int remaining_bytes_;
208 int cursor_; 210 int cursor_;
209 }; 211 };
210 212
213 class BlobURLRequestJobFactory : public net::URLRequestJobFactory {
214 public:
215 explicit BlobURLRequestJobFactory(const char** content_data)
216 : content_data_(content_data) {
217 }
218
219 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
220 const std::string& scheme,
221 net::URLRequest* request,
222 net::NetworkDelegate* network_delegate) const OVERRIDE {
223 return new FileWriterDelegateTestJob(
224 request, network_delegate, *content_data_);
225 }
226
227 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE {
228 return scheme == "blob";
229 }
230
231 virtual bool IsHandledURL(const GURL& url) const OVERRIDE {
232 return url.SchemeIs("blob");
233 }
234
235 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE {
236 return true;
237 }
238
239 private:
240 const char** content_data_;
241
242 DISALLOW_COPY_AND_ASSIGN(BlobURLRequestJobFactory);
243 };
244
211 } // namespace (anonymous) 245 } // namespace (anonymous)
212 246
213 // static
214 net::URLRequestJob* FileWriterDelegateTest::Factory(
215 net::URLRequest* request,
216 net::NetworkDelegate* network_delegate,
217 const std::string& scheme) {
218 return new FileWriterDelegateTestJob(
219 request, network_delegate, FileWriterDelegateTest::content_);
220 }
221
222 void FileWriterDelegateTest::SetUp() { 247 void FileWriterDelegateTest::SetUp() {
223 ASSERT_TRUE(dir_.CreateUniqueTempDir()); 248 ASSERT_TRUE(dir_.CreateUniqueTempDir());
224 249
225 file_system_context_ = CreateFileSystemContextForTesting( 250 file_system_context_ = CreateFileSystemContextForTesting(
226 NULL, dir_.path()); 251 NULL, dir_.path());
227 ASSERT_EQ(base::File::FILE_OK, 252 ASSERT_EQ(base::File::FILE_OK,
228 AsyncFileTestHelper::CreateFile( 253 AsyncFileTestHelper::CreateFile(
229 file_system_context_, GetFileSystemURL("test"))); 254 file_system_context_, GetFileSystemURL("test")));
230 net::URLRequest::Deprecated::RegisterProtocolFactory("blob", &Factory); 255 job_factory_.reset(new BlobURLRequestJobFactory(&content_));
256 empty_context_.set_job_factory(job_factory_.get());
231 } 257 }
232 258
233 void FileWriterDelegateTest::TearDown() { 259 void FileWriterDelegateTest::TearDown() {
234 net::URLRequest::Deprecated::RegisterProtocolFactory("blob", NULL);
235 file_system_context_ = NULL; 260 file_system_context_ = NULL;
236 base::RunLoop().RunUntilIdle(); 261 base::RunLoop().RunUntilIdle();
237 } 262 }
238 263
239 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) { 264 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) {
240 const GURL kBlobURL("blob:nolimit"); 265 const GURL kBlobURL("blob:nolimit");
241 content_ = kData; 266 content_ = kData;
242 267
243 PrepareForWrite("test", kBlobURL, 0, kint64max); 268 PrepareForWrite("test", kBlobURL, 0, kint64max);
244 269
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 file_writer_delegate_.reset(); 478 file_writer_delegate_.reset();
454 479
455 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); 480 EXPECT_EQ(pre_write_usage + allowed_growth, usage());
456 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); 481 EXPECT_EQ(GetFileSizeOnDisk("test"), usage());
457 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); 482 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written());
458 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); 483 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status());
459 } 484 }
460 } 485 }
461 486
462 } // namespace content 487 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698