| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "media/gpu/android_video_surface_chooser_impl.h" | 5 #include "media/gpu/android_video_surface_chooser_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "media/base/android/android_overlay_factory.h" | |
| 15 #include "media/base/android/mock_android_overlay.h" | 14 #include "media/base/android/mock_android_overlay.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 using ::testing::_; | 18 using ::testing::_; |
| 20 using ::testing::AnyNumber; | 19 using ::testing::AnyNumber; |
| 21 using ::testing::NiceMock; | 20 using ::testing::NiceMock; |
| 22 using ::testing::NotNull; | 21 using ::testing::NotNull; |
| 23 using ::testing::Return; | 22 using ::testing::Return; |
| 24 using ::testing::StrictMock; | 23 using ::testing::StrictMock; |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 using ::media::AndroidOverlay; | 26 using ::media::AndroidOverlay; |
| 28 using ::media::AndroidOverlayFactory; | |
| 29 using ::media::MockAndroidOverlay; | 27 using ::media::MockAndroidOverlay; |
| 30 | 28 |
| 31 class MockClient { | 29 class MockClient { |
| 32 public: | 30 public: |
| 33 MOCK_METHOD1(UseOverlay, void(AndroidOverlay*)); | 31 MOCK_METHOD1(UseOverlay, void(AndroidOverlay*)); |
| 34 | 32 |
| 35 void UseOverlayImpl(std::unique_ptr<AndroidOverlay> overlay) { | 33 void UseOverlayImpl(std::unique_ptr<AndroidOverlay> overlay) { |
| 36 UseOverlay(overlay.get()); | 34 UseOverlay(overlay.get()); |
| 37 | 35 |
| 38 // Also take ownership of the overlay, so that it's not destroyed. | 36 // Also take ownership of the overlay, so that it's not destroyed. |
| 39 overlay_ = std::move(overlay); | 37 overlay_ = std::move(overlay); |
| 40 } | 38 } |
| 41 | 39 |
| 42 // Note that this won't clear |overlay_|, which is helpful. | 40 // Note that this won't clear |overlay_|, which is helpful. |
| 43 MOCK_METHOD0(UseSurfaceTexture, void(void)); | 41 MOCK_METHOD0(UseSurfaceTexture, void(void)); |
| 44 MOCK_METHOD1(StopUsingOverlayImmediately, void(AndroidOverlay*)); | 42 MOCK_METHOD1(StopUsingOverlayImmediately, void(AndroidOverlay*)); |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 std::unique_ptr<AndroidOverlay> overlay_; | 45 std::unique_ptr<AndroidOverlay> overlay_; |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 // Mock factory which will return one overlay. | |
| 51 class MockAndroidOverlayFactory : public AndroidOverlayFactory { | |
| 52 public: | |
| 53 MockAndroidOverlayFactory() | |
| 54 : overlay_(base::MakeUnique<MockAndroidOverlay>()), | |
| 55 weak_this_factory_(this) {} | |
| 56 | |
| 57 // Called by CreateOverlay. | |
| 58 MOCK_METHOD0(MockCreateOverlay, void()); | |
| 59 | |
| 60 std::unique_ptr<AndroidOverlay> CreateOverlay( | |
| 61 const AndroidOverlay::Config& config) override { | |
| 62 MockCreateOverlay(); | |
| 63 | |
| 64 // Notify the overlay about the config that was used to create it. We | |
| 65 // can't do this during overlay construction since we might want the | |
| 66 // overlay to set test expectations. | |
| 67 if (overlay_) | |
| 68 overlay_->SetConfig(config); | |
| 69 | |
| 70 return std::move(overlay_); | |
| 71 } | |
| 72 | |
| 73 // Return the overlay, if we still own it. One the client creates an | |
| 74 // overlay, we'll re-assign ownership. | |
| 75 MockAndroidOverlay* overlay() { return overlay_.get(); } | |
| 76 | |
| 77 // Set the overlay that we'll provide next, or nullptr. | |
| 78 void SetOverlay(std::unique_ptr<MockAndroidOverlay> overlay) { | |
| 79 overlay_ = std::move(overlay); | |
| 80 } | |
| 81 | |
| 82 base::WeakPtr<MockAndroidOverlayFactory> GetWeakPtr() { | |
| 83 return weak_this_factory_.GetWeakPtr(); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 std::unique_ptr<MockAndroidOverlay> overlay_; | |
| 88 | |
| 89 base::WeakPtrFactory<MockAndroidOverlayFactory> weak_this_factory_; | |
| 90 }; | |
| 91 } // namespace | 48 } // namespace |
| 92 | 49 |
| 93 namespace media { | 50 namespace media { |
| 94 | 51 |
| 95 // Unit tests for AndroidVideoSurfaceChooserImpl | 52 // Unit tests for AndroidVideoSurfaceChooserImpl |
| 96 class AndroidVideoSurfaceChooserImplTest : public testing::Test { | 53 class AndroidVideoSurfaceChooserImplTest : public testing::Test { |
| 97 public: | 54 public: |
| 98 ~AndroidVideoSurfaceChooserImplTest() override {} | 55 ~AndroidVideoSurfaceChooserImplTest() override {} |
| 99 | 56 |
| 100 void SetUp() override { | 57 void SetUp() override { |
| 101 chooser_ = base::MakeUnique<AndroidVideoSurfaceChooserImpl>(); | 58 chooser_ = base::MakeUnique<AndroidVideoSurfaceChooserImpl>(); |
| 102 factory_ = base::MakeUnique<NiceMock<MockAndroidOverlayFactory>>(); | 59 overlay_ = base::MakeUnique<MockAndroidOverlay>(); |
| 103 factory_weak_ = factory_->GetWeakPtr(); | |
| 104 | 60 |
| 105 // We create a destruction observer. By default, the overlay must not be | 61 // We create a destruction observer. By default, the overlay must not be |
| 106 // destroyed until the test completes. Of course, the test may ask the | 62 // destroyed until the test completes. Of course, the test may ask the |
| 107 // observer to expect something else. | 63 // observer to expect something else. |
| 108 destruction_observer_ = factory_->overlay()->CreateDestructionObserver(); | 64 destruction_observer_ = overlay_->CreateDestructionObserver(); |
| 109 destruction_observer_->DoNotAllowDestruction(); | 65 destruction_observer_->DoNotAllowDestruction(); |
| 110 overlay_callbacks_ = factory_->overlay()->GetCallbacks(); | 66 overlay_callbacks_ = overlay_->GetCallbacks(); |
| 111 } | 67 } |
| 112 | 68 |
| 113 void TearDown() override { | 69 void TearDown() override { |
| 114 // If we get this far, the assume that whatever |destruction_observer_| | 70 // If we get this far, the assume that whatever |destruction_observer_| |
| 115 // was looking for should have already happened. We don't want the | 71 // was looking for should have already happened. We don't want the |
| 116 // lifetime of the observer to matter with respect to the overlay when | 72 // lifetime of the observer to matter with respect to the overlay when |
| 117 // checking expectations. | 73 // checking expectations. |
| 118 // Note that it might already be null. | 74 // Note that it might already be null. |
| 119 destruction_observer_ = nullptr; | 75 destruction_observer_ = nullptr; |
| 120 } | 76 } |
| 121 | 77 |
| 122 void StartHelper(std::unique_ptr<MockAndroidOverlayFactory> factory) { | 78 // Start the chooser, providing |factory| as the initial factory. |
| 79 void StartChooser(AndroidOverlayFactoryCB factory) { |
| 123 chooser_->Initialize( | 80 chooser_->Initialize( |
| 124 base::Bind(&MockClient::UseOverlayImpl, base::Unretained(&client_)), | 81 base::Bind(&MockClient::UseOverlayImpl, base::Unretained(&client_)), |
| 125 base::Bind(&MockClient::UseSurfaceTexture, base::Unretained(&client_)), | 82 base::Bind(&MockClient::UseSurfaceTexture, base::Unretained(&client_)), |
| 126 base::Bind(&MockClient::StopUsingOverlayImmediately, | 83 base::Bind(&MockClient::StopUsingOverlayImmediately, |
| 127 base::Unretained(&client_)), | 84 base::Unretained(&client_)), |
| 128 std::move(factory)); | 85 std::move(factory)); |
| 129 } | 86 } |
| 130 | 87 |
| 88 // AndroidOverlayFactoryCB is a RepeatingCallback, so we can't just bind |
| 89 // something that uses unique_ptr. RepeatingCallback needs to copy it. |
| 90 class Factory { |
| 91 public: |
| 92 Factory(std::unique_ptr<MockAndroidOverlay> overlay, |
| 93 base::RepeatingCallback<void()> create_overlay_cb) |
| 94 : overlay_(std::move(overlay)), |
| 95 create_overlay_cb_(std::move(create_overlay_cb)) {} |
| 96 |
| 97 // Return whatever overlay we're given. This is used to construct factory |
| 98 // callbacks for the chooser. |
| 99 std::unique_ptr<AndroidOverlay> ReturnOverlay(AndroidOverlayConfig config) { |
| 100 // Notify the mock. |
| 101 create_overlay_cb_.Run(); |
| 102 if (overlay_) |
| 103 overlay_->SetConfig(std::move(config)); |
| 104 return std::move(overlay_); |
| 105 } |
| 106 |
| 107 private: |
| 108 std::unique_ptr<MockAndroidOverlay> overlay_; |
| 109 base::RepeatingCallback<void()> create_overlay_cb_; |
| 110 }; |
| 111 |
| 112 // Create a factory that will return |overlay| when run. |
| 113 AndroidOverlayFactoryCB FactoryFor( |
| 114 std::unique_ptr<MockAndroidOverlay> overlay) { |
| 115 Factory* factory = new Factory( |
| 116 std::move(overlay), |
| 117 base::Bind(&AndroidVideoSurfaceChooserImplTest::MockOnOverlayCreated, |
| 118 base::Unretained(this))); |
| 119 |
| 120 // Leaky! |
| 121 return base::Bind(&Factory::ReturnOverlay, base::Unretained(factory)); |
| 122 } |
| 123 |
| 124 // Called by the factory when it's run. |
| 125 MOCK_METHOD0(MockOnOverlayCreated, void()); |
| 126 |
| 131 std::unique_ptr<AndroidVideoSurfaceChooserImpl> chooser_; | 127 std::unique_ptr<AndroidVideoSurfaceChooserImpl> chooser_; |
| 132 StrictMock<MockClient> client_; | 128 StrictMock<MockClient> client_; |
| 133 std::unique_ptr<NiceMock<MockAndroidOverlayFactory>> factory_; | 129 std::unique_ptr<MockAndroidOverlay> overlay_; |
| 134 base::WeakPtr<MockAndroidOverlayFactory> factory_weak_; | |
| 135 | 130 |
| 136 // Callbacks to control the overlay that will be vended by |factory_| | 131 // Callbacks to control the overlay that will be vended by |factory_| |
| 137 MockAndroidOverlay::Callbacks overlay_callbacks_; | 132 MockAndroidOverlay::Callbacks overlay_callbacks_; |
| 138 | 133 |
| 139 std::unique_ptr<MockAndroidOverlay::DestructionObserver> | 134 std::unique_ptr<MockAndroidOverlay::DestructionObserver> |
| 140 destruction_observer_; | 135 destruction_observer_; |
| 141 }; | 136 }; |
| 142 | 137 |
| 143 TEST_F(AndroidVideoSurfaceChooserImplTest, | 138 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 144 InitializeWithoutFactoryUsesSurfaceTexture) { | 139 InitializeWithoutFactoryUsesSurfaceTexture) { |
| 145 // Calling Initialize() with no factory should result in a callback to use | 140 // Calling Initialize() with no factory should result in a callback to use |
| 146 // surface texture. | 141 // surface texture. |
| 147 EXPECT_CALL(client_, UseSurfaceTexture()); | 142 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 148 StartHelper(nullptr); | 143 StartChooser(AndroidOverlayFactoryCB()); |
| 149 } | 144 } |
| 150 | 145 |
| 151 TEST_F(AndroidVideoSurfaceChooserImplTest, ProvideInitialOverlaySuccessfully) { | 146 TEST_F(AndroidVideoSurfaceChooserImplTest, ProvideInitialOverlaySuccessfully) { |
| 152 // Providing a factory at startup should result in a switch to overlay. It | 147 // Providing a factory at startup should result in a switch to overlay. It |
| 153 // should not switch to SurfaceTexture initially, since pre-M requires it. | 148 // should not switch to SurfaceTexture initially, since pre-M requires it. |
| 154 // Note that post-M (especially DS), it might be fine to start with ST. We | 149 // Note that post-M (especially DS), it might be fine to start with ST. We |
| 155 // just don't differentiate those cases yet in the impl. | 150 // just don't differentiate those cases yet in the impl. |
| 156 | 151 |
| 157 EXPECT_CALL(client_, UseSurfaceTexture()).Times(0); | 152 EXPECT_CALL(client_, UseSurfaceTexture()).Times(0); |
| 158 StartHelper(std::move(factory_)); | 153 StartChooser(FactoryFor(std::move(overlay_))); |
| 159 | 154 |
| 160 // Notify the chooser that the overlay is ready. Expect that |client_| will | 155 // Notify the chooser that the overlay is ready. Expect that |client_| will |
| 161 // be told to use it. | 156 // be told to use it. |
| 162 EXPECT_CALL(client_, UseOverlay(NotNull())); | 157 EXPECT_CALL(client_, UseOverlay(NotNull())); |
| 163 overlay_callbacks_.OverlayReady.Run(); | 158 overlay_callbacks_.OverlayReady.Run(); |
| 164 } | 159 } |
| 165 | 160 |
| 166 TEST_F(AndroidVideoSurfaceChooserImplTest, | 161 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 167 InitializingWithFactoryCreatesOverlay) { | 162 InitializingWithFactoryCreatesOverlay) { |
| 168 // Providing a factory at startup should result in a switch to overlay. It | 163 // Providing a factory at startup should result in a switch to overlay. It |
| 169 // should not switch to SurfaceTexture initially, since pre-M requires it. | 164 // should not switch to SurfaceTexture initially, since pre-M requires it. |
| 170 // Note that post-M (especially DS), it might be fine to start with ST. We | 165 // Note that post-M (especially DS), it might be fine to start with ST. We |
| 171 // just don't differentiate those cases yet in the impl. | 166 // just don't differentiate those cases yet in the impl. |
| 172 | 167 |
| 173 // Initially, there should be no callback into |client_|, since we haven't | 168 // Initially, there should be no callback into |client_|, since we haven't |
| 174 // told |chooser_| that the overlay is ready. It should, however, request the | 169 // told |chooser_| that the overlay is ready. It should, however, request the |
| 175 // overlay from |factory_|. | 170 // overlay from |factory_|. |
| 176 EXPECT_CALL(*factory_, MockCreateOverlay()); | 171 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 177 StartHelper(std::move(factory_)); | 172 StartChooser(FactoryFor(std::move(overlay_))); |
| 178 } | 173 } |
| 179 | 174 |
| 180 TEST_F(AndroidVideoSurfaceChooserImplTest, | 175 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 181 NullInitialOverlayUsesSurfaceTexture) { | 176 NullInitialOverlayUsesSurfaceTexture) { |
| 182 // If we provide a factory, but it fails to create an overlay, then |client_| | 177 // If we provide a factory, but it fails to create an overlay, then |client_| |
| 183 // should be notified to use a surface texture. | 178 // should be notified to use a surface texture. |
| 184 | 179 |
| 185 EXPECT_CALL(*factory_, MockCreateOverlay()); | 180 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 186 EXPECT_CALL(client_, UseSurfaceTexture()); | 181 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 187 // Replacing the overlay with null will destroy it. | 182 StartChooser(FactoryFor(nullptr)); |
| 188 destruction_observer_->ExpectDestruction(); | |
| 189 factory_->SetOverlay(nullptr); | |
| 190 StartHelper(std::move(factory_)); | |
| 191 } | 183 } |
| 192 | 184 |
| 193 TEST_F(AndroidVideoSurfaceChooserImplTest, | 185 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 194 FailedInitialOverlayUsesSurfaceTexture) { | 186 FailedInitialOverlayUsesSurfaceTexture) { |
| 195 // If we provide a factory, but the overlay that it provides returns 'failed', | 187 // If we provide a factory, but the overlay that it provides returns 'failed', |
| 196 // then |client_| should use surface texture. | 188 // then |client_| should use surface texture. |
| 197 EXPECT_CALL(*factory_, MockCreateOverlay()); | 189 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 198 StartHelper(std::move(factory_)); | 190 StartChooser(FactoryFor(std::move(overlay_))); |
| 199 | 191 |
| 200 testing::Mock::VerifyAndClearExpectations(&client_); | 192 testing::Mock::VerifyAndClearExpectations(&client_); |
| 201 testing::Mock::VerifyAndClearExpectations(factory_weak_.get()); | 193 testing::Mock::VerifyAndClearExpectations(this); |
| 202 | 194 |
| 203 // The overlay may be destroyed at any time after we send OverlayFailed. It | 195 // The overlay may be destroyed at any time after we send OverlayFailed. It |
| 204 // doesn't have to be destroyed. We just care that it hasn't been destroyed | 196 // doesn't have to be destroyed. We just care that it hasn't been destroyed |
| 205 // before now. | 197 // before now. |
| 206 destruction_observer_ = nullptr; | 198 destruction_observer_ = nullptr; |
| 207 EXPECT_CALL(client_, UseSurfaceTexture()); | 199 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 208 overlay_callbacks_.OverlayFailed.Run(); | 200 overlay_callbacks_.OverlayFailed.Run(); |
| 209 } | 201 } |
| 210 | 202 |
| 211 TEST_F(AndroidVideoSurfaceChooserImplTest, | 203 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 212 OnSurfaceDestroyedSendsNotification) { | 204 OnSurfaceDestroyedSendsNotification) { |
| 213 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should | 205 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should |
| 214 // also be notified. | 206 // also be notified. |
| 215 | 207 |
| 216 EXPECT_CALL(*factory_, MockCreateOverlay()); | 208 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 217 StartHelper(std::move(factory_)); | 209 StartChooser(FactoryFor(std::move(overlay_))); |
| 218 EXPECT_CALL(client_, UseOverlay(NotNull())); | 210 EXPECT_CALL(client_, UseOverlay(NotNull())); |
| 219 overlay_callbacks_.OverlayReady.Run(); | 211 overlay_callbacks_.OverlayReady.Run(); |
| 220 | 212 |
| 221 testing::Mock::VerifyAndClearExpectations(&client_); | 213 testing::Mock::VerifyAndClearExpectations(&client_); |
| 222 testing::Mock::VerifyAndClearExpectations(factory_weak_.get()); | 214 testing::Mock::VerifyAndClearExpectations(this); |
| 223 | 215 |
| 224 // Switch to a surface texture. OnSurfaceDestroyed should still be sent. | 216 // Switch to a surface texture. OnSurfaceDestroyed should still be sent. |
| 225 EXPECT_CALL(client_, UseSurfaceTexture()); | 217 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 226 chooser_->ReplaceOverlayFactory(nullptr); | 218 chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB()); |
| 227 testing::Mock::VerifyAndClearExpectations(&client_); | 219 testing::Mock::VerifyAndClearExpectations(&client_); |
| 228 | 220 |
| 229 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); | 221 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); |
| 230 overlay_callbacks_.SurfaceDestroyed.Run(); | 222 overlay_callbacks_.SurfaceDestroyed.Run(); |
| 231 } | 223 } |
| 232 | 224 |
| 233 TEST_F(AndroidVideoSurfaceChooserImplTest, | 225 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 234 OnSurfaceDestroyedSendsNotificationAfterSwitch) { | 226 OnSurfaceDestroyedSendsNotificationAfterSwitch) { |
| 235 // This tests two things. First: | 227 // This tests two things. First: |
| 236 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should | 228 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should |
| 237 // also be notified even if |chooser_| has already told |client_| to | 229 // also be notified even if |chooser_| has already told |client_| to |
| 238 // transition to SurfaceTexture. It has no idea if |client_| has actually | 230 // transition to SurfaceTexture. It has no idea if |client_| has actually |
| 239 // transitioned, so it has to notify it to stop immediately, in case it | 231 // transitioned, so it has to notify it to stop immediately, in case it |
| 240 // hasn't. Second: |chooser_| should notify |client_| to switch to surface | 232 // hasn't. Second: |chooser_| should notify |client_| to switch to surface |
| 241 // texture if it provided an overlay, and the factory is changed. This | 233 // texture if it provided an overlay, and the factory is changed. This |
| 242 // indicates that whoever provided the factory is revoking it, so we shouldn't | 234 // indicates that whoever provided the factory is revoking it, so we shouldn't |
| 243 // be using overlays from that factory anymore. We specifically test overlay | 235 // be using overlays from that factory anymore. We specifically test overlay |
| 244 // => no factory, since |chooser_| could elide multiple calls to switch to | 236 // => no factory, since |chooser_| could elide multiple calls to switch to |
| 245 // surface texture. | 237 // surface texture. |
| 246 // | 238 // |
| 247 // We test these together, since switching the factory is the only way we have | 239 // We test these together, since switching the factory is the only way we have |
| 248 // to make |chooser_| transition to SurfaceTexture without sending destroyed. | 240 // to make |chooser_| transition to SurfaceTexture without sending destroyed. |
| 249 | 241 |
| 250 EXPECT_CALL(*factory_, MockCreateOverlay()); | 242 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 251 StartHelper(std::move(factory_)); | 243 StartChooser(FactoryFor(std::move(overlay_))); |
| 252 EXPECT_CALL(client_, UseOverlay(NotNull())); | 244 EXPECT_CALL(client_, UseOverlay(NotNull())); |
| 253 overlay_callbacks_.OverlayReady.Run(); | 245 overlay_callbacks_.OverlayReady.Run(); |
| 254 | 246 |
| 255 testing::Mock::VerifyAndClearExpectations(&client_); | 247 testing::Mock::VerifyAndClearExpectations(&client_); |
| 256 testing::Mock::VerifyAndClearExpectations(factory_weak_.get()); | 248 testing::Mock::VerifyAndClearExpectations(this); |
| 257 | 249 |
| 258 // Switch factories, to notify the client back to switch to SurfaceTexture. | 250 // Switch factories, to notify the client back to switch to SurfaceTexture. |
| 259 EXPECT_CALL(client_, UseSurfaceTexture()); | 251 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 260 chooser_->ReplaceOverlayFactory(nullptr); | 252 chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB()); |
| 261 testing::Mock::VerifyAndClearExpectations(&client_); | 253 testing::Mock::VerifyAndClearExpectations(&client_); |
| 262 | 254 |
| 263 // Destroy the original surface. | 255 // Destroy the original surface. |
| 264 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); | 256 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); |
| 265 overlay_callbacks_.SurfaceDestroyed.Run(); | 257 overlay_callbacks_.SurfaceDestroyed.Run(); |
| 266 } | 258 } |
| 267 | 259 |
| 268 TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesSurfaceTexture) { | 260 TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesSurfaceTexture) { |
| 269 // If an overlay factory is provided after startup that returns a null overlay | 261 // If an overlay factory is provided after startup that returns a null overlay |
| 270 // from CreateOverlay, |chooser_| should, at most, notify |client_| to use | 262 // from CreateOverlay, |chooser_| should, at most, notify |client_| to use |
| 271 // SurfaceTexture zero or more times. | 263 // SurfaceTexture zero or more times. |
| 272 | 264 |
| 273 // Start with SurfaceTexture. | 265 // Start with SurfaceTexture. |
| 274 EXPECT_CALL(client_, UseSurfaceTexture()); | 266 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 275 StartHelper(nullptr); | 267 StartChooser(AndroidOverlayFactoryCB()); |
| 276 testing::Mock::VerifyAndClearExpectations(&client_); | 268 testing::Mock::VerifyAndClearExpectations(&client_); |
| 277 | 269 |
| 278 // Provide a factory that will return a null overlay. | 270 // Provide a factory that will return a null overlay. |
| 279 EXPECT_CALL(*factory_, MockCreateOverlay()); | 271 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 280 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); | 272 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); |
| 281 chooser_->ReplaceOverlayFactory(std::move(factory_)); | 273 chooser_->ReplaceOverlayFactory(FactoryFor(nullptr)); |
| 282 factory_weak_->SetOverlay(nullptr); | |
| 283 } | 274 } |
| 284 | 275 |
| 285 TEST_F(AndroidVideoSurfaceChooserImplTest, FailedLaterOverlayDoesNothing) { | 276 TEST_F(AndroidVideoSurfaceChooserImplTest, FailedLaterOverlayDoesNothing) { |
| 286 // If we send an overlay factory that returns an overlay, and that overlay | 277 // If we send an overlay factory that returns an overlay, and that overlay |
| 287 // fails, then the client should not be notified except for zero or more | 278 // fails, then the client should not be notified except for zero or more |
| 288 // callbacks to switch to surface texture. | 279 // callbacks to switch to surface texture. |
| 289 | 280 |
| 290 // Start with SurfaceTexture. | 281 // Start with SurfaceTexture. |
| 291 EXPECT_CALL(client_, UseSurfaceTexture()); | 282 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 292 StartHelper(nullptr); | 283 StartChooser(AndroidOverlayFactoryCB()); |
| 293 testing::Mock::VerifyAndClearExpectations(&client_); | 284 testing::Mock::VerifyAndClearExpectations(&client_); |
| 294 | 285 |
| 295 // Provide a factory. | 286 // Provide a factory. |
| 296 EXPECT_CALL(*factory_, MockCreateOverlay()); | 287 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 297 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); | 288 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); |
| 298 chooser_->ReplaceOverlayFactory(std::move(factory_)); | 289 chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_))); |
| 299 testing::Mock::VerifyAndClearExpectations(&client_); | 290 testing::Mock::VerifyAndClearExpectations(&client_); |
| 300 | 291 |
| 301 // Fail the overlay. We don't care if it's destroyed after that, as long as | 292 // Fail the overlay. We don't care if it's destroyed after that, as long as |
| 302 // it hasn't been destroyed yet. | 293 // it hasn't been destroyed yet. |
| 303 destruction_observer_ = nullptr; | 294 destruction_observer_ = nullptr; |
| 304 overlay_callbacks_.OverlayFailed.Run(); | 295 overlay_callbacks_.OverlayFailed.Run(); |
| 305 } | 296 } |
| 306 | 297 |
| 307 TEST_F(AndroidVideoSurfaceChooserImplTest, | 298 TEST_F(AndroidVideoSurfaceChooserImplTest, |
| 308 SuccessfulLaterOverlayNotifiesClient) { | 299 SuccessfulLaterOverlayNotifiesClient) { |
| 309 // |client_| is notified if we provide a factory that gets an overlay. | 300 // |client_| is notified if we provide a factory that gets an overlay. |
| 310 | 301 |
| 311 // Start with SurfaceTexture. | 302 // Start with SurfaceTexture. |
| 312 EXPECT_CALL(client_, UseSurfaceTexture()); | 303 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 313 StartHelper(nullptr); | 304 StartChooser(AndroidOverlayFactoryCB()); |
| 314 testing::Mock::VerifyAndClearExpectations(&client_); | 305 testing::Mock::VerifyAndClearExpectations(&client_); |
| 315 | 306 |
| 316 // Provide a factory. |chooser_| should try to create an overlay. We don't | 307 // Provide a factory. |chooser_| should try to create an overlay. We don't |
| 317 // care if a call to UseSurfaceTexture is elided or not. Note that AVDA will | 308 // care if a call to UseSurfaceTexture is elided or not. Note that AVDA will |
| 318 // ignore duplicate calls anyway (MultipleSurfaceTextureCallbacksAreIgnored). | 309 // ignore duplicate calls anyway (MultipleSurfaceTextureCallbacksAreIgnored). |
| 319 EXPECT_CALL(*factory_, MockCreateOverlay()); | 310 EXPECT_CALL(*this, MockOnOverlayCreated()); |
| 320 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); | 311 EXPECT_CALL(client_, UseSurfaceTexture()).Times(AnyNumber()); |
| 321 chooser_->ReplaceOverlayFactory(std::move(factory_)); | 312 chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_))); |
| 322 testing::Mock::VerifyAndClearExpectations(&client_); | 313 testing::Mock::VerifyAndClearExpectations(&client_); |
| 323 testing::Mock::VerifyAndClearExpectations(factory_weak_.get()); | 314 testing::Mock::VerifyAndClearExpectations(this); |
| 324 | 315 |
| 325 // Notify |chooser_| that the overlay is ready. | 316 // Notify |chooser_| that the overlay is ready. |
| 326 EXPECT_CALL(client_, UseOverlay(NotNull())); | 317 EXPECT_CALL(client_, UseOverlay(NotNull())); |
| 327 overlay_callbacks_.OverlayReady.Run(); | 318 overlay_callbacks_.OverlayReady.Run(); |
| 328 } | 319 } |
| 329 | 320 |
| 330 } // namespace media | 321 } // namespace media |
| OLD | NEW |