55package io .flutter .plugins .videoplayer ;
66
77import static org .junit .Assert .assertEquals ;
8+ import static org .mockito .Mockito .any ;
89import static org .mockito .Mockito .mock ;
10+ import static org .mockito .Mockito .never ;
11+ import static org .mockito .Mockito .spy ;
912import static org .mockito .Mockito .verify ;
1013import static org .mockito .Mockito .when ;
1114
1215import com .google .android .exoplayer2 .ExoPlayer ;
1316import com .google .android .exoplayer2 .Format ;
17+ import com .google .android .exoplayer2 .upstream .DefaultHttpDataSource ;
1418import io .flutter .plugin .common .EventChannel ;
1519import io .flutter .view .TextureRegistry ;
1620import java .util .HashMap ;
21+ import java .util .Map ;
1722import org .junit .Before ;
1823import org .junit .Test ;
1924import org .junit .runner .RunWith ;
@@ -29,6 +34,7 @@ public class VideoPlayerTest {
2934 private TextureRegistry .SurfaceTextureEntry fakeSurfaceTextureEntry ;
3035 private VideoPlayerOptions fakeVideoPlayerOptions ;
3136 private QueuingEventSink fakeEventSink ;
37+ private DefaultHttpDataSource .Factory httpDataSourceFactorySpy ;
3238
3339 @ Captor private ArgumentCaptor <HashMap <String , Object >> eventCaptor ;
3440
@@ -41,6 +47,76 @@ public void before() {
4147 fakeSurfaceTextureEntry = mock (TextureRegistry .SurfaceTextureEntry .class );
4248 fakeVideoPlayerOptions = mock (VideoPlayerOptions .class );
4349 fakeEventSink = mock (QueuingEventSink .class );
50+ httpDataSourceFactorySpy = spy (new DefaultHttpDataSource .Factory ());
51+ }
52+
53+ @ Test
54+ public void videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNull () {
55+ VideoPlayer videoPlayer =
56+ new VideoPlayer (
57+ fakeExoPlayer ,
58+ fakeEventChannel ,
59+ fakeSurfaceTextureEntry ,
60+ fakeVideoPlayerOptions ,
61+ fakeEventSink ,
62+ httpDataSourceFactorySpy );
63+
64+ videoPlayer .buildHttpDataSourceFactory (new HashMap <>());
65+
66+ verify (httpDataSourceFactorySpy ).setUserAgent ("ExoPlayer" );
67+ verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
68+ verify (httpDataSourceFactorySpy , never ()).setDefaultRequestProperties (any ());
69+ }
70+
71+ @ Test
72+ public void
73+ videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNonNullAndUserAgentSpecified () {
74+ VideoPlayer videoPlayer =
75+ new VideoPlayer (
76+ fakeExoPlayer ,
77+ fakeEventChannel ,
78+ fakeSurfaceTextureEntry ,
79+ fakeVideoPlayerOptions ,
80+ fakeEventSink ,
81+ httpDataSourceFactorySpy );
82+ Map <String , String > httpHeaders =
83+ new HashMap <String , String >() {
84+ {
85+ put ("header" , "value" );
86+ put ("User-Agent" , "userAgent" );
87+ }
88+ };
89+
90+ videoPlayer .buildHttpDataSourceFactory (httpHeaders );
91+
92+ verify (httpDataSourceFactorySpy ).setUserAgent ("userAgent" );
93+ verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
94+ verify (httpDataSourceFactorySpy ).setDefaultRequestProperties (httpHeaders );
95+ }
96+
97+ @ Test
98+ public void
99+ videoPlayer_buildsHttpDataSourceFactoryProperlyWhenHttpHeadersNonNullAndUserAgentNotSpecified () {
100+ VideoPlayer videoPlayer =
101+ new VideoPlayer (
102+ fakeExoPlayer ,
103+ fakeEventChannel ,
104+ fakeSurfaceTextureEntry ,
105+ fakeVideoPlayerOptions ,
106+ fakeEventSink ,
107+ httpDataSourceFactorySpy );
108+ Map <String , String > httpHeaders =
109+ new HashMap <String , String >() {
110+ {
111+ put ("header" , "value" );
112+ }
113+ };
114+
115+ videoPlayer .buildHttpDataSourceFactory (httpHeaders );
116+
117+ verify (httpDataSourceFactorySpy ).setUserAgent ("ExoPlayer" );
118+ verify (httpDataSourceFactorySpy ).setAllowCrossProtocolRedirects (true );
119+ verify (httpDataSourceFactorySpy ).setDefaultRequestProperties (httpHeaders );
44120 }
45121
46122 @ Test
@@ -51,7 +127,8 @@ public void sendInitializedSendsExpectedEvent_90RotationDegrees() {
51127 fakeEventChannel ,
52128 fakeSurfaceTextureEntry ,
53129 fakeVideoPlayerOptions ,
54- fakeEventSink );
130+ fakeEventSink ,
131+ httpDataSourceFactorySpy );
55132 Format testFormat =
56133 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (90 ).build ();
57134
@@ -79,7 +156,8 @@ public void sendInitializedSendsExpectedEvent_270RotationDegrees() {
79156 fakeEventChannel ,
80157 fakeSurfaceTextureEntry ,
81158 fakeVideoPlayerOptions ,
82- fakeEventSink );
159+ fakeEventSink ,
160+ httpDataSourceFactorySpy );
83161 Format testFormat =
84162 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (270 ).build ();
85163
@@ -107,7 +185,8 @@ public void sendInitializedSendsExpectedEvent_0RotationDegrees() {
107185 fakeEventChannel ,
108186 fakeSurfaceTextureEntry ,
109187 fakeVideoPlayerOptions ,
110- fakeEventSink );
188+ fakeEventSink ,
189+ httpDataSourceFactorySpy );
111190 Format testFormat =
112191 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (0 ).build ();
113192
@@ -135,7 +214,8 @@ public void sendInitializedSendsExpectedEvent_180RotationDegrees() {
135214 fakeEventChannel ,
136215 fakeSurfaceTextureEntry ,
137216 fakeVideoPlayerOptions ,
138- fakeEventSink );
217+ fakeEventSink ,
218+ httpDataSourceFactorySpy );
139219 Format testFormat =
140220 new Format .Builder ().setWidth (100 ).setHeight (200 ).setRotationDegrees (180 ).build ();
141221
0 commit comments