| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void AddBufferedRanges() { | 227 void AddBufferedRanges() { |
| 227 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1); | 228 wmpi_->buffered_data_source_host_.AddBufferedByteRange(0, 1); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void SetupForResumingBackgroundVideo() { | 231 void SetupForResumingBackgroundVideo() { |
| 231 #if !defined(OS_ANDROID) | 232 #if !defined(OS_ANDROID) |
| 232 // Need to enable media suspend to test resuming background videos. | 233 // Need to enable media suspend to test resuming background videos. |
| 233 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 234 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 234 switches::kEnableMediaSuspend); | 235 switches::kEnableMediaSuspend); |
| 235 #endif // !defined(OS_ANDROID) | 236 #endif // !defined(OS_ANDROID) |
| 236 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 237 scoped_feature_list_.InitAndEnableFeature(kResumeBackgroundVideo); |
| 237 feature_list->InitializeFromCommandLine(kResumeBackgroundVideo.name, ""); | |
| 238 base::FeatureList::ClearInstanceForTesting(); | |
| 239 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 240 } | 238 } |
| 241 | 239 |
| 242 // "Renderer" thread. | 240 // "Renderer" thread. |
| 243 base::MessageLoop message_loop_; | 241 base::MessageLoop message_loop_; |
| 244 | 242 |
| 245 // "Media" thread. This is necessary because WMPI destruction waits on a | 243 // "Media" thread. This is necessary because WMPI destruction waits on a |
| 246 // WaitableEvent. | 244 // WaitableEvent. |
| 247 base::Thread media_thread_; | 245 base::Thread media_thread_; |
| 248 | 246 |
| 249 // Blink state. | 247 // Blink state. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 260 // The client interface used by |wmpi_|. Just a dummy for now, but later we | 258 // The client interface used by |wmpi_|. Just a dummy for now, but later we |
| 261 // may want a mock or intelligent fake. | 259 // may want a mock or intelligent fake. |
| 262 DummyWebMediaPlayerClient client_; | 260 DummyWebMediaPlayerClient client_; |
| 263 | 261 |
| 264 testing::NiceMock<MockWebMediaPlayerDelegate> delegate_; | 262 testing::NiceMock<MockWebMediaPlayerDelegate> delegate_; |
| 265 | 263 |
| 266 // The WebMediaPlayerImpl instance under test. | 264 // The WebMediaPlayerImpl instance under test. |
| 267 std::unique_ptr<WebMediaPlayerImpl> wmpi_; | 265 std::unique_ptr<WebMediaPlayerImpl> wmpi_; |
| 268 | 266 |
| 269 private: | 267 private: |
| 268 base::test::ScopedFeatureList scoped_feature_list_; |
| 269 |
| 270 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImplTest); | 270 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImplTest); |
| 271 }; | 271 }; |
| 272 | 272 |
| 273 TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) { | 273 TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) { |
| 274 InitializeWebMediaPlayerImpl(); | 274 InitializeWebMediaPlayerImpl(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledBeforeLoadingBegins) { | 277 TEST_F(WebMediaPlayerImplTest, IdleSuspendIsEnabledBeforeLoadingBegins) { |
| 278 InitializeWebMediaPlayerImpl(); | 278 InitializeWebMediaPlayerImpl(); |
| 279 wmpi_->OnSuspendRequested(false); | 279 wmpi_->OnSuspendRequested(false); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); | 716 EXPECT_CALL(delegate_, DidPlay(_, true, false, false, _)); |
| 717 client_.set_is_autoplaying_muted(true); | 717 client_.set_is_autoplaying_muted(true); |
| 718 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); | 718 SetDelegateState(WebMediaPlayerImpl::DelegateState::PLAYING); |
| 719 | 719 |
| 720 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); | 720 EXPECT_CALL(delegate_, DidPlay(_, true, true, false, _)); |
| 721 client_.set_is_autoplaying_muted(false); | 721 client_.set_is_autoplaying_muted(false); |
| 722 wmpi_->setVolume(1.0); | 722 wmpi_->setVolume(1.0); |
| 723 } | 723 } |
| 724 | 724 |
| 725 } // namespace media | 725 } // namespace media |
| OLD | NEW |