| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/drive_backend/callback_helper.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace sync_file_system { | 14 namespace sync_file_system { |
| 15 namespace drive_backend { | 15 namespace drive_backend { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void SimpleCallback(bool* called, int) { | 19 void SimpleCallback(bool* called, int) { |
| 20 ASSERT_TRUE(called); | 20 ASSERT_TRUE(called); |
| 21 EXPECT_FALSE(*called); | 21 EXPECT_FALSE(*called); |
| 22 *called = true; | 22 *called = true; |
| 23 } | 23 } |
| 24 | 24 |
| 25 void CallbackWithPassed(bool* called, scoped_ptr<int>) { | 25 void CallbackWithPassed(bool* called, std::unique_ptr<int>) { |
| 26 ASSERT_TRUE(called); | 26 ASSERT_TRUE(called); |
| 27 EXPECT_FALSE(*called); | 27 EXPECT_FALSE(*called); |
| 28 *called = true; | 28 *called = true; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void VerifyCalledOnTaskRunner(base::TaskRunner* task_runner, | 31 void VerifyCalledOnTaskRunner(base::TaskRunner* task_runner, |
| 32 bool* called) { | 32 bool* called) { |
| 33 ASSERT_TRUE(called); | 33 ASSERT_TRUE(called); |
| 34 ASSERT_TRUE(task_runner); | 34 ASSERT_TRUE(task_runner); |
| 35 | 35 |
| 36 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 36 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
| 37 EXPECT_FALSE(*called); | 37 EXPECT_FALSE(*called); |
| 38 *called = true; | 38 *called = true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 TEST(DriveBackendCallbackHelperTest, BasicTest) { | 43 TEST(DriveBackendCallbackHelperTest, BasicTest) { |
| 44 base::MessageLoop message_loop; | 44 base::MessageLoop message_loop; |
| 45 | 45 |
| 46 bool called = false; | 46 bool called = false; |
| 47 RelayCallbackToCurrentThread( | 47 RelayCallbackToCurrentThread( |
| 48 FROM_HERE, | 48 FROM_HERE, |
| 49 base::Bind(&SimpleCallback, &called)).Run(0); | 49 base::Bind(&SimpleCallback, &called)).Run(0); |
| 50 EXPECT_FALSE(called); | 50 EXPECT_FALSE(called); |
| 51 base::RunLoop().RunUntilIdle(); | 51 base::RunLoop().RunUntilIdle(); |
| 52 EXPECT_TRUE(called); | 52 EXPECT_TRUE(called); |
| 53 | 53 |
| 54 called = false; | 54 called = false; |
| 55 RelayCallbackToCurrentThread( | 55 RelayCallbackToCurrentThread(FROM_HERE, |
| 56 FROM_HERE, | 56 base::Bind(&CallbackWithPassed, &called)) |
| 57 base::Bind(&CallbackWithPassed, &called)) | 57 .Run(std::unique_ptr<int>(new int)); |
| 58 .Run(scoped_ptr<int>(new int)); | |
| 59 EXPECT_FALSE(called); | 58 EXPECT_FALSE(called); |
| 60 base::RunLoop().RunUntilIdle(); | 59 base::RunLoop().RunUntilIdle(); |
| 61 EXPECT_TRUE(called); | 60 EXPECT_TRUE(called); |
| 62 } | 61 } |
| 63 | 62 |
| 64 TEST(DriveBackendCallbackHelperTest, RunOnOtherThreadTest) { | 63 TEST(DriveBackendCallbackHelperTest, RunOnOtherThreadTest) { |
| 65 base::MessageLoop message_loop; | 64 base::MessageLoop message_loop; |
| 66 base::Thread thread("WorkerThread"); | 65 base::Thread thread("WorkerThread"); |
| 67 thread.Start(); | 66 thread.Start(); |
| 68 | 67 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 92 TEST(DriveBackendCallbackHelperTest, PassNullFunctionTest) { | 91 TEST(DriveBackendCallbackHelperTest, PassNullFunctionTest) { |
| 93 base::MessageLoop message_loop; | 92 base::MessageLoop message_loop; |
| 94 base::Closure closure = RelayCallbackToCurrentThread( | 93 base::Closure closure = RelayCallbackToCurrentThread( |
| 95 FROM_HERE, | 94 FROM_HERE, |
| 96 base::Closure()); | 95 base::Closure()); |
| 97 EXPECT_TRUE(closure.is_null()); | 96 EXPECT_TRUE(closure.is_null()); |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace drive_backend | 99 } // namespace drive_backend |
| 101 } // namespace sync_file_system | 100 } // namespace sync_file_system |
| OLD | NEW |