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

Side by Side Diff: webkit/fileapi/local_file_system_operation_write_unittest.cc

Issue 10870040: Rename FileSystemOperationInterface to FileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 virtual void SetUp(); 93 virtual void SetUp();
94 virtual void TearDown(); 94 virtual void TearDown();
95 95
96 protected: 96 protected:
97 FileSystemURL URLForPath(const FilePath& path) const { 97 FileSystemURL URLForPath(const FilePath& path) const {
98 return test_helper_.CreateURL(path); 98 return test_helper_.CreateURL(path);
99 } 99 }
100 100
101 // Callback function for recording test results. 101 // Callback function for recording test results.
102 FileSystemOperationInterface::WriteCallback RecordWriteCallback() { 102 FileSystemOperation::WriteCallback RecordWriteCallback() {
103 return base::Bind(&LocalFileSystemOperationWriteTest::DidWrite, 103 return base::Bind(&LocalFileSystemOperationWriteTest::DidWrite,
104 AsWeakPtr()); 104 AsWeakPtr());
105 } 105 }
106 106
107 FileSystemOperationInterface::StatusCallback RecordCancelCallback() { 107 FileSystemOperation::StatusCallback RecordCancelCallback() {
108 return base::Bind(&LocalFileSystemOperationWriteTest::DidCancel, 108 return base::Bind(&LocalFileSystemOperationWriteTest::DidCancel,
109 AsWeakPtr()); 109 AsWeakPtr());
110 } 110 }
111 111
112 void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) { 112 void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) {
113 if (status == base::PLATFORM_FILE_OK) { 113 if (status == base::PLATFORM_FILE_OK) {
114 add_bytes_written(bytes, complete); 114 add_bytes_written(bytes, complete);
115 if (complete) 115 if (complete)
116 MessageLoop::current()->Quit(); 116 MessageLoop::current()->Quit();
117 } else { 117 } else {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) { 349 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) {
350 GURL blob_url("blob:success"); 350 GURL blob_url("blob:success");
351 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 351 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
352 blob_data->AppendData("Hello, world!\n"); 352 blob_data->AppendData("Hello, world!\n");
353 353
354 TestURLRequestContext url_request_context; 354 TestURLRequestContext url_request_context;
355 url_request_context.blob_storage_controller()->AddFinishedBlob( 355 url_request_context.blob_storage_controller()->AddFinishedBlob(
356 blob_url, blob_data); 356 blob_url, blob_data);
357 357
358 FileSystemOperationInterface* write_operation = operation(); 358 FileSystemOperation* write_operation = operation();
359 write_operation->Write(&url_request_context, URLForPath(virtual_path_), 359 write_operation->Write(&url_request_context, URLForPath(virtual_path_),
360 blob_url, 0, RecordWriteCallback()); 360 blob_url, 0, RecordWriteCallback());
361 write_operation->Cancel(RecordCancelCallback()); 361 write_operation->Cancel(RecordCancelCallback());
362 // We use RunAllPendings() instead of Run() here, because we won't dispatch 362 // We use RunAllPendings() instead of Run() here, because we won't dispatch
363 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need 363 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need
364 // to run another write cycle. 364 // to run another write cycle.
365 MessageLoop::current()->RunAllPending(); 365 MessageLoop::current()->RunAllPending();
366 366
367 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); 367 url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
368 368
369 // Issued Cancel() before receiving any response from Write(), 369 // Issued Cancel() before receiving any response from Write(),
370 // so nothing should have happen. 370 // so nothing should have happen.
371 EXPECT_EQ(0, bytes_written()); 371 EXPECT_EQ(0, bytes_written());
372 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); 372 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status());
373 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); 373 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status());
374 EXPECT_TRUE(complete()); 374 EXPECT_TRUE(complete());
375 } 375 }
376 376
377 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) { 377 TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) {
378 GURL blob_url("blob:writeinvalidfile"); 378 GURL blob_url("blob:writeinvalidfile");
379 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 379 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
380 blob_data->AppendData("It\'ll not be written."); 380 blob_data->AppendData("It\'ll not be written.");
381 381
382 TestURLRequestContext url_request_context; 382 TestURLRequestContext url_request_context;
383 url_request_context.blob_storage_controller()->AddFinishedBlob( 383 url_request_context.blob_storage_controller()->AddFinishedBlob(
384 blob_url, blob_data); 384 blob_url, blob_data);
385 385
386 FileSystemOperationInterface* write_operation = operation(); 386 FileSystemOperation* write_operation = operation();
387 write_operation->Write(&url_request_context, 387 write_operation->Write(&url_request_context,
388 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), 388 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))),
389 blob_url, 0, RecordWriteCallback()); 389 blob_url, 0, RecordWriteCallback());
390 write_operation->Cancel(RecordCancelCallback()); 390 write_operation->Cancel(RecordCancelCallback());
391 // We use RunAllPendings() instead of Run() here, because we won't dispatch 391 // We use RunAllPendings() instead of Run() here, because we won't dispatch
392 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need 392 // callbacks after Cancel() is issued (so no chance to Quit) nor do we need
393 // to run another write cycle. 393 // to run another write cycle.
394 MessageLoop::current()->RunAllPending(); 394 MessageLoop::current()->RunAllPending();
395 395
396 url_request_context.blob_storage_controller()->RemoveBlob(blob_url); 396 url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
397 397
398 // Issued Cancel() before receiving any response from Write(), 398 // Issued Cancel() before receiving any response from Write(),
399 // so nothing should have happen. 399 // so nothing should have happen.
400 EXPECT_EQ(0, bytes_written()); 400 EXPECT_EQ(0, bytes_written());
401 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); 401 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status());
402 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); 402 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status());
403 EXPECT_TRUE(complete()); 403 EXPECT_TRUE(complete());
404 } 404 }
405 405
406 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases. 406 // TODO(ericu,dmikurube,kinuko): Add more tests for cancel cases.
407 407
408 } // namespace fileapi 408 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698