| Index: chrome/browser/chromeos/file_system_provider/queue_unittest.cc
|
| diff --git a/chrome/browser/chromeos/file_system_provider/queue_unittest.cc b/chrome/browser/chromeos/file_system_provider/queue_unittest.cc
|
| index 9cda477697b7d5a40e3330c94664d0e4ee15dd27..30d1c8c28ca8eaceb6a0403809d67a82b1dd1968 100644
|
| --- a/chrome/browser/chromeos/file_system_provider/queue_unittest.cc
|
| +++ b/chrome/browser/chromeos/file_system_provider/queue_unittest.cc
|
| @@ -15,22 +15,24 @@ namespace chromeos {
|
| namespace file_system_provider {
|
| namespace {
|
|
|
| -void OnAbort(int* abort_counter,
|
| - const storage::AsyncFileUtil::StatusCallback& callback) {
|
| - (*abort_counter)++;
|
| - callback.Run(base::File::FILE_ERROR_FAILED);
|
| +void OnAbort(int* abort_counter) {
|
| + ++(*abort_counter);
|
| }
|
|
|
| AbortCallback OnRun(int* run_counter, int* abort_counter) {
|
| - (*run_counter)++;
|
| + ++(*run_counter);
|
| return base::Bind(&OnAbort, abort_counter);
|
| }
|
|
|
| -void OnAbortCallback(std::vector<base::File::Error>* log,
|
| - base::File::Error result) {
|
| - log->push_back(result);
|
| +#if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST)
|
| +
|
| +AbortCallback OnRunNonAbortable(int* run_counter, int* abort_counter) {
|
| + ++(*run_counter);
|
| + return AbortCallback();
|
| }
|
|
|
| +#endif
|
| +
|
| } // namespace
|
|
|
| class FileSystemProviderQueueTest : public testing::Test {
|
| @@ -59,8 +61,8 @@ TEST_F(FileSystemProviderQueueTest, Enqueue_OneAtOnce) {
|
| const size_t second_token = queue.NewToken();
|
| int second_counter = 0;
|
| int second_abort_counter = 0;
|
| - const AbortCallback abort_callback = queue.Enqueue(
|
| - second_token, base::Bind(&OnRun, &second_counter, &second_abort_counter));
|
| + queue.Enqueue(second_token,
|
| + base::Bind(&OnRun, &second_counter, &second_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, first_counter);
|
| @@ -100,15 +102,12 @@ TEST_F(FileSystemProviderQueueTest, Enqueue_OneAtOnce) {
|
| EXPECT_EQ(0, third_abort_counter);
|
|
|
| // After aborting the second task, the third should run.
|
| - std::vector<base::File::Error> abort_callback_log;
|
| - abort_callback.Run(base::Bind(&OnAbortCallback, &abort_callback_log));
|
| + queue.Abort(second_token);
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, first_counter);
|
| EXPECT_EQ(0, first_abort_counter);
|
| EXPECT_EQ(1, second_counter);
|
| EXPECT_EQ(1, second_abort_counter);
|
| - ASSERT_EQ(1u, abort_callback_log.size());
|
| - EXPECT_EQ(base::File::FILE_ERROR_FAILED, abort_callback_log[0]);
|
| EXPECT_EQ(1, third_counter);
|
| EXPECT_EQ(0, third_abort_counter);
|
| }
|
| @@ -185,7 +184,7 @@ TEST_F(FileSystemProviderQueueTest, InvalidUsage_CompleteNotStarted) {
|
| EXPECT_DEATH(queue.Remove(first_token), "");
|
| }
|
|
|
| -TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveNotCompleted) {
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveNotCompletedNorAborted) {
|
| Queue queue(1);
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| @@ -204,61 +203,97 @@ TEST_F(FileSystemProviderQueueTest, InvalidUsage_CompleteAfterAborting) {
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| int first_abort_counter = 0;
|
| - AbortCallback first_abort_callback = queue.Enqueue(
|
| - first_token, base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| // Run, then abort.
|
| std::vector<base::File::Error> first_abort_callback_log;
|
| - first_abort_callback.Run(
|
| - base::Bind(&OnAbortCallback, &first_abort_callback_log));
|
| + queue.Abort(first_token);
|
|
|
| EXPECT_DEATH(queue.Complete(first_token), "");
|
| }
|
|
|
| -TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveAfterAborting) {
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_AbortAfterCompleting) {
|
| Queue queue(1);
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| int first_abort_counter = 0;
|
| - AbortCallback first_abort_callback = queue.Enqueue(
|
| - first_token, base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| - // Abort after executing.
|
| - std::vector<base::File::Error> first_abort_callback_log;
|
| - first_abort_callback.Run(
|
| - base::Bind(&OnAbortCallback, &first_abort_callback_log));
|
| + queue.Complete(first_token);
|
| + EXPECT_DEATH(queue.Abort(first_token), "");
|
| +}
|
| +
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_CompleteTwice) {
|
| + Queue queue(1);
|
| + const size_t first_token = queue.NewToken();
|
| + int first_counter = 0;
|
| + int first_abort_counter = 0;
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| - // Remove before completing.
|
| - EXPECT_DEATH(queue.Remove(first_token), "");
|
| + queue.Complete(first_token);
|
| + EXPECT_DEATH(queue.Complete(first_token), "");
|
| }
|
|
|
| -TEST_F(FileSystemProviderQueueTest, InvalidUsage_CompleteTwice) {
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_AbortTwice) {
|
| Queue queue(1);
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| int first_abort_counter = 0;
|
| - AbortCallback first_abort_callback = queue.Enqueue(
|
| - first_token, base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + queue.Abort(first_token);
|
| + EXPECT_DEATH(queue.Abort(first_token), "");
|
| +}
|
| +
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveTwice) {
|
| + Queue queue(1);
|
| + const size_t first_token = queue.NewToken();
|
| + int first_counter = 0;
|
| + int first_abort_counter = 0;
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| queue.Complete(first_token);
|
| + queue.Remove(first_token);
|
| EXPECT_DEATH(queue.Complete(first_token), "");
|
| }
|
|
|
| -TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveTwice) {
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_AbortAfterRemoving) {
|
| + Queue queue(1);
|
| + const size_t first_token = queue.NewToken();
|
| + int first_counter = 0;
|
| + int first_abort_counter = 0;
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + queue.Complete(first_token);
|
| + queue.Remove(first_token);
|
| + EXPECT_DEATH(queue.Abort(first_token), "");
|
| +}
|
| +
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_CompleteAfterRemoving) {
|
| Queue queue(1);
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| int first_abort_counter = 0;
|
| - AbortCallback first_abort_callback = queue.Enqueue(
|
| - first_token, base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| @@ -267,6 +302,19 @@ TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveTwice) {
|
| EXPECT_DEATH(queue.Complete(first_token), "");
|
| }
|
|
|
| +TEST_F(FileSystemProviderQueueTest, InvalidUsage_AbortNonAbortable) {
|
| + Queue queue(1);
|
| + const size_t first_token = queue.NewToken();
|
| + int first_counter = 0;
|
| + int first_abort_counter = 0;
|
| + queue.Enqueue(first_token, base::Bind(&OnRunNonAbortable, &first_counter,
|
| + &first_abort_counter));
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + EXPECT_DEATH(queue.Abort(first_token), "");
|
| +}
|
| +
|
| #endif
|
|
|
| TEST_F(FileSystemProviderQueueTest, Enqueue_Abort) {
|
| @@ -274,14 +322,14 @@ TEST_F(FileSystemProviderQueueTest, Enqueue_Abort) {
|
| const size_t first_token = queue.NewToken();
|
| int first_counter = 0;
|
| int first_abort_counter = 0;
|
| - const AbortCallback first_abort_callback = queue.Enqueue(
|
| - first_token, base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
| + queue.Enqueue(first_token,
|
| + base::Bind(&OnRun, &first_counter, &first_abort_counter));
|
|
|
| const size_t second_token = queue.NewToken();
|
| int second_counter = 0;
|
| int second_abort_counter = 0;
|
| - const AbortCallback second_abort_callback = queue.Enqueue(
|
| - second_token, base::Bind(&OnRun, &second_counter, &second_abort_counter));
|
| + queue.Enqueue(second_token,
|
| + base::Bind(&OnRun, &second_counter, &second_abort_counter));
|
|
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, first_counter);
|
| @@ -290,34 +338,17 @@ TEST_F(FileSystemProviderQueueTest, Enqueue_Abort) {
|
| EXPECT_EQ(0, second_abort_counter);
|
|
|
| // Abort the first task while it's being executed.
|
| - std::vector<base::File::Error> first_abort_callback_log;
|
| - first_abort_callback.Run(
|
| - base::Bind(&OnAbortCallback, &first_abort_callback_log));
|
| + queue.Abort(first_token);
|
|
|
| // Abort the second task, before it's started.
|
| EXPECT_EQ(0, second_counter);
|
| - std::vector<base::File::Error> second_abort_callback_log;
|
| - second_abort_callback.Run(
|
| - base::Bind(&OnAbortCallback, &second_abort_callback_log));
|
| + queue.Abort(second_token);
|
|
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(1, first_counter);
|
| EXPECT_EQ(1, first_abort_counter);
|
| - ASSERT_EQ(1u, first_abort_callback_log.size());
|
| - EXPECT_EQ(base::File::FILE_ERROR_FAILED, first_abort_callback_log[0]);
|
| EXPECT_EQ(0, second_counter);
|
| EXPECT_EQ(0, second_abort_counter);
|
| - ASSERT_EQ(1u, second_abort_callback_log.size());
|
| - EXPECT_EQ(base::File::FILE_OK, second_abort_callback_log[0]);
|
| -
|
| - // Aborting again, should result in the FILE_ERROR_INVALID_MODIFICATION error
|
| - // code.
|
| - second_abort_callback.Run(
|
| - base::Bind(&OnAbortCallback, &second_abort_callback_log));
|
| -
|
| - ASSERT_EQ(2u, second_abort_callback_log.size());
|
| - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
|
| - second_abort_callback_log[1]);
|
| }
|
|
|
| } // namespace file_system_provider
|
|
|