| Index: media/gpu/android_video_surface_chooser_impl_unittest.cc
|
| diff --git a/media/gpu/android_video_surface_chooser_impl_unittest.cc b/media/gpu/android_video_surface_chooser_impl_unittest.cc
|
| index b30cfbfeadb3986f885512fcdf724dcdd7c23620..58023076b24808a4727fd6434d30980e1713c89d 100644
|
| --- a/media/gpu/android_video_surface_chooser_impl_unittest.cc
|
| +++ b/media/gpu/android_video_surface_chooser_impl_unittest.cc
|
| @@ -11,7 +11,6 @@
|
| #include "base/bind.h"
|
| #include "base/logging.h"
|
| #include "base/memory/ptr_util.h"
|
| -#include "media/base/android/android_overlay_factory.h"
|
| #include "media/base/android/mock_android_overlay.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -25,7 +24,6 @@ using ::testing::StrictMock;
|
|
|
| namespace {
|
| using ::media::AndroidOverlay;
|
| -using ::media::AndroidOverlayFactory;
|
| using ::media::MockAndroidOverlay;
|
|
|
| class MockClient {
|
| @@ -47,47 +45,6 @@ class MockClient {
|
| std::unique_ptr<AndroidOverlay> overlay_;
|
| };
|
|
|
| -// Mock factory which will return one overlay.
|
| -class MockAndroidOverlayFactory : public AndroidOverlayFactory {
|
| - public:
|
| - MockAndroidOverlayFactory()
|
| - : overlay_(base::MakeUnique<MockAndroidOverlay>()),
|
| - weak_this_factory_(this) {}
|
| -
|
| - // Called by CreateOverlay.
|
| - MOCK_METHOD0(MockCreateOverlay, void());
|
| -
|
| - std::unique_ptr<AndroidOverlay> CreateOverlay(
|
| - const AndroidOverlay::Config& config) override {
|
| - MockCreateOverlay();
|
| -
|
| - // Notify the overlay about the config that was used to create it. We
|
| - // can't do this during overlay construction since we might want the
|
| - // overlay to set test expectations.
|
| - if (overlay_)
|
| - overlay_->SetConfig(config);
|
| -
|
| - return std::move(overlay_);
|
| - }
|
| -
|
| - // Return the overlay, if we still own it. One the client creates an
|
| - // overlay, we'll re-assign ownership.
|
| - MockAndroidOverlay* overlay() { return overlay_.get(); }
|
| -
|
| - // Set the overlay that we'll provide next, or nullptr.
|
| - void SetOverlay(std::unique_ptr<MockAndroidOverlay> overlay) {
|
| - overlay_ = std::move(overlay);
|
| - }
|
| -
|
| - base::WeakPtr<MockAndroidOverlayFactory> GetWeakPtr() {
|
| - return weak_this_factory_.GetWeakPtr();
|
| - }
|
| -
|
| - private:
|
| - std::unique_ptr<MockAndroidOverlay> overlay_;
|
| -
|
| - base::WeakPtrFactory<MockAndroidOverlayFactory> weak_this_factory_;
|
| -};
|
| } // namespace
|
|
|
| namespace media {
|
| @@ -99,15 +56,14 @@ class AndroidVideoSurfaceChooserImplTest : public testing::Test {
|
|
|
| void SetUp() override {
|
| chooser_ = base::MakeUnique<AndroidVideoSurfaceChooserImpl>();
|
| - factory_ = base::MakeUnique<NiceMock<MockAndroidOverlayFactory>>();
|
| - factory_weak_ = factory_->GetWeakPtr();
|
| + overlay_ = base::MakeUnique<MockAndroidOverlay>();
|
|
|
| // We create a destruction observer. By default, the overlay must not be
|
| // destroyed until the test completes. Of course, the test may ask the
|
| // observer to expect something else.
|
| - destruction_observer_ = factory_->overlay()->CreateDestructionObserver();
|
| + destruction_observer_ = overlay_->CreateDestructionObserver();
|
| destruction_observer_->DoNotAllowDestruction();
|
| - overlay_callbacks_ = factory_->overlay()->GetCallbacks();
|
| + overlay_callbacks_ = overlay_->GetCallbacks();
|
| }
|
|
|
| void TearDown() override {
|
| @@ -119,7 +75,8 @@ class AndroidVideoSurfaceChooserImplTest : public testing::Test {
|
| destruction_observer_ = nullptr;
|
| }
|
|
|
| - void StartHelper(std::unique_ptr<MockAndroidOverlayFactory> factory) {
|
| + // Start the chooser, providing |factory| as the initial factory.
|
| + void StartChooser(AndroidOverlayFactoryCB factory) {
|
| chooser_->Initialize(
|
| base::Bind(&MockClient::UseOverlayImpl, base::Unretained(&client_)),
|
| base::Bind(&MockClient::UseSurfaceTexture, base::Unretained(&client_)),
|
| @@ -128,10 +85,48 @@ class AndroidVideoSurfaceChooserImplTest : public testing::Test {
|
| std::move(factory));
|
| }
|
|
|
| + // AndroidOverlayFactoryCB is a RepeatingCallback, so we can't just bind
|
| + // something that uses unique_ptr. RepeatingCallback needs to copy it.
|
| + class Factory {
|
| + public:
|
| + Factory(std::unique_ptr<MockAndroidOverlay> overlay,
|
| + base::RepeatingCallback<void()> create_overlay_cb)
|
| + : overlay_(std::move(overlay)),
|
| + create_overlay_cb_(std::move(create_overlay_cb)) {}
|
| +
|
| + // Return whatever overlay we're given. This is used to construct factory
|
| + // callbacks for the chooser.
|
| + std::unique_ptr<AndroidOverlay> ReturnOverlay(AndroidOverlayConfig config) {
|
| + // Notify the mock.
|
| + create_overlay_cb_.Run();
|
| + if (overlay_)
|
| + overlay_->SetConfig(std::move(config));
|
| + return std::move(overlay_);
|
| + }
|
| +
|
| + private:
|
| + std::unique_ptr<MockAndroidOverlay> overlay_;
|
| + base::RepeatingCallback<void()> create_overlay_cb_;
|
| + };
|
| +
|
| + // Create a factory that will return |overlay| when run.
|
| + AndroidOverlayFactoryCB FactoryFor(
|
| + std::unique_ptr<MockAndroidOverlay> overlay) {
|
| + Factory* factory = new Factory(
|
| + std::move(overlay),
|
| + base::Bind(&AndroidVideoSurfaceChooserImplTest::MockOnOverlayCreated,
|
| + base::Unretained(this)));
|
| +
|
| + // Leaky!
|
| + return base::Bind(&Factory::ReturnOverlay, base::Unretained(factory));
|
| + }
|
| +
|
| + // Called by the factory when it's run.
|
| + MOCK_METHOD0(MockOnOverlayCreated, void());
|
| +
|
| std::unique_ptr<AndroidVideoSurfaceChooserImpl> chooser_;
|
| StrictMock<MockClient> client_;
|
| - std::unique_ptr<NiceMock<MockAndroidOverlayFactory>> factory_;
|
| - base::WeakPtr<MockAndroidOverlayFactory> factory_weak_;
|
| + std::unique_ptr<MockAndroidOverlay> overlay_;
|
|
|
| // Callbacks to control the overlay that will be vended by |factory_|
|
| MockAndroidOverlay::Callbacks overlay_callbacks_;
|
| @@ -145,7 +140,7 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| // Calling Initialize() with no factory should result in a callback to use
|
| // surface texture.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - StartHelper(nullptr);
|
| + StartChooser(AndroidOverlayFactoryCB());
|
| }
|
|
|
| TEST_F(AndroidVideoSurfaceChooserImplTest, ProvideInitialOverlaySuccessfully) {
|
| @@ -155,7 +150,7 @@ TEST_F(AndroidVideoSurfaceChooserImplTest, ProvideInitialOverlaySuccessfully) {
|
| // just don't differentiate those cases yet in the impl.
|
|
|
| EXPECT_CALL(client_, UseSurfaceTexture()).Times(0);
|
| - StartHelper(std::move(factory_));
|
| + StartChooser(FactoryFor(std::move(overlay_)));
|
|
|
| // Notify the chooser that the overlay is ready. Expect that |client_| will
|
| // be told to use it.
|
| @@ -173,8 +168,8 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| // Initially, there should be no callback into |client_|, since we haven't
|
| // told |chooser_| that the overlay is ready. It should, however, request the
|
| // overlay from |factory_|.
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| - StartHelper(std::move(factory_));
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| + StartChooser(FactoryFor(std::move(overlay_)));
|
| }
|
|
|
| TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| @@ -182,23 +177,20 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| // If we provide a factory, but it fails to create an overlay, then |client_|
|
| // should be notified to use a surface texture.
|
|
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - // Replacing the overlay with null will destroy it.
|
| - destruction_observer_->ExpectDestruction();
|
| - factory_->SetOverlay(nullptr);
|
| - StartHelper(std::move(factory_));
|
| + StartChooser(FactoryFor(nullptr));
|
| }
|
|
|
| TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| FailedInitialOverlayUsesSurfaceTexture) {
|
| // If we provide a factory, but the overlay that it provides returns 'failed',
|
| // then |client_| should use surface texture.
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| - StartHelper(std::move(factory_));
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| + StartChooser(FactoryFor(std::move(overlay_)));
|
|
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
| - testing::Mock::VerifyAndClearExpectations(factory_weak_.get());
|
| + testing::Mock::VerifyAndClearExpectations(this);
|
|
|
| // The overlay may be destroyed at any time after we send OverlayFailed. It
|
| // doesn't have to be destroyed. We just care that it hasn't been destroyed
|
| @@ -213,17 +205,17 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should
|
| // also be notified.
|
|
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| - StartHelper(std::move(factory_));
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| + StartChooser(FactoryFor(std::move(overlay_)));
|
| EXPECT_CALL(client_, UseOverlay(NotNull()));
|
| overlay_callbacks_.OverlayReady.Run();
|
|
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
| - testing::Mock::VerifyAndClearExpectations(factory_weak_.get());
|
| + testing::Mock::VerifyAndClearExpectations(this);
|
|
|
| // Switch to a surface texture. OnSurfaceDestroyed should still be sent.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - chooser_->ReplaceOverlayFactory(nullptr);
|
| + chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB());
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull()));
|
| @@ -247,17 +239,17 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
| // We test these together, since switching the factory is the only way we have
|
| // to make |chooser_| transition to SurfaceTexture without sending destroyed.
|
|
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| - StartHelper(std::move(factory_));
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| + StartChooser(FactoryFor(std::move(overlay_)));
|
| EXPECT_CALL(client_, UseOverlay(NotNull()));
|
| overlay_callbacks_.OverlayReady.Run();
|
|
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
| - testing::Mock::VerifyAndClearExpectations(factory_weak_.get());
|
| + testing::Mock::VerifyAndClearExpectations(this);
|
|
|
| // Switch factories, to notify the client back to switch to SurfaceTexture.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - chooser_->ReplaceOverlayFactory(nullptr);
|
| + chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB());
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| // Destroy the original surface.
|
| @@ -272,14 +264,13 @@ TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesSurfaceTexture) {
|
|
|
| // Start with SurfaceTexture.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - StartHelper(nullptr);
|
| + StartChooser(AndroidOverlayFactoryCB());
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| // Provide a factory that will return a null overlay.
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber());
|
| - chooser_->ReplaceOverlayFactory(std::move(factory_));
|
| - factory_weak_->SetOverlay(nullptr);
|
| + chooser_->ReplaceOverlayFactory(FactoryFor(nullptr));
|
| }
|
|
|
| TEST_F(AndroidVideoSurfaceChooserImplTest, FailedLaterOverlayDoesNothing) {
|
| @@ -289,13 +280,13 @@ TEST_F(AndroidVideoSurfaceChooserImplTest, FailedLaterOverlayDoesNothing) {
|
|
|
| // Start with SurfaceTexture.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - StartHelper(nullptr);
|
| + StartChooser(AndroidOverlayFactoryCB());
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| // Provide a factory.
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber());
|
| - chooser_->ReplaceOverlayFactory(std::move(factory_));
|
| + chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_)));
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| // Fail the overlay. We don't care if it's destroyed after that, as long as
|
| @@ -310,17 +301,17 @@ TEST_F(AndroidVideoSurfaceChooserImplTest,
|
|
|
| // Start with SurfaceTexture.
|
| EXPECT_CALL(client_, UseSurfaceTexture());
|
| - StartHelper(nullptr);
|
| + StartChooser(AndroidOverlayFactoryCB());
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
|
|
| // Provide a factory. |chooser_| should try to create an overlay. We don't
|
| // care if a call to UseSurfaceTexture is elided or not. Note that AVDA will
|
| // ignore duplicate calls anyway (MultipleSurfaceTextureCallbacksAreIgnored).
|
| - EXPECT_CALL(*factory_, MockCreateOverlay());
|
| + EXPECT_CALL(*this, MockOnOverlayCreated());
|
| EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber());
|
| - chooser_->ReplaceOverlayFactory(std::move(factory_));
|
| + chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_)));
|
| testing::Mock::VerifyAndClearExpectations(&client_);
|
| - testing::Mock::VerifyAndClearExpectations(factory_weak_.get());
|
| + testing::Mock::VerifyAndClearExpectations(this);
|
|
|
| // Notify |chooser_| that the overlay is ready.
|
| EXPECT_CALL(client_, UseOverlay(NotNull()));
|
|
|