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

Unified Diff: media/filters/pipeline_controller_unittest.cc

Issue 1641423002: Re-land extract state management from WebMediaPlayerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More unit tests. Created 4 years, 10 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
Index: media/filters/pipeline_controller_unittest.cc
diff --git a/media/filters/pipeline_controller_unittest.cc b/media/filters/pipeline_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d522ac8742b6f767576b6584c189b636621b0f34
--- /dev/null
+++ b/media/filters/pipeline_controller_unittest.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
DaleCurtis 2016/02/25 01:58:30 No (c) these days.
sandersd (OOO until July 31) 2016/02/25 20:33:46 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "media/base/mock_filters.h"
+#include "media/base/pipeline.h"
+#include "media/filters/pipeline_controller.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
DaleCurtis 2016/02/25 01:58:30 We generally elide the first ::
sandersd (OOO until July 31) 2016/02/25 20:33:46 That seems to be just you. (And separately I have
DaleCurtis 2016/02/26 02:59:34 3652 hits https://code.google.com/p/chromium/codes
sandersd (OOO until July 31) 2016/02/26 22:10:48 https://code.google.com/p/chromium/codesearch#sear
+using ::testing::DoAll;
+using ::testing::Mock;
+using ::testing::Return;
+using ::testing::SaveArg;
+using ::testing::StrictMock;
+
+namespace media {
+
+class PipelineControllerTest : public ::testing::Test {
+ public:
+ PipelineControllerTest()
+ : pipeline_controller_(&pipeline_,
+ base::Bind(&PipelineControllerTest::CreateRenderer,
+ base::Unretained(this)),
+ base::Bind(&PipelineControllerTest::OnSeeked,
+ base::Unretained(this)),
+ base::Bind(&PipelineControllerTest::OnSuspended,
+ base::Unretained(this)),
+ base::Bind(&PipelineControllerTest::OnError,
+ base::Unretained(this))) {}
+
+ ~PipelineControllerTest() override {}
+
+ PipelineStatusCB StartPipeline() {
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ PipelineStatusCB start_cb;
+ EXPECT_CALL(pipeline_, Start(_, _, _, _, _, _, _, _, _, _))
+ .WillOnce(SaveArg<4>(&start_cb));
+ pipeline_controller_.Start(
+ nullptr, nullptr, false, base::Closure(), PipelineMetadataCB(),
+ BufferingStateCB(), base::Closure(), AddTextTrackCB(), base::Closure());
+ Mock::VerifyAndClear(&pipeline_);
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ return start_cb;
+ }
+
+ PipelineStatusCB SeekPipeline(base::TimeDelta time) {
+ EXPECT_TRUE(pipeline_controller_.IsStable());
+ PipelineStatusCB seek_cb;
+ EXPECT_CALL(pipeline_, Seek(time, _)).WillOnce(SaveArg<1>(&seek_cb));
+ pipeline_controller_.Seek(time, true);
+ Mock::VerifyAndClear(&pipeline_);
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ return seek_cb;
+ }
+
+ PipelineStatusCB SuspendPipeline() {
+ EXPECT_TRUE(pipeline_controller_.IsStable());
+ PipelineStatusCB suspend_cb;
+ EXPECT_CALL(pipeline_, Suspend(_)).WillOnce(SaveArg<0>(&suspend_cb));
+ pipeline_controller_.Suspend();
+ Mock::VerifyAndClear(&pipeline_);
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ EXPECT_FALSE(pipeline_controller_.IsSuspended());
+ return suspend_cb;
+ }
+
+ PipelineStatusCB ResumePipeline() {
+ EXPECT_TRUE(pipeline_controller_.IsSuspended());
+ PipelineStatusCB resume_cb;
+ EXPECT_CALL(pipeline_, Resume(_, _, _))
+ .WillOnce(
+ DoAll(SaveArg<1>(&last_resume_time_), SaveArg<2>(&resume_cb)));
+ EXPECT_CALL(pipeline_, GetMediaTime())
+ .WillRepeatedly(Return(base::TimeDelta()));
+ pipeline_controller_.Resume();
+ Mock::VerifyAndClear(&pipeline_);
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ EXPECT_FALSE(pipeline_controller_.IsSuspended());
+ return resume_cb;
+ }
+
+ protected:
+ scoped_ptr<Renderer> CreateRenderer() { return scoped_ptr<Renderer>(); }
+
+ void OnSeeked(bool time_updated) {}
DaleCurtis 2016/02/25 01:58:30 Seems you might want to verify these two?
sandersd (OOO until July 31) 2016/02/25 20:33:46 Done.
+
+ void OnSuspended() {}
+
+ void OnError(PipelineStatus status) { NOTREACHED(); }
+
+ StrictMock<MockPipeline> pipeline_;
+ PipelineController pipeline_controller_;
+ base::TimeDelta last_resume_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest);
+};
+
+TEST_F(PipelineControllerTest, SuspendResume) {
+ StartPipeline().Run(PIPELINE_OK);
+ SuspendPipeline().Run(PIPELINE_OK);
+ EXPECT_FALSE(pipeline_controller_.IsStable());
+ ResumePipeline().Run(PIPELINE_OK);
+ EXPECT_TRUE(pipeline_controller_.IsStable());
+}
+
+TEST_F(PipelineControllerTest, PendingSuspend) {
+ StartPipeline().Run(PIPELINE_OK);
+
+ // Start a seek, but do not complete it yet.
+ base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
+ PipelineStatusCB seek_cb = SeekPipeline(seek_time);
+
+ // Request a suspend. It will be a mock failure it happens immediately.
+ pipeline_controller_.Suspend();
+
+ // Expect the suspend to trigger when the seek is completed.
+ EXPECT_CALL(pipeline_, Suspend(_));
+ seek_cb.Run(PIPELINE_OK);
+}
+
+TEST_F(PipelineControllerTest, SeekMergesWithResume) {
+ StartPipeline().Run(PIPELINE_OK);
+ SuspendPipeline().Run(PIPELINE_OK);
+
+ // Request a seek. It will be a mock failure it happens.
+ base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
+ pipeline_controller_.Seek(seek_time, true);
+
+ // Resume and verify the resume time.
+ ResumePipeline().Run(PIPELINE_OK);
+ EXPECT_EQ(seek_time, last_resume_time_);
+}
+
+TEST_F(PipelineControllerTest, SeekMergesWithSeek) {
+ StartPipeline().Run(PIPELINE_OK);
+
+ // Start a seek, but do not complete it yet.
+ base::TimeDelta seek_time_1 = base::TimeDelta::FromSeconds(5);
+ PipelineStatusCB seek_cb_1 = SeekPipeline(seek_time_1);
+
+ // Request another seek. It will be a mock failure it happens.
+ base::TimeDelta seek_time_2 = base::TimeDelta::FromSeconds(10);
+ pipeline_controller_.Seek(seek_time_2, true);
+
+ // Request a third seek. (It should replace the second.)
+ base::TimeDelta seek_time_3 = base::TimeDelta::FromSeconds(15);
+ pipeline_controller_.Seek(seek_time_3, true);
+
+ // Expect that the third seek triggers when the first seek completes.
+ EXPECT_CALL(pipeline_, Seek(seek_time_3, _));
+ seek_cb_1.Run(PIPELINE_OK);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698