| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_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/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/test/scoped_feature_list.h" |
| 19 #include "base/test/simple_test_tick_clock.h" | 20 #include "base/test/simple_test_tick_clock.h" |
| 20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "media/base/media_log.h" | 23 #include "media/base/media_log.h" |
| 23 #include "media/base/media_switches.h" | 24 #include "media/base/media_switches.h" |
| 24 #include "media/base/test_helpers.h" | 25 #include "media/base/test_helpers.h" |
| 25 #include "media/blink/webmediaplayer_delegate.h" | 26 #include "media/blink/webmediaplayer_delegate.h" |
| 26 #include "media/blink/webmediaplayer_params.h" | 27 #include "media/blink/webmediaplayer_params.h" |
| 27 #include "media/renderers/default_renderer_factory.h" | 28 #include "media/renderers/default_renderer_factory.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void AddBufferedRanges() { | 228 void AddBufferedRanges() { |
| 228 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1); | 229 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void SetupForResumingBackgroundVideo() { | 232 void SetupForResumingBackgroundVideo() { |
| 232 #if !defined(OS_ANDROID) | 233 #if !defined(OS_ANDROID) |
| 233 // Need to enable media suspend to test resuming background videos. | 234 // Need to enable media suspend to test resuming background videos. |
| 234 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 235 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 235 switches::kEnableMediaSuspend); | 236 switches::kEnableMediaSuspend); |
| 236 #endif // !defined(OS_ANDROID) | 237 #endif // !defined(OS_ANDROID) |
| 237 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 238 scoped_feature_list_.InitAndEnableFeature(kResumeBackgroundVideo); |
| 238 feature_list->InitializeFromCommandLine(kResumeBackgroundVideo.name, ""); | |
| 239 base::FeatureList::ClearInstanceForTesting(); | |
| 240 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 241 } | 239 } |
| 242 | 240 |
| 243 // "Renderer" thread. | 241 // "Renderer" thread. |
| 244 base::MessageLoop message_loop_; | 242 base::MessageLoop message_loop_; |
| 245 | 243 |
| 246 // "Media" thread. This is necessary because WMPI destruction waits on a | 244 // "Media" thread. This is necessary because WMPI destruction waits on a |
| 247 // WaitableEvent. | 245 // WaitableEvent. |
| 248 base::Thread media_thread_; | 246 base::Thread media_thread_; |
| 249 | 247 |
| 250 // Blink state. | 248 // Blink state. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 261 // The client interface used by |wmpi_|. Just a dummy for now, but later we | 259 // The client interface used by |wmpi_|. Just a dummy for now, but later we |
| 262 // may want a mock or intelligent fake. | 260 // may want a mock or intelligent fake. |
| 263 DummyWebMediaPlayerClient client_; | 261 DummyWebMediaPlayerClient client_; |
| 264 | 262 |
| 265 testing::NiceMock<MockWebMediaPlayerDelegate> delegate_; | 263 testing::NiceMock<MockWebMediaPlayerDelegate> delegate_; |
| 266 | 264 |
| 267 // The WebMediaPlayerImpl instance under test. | 265 // The WebMediaPlayerImpl instance under test. |
| 268 std::unique_ptr<WebMediaPlayerImpl> wmpi_; | 266 std::unique_ptr<WebMediaPlayerImpl> wmpi_; |
| 269 | 267 |
| 270 private: | 268 private: |
| 269 base::test::ScopedFeatureList scoped_feature_list_; |
| 270 |
| 271 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImplTest); | 271 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImplTest); |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) { | 274 TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) { |
| 275 InitializeWebMediaPlayerImpl(); | 275 InitializeWebMediaPlayerImpl(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledBeforeLoadingBegins) { | 278 TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledBeforeLoadingBegins) { |
| 279 InitializeWebMediaPlayerImpl(); | 279 InitializeWebMediaPlayerImpl(); |
| 280 wmpi_->OnSuspendRequested(false); | 280 wmpi_->OnSuspendRequested(false); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); | 717 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); |
| 718 client_.set_is_autoplaying_muted(true); | 718 client_.set_is_autoplaying_muted(true); |
| 719 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); | 719 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); |
| 720 | 720 |
| 721 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); | 721 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); |
| 722 client_.set_is_autoplaying_muted(false); | 722 client_.set_is_autoplaying_muted(false); |
| 723 wmpi_->setVolume(1.0); | 723 wmpi_->setVolume(1.0); |
| 724 } | 724 } |
| 725 | 725 |
| 726 } // namespace media | 726 } // namespace media |
| OLD | NEW |