| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/file_system_provider/queue.h" | 5 #include "chrome/browser/chromeos/file_system_provider/queue.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 int first_abort_counter = 0; | 275 int first_abort_counter = 0; |
| 276 queue.Enqueue(first_token, | 276 queue.Enqueue(first_token, |
| 277 base::Bind(&OnRun, &first_counter, &first_abort_counter)); | 277 base::Bind(&OnRun, &first_counter, &first_abort_counter)); |
| 278 | 278 |
| 279 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 280 | 280 |
| 281 queue.Abort(first_token); | 281 queue.Abort(first_token); |
| 282 EXPECT_DEATH(queue.Abort(first_token), ""); | 282 EXPECT_DEATH(queue.Abort(first_token), ""); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_F(FileSystemProviderQueueTest, InvalidUsage_IsAbortedWhileNotInQueue) { |
| 286 Queue queue(1); |
| 287 EXPECT_DEATH(queue.IsAborted(1234), ""); |
| 288 } |
| 289 |
| 290 TEST_F(FileSystemProviderQueueTest, InvalidUsage_IsAbortedAfterRemoved) { |
| 291 Queue queue(1); |
| 292 const size_t first_token = queue.NewToken(); |
| 293 int first_counter = 0; |
| 294 int first_abort_counter = 0; |
| 295 queue.Enqueue(first_token, |
| 296 base::Bind(&OnRun, &first_counter, &first_abort_counter)); |
| 297 |
| 298 base::RunLoop().RunUntilIdle(); |
| 299 |
| 300 queue.Abort(first_token); |
| 301 queue.Remove(first_token); |
| 302 EXPECT_DEATH(queue.IsAborted(first_token), ""); |
| 303 } |
| 304 |
| 285 TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveTwice) { | 305 TEST_F(FileSystemProviderQueueTest, InvalidUsage_RemoveTwice) { |
| 286 Queue queue(1); | 306 Queue queue(1); |
| 287 const size_t first_token = queue.NewToken(); | 307 const size_t first_token = queue.NewToken(); |
| 288 int first_counter = 0; | 308 int first_counter = 0; |
| 289 int first_abort_counter = 0; | 309 int first_abort_counter = 0; |
| 290 queue.Enqueue(first_token, | 310 queue.Enqueue(first_token, |
| 291 base::Bind(&OnRun, &first_counter, &first_abort_counter)); | 311 base::Bind(&OnRun, &first_counter, &first_abort_counter)); |
| 292 | 312 |
| 293 base::RunLoop().RunUntilIdle(); | 313 base::RunLoop().RunUntilIdle(); |
| 294 | 314 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 queue.Enqueue(second_token, | 376 queue.Enqueue(second_token, |
| 357 base::Bind(&OnRun, &second_counter, &second_abort_counter)); | 377 base::Bind(&OnRun, &second_counter, &second_abort_counter)); |
| 358 | 378 |
| 359 base::RunLoop().RunUntilIdle(); | 379 base::RunLoop().RunUntilIdle(); |
| 360 EXPECT_EQ(1, first_counter); | 380 EXPECT_EQ(1, first_counter); |
| 361 EXPECT_EQ(0, first_abort_counter); | 381 EXPECT_EQ(0, first_abort_counter); |
| 362 EXPECT_EQ(0, second_counter); | 382 EXPECT_EQ(0, second_counter); |
| 363 EXPECT_EQ(0, second_abort_counter); | 383 EXPECT_EQ(0, second_abort_counter); |
| 364 | 384 |
| 365 // Abort the first task while it's being executed. | 385 // Abort the first task while it's being executed. |
| 386 EXPECT_FALSE(queue.IsAborted(first_token)); |
| 366 queue.Abort(first_token); | 387 queue.Abort(first_token); |
| 388 EXPECT_TRUE(queue.IsAborted(first_token)); |
| 367 queue.Remove(first_token); | 389 queue.Remove(first_token); |
| 368 | 390 |
| 369 // Abort the second task, before it's started. | 391 // Abort the second task, before it's started. |
| 370 EXPECT_EQ(0, second_counter); | 392 EXPECT_EQ(0, second_counter); |
| 393 EXPECT_FALSE(queue.IsAborted(second_token)); |
| 371 queue.Abort(second_token); | 394 queue.Abort(second_token); |
| 395 EXPECT_TRUE(queue.IsAborted(second_token)); |
| 372 queue.Remove(second_token); | 396 queue.Remove(second_token); |
| 373 | 397 |
| 374 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
| 375 EXPECT_EQ(1, first_counter); | 399 EXPECT_EQ(1, first_counter); |
| 376 EXPECT_EQ(1, first_abort_counter); | 400 EXPECT_EQ(1, first_abort_counter); |
| 377 EXPECT_EQ(0, second_counter); | 401 EXPECT_EQ(0, second_counter); |
| 378 EXPECT_EQ(0, second_abort_counter); | 402 EXPECT_EQ(0, second_abort_counter); |
| 379 } | 403 } |
| 380 | 404 |
| 381 } // namespace file_system_provider | 405 } // namespace file_system_provider |
| 382 } // namespace chromeos | 406 } // namespace chromeos |
| OLD | NEW |