| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 12 #include "media/base/pipeline_status.h" | 14 #include "media/base/pipeline_status.h" |
| 13 #include "media/base/serial_runner.h" | 15 #include "media/base/serial_runner.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace media { | 18 namespace media { |
| 17 | 19 |
| 18 class SerialRunnerTest : public ::testing::Test { | 20 class SerialRunnerTest : public ::testing::Test { |
| 19 public: | 21 public: |
| 20 SerialRunnerTest() | 22 SerialRunnerTest() |
| 21 : inside_start_(false), done_called_(false), done_status_(PIPELINE_OK) {} | 23 : inside_start_(false), done_called_(false), done_status_(PIPELINE_OK) {} |
| 22 ~SerialRunnerTest() override {} | 24 ~SerialRunnerTest() override {} |
| 23 | 25 |
| 24 void RunSerialRunner() { | 26 void RunSerialRunner() { |
| 25 message_loop_.PostTask(FROM_HERE, base::Bind( | 27 message_loop_.task_runner()->PostTask( |
| 26 &SerialRunnerTest::StartRunnerInternal, base::Unretained(this), | 28 FROM_HERE, base::Bind(&SerialRunnerTest::StartRunnerInternal, |
| 27 bound_fns_)); | 29 base::Unretained(this), bound_fns_)); |
| 28 message_loop_.RunUntilIdle(); | 30 base::RunLoop().RunUntilIdle(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 // Pushes a bound function to the queue that will run its callback with | 33 // Pushes a bound function to the queue that will run its callback with |
| 32 // |status|. called(i) returns whether the i'th bound function pushed to the | 34 // |status|. called(i) returns whether the i'th bound function pushed to the |
| 33 // queue was called while running the SerialRunner. | 35 // queue was called while running the SerialRunner. |
| 34 void PushBoundFunction(PipelineStatus status) { | 36 void PushBoundFunction(PipelineStatus status) { |
| 35 bound_fns_.Push(base::Bind(&SerialRunnerTest::RunBoundFunction, | 37 bound_fns_.Push(base::Bind(&SerialRunnerTest::RunBoundFunction, |
| 36 base::Unretained(this), | 38 base::Unretained(this), |
| 37 status, | 39 status, |
| 38 called_.size())); | 40 called_.size())); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 << "Done callback should not run on same stack as SerialRunner::Run()\n" | 113 << "Done callback should not run on same stack as SerialRunner::Run()\n" |
| 112 << base::debug::StackTrace().ToString(); | 114 << base::debug::StackTrace().ToString(); |
| 113 | 115 |
| 114 done_called_ = true; | 116 done_called_ = true; |
| 115 done_status_ = status; | 117 done_status_ = status; |
| 116 message_loop_.QuitWhenIdle(); | 118 message_loop_.QuitWhenIdle(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 void CancelSerialRunner(const PipelineStatusCB& status_cb) { | 121 void CancelSerialRunner(const PipelineStatusCB& status_cb) { |
| 120 // Tasks run by |runner_| shouldn't reset it, hence we post a task to do so. | 122 // Tasks run by |runner_| shouldn't reset it, hence we post a task to do so. |
| 121 message_loop_.PostTask(FROM_HERE, base::Bind( | 123 message_loop_.task_runner()->PostTask( |
| 122 &SerialRunnerTest::ResetSerialRunner, base::Unretained(this))); | 124 FROM_HERE, base::Bind(&SerialRunnerTest::ResetSerialRunner, |
| 125 base::Unretained(this))); |
| 123 status_cb.Run(PIPELINE_OK); | 126 status_cb.Run(PIPELINE_OK); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void ResetSerialRunner() { | 129 void ResetSerialRunner() { |
| 127 runner_.reset(); | 130 runner_.reset(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 base::MessageLoop message_loop_; | 133 base::MessageLoop message_loop_; |
| 131 SerialRunner::Queue bound_fns_; | 134 SerialRunner::Queue bound_fns_; |
| 132 std::unique_ptr<SerialRunner> runner_; | 135 std::unique_ptr<SerialRunner> runner_; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 TEST_F(SerialRunnerTest, Closure) { | 226 TEST_F(SerialRunnerTest, Closure) { |
| 224 PushClosure(); | 227 PushClosure(); |
| 225 RunSerialRunner(); | 228 RunSerialRunner(); |
| 226 | 229 |
| 227 EXPECT_TRUE(called(0)); | 230 EXPECT_TRUE(called(0)); |
| 228 EXPECT_TRUE(done_called()); | 231 EXPECT_TRUE(done_called()); |
| 229 EXPECT_EQ(PIPELINE_OK, done_status()); | 232 EXPECT_EQ(PIPELINE_OK, done_status()); |
| 230 } | 233 } |
| 231 | 234 |
| 232 } // namespace media | 235 } // namespace media |
| OLD | NEW |