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 |
| 11 #include <vector> |
| 12 |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
13 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
14 #include "base/message_loop_proxy.h" | 16 #include "base/message_loop_proxy.h" |
15 #include "base/scoped_temp_dir.h" | 17 #include "base/scoped_temp_dir.h" |
16 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
17 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
19 #include "net/url_request/url_request_job.h" | 21 #include "net/url_request/url_request_job.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 return test_helper_.NewOperation(new MockDispatcher(this)); | 218 return test_helper_.NewOperation(new MockDispatcher(this)); |
217 } | 219 } |
218 | 220 |
219 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { | 221 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { |
220 GURL blob_url("blob:success"); | 222 GURL blob_url("blob:success"); |
221 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 223 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
222 blob_data->AppendData("Hello, world!\n"); | 224 blob_data->AppendData("Hello, world!\n"); |
223 | 225 |
224 scoped_refptr<TestURLRequestContext> url_request_context( | 226 scoped_refptr<TestURLRequestContext> url_request_context( |
225 new TestURLRequestContext()); | 227 new TestURLRequestContext()); |
226 url_request_context->blob_storage_controller()-> | 228 url_request_context->blob_storage_controller()->AddFinishedBlob( |
227 RegisterBlobUrl(blob_url, blob_data); | 229 blob_url, blob_data); |
228 | 230 |
229 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, | 231 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, |
230 0); | 232 0); |
231 MessageLoop::current()->Run(); | 233 MessageLoop::current()->Run(); |
232 | 234 |
233 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 235 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
234 | 236 |
235 EXPECT_EQ(14, bytes_written()); | 237 EXPECT_EQ(14, bytes_written()); |
236 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 238 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
237 EXPECT_TRUE(complete()); | 239 EXPECT_TRUE(complete()); |
238 } | 240 } |
239 | 241 |
240 TEST_F(FileSystemOperationWriteTest, TestWriteZero) { | 242 TEST_F(FileSystemOperationWriteTest, TestWriteZero) { |
241 GURL blob_url("blob:zero"); | 243 GURL blob_url("blob:zero"); |
242 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 244 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
243 blob_data->AppendData(""); | 245 blob_data->AppendData(""); |
244 | 246 |
245 scoped_refptr<TestURLRequestContext> url_request_context( | 247 scoped_refptr<TestURLRequestContext> url_request_context( |
246 new TestURLRequestContext()); | 248 new TestURLRequestContext()); |
247 url_request_context->blob_storage_controller()-> | 249 url_request_context->blob_storage_controller()->AddFinishedBlob( |
248 RegisterBlobUrl(blob_url, blob_data); | 250 blob_url, blob_data); |
249 | 251 |
250 operation()->Write(url_request_context, URLForPath(virtual_path_), | 252 operation()->Write(url_request_context, URLForPath(virtual_path_), |
251 blob_url, 0); | 253 blob_url, 0); |
252 MessageLoop::current()->Run(); | 254 MessageLoop::current()->Run(); |
253 | 255 |
254 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 256 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
255 | 257 |
256 EXPECT_EQ(0, bytes_written()); | 258 EXPECT_EQ(0, bytes_written()); |
257 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 259 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
258 EXPECT_TRUE(complete()); | 260 EXPECT_TRUE(complete()); |
259 } | 261 } |
260 | 262 |
261 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { | 263 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { |
262 scoped_refptr<TestURLRequestContext> url_request_context( | 264 scoped_refptr<TestURLRequestContext> url_request_context( |
263 new TestURLRequestContext()); | 265 new TestURLRequestContext()); |
264 | 266 |
265 operation()->Write(url_request_context, URLForPath(virtual_path_), | 267 operation()->Write(url_request_context, URLForPath(virtual_path_), |
266 GURL("blob:invalid"), 0); | 268 GURL("blob:invalid"), 0); |
267 MessageLoop::current()->Run(); | 269 MessageLoop::current()->Run(); |
268 | 270 |
269 EXPECT_EQ(0, bytes_written()); | 271 EXPECT_EQ(0, bytes_written()); |
270 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 272 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
271 EXPECT_TRUE(complete()); | 273 EXPECT_TRUE(complete()); |
272 } | 274 } |
273 | 275 |
274 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { | 276 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { |
275 GURL blob_url("blob:writeinvalidfile"); | 277 GURL blob_url("blob:writeinvalidfile"); |
276 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 278 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
277 blob_data->AppendData("It\'ll not be written."); | 279 blob_data->AppendData("It\'ll not be written."); |
278 | 280 |
279 scoped_refptr<TestURLRequestContext> url_request_context( | 281 scoped_refptr<TestURLRequestContext> url_request_context( |
280 new TestURLRequestContext()); | 282 new TestURLRequestContext()); |
281 url_request_context->blob_storage_controller()-> | 283 url_request_context->blob_storage_controller()->AddFinishedBlob( |
282 RegisterBlobUrl(blob_url, blob_data); | 284 blob_url, blob_data); |
283 | 285 |
284 operation()->Write(url_request_context, | 286 operation()->Write(url_request_context, |
285 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), | 287 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), |
286 blob_url, 0); | 288 blob_url, 0); |
287 MessageLoop::current()->Run(); | 289 MessageLoop::current()->Run(); |
288 | 290 |
289 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 291 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
290 | 292 |
291 EXPECT_EQ(0, bytes_written()); | 293 EXPECT_EQ(0, bytes_written()); |
292 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 294 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
293 EXPECT_TRUE(complete()); | 295 EXPECT_TRUE(complete()); |
294 } | 296 } |
295 | 297 |
296 TEST_F(FileSystemOperationWriteTest, TestWriteDir) { | 298 TEST_F(FileSystemOperationWriteTest, TestWriteDir) { |
297 FilePath subdir; | 299 FilePath subdir; |
298 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(filesystem_dir_, | 300 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(filesystem_dir_, |
299 FILE_PATH_LITERAL("d"), | 301 FILE_PATH_LITERAL("d"), |
300 &subdir)); | 302 &subdir)); |
301 FilePath virtual_subdir_path = subdir.BaseName(); | 303 FilePath virtual_subdir_path = subdir.BaseName(); |
302 | 304 |
303 GURL blob_url("blob:writedir"); | 305 GURL blob_url("blob:writedir"); |
304 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 306 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
305 blob_data->AppendData("It\'ll not be written, too."); | 307 blob_data->AppendData("It\'ll not be written, too."); |
306 | 308 |
307 scoped_refptr<TestURLRequestContext> url_request_context( | 309 scoped_refptr<TestURLRequestContext> url_request_context( |
308 new TestURLRequestContext()); | 310 new TestURLRequestContext()); |
309 url_request_context->blob_storage_controller()-> | 311 url_request_context->blob_storage_controller()->AddFinishedBlob( |
310 RegisterBlobUrl(blob_url, blob_data); | 312 blob_url, blob_data); |
311 | 313 |
312 operation()->Write(url_request_context, URLForPath(virtual_subdir_path), | 314 operation()->Write(url_request_context, URLForPath(virtual_subdir_path), |
313 blob_url, 0); | 315 blob_url, 0); |
314 MessageLoop::current()->Run(); | 316 MessageLoop::current()->Run(); |
315 | 317 |
316 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 318 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
317 | 319 |
318 EXPECT_EQ(0, bytes_written()); | 320 EXPECT_EQ(0, bytes_written()); |
319 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); | 321 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); |
320 EXPECT_TRUE(complete()); | 322 EXPECT_TRUE(complete()); |
321 } | 323 } |
322 | 324 |
323 TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) { | 325 TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) { |
324 GURL blob_url("blob:success"); | 326 GURL blob_url("blob:success"); |
325 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 327 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
326 blob_data->AppendData("Hello, world!\n"); | 328 blob_data->AppendData("Hello, world!\n"); |
327 | 329 |
328 scoped_refptr<TestURLRequestContext> url_request_context( | 330 scoped_refptr<TestURLRequestContext> url_request_context( |
329 new TestURLRequestContext()); | 331 new TestURLRequestContext()); |
330 url_request_context->blob_storage_controller()-> | 332 url_request_context->blob_storage_controller()->AddFinishedBlob( |
331 RegisterBlobUrl(blob_url, blob_data); | 333 blob_url, blob_data); |
332 | 334 |
333 quota_manager_->set_quota(10); | 335 quota_manager_->set_quota(10); |
334 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, | 336 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, |
335 0); | 337 0); |
336 MessageLoop::current()->Run(); | 338 MessageLoop::current()->Run(); |
337 | 339 |
338 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 340 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
339 | 341 |
340 EXPECT_EQ(10, bytes_written()); | 342 EXPECT_EQ(10, bytes_written()); |
341 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 343 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
342 EXPECT_TRUE(complete()); | 344 EXPECT_TRUE(complete()); |
343 } | 345 } |
344 | 346 |
345 // TODO(ericu,dmikurube): Add tests for Cancel. | 347 // TODO(ericu,dmikurube): Add tests for Cancel. |
346 | 348 |
347 } // namespace fileapi | 349 } // namespace fileapi |
OLD | NEW |