Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: media/base/android/media_codec_loop_unittest.cc

Issue 2491613004: Make base::Timer sequence-friendly. (Closed)
Patch Set: add back commented out DCHECK in Stop() Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/android/media_codec_loop.cc ('k') | media/filters/android/media_codec_audio_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/media_codec_loop_unittest.cc
diff --git a/media/base/android/media_codec_loop_unittest.cc b/media/base/android/media_codec_loop_unittest.cc
index 8396e3b6acfb1af7107740e6d6b8b0f8109e3e5e..5c034e486b79600ca3801be9703796134090407b 100644
--- a/media/base/android/media_codec_loop_unittest.cc
+++ b/media/base/android/media_codec_loop_unittest.cc
@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/base/android/media_codec_loop.h"
+
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
+#include "base/test/test_mock_time_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "media/base/android/media_codec_bridge.h"
-#include "media/base/android/media_codec_loop.h"
#include "media/base/android/mock_media_codec_bridge.h"
-#include "media/base/fake_single_thread_task_runner.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -46,8 +48,8 @@ class MockMediaCodecLoopClient : public StrictMock<MediaCodecLoop::Client> {
class MediaCodecLoopTest : public testing::Test {
public:
MediaCodecLoopTest()
- : client_(new StrictMock<MockMediaCodecLoopClient>()),
- task_runner_(new FakeSingleThreadTaskRunner(&clock_)) {}
+ : task_runner_handle_(mock_task_runner_),
+ client_(new StrictMock<MockMediaCodecLoopClient>()) {}
~MediaCodecLoopTest() override {}
@@ -84,7 +86,7 @@ class MediaCodecLoopTest : public testing::Test {
// TODO(liberato): assume that MCL doesn't retry for 30 seconds. Note
// that this doesn't actually wall-clock wait.
- task_runner_->Sleep(base::TimeDelta::FromSeconds(30));
+ mock_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(30));
}
void ConstructCodecLoop(int sdk_int = kLollipop) {
@@ -92,8 +94,8 @@ class MediaCodecLoopTest : public testing::Test {
// Since we're providing a codec, we do not expect an error.
EXPECT_CALL(*client_, OnCodecLoopError()).Times(0);
codec_loop_.reset(new MediaCodecLoop(sdk_int, client_.get(),
- std::move(codec), task_runner_));
- codec_loop_->SetTestTickClock(&clock_);
+ std::move(codec), mock_task_runner_));
+ codec_loop_->SetTestTickClock(clock_.get());
Mock::VerifyAndClearExpectations(client_.get());
}
@@ -182,12 +184,18 @@ class MediaCodecLoopTest : public testing::Test {
}
public:
+ // Mocks the current thread's task runner which will also be used as the
+ // MediaCodecLoop's task runner.
+ scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_ =
+ new base::TestMockTimeTaskRunner;
+ base::ThreadTaskRunnerHandle task_runner_handle_;
+
+ // A reference to |mock_task_runner_|'s TickClock handed to |codec_loop_|.
+ std::unique_ptr<base::TickClock> clock_ =
+ mock_task_runner_->GetMockTickClock();
+
std::unique_ptr<MediaCodecLoop> codec_loop_;
std::unique_ptr<MockMediaCodecLoopClient> client_;
- // TODO: how is the lifecycle of |clock_| handled? |task_runner_| can outlive
- // us, since it's a refptr.
- base::SimpleTestTickClock clock_;
- scoped_refptr<FakeSingleThreadTaskRunner> task_runner_;
DISALLOW_COPY_AND_ASSIGN(MediaCodecLoopTest);
};
@@ -197,7 +205,8 @@ TEST_F(MediaCodecLoopTest, TestConstructionWithNullCodec) {
EXPECT_CALL(*client_, OnCodecLoopError()).Times(1);
const int sdk_int = kLollipop;
codec_loop_.reset(
- new MediaCodecLoop(sdk_int, client_.get(), std::move(codec)));
+ new MediaCodecLoop(sdk_int, client_.get(), std::move(codec),
+ scoped_refptr<base::SingleThreadTaskRunner>()));
// Do not WaitUntilIdle() here, since that assumes that we have a codec.
ASSERT_FALSE(codec_loop_->GetCodec());
« no previous file with comments | « media/base/android/media_codec_loop.cc ('k') | media/filters/android/media_codec_audio_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698