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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <list> | 7 #include <list> |
| 8 #include <memory> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" | 17 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" |
18 #include "chromecast/media/cma/base/media_task_runner.h" | 18 #include "chromecast/media/cma/base/media_task_runner.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace chromecast { | 21 namespace chromecast { |
22 namespace media { | 22 namespace media { |
23 | 23 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 void BalancedMediaTaskRunnerTest::OnTestTimeout() { | 203 void BalancedMediaTaskRunnerTest::OnTestTimeout() { |
204 ADD_FAILURE() << "Test timed out"; | 204 ADD_FAILURE() << "Test timed out"; |
205 if (base::MessageLoop::current()) | 205 if (base::MessageLoop::current()) |
206 base::MessageLoop::current()->QuitWhenIdle(); | 206 base::MessageLoop::current()->QuitWhenIdle(); |
207 } | 207 } |
208 | 208 |
209 TEST_F(BalancedMediaTaskRunnerTest, OneTaskRunner) { | 209 TEST_F(BalancedMediaTaskRunnerTest, OneTaskRunner) { |
210 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); | 210 std::unique_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); |
211 | 211 |
212 // Timestamps of tasks for the single task runner. | 212 // Timestamps of tasks for the single task runner. |
213 int timestamps0_ms[] = {0, 10, 20, 30, 40, 30, 50, 60, 20, 30, 70}; | 213 int timestamps0_ms[] = {0, 10, 20, 30, 40, 30, 50, 60, 20, 30, 70}; |
214 std::vector<std::vector<int> > timestamps_ms(1); | 214 std::vector<std::vector<int> > timestamps_ms(1); |
215 timestamps_ms[0] = std::vector<int>( | 215 timestamps_ms[0] = std::vector<int>( |
216 timestamps0_ms, timestamps0_ms + arraysize(timestamps0_ms)); | 216 timestamps0_ms, timestamps0_ms + arraysize(timestamps0_ms)); |
217 | 217 |
218 // Scheduling pattern. | 218 // Scheduling pattern. |
219 std::vector<size_t> scheduling_pattern(1); | 219 std::vector<size_t> scheduling_pattern(1); |
220 scheduling_pattern[0] = 0; | 220 scheduling_pattern[0] = 0; |
221 | 221 |
222 // Expected results. | 222 // Expected results. |
223 int expected_timestamps[] = {0, 10, 20, 30, 40, 50, 60, 70}; | 223 int expected_timestamps[] = {0, 10, 20, 30, 40, 50, 60, 70}; |
224 std::vector<int> expected_timestamps_ms(std::vector<int>( | 224 std::vector<int> expected_timestamps_ms(std::vector<int>( |
225 expected_timestamps, | 225 expected_timestamps, |
226 expected_timestamps + arraysize(expected_timestamps))); | 226 expected_timestamps + arraysize(expected_timestamps))); |
227 | 227 |
228 SetupTest(base::TimeDelta::FromMilliseconds(30), | 228 SetupTest(base::TimeDelta::FromMilliseconds(30), |
229 timestamps_ms, | 229 timestamps_ms, |
230 scheduling_pattern, | 230 scheduling_pattern, |
231 expected_timestamps_ms); | 231 expected_timestamps_ms); |
232 ProcessAllTasks(); | 232 ProcessAllTasks(); |
233 message_loop->Run(); | 233 message_loop->Run(); |
234 EXPECT_TRUE(expected_task_timestamps_.empty()); | 234 EXPECT_TRUE(expected_task_timestamps_.empty()); |
235 } | 235 } |
236 | 236 |
237 TEST_F(BalancedMediaTaskRunnerTest, TwoTaskRunnerUnbalanced) { | 237 TEST_F(BalancedMediaTaskRunnerTest, TwoTaskRunnerUnbalanced) { |
238 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); | 238 std::unique_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); |
239 | 239 |
240 // Timestamps of tasks for the 2 task runners. | 240 // Timestamps of tasks for the 2 task runners. |
241 int timestamps0_ms[] = {0, 10, 20, 30, 40, 30, 50, 60, 20, 30, 70}; | 241 int timestamps0_ms[] = {0, 10, 20, 30, 40, 30, 50, 60, 20, 30, 70}; |
242 int timestamps1_ms[] = {5, 15, 25, 35, 45, 35, 55, 65, 25, 35, 75}; | 242 int timestamps1_ms[] = {5, 15, 25, 35, 45, 35, 55, 65, 25, 35, 75}; |
243 std::vector<std::vector<int> > timestamps_ms(2); | 243 std::vector<std::vector<int> > timestamps_ms(2); |
244 timestamps_ms[0] = std::vector<int>( | 244 timestamps_ms[0] = std::vector<int>( |
245 timestamps0_ms, timestamps0_ms + arraysize(timestamps0_ms)); | 245 timestamps0_ms, timestamps0_ms + arraysize(timestamps0_ms)); |
246 timestamps_ms[1] = std::vector<int>( | 246 timestamps_ms[1] = std::vector<int>( |
247 timestamps1_ms, timestamps1_ms + arraysize(timestamps1_ms)); | 247 timestamps1_ms, timestamps1_ms + arraysize(timestamps1_ms)); |
248 | 248 |
(...skipping 12 matching lines...) Expand all Loading... |
261 SetupTest(base::TimeDelta::FromMilliseconds(30), | 261 SetupTest(base::TimeDelta::FromMilliseconds(30), |
262 timestamps_ms, | 262 timestamps_ms, |
263 scheduling_pattern, | 263 scheduling_pattern, |
264 expected_timestamps_ms); | 264 expected_timestamps_ms); |
265 ProcessAllTasks(); | 265 ProcessAllTasks(); |
266 message_loop->Run(); | 266 message_loop->Run(); |
267 EXPECT_TRUE(expected_task_timestamps_.empty()); | 267 EXPECT_TRUE(expected_task_timestamps_.empty()); |
268 } | 268 } |
269 | 269 |
270 TEST_F(BalancedMediaTaskRunnerTest, TwoStreamsOfDifferentLength) { | 270 TEST_F(BalancedMediaTaskRunnerTest, TwoStreamsOfDifferentLength) { |
271 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); | 271 std::unique_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); |
272 | 272 |
273 std::vector<std::vector<int>> timestamps = { | 273 std::vector<std::vector<int>> timestamps = { |
274 // One longer stream and one shorter stream. | 274 // One longer stream and one shorter stream. |
275 // The longer stream runs first, then the shorter stream begins. | 275 // The longer stream runs first, then the shorter stream begins. |
276 // After shorter stream ends, it shouldn't block the longer one. | 276 // After shorter stream ends, it shouldn't block the longer one. |
277 {0, 20, 40, 60, 80, 100, 120, 140, 160}, | 277 {0, 20, 40, 60, 80, 100, 120, 140, 160}, |
278 {51, 61, 71, 81}, | 278 {51, 61, 71, 81}, |
279 }; | 279 }; |
280 | 280 |
281 std::vector<int> expected_timestamps = { | 281 std::vector<int> expected_timestamps = { |
282 0, 20, 40, 60, 51, 80, 61, 71, 81, 100, 120, 140, 160}; | 282 0, 20, 40, 60, 51, 80, 61, 71, 81, 100, 120, 140, 160}; |
283 | 283 |
284 std::vector<size_t> scheduling_pattern = { | 284 std::vector<size_t> scheduling_pattern = { |
285 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0}; | 285 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0}; |
286 | 286 |
287 SetupTest(base::TimeDelta::FromMilliseconds(30), timestamps, | 287 SetupTest(base::TimeDelta::FromMilliseconds(30), timestamps, |
288 scheduling_pattern, expected_timestamps); | 288 scheduling_pattern, expected_timestamps); |
289 ProcessAllTasks(); | 289 ProcessAllTasks(); |
290 message_loop->Run(); | 290 message_loop->Run(); |
291 EXPECT_TRUE(expected_task_timestamps_.empty()); | 291 EXPECT_TRUE(expected_task_timestamps_.empty()); |
292 } | 292 } |
293 | 293 |
294 } // namespace media | 294 } // namespace media |
295 } // namespace chromecast | 295 } // namespace chromecast |
OLD | NEW |