forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebmediaplayer_impl_unittest.cc
2398 lines (1984 loc) · 87.8 KB
/
webmediaplayer_impl_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/blink/webmediaplayer_impl.h"
#include <stdint.h>
#include <memory>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner_util.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "cc/layers/layer.h"
#include "components/viz/test/test_context_provider.h"
#include "media/base/decoder_buffer.h"
#include "media/base/media_content_type.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/memory_dump_provider_proxy.h"
#include "media/base/mock_audio_renderer_sink.h"
#include "media/base/mock_filters.h"
#include "media/base/mock_media_log.h"
#include "media/base/test_data_util.h"
#include "media/base/test_helpers.h"
#include "media/blink/mock_resource_fetch_context.h"
#include "media/blink/mock_webassociatedurlloader.h"
#include "media/blink/resource_multibuffer_data_provider.h"
#include "media/blink/video_decode_stats_reporter.h"
#include "media/blink/webcontentdecryptionmodule_impl.h"
#include "media/blink/webmediaplayer_params.h"
#include "media/mojo/services/media_metrics_provider.h"
#include "media/mojo/services/video_decode_stats_recorder.h"
#include "media/mojo/services/watch_time_recorder.h"
#include "media/renderers/default_decoder_factory.h"
#include "media/renderers/default_renderer_factory.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/platform/media/webmediaplayer_delegate.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/platform/web_fullscreen_video_status.h"
#include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/platform/web_media_player_client.h"
#include "third_party/blink/public/platform/web_media_player_encrypted_media_client.h"
#include "third_party/blink/public/platform/web_media_player_source.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_surface_layer_bridge.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_testing_support.h"
#include "third_party/blink/public/web/web_view.h"
#include "third_party/blink/public/web/web_widget.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
using ::base::test::RunClosure;
using ::base::test::RunOnceCallback;
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Gt;
using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::NiceMock;
using ::testing::NotNull;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::StrictMock;
using ::testing::WithArg;
using ::testing::WithoutArgs;
namespace media {
constexpr char kAudioOnlyTestFile[] = "sfx-opus-441.webm";
constexpr char kVideoOnlyTestFile[] = "bear-320x240-video-only.webm";
constexpr char kVideoAudioTestFile[] = "bear-320x240-16x9-aspect.webm";
constexpr char kEncryptedVideoOnlyTestFile[] = "bear-320x240-av_enc-v.webm";
constexpr base::TimeDelta kAudioOnlyTestFileDuration =
base::TimeDelta::FromMilliseconds(296);
MATCHER(WmpiDestroyed, "") {
return CONTAINS_STRING(arg, "{\"event\":\"kWebMediaPlayerDestroyed\"}");
}
MATCHER_P2(PlaybackRateChanged, old_rate_string, new_rate_string, "") {
return CONTAINS_STRING(arg, "Effective playback rate changed from " +
std::string(old_rate_string) + " to " +
std::string(new_rate_string));
}
class MockWebMediaPlayerClient : public blink::WebMediaPlayerClient {
public:
MockWebMediaPlayerClient() = default;
MOCK_METHOD0(NetworkStateChanged, void());
MOCK_METHOD0(ReadyStateChanged, void());
MOCK_METHOD0(TimeChanged, void());
MOCK_METHOD0(Repaint, void());
MOCK_METHOD0(DurationChanged, void());
MOCK_METHOD0(SizeChanged, void());
MOCK_METHOD1(SetCcLayer, void(cc::Layer*));
MOCK_METHOD5(AddAudioTrack,
blink::WebMediaPlayer::TrackId(
const blink::WebString&,
blink::WebMediaPlayerClient::AudioTrackKind,
const blink::WebString&,
const blink::WebString&,
bool));
MOCK_METHOD1(RemoveAudioTrack, void(blink::WebMediaPlayer::TrackId));
MOCK_METHOD5(AddVideoTrack,
blink::WebMediaPlayer::TrackId(
const blink::WebString&,
blink::WebMediaPlayerClient::VideoTrackKind,
const blink::WebString&,
const blink::WebString&,
bool));
MOCK_METHOD1(RemoveVideoTrack, void(blink::WebMediaPlayer::TrackId));
MOCK_METHOD1(AddTextTrack, void(blink::WebInbandTextTrack*));
MOCK_METHOD1(RemoveTextTrack, void(blink::WebInbandTextTrack*));
MOCK_METHOD1(MediaSourceOpened, void(blink::WebMediaSource*));
MOCK_METHOD2(RemotePlaybackCompatibilityChanged,
void(const blink::WebURL&, bool));
MOCK_METHOD1(OnBecamePersistentVideo, void(bool));
MOCK_METHOD0(WasAlwaysMuted, bool());
MOCK_METHOD0(HasSelectedVideoTrack, bool());
MOCK_METHOD0(GetSelectedVideoTrackId, blink::WebMediaPlayer::TrackId());
MOCK_METHOD0(HasNativeControls, bool());
MOCK_METHOD0(IsAudioElement, bool());
MOCK_CONST_METHOD0(GetDisplayType, blink::DisplayType());
MOCK_CONST_METHOD0(IsInAutoPIP, bool());
MOCK_METHOD1(MediaRemotingStarted, void(const blink::WebString&));
MOCK_METHOD1(MediaRemotingStopped, void(int));
MOCK_METHOD0(PictureInPictureStopped, void());
MOCK_METHOD0(OnPictureInPictureStateChange, void());
MOCK_CONST_METHOD0(CouldPlayIfEnoughData, bool());
MOCK_METHOD0(ResumePlayback, void());
MOCK_METHOD0(PausePlayback, void());
MOCK_METHOD0(DidPlayerStartPlaying, void());
MOCK_METHOD1(DidPlayerPaused, void(bool));
MOCK_METHOD1(DidPlayerMutedStatusChange, void(bool));
MOCK_METHOD3(DidMediaMetadataChange,
void(bool, bool, media::MediaContentType));
MOCK_METHOD3(DidPlayerMediaPositionStateChange,
void(double, base::TimeDelta, base::TimeDelta position));
MOCK_METHOD0(DidDisableAudioOutputSinkChanges, void());
MOCK_METHOD1(DidPlayerSizeChange, void(const gfx::Size&));
MOCK_METHOD0(DidBufferUnderflow, void());
MOCK_METHOD0(DidSeek, void());
MOCK_METHOD0(GetFeatures, Features(void));
MOCK_METHOD0(OnRequestVideoFrameCallback, void());
MOCK_METHOD0(GetTextTrackMetadata, std::vector<blink::TextTrackMetadata>());
bool was_always_muted_ = false;
private:
DISALLOW_COPY_AND_ASSIGN(MockWebMediaPlayerClient);
};
class MockWebMediaPlayerEncryptedMediaClient
: public blink::WebMediaPlayerEncryptedMediaClient {
public:
MockWebMediaPlayerEncryptedMediaClient() = default;
MOCK_METHOD3(Encrypted,
void(EmeInitDataType, const unsigned char*, unsigned));
MOCK_METHOD0(DidBlockPlaybackWaitingForKey, void());
MOCK_METHOD0(DidResumePlaybackBlockedForKey, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockWebMediaPlayerEncryptedMediaClient);
};
class MockWebMediaPlayerDelegate : public blink::WebMediaPlayerDelegate {
public:
MockWebMediaPlayerDelegate() = default;
~MockWebMediaPlayerDelegate() override = default;
// blink::WebMediaPlayerDelegate implementation.
int AddObserver(Observer* observer) override {
DCHECK_EQ(nullptr, observer_);
observer_ = observer;
return player_id_;
}
void RemoveObserver(int player_id) override {
DCHECK_EQ(player_id_, player_id);
observer_ = nullptr;
}
MOCK_METHOD4(DidMediaMetadataChange, void(int, bool, bool, MediaContentType));
void DidPlay(int player_id) override { DCHECK_EQ(player_id_, player_id); }
void DidPause(int player_id, bool reached_end_of_stream) override {
DCHECK_EQ(player_id_, player_id);
}
void PlayerGone(int player_id) override { DCHECK_EQ(player_id_, player_id); }
void SetIdle(int player_id, bool is_idle) override {
DCHECK_EQ(player_id_, player_id);
is_idle_ = is_idle;
is_stale_ &= is_idle;
}
bool IsIdle(int player_id) override {
DCHECK_EQ(player_id_, player_id);
return is_idle_;
}
void ClearStaleFlag(int player_id) override {
DCHECK_EQ(player_id_, player_id);
is_stale_ = false;
}
bool IsStale(int player_id) override {
DCHECK_EQ(player_id_, player_id);
return is_stale_;
}
bool IsFrameHidden() override { return is_hidden_; }
void SetIdleForTesting(bool is_idle) { is_idle_ = is_idle; }
void SetStaleForTesting(bool is_stale) {
is_idle_ |= is_stale;
is_stale_ = is_stale;
}
// Returns true if the player does in fact expire.
bool ExpireForTesting() {
if (is_idle_ && !is_stale_) {
is_stale_ = true;
observer_->OnIdleTimeout();
}
return is_stale_;
}
void SetFrameHiddenForTesting(bool is_hidden) { is_hidden_ = is_hidden; }
int player_id() { return player_id_; }
private:
Observer* observer_ = nullptr;
int player_id_ = 1234;
bool is_idle_ = false;
bool is_stale_ = false;
bool is_hidden_ = false;
};
class MockSurfaceLayerBridge : public blink::WebSurfaceLayerBridge {
public:
MOCK_CONST_METHOD0(GetCcLayer, cc::Layer*());
MOCK_CONST_METHOD0(GetFrameSinkId, const viz::FrameSinkId&());
MOCK_CONST_METHOD0(GetSurfaceId, const viz::SurfaceId&());
MOCK_METHOD0(ClearSurfaceId, void());
MOCK_METHOD1(SetContentsOpaque, void(bool));
MOCK_METHOD0(CreateSurfaceLayer, void());
MOCK_METHOD0(ClearObserver, void());
};
class MockVideoFrameCompositor : public VideoFrameCompositor {
public:
MockVideoFrameCompositor(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
: VideoFrameCompositor(task_runner, nullptr) {}
~MockVideoFrameCompositor() override = default;
// MOCK_METHOD doesn't like OnceCallback.
MOCK_METHOD1(SetOnFramePresentedCallback, void(OnNewFramePresentedCB));
MOCK_METHOD1(SetIsPageVisible, void(bool));
MOCK_METHOD0(
GetLastPresentedFrameMetadata,
std::unique_ptr<blink::WebMediaPlayer::VideoFramePresentationMetadata>());
MOCK_METHOD0(GetCurrentFrameOnAnyThread, scoped_refptr<VideoFrame>());
MOCK_METHOD1(UpdateCurrentFrameIfStale,
void(VideoFrameCompositor::UpdateType));
MOCK_METHOD3(EnableSubmission,
void(const viz::SurfaceId&, media::VideoRotation, bool));
};
class WebMediaPlayerImplTest
: public testing::Test,
private blink::WebTestingSupport::WebScopedMockScrollbars {
public:
WebMediaPlayerImplTest()
: WebMediaPlayerImplTest(
blink::scheduler::WebThreadScheduler::MainThreadScheduler()
->CreateAgentGroupScheduler()) {}
explicit WebMediaPlayerImplTest(
std::unique_ptr<blink::scheduler::WebAgentGroupScheduler>
agent_group_scheduler)
: media_thread_("MediaThreadForTest"),
web_view_(blink::WebView::Create(
/*client=*/nullptr,
/*is_hidden=*/false,
/*is_inside_portal=*/false,
/*compositing_enabled=*/false,
/*opener=*/nullptr,
mojo::NullAssociatedReceiver(),
*agent_group_scheduler,
/*session_storage_namespace_id=*/base::EmptyString())),
web_local_frame_(
blink::WebLocalFrame::CreateMainFrame(web_view_,
&web_frame_client_,
nullptr,
blink::LocalFrameToken(),
nullptr)),
context_provider_(viz::TestContextProvider::Create()),
audio_parameters_(TestAudioParameters::Normal()),
memory_dump_manager_(
base::trace_event::MemoryDumpManager::CreateInstanceForTesting()),
agent_group_scheduler_(std::move(agent_group_scheduler)) {
media_thread_.StartAndWaitForTesting();
}
void InitializeSurfaceLayerBridge() {
surface_layer_bridge_ =
std::make_unique<NiceMock<MockSurfaceLayerBridge>>();
surface_layer_bridge_ptr_ = surface_layer_bridge_.get();
EXPECT_CALL(client_, SetCcLayer(_)).Times(0);
ON_CALL(*surface_layer_bridge_ptr_, GetSurfaceId())
.WillByDefault(ReturnRef(surface_id_));
}
void InitializeWebMediaPlayerImpl() {
InitializeWebMediaPlayerImplInternal(nullptr);
}
~WebMediaPlayerImplTest() override {
if (!wmpi_)
return;
EXPECT_CALL(client_, SetCcLayer(nullptr));
EXPECT_CALL(client_, MediaRemotingStopped(_));
// Destruct WebMediaPlayerImpl and pump the message loop to ensure that
// objects passed to the message loop for destruction are released.
//
// NOTE: This should be done before any other member variables are
// destructed since WMPI may reference them during destruction.
wmpi_.reset();
CycleThreads();
web_view_->Close();
agent_group_scheduler_ = nullptr;
}
protected:
void InitializeWebMediaPlayerImplInternal(
std::unique_ptr<media::Demuxer> demuxer_override) {
auto media_log = std::make_unique<NiceMock<MockMediaLog>>();
InitializeSurfaceLayerBridge();
// Retain a raw pointer to |media_log| for use by tests. Meanwhile, give its
// ownership to |wmpi_|. Reject attempts to reinitialize to prevent orphaned
// expectations on previous |media_log_|.
ASSERT_FALSE(media_log_) << "Reinitialization of media_log_ is disallowed";
media_log_ = media_log.get();
auto factory_selector = std::make_unique<RendererFactorySelector>();
renderer_factory_selector_ = factory_selector.get();
decoder_factory_.reset(new media::DefaultDecoderFactory(nullptr));
#if defined(OS_ANDROID)
factory_selector->AddBaseFactory(
RendererFactoryType::kDefault,
std::make_unique<DefaultRendererFactory>(
media_log.get(), decoder_factory_.get(),
DefaultRendererFactory::GetGpuFactoriesCB()));
factory_selector->StartRequestRemotePlayStateCB(base::DoNothing());
#else
factory_selector->AddBaseFactory(
RendererFactoryType::kDefault,
std::make_unique<DefaultRendererFactory>(
media_log.get(), decoder_factory_.get(),
DefaultRendererFactory::GetGpuFactoriesCB(), nullptr));
#endif
mojo::Remote<mojom::MediaMetricsProvider> provider;
MediaMetricsProvider::Create(
MediaMetricsProvider::BrowsingMode::kNormal,
MediaMetricsProvider::FrameStatus::kNotTopFrame,
base::BindRepeating([]() { return ukm::kInvalidSourceId; }),
base::BindRepeating([]() { return learning::FeatureValue(0); }),
VideoDecodePerfHistory::SaveCallback(),
MediaMetricsProvider::GetLearningSessionCallback(),
base::BindRepeating(
&WebMediaPlayerImplTest::GetRecordAggregateWatchTimeCallback,
base::Unretained(this)),
provider.BindNewPipeAndPassReceiver());
// Initialize provider since none of the tests below actually go through the
// full loading/pipeline initialize phase. If this ever changes the provider
// will start DCHECK failing.
provider->Initialize(false, mojom::MediaURLScheme::kHttp,
mojom::MediaStreamType::kNone);
audio_sink_ = base::WrapRefCounted(new NiceMock<MockAudioRendererSink>());
url_index_.reset(new UrlIndex(&mock_resource_fetch_context_));
auto params = std::make_unique<WebMediaPlayerParams>(
std::move(media_log), WebMediaPlayerParams::DeferLoadCB(), audio_sink_,
media_thread_.task_runner(), base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get(), media_thread_.task_runner(),
base::BindRepeating(&WebMediaPlayerImplTest::OnAdjustAllocatedMemory,
base::Unretained(this)),
nullptr, RequestRoutingTokenCallback(), nullptr, false, false,
provider.Unbind(),
base::BindOnce(&WebMediaPlayerImplTest::CreateMockSurfaceLayerBridge,
base::Unretained(this)),
viz::TestContextProvider::Create(),
blink::WebMediaPlayer::SurfaceLayerMode::kAlways,
is_background_suspend_enabled_, is_background_video_playback_enabled_,
true, std::move(demuxer_override), nullptr);
auto compositor = std::make_unique<NiceMock<MockVideoFrameCompositor>>(
params->video_frame_compositor_task_runner());
compositor_ = compositor.get();
wmpi_ = std::make_unique<WebMediaPlayerImpl>(
web_local_frame_, &client_, &encrypted_client_, &delegate_,
std::move(factory_selector), url_index_.get(), std::move(compositor),
std::move(params));
}
std::unique_ptr<blink::WebSurfaceLayerBridge> CreateMockSurfaceLayerBridge(
blink::WebSurfaceLayerBridgeObserver*,
cc::UpdateSubmissionStateCB) {
return std::move(surface_layer_bridge_);
}
blink::WebLocalFrame* GetWebLocalFrame() { return web_local_frame_; }
int64_t OnAdjustAllocatedMemory(int64_t delta) {
reported_memory_ += delta;
return 0;
}
void SetNetworkState(blink::WebMediaPlayer::NetworkState state) {
EXPECT_CALL(client_, NetworkStateChanged());
wmpi_->SetNetworkState(state);
}
void SetReadyState(blink::WebMediaPlayer::ReadyState state) {
EXPECT_CALL(client_, ReadyStateChanged());
wmpi_->SetReadyState(state);
}
void SetDuration(base::TimeDelta value) {
wmpi_->SetPipelineMediaDurationForTest(value);
wmpi_->OnDurationChange();
}
MediaMetricsProvider::RecordAggregateWatchTimeCallback
GetRecordAggregateWatchTimeCallback() {
return base::NullCallback();
}
base::TimeDelta GetCurrentTimeInternal() {
return wmpi_->GetCurrentTimeInternal();
}
void SetPaused(bool is_paused) { wmpi_->paused_ = is_paused; }
void SetSeeking(bool is_seeking) { wmpi_->seeking_ = is_seeking; }
void SetEnded(bool is_ended) { wmpi_->ended_ = is_ended; }
void SetTickClock(const base::TickClock* clock) {
wmpi_->SetTickClockForTest(clock);
}
void SetWasSuspendedForFrameClosed(bool is_suspended) {
wmpi_->was_suspended_for_frame_closed_ = is_suspended;
}
void SetFullscreen(bool is_fullscreen) {
wmpi_->overlay_enabled_ = is_fullscreen;
}
void SetMetadata(bool has_audio, bool has_video) {
wmpi_->SetNetworkState(blink::WebMediaPlayer::kNetworkStateLoaded);
EXPECT_CALL(client_, ReadyStateChanged());
wmpi_->SetReadyState(blink::WebMediaPlayer::kReadyStateHaveMetadata);
wmpi_->pipeline_metadata_.has_audio = has_audio;
wmpi_->pipeline_metadata_.has_video = has_video;
if (has_video)
wmpi_->pipeline_metadata_.video_decoder_config =
TestVideoConfig::Normal();
if (has_audio)
wmpi_->pipeline_metadata_.audio_decoder_config =
TestAudioConfig::Normal();
}
void SetError(PipelineStatus status = PIPELINE_ERROR_DECODE) {
wmpi_->OnError(status);
}
void OnMetadata(const PipelineMetadata& metadata) {
wmpi_->OnMetadata(metadata);
}
void OnWaiting(WaitingReason reason) { wmpi_->OnWaiting(reason); }
void OnVideoNaturalSizeChange(const gfx::Size& size) {
wmpi_->OnVideoNaturalSizeChange(size);
}
void OnVideoConfigChange(const VideoDecoderConfig& config) {
wmpi_->OnVideoConfigChange(config);
}
WebMediaPlayerImpl::PlayState ComputePlayState() {
return wmpi_->UpdatePlayState_ComputePlayState(false, true, false, false);
}
WebMediaPlayerImpl::PlayState ComputePlayState_FrameHidden() {
return wmpi_->UpdatePlayState_ComputePlayState(false, true, false, true);
}
WebMediaPlayerImpl::PlayState ComputePlayState_Suspended() {
return wmpi_->UpdatePlayState_ComputePlayState(false, true, true, false);
}
WebMediaPlayerImpl::PlayState ComputePlayState_Flinging() {
return wmpi_->UpdatePlayState_ComputePlayState(true, true, false, false);
}
WebMediaPlayerImpl::PlayState ComputePlayState_BackgroundedStreaming() {
return wmpi_->UpdatePlayState_ComputePlayState(false, false, false, true);
}
bool IsSuspended() { return wmpi_->pipeline_controller_->IsSuspended(); }
int64_t GetDataSourceMemoryUsage() const {
return wmpi_->data_source_->GetMemoryUsage();
}
void AddBufferedRanges() {
wmpi_->buffered_data_source_host_->AddBufferedByteRange(0, 1);
}
void SetDelegateState(WebMediaPlayerImpl::DelegateState state) {
wmpi_->SetDelegateState(state, false);
}
void SetUpMediaSuspend(bool enable) {
is_background_suspend_enabled_ = enable;
}
void SetUpBackgroundVideoPlayback(bool enable) {
is_background_video_playback_enabled_ = enable;
}
bool IsVideoLockedWhenPausedWhenHidden() const {
return wmpi_->video_locked_when_paused_when_hidden_;
}
void BackgroundPlayer() {
base::RunLoop loop;
EXPECT_CALL(*compositor_, SetIsPageVisible(false))
.WillOnce(RunClosure(loop.QuitClosure()));
delegate_.SetFrameHiddenForTesting(true);
SetWasSuspendedForFrameClosed(false);
wmpi_->OnFrameHidden();
loop.Run();
// Clear the mock so it doesn't have a stale QuitClosure.
testing::Mock::VerifyAndClearExpectations(compositor_);
}
void ForegroundPlayer() {
base::RunLoop loop;
EXPECT_CALL(*compositor_, SetIsPageVisible(true))
.WillOnce(RunClosure(loop.QuitClosure()));
delegate_.SetFrameHiddenForTesting(false);
SetWasSuspendedForFrameClosed(false);
wmpi_->OnFrameShown();
loop.Run();
// Clear the mock so it doesn't have a stale QuitClosure.
testing::Mock::VerifyAndClearExpectations(compositor_);
}
void Play() { wmpi_->Play(); }
void Pause() { wmpi_->Pause(); }
void ScheduleIdlePauseTimer() { wmpi_->ScheduleIdlePauseTimer(); }
bool IsIdlePauseTimerRunning() {
return wmpi_->background_pause_timer_.IsRunning();
}
void SetSuspendState(bool is_suspended) {
wmpi_->SetSuspendState(is_suspended);
}
void SetLoadType(blink::WebMediaPlayer::LoadType load_type) {
wmpi_->load_type_ = load_type;
}
bool IsVideoTrackDisabled() const { return wmpi_->video_track_disabled_; }
bool IsDisableVideoTrackPending() const {
return !wmpi_->is_background_status_change_cancelled_;
}
gfx::Size GetNaturalSize() const {
return wmpi_->pipeline_metadata_.natural_size;
}
VideoDecodeStatsReporter* GetVideoStatsReporter() const {
return wmpi_->video_decode_stats_reporter_.get();
}
VideoCodecProfile GetVideoStatsReporterCodecProfile() const {
DCHECK(GetVideoStatsReporter());
return GetVideoStatsReporter()->codec_profile_;
}
bool ShouldCancelUponDefer() const {
return wmpi_->mb_data_source_->cancel_on_defer_for_testing();
}
bool IsDataSourceMarkedAsPlaying() const {
return wmpi_->mb_data_source_->media_has_played();
}
scoped_refptr<VideoFrame> CreateFrame() {
gfx::Size size(8, 8);
return VideoFrame::CreateFrame(PIXEL_FORMAT_I420, size, gfx::Rect(size),
size, base::TimeDelta());
}
void RequestVideoFrameCallback() { wmpi_->RequestVideoFrameCallback(); }
void GetVideoFramePresentationMetadata() {
wmpi_->GetVideoFramePresentationMetadata();
}
void UpdateFrameIfStale() { wmpi_->UpdateFrameIfStale(); }
void OnNewFramePresentedCallback() { wmpi_->OnNewFramePresentedCallback(); }
scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor() {
return wmpi_->GetCurrentFrameFromCompositor();
}
enum class LoadType { kFullyBuffered, kStreaming };
void Load(std::string data_file,
LoadType load_type = LoadType::kFullyBuffered) {
const bool is_streaming = load_type == LoadType::kStreaming;
// The URL is used by MultibufferDataSource to determine if it should assume
// the resource is fully buffered locally. We can use a fake one here since
// we're injecting the response artificially. It's value is unknown to the
// underlying demuxer.
const GURL kTestURL(std::string(is_streaming ? "http" : "file") +
"://example.com/sample.webm");
// This block sets up a fetch context which ultimately provides us a pointer
// to the WebAssociatedURLLoaderClient handed out by the DataSource after it
// requests loading of a resource. We then use that client as if we are the
// network stack and "serve" an in memory file to the DataSource.
blink::WebAssociatedURLLoaderClient* client = nullptr;
EXPECT_CALL(mock_resource_fetch_context_, CreateUrlLoader(_))
.WillRepeatedly(
Invoke([&client](const blink::WebAssociatedURLLoaderOptions&) {
auto a = std::make_unique<NiceMock<MockWebAssociatedURLLoader>>();
EXPECT_CALL(*a, LoadAsynchronously(_, _))
.WillRepeatedly(testing::SaveArg<1>(&client));
return a;
}));
wmpi_->Load(blink::WebMediaPlayer::kLoadTypeURL,
blink::WebMediaPlayerSource(blink::WebURL(kTestURL)),
blink::WebMediaPlayer::kCorsModeUnspecified,
/*is_cache_disabled=*/false);
base::RunLoop().RunUntilIdle();
// Load a real media file into memory.
scoped_refptr<DecoderBuffer> data = ReadTestDataFile(data_file);
// "Serve" the file to the DataSource. Note: We respond with 200 okay, which
// will prevent range requests or partial responses from being used. For
// streaming responses, we'll pretend we don't know the content length.
blink::WebURLResponse response(kTestURL);
response.SetHttpHeaderField(
blink::WebString::FromUTF8("Content-Length"),
blink::WebString::FromUTF8(
is_streaming ? "-1" : base::NumberToString(data->data_size())));
response.SetExpectedContentLength(is_streaming ? -1 : data->data_size());
response.SetHttpStatusCode(200);
client->DidReceiveResponse(response);
// Copy over the file data.
client->DidReceiveData(reinterpret_cast<const char*>(data->data()),
data->data_size());
// If we're pretending to be a streaming resource, don't complete the load;
// otherwise the DataSource will not be marked as streaming.
if (!is_streaming)
client->DidFinishLoading();
}
// This runs until we reach the |ready_state_|. Attempting to wait for ready
// states < kReadyStateHaveCurrentData in non-startup-suspend test cases is
// unreliable due to asynchronous execution of tasks on the
// base::test:TaskEnvironment.
void LoadAndWaitForReadyState(std::string data_file,
blink::WebMediaPlayer::ReadyState ready_state) {
Load(data_file);
while (wmpi_->GetReadyState() < ready_state) {
base::RunLoop loop;
EXPECT_CALL(client_, ReadyStateChanged())
.WillRepeatedly(RunClosure(loop.QuitClosure()));
loop.Run();
// Clear the mock so it doesn't have a stale QuitClosure.
testing::Mock::VerifyAndClearExpectations(&client_);
}
// Verify we made it through pipeline startup.
EXPECT_TRUE(wmpi_->data_source_);
EXPECT_TRUE(wmpi_->demuxer_);
if (ready_state > blink::WebMediaPlayer::kReadyStateHaveCurrentData)
EXPECT_FALSE(wmpi_->seeking_);
}
void LoadAndWaitForCurrentData(std::string data_file) {
LoadAndWaitForReadyState(data_file,
blink::WebMediaPlayer::kReadyStateHaveCurrentData);
}
void CycleThreads() {
// Ensure any tasks waiting to be posted to the media thread are posted.
base::RunLoop().RunUntilIdle();
// Flush all media tasks.
media_thread_.FlushForTesting();
// Cycle anything that was posted back from the media thread.
base::RunLoop().RunUntilIdle();
}
void OnProgress() { wmpi_->OnProgress(); }
void OnCdmCreated(base::RepeatingClosure quit_closure,
blink::WebContentDecryptionModule* cdm,
const std::string& error_message) {
LOG_IF(ERROR, !error_message.empty()) << error_message;
EXPECT_TRUE(cdm);
web_cdm_.reset(cdm);
quit_closure.Run();
}
void CreateCdm() {
// Must use a supported key system on a secure context.
auto key_system = base::ASCIIToUTF16("org.w3.clearkey");
auto test_origin = blink::WebSecurityOrigin::CreateFromString(
blink::WebString::FromUTF8("https://test.origin"));
base::RunLoop run_loop;
WebContentDecryptionModuleImpl::Create(
&mock_cdm_factory_, key_system, test_origin, CdmConfig(),
base::BindOnce(&WebMediaPlayerImplTest::OnCdmCreated,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
EXPECT_TRUE(web_cdm_);
}
void SetCdm() {
DCHECK(web_cdm_);
EXPECT_CALL(*mock_cdm_, GetCdmContext())
.WillRepeatedly(Return(&mock_cdm_context_));
wmpi_->SetCdmInternal(web_cdm_.get());
}
MemoryDumpProviderProxy* GetMainThreadMemDumper() {
return wmpi_->main_thread_mem_dumper_.get();
}
MemoryDumpProviderProxy* GetMediaThreadMemDumper() {
return wmpi_->media_thread_mem_dumper_.get();
}
int32_t GetMediaLogId() { return media_log_->id(); }
// "Media" thread. This is necessary because WMPI destruction waits on a
// WaitableEvent.
base::Thread media_thread_;
// Blink state.
blink::WebLocalFrameClient web_frame_client_;
blink::WebView* web_view_;
blink::WebLocalFrame* web_local_frame_;
scoped_refptr<viz::TestContextProvider> context_provider_;
NiceMock<MockVideoFrameCompositor>* compositor_;
scoped_refptr<NiceMock<MockAudioRendererSink>> audio_sink_;
MockResourceFetchContext mock_resource_fetch_context_;
std::unique_ptr<media::UrlIndex> url_index_;
// Audio hardware configuration.
AudioParameters audio_parameters_;
bool is_background_suspend_enabled_ = false;
bool is_background_video_playback_enabled_ = true;
// The client interface used by |wmpi_|.
NiceMock<MockWebMediaPlayerClient> client_;
MockWebMediaPlayerEncryptedMediaClient encrypted_client_;
// Used to create the MockCdm to test encrypted playback.
scoped_refptr<MockCdm> mock_cdm_{new MockCdm()};
MockCdmFactory mock_cdm_factory_{mock_cdm_};
std::unique_ptr<blink::WebContentDecryptionModule> web_cdm_;
MockCdmContext mock_cdm_context_;
viz::FrameSinkId frame_sink_id_ = viz::FrameSinkId(1, 1);
viz::LocalSurfaceId local_surface_id_ =
viz::LocalSurfaceId(11, base::UnguessableToken::Deserialize(0x111111, 0));
viz::SurfaceId surface_id_ =
viz::SurfaceId(frame_sink_id_, local_surface_id_);
NiceMock<MockWebMediaPlayerDelegate> delegate_;
// Use NiceMock since most tests do not care about this.
std::unique_ptr<NiceMock<MockSurfaceLayerBridge>> surface_layer_bridge_;
NiceMock<MockSurfaceLayerBridge>* surface_layer_bridge_ptr_ = nullptr;
// Only valid once set by InitializeWebMediaPlayerImpl(), this is for
// verifying a subset of potential media logs.
NiceMock<MockMediaLog>* media_log_ = nullptr;
// Total memory in bytes allocated by the WebMediaPlayerImpl instance.
int64_t reported_memory_ = 0;
// Raw pointer of the RendererFactorySelector owned by |wmpi_|.
RendererFactorySelector* renderer_factory_selector_ = nullptr;
// default decoder factory for WMPI
std::unique_ptr<DecoderFactory> decoder_factory_;
// The WebMediaPlayerImpl instance under test.
std::unique_ptr<WebMediaPlayerImpl> wmpi_;
std::unique_ptr<base::trace_event::MemoryDumpManager> memory_dump_manager_;
std::unique_ptr<blink::scheduler::WebAgentGroupScheduler>
agent_group_scheduler_;
private:
DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImplTest);
};
TEST_F(WebMediaPlayerImplTest, ConstructAndDestroy) {
InitializeWebMediaPlayerImpl();
EXPECT_FALSE(IsSuspended());
}
// Verify LoadAndWaitForCurrentData() functions without issue.
TEST_F(WebMediaPlayerImplTest, LoadAndDestroy) {
InitializeWebMediaPlayerImpl();
EXPECT_FALSE(IsSuspended());
wmpi_->SetPreload(blink::WebMediaPlayer::kPreloadAuto);
LoadAndWaitForCurrentData(kAudioOnlyTestFile);
EXPECT_FALSE(IsSuspended());
CycleThreads();
// The data source contains the entire file, so subtract it from the memory
// usage to ensure we're getting audio buffer and demuxer usage too.
const int64_t data_source_size = GetDataSourceMemoryUsage();
EXPECT_GT(data_source_size, 0);
EXPECT_GT(reported_memory_ - data_source_size, 0);
}
// Verify LoadAndWaitForCurrentData() functions without issue.
TEST_F(WebMediaPlayerImplTest, LoadAndDestroyDataUrl) {
InitializeWebMediaPlayerImpl();
EXPECT_FALSE(IsSuspended());
wmpi_->SetPreload(blink::WebMediaPlayer::kPreloadAuto);
const GURL kMp3DataUrl(
"data://audio/mp3;base64,SUQzAwAAAAAAFlRFTkMAAAAMAAAAQW1hZGV1cyBQcm//"
"+5DEAAAAAAAAAAAAAAAAAAAAAABYaW5nAAAADwAAAAwAAAftABwcHBwcHBwcMTExMTExMTFG"
"RkZGRkZGRlpaWlpaWlpaWm9vb29vb29vhISEhISEhISYmJiYmJiYmJitra2tra2trcLCwsLC"
"wsLC3t7e3t7e3t7e7+/v7+/v7+///////////"
"wAAADxMQU1FMy45OHIErwAAAAAudQAANCAkCK9BAAHMAAAHbZV/"
"jdYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/"
"+0DEAAABcAOH1AAAIhcbaLc80EgAAAAAAPAAAP/"
"0QfAAQdBwGBwf8AwGAgAAMBYxgxBgaTANj4NBIJgwVX+"
"jXKCAMFgC8LgBGBmB3KTAhAT8wIQFjATAWhyLf4TUFdHcW4WkdwwxdMT3EaJEeo4UknR8dww"
"wlxIj1RZJJ98S0khhhhiaPX/8LqO4YYS4kRhRhf/8nD2HsYj1HqZF4vf9YKiIKgqIlQAMA3/"
"kQAMHsToyV0cDdv/"
"7IMQHgEgUaSld4QAg1A0lde4cXDskP7w0MysiKzEUARMCEBQwLQPAwC8VADBwCsOwF+v///"
"6ydVW3tR1HNzg22xv+3Z9gAAOgA//"
"pg1gxGG0G6aJdDp5LCgnFycZmDJi0ADQhRrZGzKGQAqP//3t3Xe3pUv19yF6v7FIAAiMAb/"
"3/"
"+yDEAwBGpBsprn9gIN0NZOn9lFyAAGa1QaI6ZhLqtGY3QFgnJ4BlymYWTBYNQ4LcX88rfX/"
"1Yu+8WKLoSm09u7Fd1QADgbfwwBECUMBpB+TDDGAUySsMLO80jP18xowMNGTBgotYkm3gPv/"
"/6P1v2pspRShZJjXgT7V1AAAoAG/9//"
"sgxAMCxzRpKa9k5KDODOUR7ihciAAsEwYdoVZqATrn1uJSYowIBg9gKn0MboJlBF3Fh4YAfX"
"//9+52v6qhZt7o244rX/JfRoADB+B5MPsQ401sRj4pGKOeGUzuJDGwHEhUhAvBuMNAM1b//"
"t9kSl70NlDrbJecU/t99aoAACMAD//7IMQCggY0Gymuf2Ag7A0k9f2UXPwAAGaFSZ/"
"7BhFSu4Yy2FjHCYZlKoYQTiEMTLaGxV5nNu/8UddjmtWbl6r/SYAN/pAADACAI8wHQHwMM/"
"XrDJuAv48nRNEXDHS8w4YMJCy0aSDbgm3//26S0noiIgkPfZn1Sa9V16dNAAAgAA//"
"+yDEAoBHCGkpr2SkoMgDZXW/cAT4iAA8FEYeASxqGx/H20IYYpYHJg+AHH2GbgBlgl/"
"1yQ2AFP///YpK32okeasc/f/+xXsAAJ1AA/"
"9Ntaj1Pc0K7Yzw6FrOHlozEHzFYEEg6NANZbIn9a8p//j7HC6VvlmStt3o+pUAACMADfyA//"
"sgxAOCRkwbKa5/YCDUDWU1/ZxcAGZVQZ27Zg/KweYuMFmm74hkSqYKUCINS0ZoxZ5XOv/"
"8X7EgE4lCZDu7fc4AN/6BQHQwG0GpMMAUczI/wpM7iuM9TTGCQwsRMEBi8Cl7yAnv//"
"2+belL59SGkk1ENqvyagAAKAAP/aAAEBGmGv/"
"7IMQGAobYaSuvcOLgzA1lNe4cXGDeaOzj56RhnnIBMZrA4GMAKF4GBCJjK4gC+v///"
"uh3b1WWRQNv2e/syS7ABAADCACBMPUSw0sNqj23G4OZHMzmKjGgLDBMkAzxpMNAE1b///"
"od72VdCOtlpw1/764AAhwAf/0AAGUkeZb0Bgz/"
"+yDEB4CGMBsrrn9gINgNJXX9qFxCcAYkOE7GsVJi6QBCEZCEEav2owqE3f4+KbGKLWKN29/"
"YsAAC0AUAARAL5gMgLQYWGjRGQkBGh1MmZseGKjpgwUYCBoprUgcDlG//7372tX0y/"
"zl33dN2ugIf/yIADoERhDlqm9CtAfsRzhlK//"
"tAxAoAB7RpKPXhACHRkia3PPAAEkGL4EUFgCTA3BTMDkAcEgMgoCeefz/////"
"oxOy73ryRx97nI2//YryIAhX0mveu/"
"3tEgAAAABh2nnnBAAOYOK6ZtxB4mEYkiaDwX5gzgHGAkAUYGwB0kMGQFaKGBEAwDgHAUAcvP"
"KwDfJeHEGqcMk3iN5blKocU8c6FA4FxhTqXf/OtXzv37ErkOYWXP/"
"93kTV91+YNo3Lh8ECwliUABv7/"
"+xDEAYPIREMrXcMAKAAAP8AAAARfwAADHinN1RU5NKTjkHN1Mc08dTJQjL4GBwgYEAK/"
"X2a8/1qZjMtcFCUTiSXmteUeFNBWIqEKCioLiKyO10VVTEFNRTMuOTguMlVVVVVVVVVVVf/"
"7EMQJg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
"VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVEFHAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAP8=");
wmpi_->Load(blink::WebMediaPlayer::kLoadTypeURL,
blink::WebMediaPlayerSource(blink::WebURL(kMp3DataUrl)),
blink::WebMediaPlayer::kCorsModeUnspecified,
/*is_cache_disabled=*/false);
base::RunLoop().RunUntilIdle();
// This runs until we reach the have current data state. Attempting to wait
// for states < kReadyStateHaveCurrentData is unreliable due to asynchronous
// execution of tasks on the base::test:TaskEnvironment.
while (wmpi_->GetReadyState() <
blink::WebMediaPlayer::kReadyStateHaveCurrentData) {
base::RunLoop loop;
EXPECT_CALL(client_, ReadyStateChanged())
.WillRepeatedly(RunClosure(loop.QuitClosure()));
loop.Run();
// Clear the mock so it doesn't have a stale QuitClosure.
testing::Mock::VerifyAndClearExpectations(&client_);
}
EXPECT_FALSE(IsSuspended());
CycleThreads();
}
// Verify that preload=metadata suspend works properly.
TEST_F(WebMediaPlayerImplTest, LoadPreloadMetadataSuspend) {
InitializeWebMediaPlayerImpl();
EXPECT_CALL(client_, CouldPlayIfEnoughData()).WillRepeatedly(Return(false));
wmpi_->SetPreload(blink::WebMediaPlayer::kPreloadMetaData);
LoadAndWaitForReadyState(kAudioOnlyTestFile,
blink::WebMediaPlayer::kReadyStateHaveMetadata);