| 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 "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" | 5 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 file_system_.operation_runner()->Write( | 320 file_system_.operation_runner()->Write( |
| 321 &url_request_context_, | 321 &url_request_context_, |
| 322 URL(kFile), blob.GetBlobDataHandle(), 0, GetWriteCallback(FROM_HERE)); | 322 URL(kFile), blob.GetBlobDataHandle(), 0, GetWriteCallback(FROM_HERE)); |
| 323 base::RunLoop().RunUntilIdle(); | 323 base::RunLoop().RunUntilIdle(); |
| 324 EXPECT_EQ(0, callback_count_); | 324 EXPECT_EQ(0, callback_count_); |
| 325 | 325 |
| 326 sync_status()->EndSyncing(URL(kFile)); | 326 sync_status()->EndSyncing(URL(kFile)); |
| 327 ResetCallbackStatus(); | 327 ResetCallbackStatus(); |
| 328 | 328 |
| 329 while (!write_complete_) | 329 while (!write_complete_) |
| 330 base::MessageLoop::current()->RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 331 | 331 |
| 332 EXPECT_EQ(File::FILE_OK, write_status_); | 332 EXPECT_EQ(File::FILE_OK, write_status_); |
| 333 EXPECT_EQ(kData.size(), write_bytes_); | 333 EXPECT_EQ(kData.size(), write_bytes_); |
| 334 EXPECT_TRUE(write_complete_); | 334 EXPECT_TRUE(write_complete_); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST_F(SyncableFileOperationRunnerTest, QueueAndCancel) { | 337 TEST_F(SyncableFileOperationRunnerTest, QueueAndCancel) { |
| 338 sync_status()->StartSyncing(URL(kFile)); | 338 sync_status()->StartSyncing(URL(kFile)); |
| 339 ASSERT_FALSE(sync_status()->IsWritable(URL(kFile))); | 339 ASSERT_FALSE(sync_status()->IsWritable(URL(kFile))); |
| 340 | 340 |
| 341 ResetCallbackStatus(); | 341 ResetCallbackStatus(); |
| 342 file_system_.operation_runner()->CreateFile( | 342 file_system_.operation_runner()->CreateFile( |
| 343 URL(kFile), false /* exclusive */, | 343 URL(kFile), false /* exclusive */, |
| 344 ExpectStatus(FROM_HERE, File::FILE_ERROR_ABORT)); | 344 ExpectStatus(FROM_HERE, File::FILE_ERROR_ABORT)); |
| 345 file_system_.operation_runner()->Truncate( | 345 file_system_.operation_runner()->Truncate( |
| 346 URL(kFile), 1, | 346 URL(kFile), 1, |
| 347 ExpectStatus(FROM_HERE, File::FILE_ERROR_ABORT)); | 347 ExpectStatus(FROM_HERE, File::FILE_ERROR_ABORT)); |
| 348 base::MessageLoop::current()->RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
| 349 EXPECT_EQ(0, callback_count_); | 349 EXPECT_EQ(0, callback_count_); |
| 350 | 350 |
| 351 ResetCallbackStatus(); | 351 ResetCallbackStatus(); |
| 352 | 352 |
| 353 // This shouldn't crash nor leak memory. | 353 // This shouldn't crash nor leak memory. |
| 354 sync_context_->ShutdownOnUIThread(); | 354 sync_context_->ShutdownOnUIThread(); |
| 355 sync_context_ = nullptr; | 355 sync_context_ = nullptr; |
| 356 base::MessageLoop::current()->RunUntilIdle(); | 356 base::RunLoop().RunUntilIdle(); |
| 357 EXPECT_EQ(2, callback_count_); | 357 EXPECT_EQ(2, callback_count_); |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Test if CopyInForeignFile runs cooperatively with other Sync operations. | 360 // Test if CopyInForeignFile runs cooperatively with other Sync operations. |
| 361 TEST_F(SyncableFileOperationRunnerTest, CopyInForeignFile) { | 361 TEST_F(SyncableFileOperationRunnerTest, CopyInForeignFile) { |
| 362 const std::string kTestData("test data"); | 362 const std::string kTestData("test data"); |
| 363 | 363 |
| 364 base::FilePath temp_path; | 364 base::FilePath temp_path; |
| 365 ASSERT_TRUE(CreateTempFile(&temp_path)); | 365 ASSERT_TRUE(CreateTempFile(&temp_path)); |
| 366 ASSERT_EQ(static_cast<int>(kTestData.size()), | 366 ASSERT_EQ(static_cast<int>(kTestData.size()), |
| 367 base::WriteFile( | 367 base::WriteFile( |
| 368 temp_path, kTestData.data(), kTestData.size())); | 368 temp_path, kTestData.data(), kTestData.size())); |
| 369 | 369 |
| 370 sync_status()->StartSyncing(URL(kFile)); | 370 sync_status()->StartSyncing(URL(kFile)); |
| 371 ASSERT_FALSE(sync_status()->IsWritable(URL(kFile))); | 371 ASSERT_FALSE(sync_status()->IsWritable(URL(kFile))); |
| 372 | 372 |
| 373 // The URL is in syncing so CopyIn (which is a write operation) won't run. | 373 // The URL is in syncing so CopyIn (which is a write operation) won't run. |
| 374 ResetCallbackStatus(); | 374 ResetCallbackStatus(); |
| 375 file_system_.operation_runner()->CopyInForeignFile( | 375 file_system_.operation_runner()->CopyInForeignFile( |
| 376 temp_path, URL(kFile), | 376 temp_path, URL(kFile), |
| 377 ExpectStatus(FROM_HERE, File::FILE_OK)); | 377 ExpectStatus(FROM_HERE, File::FILE_OK)); |
| 378 base::MessageLoop::current()->RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
| 379 EXPECT_EQ(0, callback_count_); | 379 EXPECT_EQ(0, callback_count_); |
| 380 | 380 |
| 381 // End syncing (to enable write). | 381 // End syncing (to enable write). |
| 382 sync_status()->EndSyncing(URL(kFile)); | 382 sync_status()->EndSyncing(URL(kFile)); |
| 383 ASSERT_TRUE(sync_status()->IsWritable(URL(kFile))); | 383 ASSERT_TRUE(sync_status()->IsWritable(URL(kFile))); |
| 384 | 384 |
| 385 ResetCallbackStatus(); | 385 ResetCallbackStatus(); |
| 386 base::MessageLoop::current()->RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
| 387 EXPECT_EQ(1, callback_count_); | 387 EXPECT_EQ(1, callback_count_); |
| 388 | 388 |
| 389 // Now the file must have been created and have the same content as temp_path. | 389 // Now the file must have been created and have the same content as temp_path. |
| 390 ResetCallbackStatus(); | 390 ResetCallbackStatus(); |
| 391 file_system_.DoVerifyFile( | 391 file_system_.DoVerifyFile( |
| 392 URL(kFile), kTestData, | 392 URL(kFile), kTestData, |
| 393 ExpectStatus(FROM_HERE, File::FILE_OK)); | 393 ExpectStatus(FROM_HERE, File::FILE_OK)); |
| 394 base::MessageLoop::current()->RunUntilIdle(); | 394 base::RunLoop().RunUntilIdle(); |
| 395 EXPECT_EQ(1, callback_count_); | 395 EXPECT_EQ(1, callback_count_); |
| 396 } | 396 } |
| 397 | 397 |
| 398 TEST_F(SyncableFileOperationRunnerTest, Cancel) { | 398 TEST_F(SyncableFileOperationRunnerTest, Cancel) { |
| 399 // Prepare a file. | 399 // Prepare a file. |
| 400 file_system_.operation_runner()->CreateFile( | 400 file_system_.operation_runner()->CreateFile( |
| 401 URL(kFile), false /* exclusive */, | 401 URL(kFile), false /* exclusive */, |
| 402 ExpectStatus(FROM_HERE, File::FILE_OK)); | 402 ExpectStatus(FROM_HERE, File::FILE_OK)); |
| 403 base::MessageLoop::current()->RunUntilIdle(); | 403 base::RunLoop().RunUntilIdle(); |
| 404 EXPECT_EQ(1, callback_count_); | 404 EXPECT_EQ(1, callback_count_); |
| 405 | 405 |
| 406 // Run Truncate and immediately cancel. This shouldn't crash. | 406 // Run Truncate and immediately cancel. This shouldn't crash. |
| 407 ResetCallbackStatus(); | 407 ResetCallbackStatus(); |
| 408 storage::FileSystemOperationRunner::OperationID id = | 408 storage::FileSystemOperationRunner::OperationID id = |
| 409 file_system_.operation_runner()->Truncate( | 409 file_system_.operation_runner()->Truncate( |
| 410 URL(kFile), 10, ExpectStatus(FROM_HERE, File::FILE_OK)); | 410 URL(kFile), 10, ExpectStatus(FROM_HERE, File::FILE_OK)); |
| 411 file_system_.operation_runner()->Cancel( | 411 file_system_.operation_runner()->Cancel( |
| 412 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION)); | 412 id, ExpectStatus(FROM_HERE, File::FILE_ERROR_INVALID_OPERATION)); |
| 413 base::RunLoop().Run(); | 413 base::RunLoop().Run(); |
| 414 EXPECT_EQ(2, callback_count_); | 414 EXPECT_EQ(2, callback_count_); |
| 415 } | 415 } |
| 416 | 416 |
| 417 } // namespace sync_file_system | 417 } // namespace sync_file_system |
| OLD | NEW |