1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/message_loop/message_loop.h"
7 #include "content/public/common/url_constants.h"
8 #include "content/renderer/media/buffered_data_source.h"
9 #include "content/renderer/media/test_response_generator.h"
10 #include "content/test/mock_webframeclient.h"
11 #include "content/test/mock_weburlloader.h"
12 #include "media/base/media_log.h"
13 #include "media/base/mock_filters.h"
14 #include "media/base/test_helpers.h"
15 #include "third_party/WebKit/public/platform/WebURLResponse.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h"
17 #include "third_party/WebKit/public/web/WebView.h"
20 using ::testing::Assign
;
21 using ::testing::Invoke
;
22 using ::testing::InSequence
;
23 using ::testing::NiceMock
;
24 using ::testing::StrictMock
;
26 using blink::WebLocalFrame
;
27 using blink::WebString
;
28 using blink::WebURLLoader
;
29 using blink::WebURLResponse
;
34 class MockBufferedDataSourceHost
: public BufferedDataSourceHost
{
36 MockBufferedDataSourceHost() {}
37 virtual ~MockBufferedDataSourceHost() {}
39 MOCK_METHOD1(SetTotalBytes
, void(int64 total_bytes
));
40 MOCK_METHOD2(AddBufferedByteRange
, void(int64 start
, int64 end
));
43 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost
);
46 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader.
47 // Also keeps track of whether said MockWebURLLoader is actively loading.
48 class MockBufferedDataSource
: public BufferedDataSource
{
50 MockBufferedDataSource(
52 const scoped_refptr
<base::MessageLoopProxy
>& message_loop
,
54 BufferedDataSourceHost
* host
)
55 : BufferedDataSource(url
,
56 BufferedResourceLoader::kUnspecified
,
59 new media::MediaLog(),
61 base::Bind(&MockBufferedDataSource::set_downloading
,
62 base::Unretained(this))),
65 virtual ~MockBufferedDataSource() {}
67 MOCK_METHOD2(CreateResourceLoader
, BufferedResourceLoader
*(int64
, int64
));
68 BufferedResourceLoader
* CreateMockResourceLoader(int64 first_byte_position
,
69 int64 last_byte_position
) {
70 CHECK(!loading_
) << "Previous resource load wasn't cancelled";
72 BufferedResourceLoader
* loader
=
73 BufferedDataSource::CreateResourceLoader(first_byte_position
,
76 // Keep track of active loading state via loadAsynchronously() and cancel().
77 NiceMock
<MockWebURLLoader
>* url_loader
= new NiceMock
<MockWebURLLoader
>();
78 ON_CALL(*url_loader
, loadAsynchronously(_
, _
))
79 .WillByDefault(Assign(&loading_
, true));
80 ON_CALL(*url_loader
, cancel())
81 .WillByDefault(Assign(&loading_
, false));
83 // |test_loader_| will be used when Start() is called.
84 loader
->test_loader_
= scoped_ptr
<WebURLLoader
>(url_loader
);
88 bool loading() { return loading_
; }
89 void set_loading(bool loading
) { loading_
= loading
; }
90 bool downloading() { return downloading_
; }
91 void set_downloading(bool downloading
) { downloading_
= downloading
; }
94 // Whether the resource is downloading or deferred.
97 // Whether the resource load has starting loading but yet to been cancelled.
100 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource
);
103 static const int64 kFileSize
= 5000000;
104 static const int64 kFarReadPosition
= 4000000;
105 static const int kDataSize
= 1024;
107 static const char kHttpUrl
[] = "http://localhost/foo.webm";
108 static const char kFileUrl
[] = "file:///tmp/bar.webm";
110 class BufferedDataSourceTest
: public testing::Test
{
112 BufferedDataSourceTest()
113 : view_(WebView::create(NULL
)),
114 frame_(WebLocalFrame::create(&client_
)),
116 view_
->setMainFrame(frame_
);
119 virtual ~BufferedDataSourceTest() {
124 MOCK_METHOD1(OnInitialize
, void(bool));
126 void Initialize(const char* url
, bool expected
) {
129 new MockBufferedDataSource(gurl
,
130 message_loop_
.message_loop_proxy(),
131 view_
->mainFrame()->toWebLocalFrame(),
133 data_source_
->SetPreload(preload_
);
135 response_generator_
.reset(new TestResponseGenerator(gurl
, kFileSize
));
136 ExpectCreateResourceLoader();
137 EXPECT_CALL(*this, OnInitialize(expected
));
138 data_source_
->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize
,
139 base::Unretained(this)));
140 message_loop_
.RunUntilIdle();
142 bool is_http
= gurl
.SchemeIsHTTPOrHTTPS();
143 EXPECT_EQ(data_source_
->downloading(), is_http
);
146 // Helper to initialize tests with a valid 200 response.
147 void InitializeWith200Response() {
148 Initialize(kHttpUrl
, true);
150 EXPECT_CALL(host_
, SetTotalBytes(response_generator_
->content_length()));
151 Respond(response_generator_
->Generate200());
154 // Helper to initialize tests with a valid 206 response.
155 void InitializeWith206Response() {
156 Initialize(kHttpUrl
, true);
158 EXPECT_CALL(host_
, SetTotalBytes(response_generator_
->content_length()));
159 Respond(response_generator_
->Generate206(0));
162 // Helper to initialize tests with a valid file:// response.
163 void InitializeWithFileResponse() {
164 Initialize(kFileUrl
, true);
166 EXPECT_CALL(host_
, SetTotalBytes(kFileSize
));
167 EXPECT_CALL(host_
, AddBufferedByteRange(0, kFileSize
));
168 Respond(response_generator_
->GenerateFileResponse(0));
171 // Stops any active loaders and shuts down the data source.
173 // This typically happens when the page is closed and for our purposes is
174 // appropriate to do when tearing down a test.
176 if (data_source_
->loading()) {
177 loader()->didFail(url_loader(), response_generator_
->GenerateError());
178 message_loop_
.RunUntilIdle();
181 data_source_
->Stop();
182 message_loop_
.RunUntilIdle();
185 void ExpectCreateResourceLoader() {
186 EXPECT_CALL(*data_source_
, CreateResourceLoader(_
, _
))
187 .WillOnce(Invoke(data_source_
.get(),
188 &MockBufferedDataSource::CreateMockResourceLoader
));
189 message_loop_
.RunUntilIdle();
192 void Respond(const WebURLResponse
& response
) {
193 loader()->didReceiveResponse(url_loader(), response
);
194 message_loop_
.RunUntilIdle();
197 void ReceiveData(int size
) {
198 scoped_ptr
<char[]> data(new char[size
]);
199 memset(data
.get(), 0xA5, size
); // Arbitrary non-zero value.
201 loader()->didReceiveData(url_loader(), data
.get(), size
, size
);
202 message_loop_
.RunUntilIdle();
205 void FinishLoading() {
206 data_source_
->set_loading(false);
207 loader()->didFinishLoading(url_loader(), 0, -1);
208 message_loop_
.RunUntilIdle();
211 MOCK_METHOD1(ReadCallback
, void(int size
));
213 void ReadAt(int64 position
) {
214 data_source_
->Read(position
, kDataSize
, buffer_
,
215 base::Bind(&BufferedDataSourceTest::ReadCallback
,
216 base::Unretained(this)));
217 message_loop_
.RunUntilIdle();
220 // Accessors for private variables on |data_source_|.
221 BufferedResourceLoader
* loader() {
222 return data_source_
->loader_
.get();
224 WebURLLoader
* url_loader() {
225 return loader()->active_loader_
->loader_
.get();
228 Preload
preload() { return data_source_
->preload_
; }
229 void set_preload(Preload preload
) { preload_
= preload
; }
230 BufferedResourceLoader::DeferStrategy
defer_strategy() {
231 return loader()->defer_strategy_
;
233 int data_source_bitrate() { return data_source_
->bitrate_
; }
234 int data_source_playback_rate() { return data_source_
->playback_rate_
; }
235 int loader_bitrate() { return loader()->bitrate_
; }
236 int loader_playback_rate() { return loader()->playback_rate_
; }
237 bool is_local_source() { return data_source_
->assume_fully_buffered(); }
238 void set_might_be_reused_from_cache_in_future(bool value
) {
239 loader()->might_be_reused_from_cache_in_future_
= value
;
242 scoped_ptr
<MockBufferedDataSource
> data_source_
;
244 scoped_ptr
<TestResponseGenerator
> response_generator_
;
245 MockWebFrameClient client_
;
247 WebLocalFrame
* frame_
;
249 StrictMock
<MockBufferedDataSourceHost
> host_
;
250 base::MessageLoop message_loop_
;
253 // Used for calling BufferedDataSource::Read().
254 uint8 buffer_
[kDataSize
];
258 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest
);
261 TEST_F(BufferedDataSourceTest
, Range_Supported
) {
262 InitializeWith206Response();
264 EXPECT_TRUE(data_source_
->loading());
265 EXPECT_FALSE(data_source_
->IsStreaming());
269 TEST_F(BufferedDataSourceTest
, Range_InstanceSizeUnknown
) {
270 Initialize(kHttpUrl
, true);
272 Respond(response_generator_
->Generate206(
273 0, TestResponseGenerator::kNoContentRangeInstanceSize
));
275 EXPECT_TRUE(data_source_
->loading());
276 EXPECT_TRUE(data_source_
->IsStreaming());
280 TEST_F(BufferedDataSourceTest
, Range_NotFound
) {
281 Initialize(kHttpUrl
, false);
282 Respond(response_generator_
->Generate404());
284 EXPECT_FALSE(data_source_
->loading());
288 TEST_F(BufferedDataSourceTest
, Range_NotSupported
) {
289 InitializeWith200Response();
291 EXPECT_TRUE(data_source_
->loading());
292 EXPECT_TRUE(data_source_
->IsStreaming());
296 // Special carve-out for Apache versions that choose to return a 200 for
297 // Range:0- ("because it's more efficient" than a 206)
298 TEST_F(BufferedDataSourceTest
, Range_SupportedButReturned200
) {
299 Initialize(kHttpUrl
, true);
300 EXPECT_CALL(host_
, SetTotalBytes(response_generator_
->content_length()));
301 WebURLResponse response
= response_generator_
->Generate200();
302 response
.setHTTPHeaderField(WebString::fromUTF8("Accept-Ranges"),
303 WebString::fromUTF8("bytes"));
306 EXPECT_TRUE(data_source_
->loading());
307 EXPECT_FALSE(data_source_
->IsStreaming());
311 TEST_F(BufferedDataSourceTest
, Range_MissingContentRange
) {
312 Initialize(kHttpUrl
, false);
313 Respond(response_generator_
->Generate206(
314 0, TestResponseGenerator::kNoContentRange
));
316 EXPECT_FALSE(data_source_
->loading());
320 TEST_F(BufferedDataSourceTest
, Range_MissingContentLength
) {
321 Initialize(kHttpUrl
, true);
323 // It'll manage without a Content-Length response.
324 EXPECT_CALL(host_
, SetTotalBytes(response_generator_
->content_length()));
325 Respond(response_generator_
->Generate206(
326 0, TestResponseGenerator::kNoContentLength
));
328 EXPECT_TRUE(data_source_
->loading());
329 EXPECT_FALSE(data_source_
->IsStreaming());
333 TEST_F(BufferedDataSourceTest
, Range_WrongContentRange
) {
334 Initialize(kHttpUrl
, false);
336 // Now it's done and will fail.
337 Respond(response_generator_
->Generate206(1337));
339 EXPECT_FALSE(data_source_
->loading());
343 // Test the case where the initial response from the server indicates that
344 // Range requests are supported, but a later request prove otherwise.
345 TEST_F(BufferedDataSourceTest
, Range_ServerLied
) {
346 InitializeWith206Response();
348 // Read causing a new request to be made -- we'll expect it to error.
349 ExpectCreateResourceLoader();
350 ReadAt(kFarReadPosition
);
352 // Return a 200 in response to a range request.
353 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
354 Respond(response_generator_
->Generate200());
356 EXPECT_FALSE(data_source_
->loading());
360 TEST_F(BufferedDataSourceTest
, Http_AbortWhileReading
) {
361 InitializeWith206Response();
363 // Make sure there's a pending read -- we'll expect it to error.
367 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
368 data_source_
->Abort();
369 message_loop_
.RunUntilIdle();
371 EXPECT_FALSE(data_source_
->loading());
375 TEST_F(BufferedDataSourceTest
, File_AbortWhileReading
) {
376 InitializeWithFileResponse();
378 // Make sure there's a pending read -- we'll expect it to error.
382 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
383 data_source_
->Abort();
384 message_loop_
.RunUntilIdle();
386 EXPECT_FALSE(data_source_
->loading());
390 TEST_F(BufferedDataSourceTest
, Http_Retry
) {
391 InitializeWith206Response();
393 // Read to advance our position.
394 EXPECT_CALL(*this, ReadCallback(kDataSize
));
395 EXPECT_CALL(host_
, AddBufferedByteRange(0, kDataSize
- 1));
397 ReceiveData(kDataSize
);
399 // Issue a pending read but terminate the connection to force a retry.
401 ExpectCreateResourceLoader();
403 Respond(response_generator_
->Generate206(kDataSize
));
405 // Complete the read.
406 EXPECT_CALL(*this, ReadCallback(kDataSize
));
407 EXPECT_CALL(host_
, AddBufferedByteRange(kDataSize
, (kDataSize
* 2) - 1));
408 ReceiveData(kDataSize
);
410 EXPECT_TRUE(data_source_
->loading());
414 TEST_F(BufferedDataSourceTest
, File_Retry
) {
415 InitializeWithFileResponse();
417 // Read to advance our position.
418 EXPECT_CALL(*this, ReadCallback(kDataSize
));
420 ReceiveData(kDataSize
);
422 // Issue a pending read but terminate the connection to force a retry.
424 ExpectCreateResourceLoader();
426 Respond(response_generator_
->GenerateFileResponse(kDataSize
));
428 // Complete the read.
429 EXPECT_CALL(*this, ReadCallback(kDataSize
));
430 ReceiveData(kDataSize
);
432 EXPECT_TRUE(data_source_
->loading());
436 TEST_F(BufferedDataSourceTest
, Http_TooManyRetries
) {
437 InitializeWith206Response();
439 // Make sure there's a pending read -- we'll expect it to error.
442 // It'll try three times.
443 ExpectCreateResourceLoader();
445 Respond(response_generator_
->Generate206(0));
447 ExpectCreateResourceLoader();
449 Respond(response_generator_
->Generate206(0));
451 ExpectCreateResourceLoader();
453 Respond(response_generator_
->Generate206(0));
455 // It'll error after this.
456 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
459 EXPECT_FALSE(data_source_
->loading());
463 TEST_F(BufferedDataSourceTest
, File_TooManyRetries
) {
464 InitializeWithFileResponse();
466 // Make sure there's a pending read -- we'll expect it to error.
469 // It'll try three times.
470 ExpectCreateResourceLoader();
472 Respond(response_generator_
->GenerateFileResponse(0));
474 ExpectCreateResourceLoader();
476 Respond(response_generator_
->GenerateFileResponse(0));
478 ExpectCreateResourceLoader();
480 Respond(response_generator_
->GenerateFileResponse(0));
482 // It'll error after this.
483 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
486 EXPECT_FALSE(data_source_
->loading());
490 TEST_F(BufferedDataSourceTest
, File_InstanceSizeUnknown
) {
491 Initialize(kFileUrl
, false);
492 EXPECT_FALSE(data_source_
->downloading());
494 Respond(response_generator_
->GenerateFileResponse(-1));
496 EXPECT_FALSE(data_source_
->loading());
500 TEST_F(BufferedDataSourceTest
, File_Successful
) {
501 InitializeWithFileResponse();
503 EXPECT_TRUE(data_source_
->loading());
504 EXPECT_FALSE(data_source_
->IsStreaming());
508 TEST_F(BufferedDataSourceTest
, StopDuringRead
) {
509 InitializeWith206Response();
512 data_source_
->Read(0, arraysize(buffer
), buffer
, base::Bind(
513 &BufferedDataSourceTest::ReadCallback
, base::Unretained(this)));
515 // The outstanding read should fail before the stop callback runs.
518 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
519 data_source_
->Stop();
521 message_loop_
.RunUntilIdle();
524 TEST_F(BufferedDataSourceTest
, DefaultValues
) {
525 InitializeWith206Response();
527 // Ensure we have sane values for default loading scenario.
528 EXPECT_EQ(AUTO
, preload());
529 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
531 EXPECT_EQ(0, data_source_bitrate());
532 EXPECT_EQ(0.0f
, data_source_playback_rate());
533 EXPECT_EQ(0, loader_bitrate());
534 EXPECT_EQ(0.0f
, loader_playback_rate());
536 EXPECT_TRUE(data_source_
->loading());
540 TEST_F(BufferedDataSourceTest
, SetBitrate
) {
541 InitializeWith206Response();
543 data_source_
->SetBitrate(1234);
544 message_loop_
.RunUntilIdle();
545 EXPECT_EQ(1234, data_source_bitrate());
546 EXPECT_EQ(1234, loader_bitrate());
548 // Read so far ahead to cause the loader to get recreated.
549 BufferedResourceLoader
* old_loader
= loader();
550 ExpectCreateResourceLoader();
551 ReadAt(kFarReadPosition
);
552 Respond(response_generator_
->Generate206(kFarReadPosition
));
554 // Verify loader changed but still has same bitrate.
555 EXPECT_NE(old_loader
, loader());
556 EXPECT_EQ(1234, loader_bitrate());
558 EXPECT_TRUE(data_source_
->loading());
559 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
563 TEST_F(BufferedDataSourceTest
, MediaPlaybackRateChanged
) {
564 InitializeWith206Response();
566 data_source_
->MediaPlaybackRateChanged(2.0f
);
567 message_loop_
.RunUntilIdle();
568 EXPECT_EQ(2.0f
, data_source_playback_rate());
569 EXPECT_EQ(2.0f
, loader_playback_rate());
571 // Read so far ahead to cause the loader to get recreated.
572 BufferedResourceLoader
* old_loader
= loader();
573 ExpectCreateResourceLoader();
574 ReadAt(kFarReadPosition
);
575 Respond(response_generator_
->Generate206(kFarReadPosition
));
577 // Verify loader changed but still has same playback rate.
578 EXPECT_NE(old_loader
, loader());
580 EXPECT_TRUE(data_source_
->loading());
581 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError
));
585 TEST_F(BufferedDataSourceTest
, Http_Read
) {
586 InitializeWith206Response();
590 // Receive first half of the read.
591 EXPECT_CALL(host_
, AddBufferedByteRange(0, (kDataSize
/ 2) - 1));
592 ReceiveData(kDataSize
/ 2);
594 // Receive last half of the read.
595 EXPECT_CALL(*this, ReadCallback(kDataSize
));
596 EXPECT_CALL(host_
, AddBufferedByteRange(0, kDataSize
- 1));
597 ReceiveData(kDataSize
/ 2);
599 EXPECT_TRUE(data_source_
->downloading());
603 TEST_F(BufferedDataSourceTest
, Http_Read_Seek
) {
604 InitializeWith206Response();
606 // Read a bit from the beginning.
608 EXPECT_CALL(*this, ReadCallback(kDataSize
));
609 EXPECT_CALL(host_
, AddBufferedByteRange(0, kDataSize
- 1));
610 ReceiveData(kDataSize
);
612 // Simulate a seek by reading a bit beyond kDataSize.
613 ReadAt(kDataSize
* 2);
615 // We receive data leading up to but not including our read.
616 EXPECT_CALL(host_
, AddBufferedByteRange(0, kDataSize
* 2 - 1));
617 ReceiveData(kDataSize
);
619 // We now receive the rest of the data for our read.
620 EXPECT_CALL(*this, ReadCallback(kDataSize
));
621 EXPECT_CALL(host_
, AddBufferedByteRange(0, kDataSize
* 3 - 1));
622 ReceiveData(kDataSize
);
624 EXPECT_TRUE(data_source_
->downloading());
628 TEST_F(BufferedDataSourceTest
, File_Read
) {
629 InitializeWithFileResponse();
633 // Receive first half of the read but no buffering update.
634 ReceiveData(kDataSize
/ 2);
636 // Receive last half of the read but no buffering update.
637 EXPECT_CALL(*this, ReadCallback(kDataSize
));
638 ReceiveData(kDataSize
/ 2);
643 TEST_F(BufferedDataSourceTest
, Http_FinishLoading
) {
644 InitializeWith206Response();
646 EXPECT_TRUE(data_source_
->downloading());
648 EXPECT_FALSE(data_source_
->downloading());
653 TEST_F(BufferedDataSourceTest
, File_FinishLoading
) {
654 InitializeWithFileResponse();
656 EXPECT_FALSE(data_source_
->downloading());
658 EXPECT_FALSE(data_source_
->downloading());
663 TEST_F(BufferedDataSourceTest
, LocalResource_DeferStrategy
) {
664 InitializeWithFileResponse();
666 EXPECT_EQ(AUTO
, preload());
667 EXPECT_TRUE(is_local_source());
668 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
670 data_source_
->MediaIsPlaying();
671 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
673 data_source_
->MediaIsPaused();
674 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
679 TEST_F(BufferedDataSourceTest
, LocalResource_PreloadMetadata_DeferStrategy
) {
680 set_preload(METADATA
);
681 InitializeWithFileResponse();
683 EXPECT_EQ(METADATA
, preload());
684 EXPECT_TRUE(is_local_source());
685 EXPECT_EQ(BufferedResourceLoader::kReadThenDefer
, defer_strategy());
687 data_source_
->MediaIsPlaying();
688 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
690 data_source_
->MediaIsPaused();
691 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
696 TEST_F(BufferedDataSourceTest
, ExternalResource_Reponse200_DeferStrategy
) {
697 InitializeWith200Response();
699 EXPECT_EQ(AUTO
, preload());
700 EXPECT_FALSE(is_local_source());
701 EXPECT_FALSE(loader()->range_supported());
702 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
704 data_source_
->MediaIsPlaying();
705 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
707 data_source_
->MediaIsPaused();
708 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
713 TEST_F(BufferedDataSourceTest
,
714 ExternalResource_Response200_PreloadMetadata_DeferStrategy
) {
715 set_preload(METADATA
);
716 InitializeWith200Response();
718 EXPECT_EQ(METADATA
, preload());
719 EXPECT_FALSE(is_local_source());
720 EXPECT_FALSE(loader()->range_supported());
721 EXPECT_EQ(BufferedResourceLoader::kReadThenDefer
, defer_strategy());
723 data_source_
->MediaIsPlaying();
724 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
726 data_source_
->MediaIsPaused();
727 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
732 TEST_F(BufferedDataSourceTest
, ExternalResource_Reponse206_DeferStrategy
) {
733 InitializeWith206Response();
735 EXPECT_EQ(AUTO
, preload());
736 EXPECT_FALSE(is_local_source());
737 EXPECT_TRUE(loader()->range_supported());
738 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
740 data_source_
->MediaIsPlaying();
741 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
742 set_might_be_reused_from_cache_in_future(true);
743 data_source_
->MediaIsPaused();
744 EXPECT_EQ(BufferedResourceLoader::kNeverDefer
, defer_strategy());
746 data_source_
->MediaIsPlaying();
747 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
748 set_might_be_reused_from_cache_in_future(false);
749 data_source_
->MediaIsPaused();
750 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
755 TEST_F(BufferedDataSourceTest
,
756 ExternalResource_Response206_PreloadMetadata_DeferStrategy
) {
757 set_preload(METADATA
);
758 InitializeWith206Response();
760 EXPECT_EQ(METADATA
, preload());
761 EXPECT_FALSE(is_local_source());
762 EXPECT_TRUE(loader()->range_supported());
763 EXPECT_EQ(BufferedResourceLoader::kReadThenDefer
, defer_strategy());
765 data_source_
->MediaIsPlaying();
766 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
767 set_might_be_reused_from_cache_in_future(true);
768 data_source_
->MediaIsPaused();
769 EXPECT_EQ(BufferedResourceLoader::kNeverDefer
, defer_strategy());
771 data_source_
->MediaIsPlaying();
772 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
773 set_might_be_reused_from_cache_in_future(false);
774 data_source_
->MediaIsPaused();
775 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer
, defer_strategy());
780 } // namespace content