Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1579)

Unified Diff: media/blink/buffered_data_source_host_impl_unittest.cc

Issue 2796193002: fix canplaythrough (Closed)
Patch Set: kSpecCompliantCanPlayThrough Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/buffered_data_source_host_impl.cc ('k') | media/blink/webmediaplayer_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/buffered_data_source_host_impl_unittest.cc
diff --git a/media/blink/buffered_data_source_host_impl_unittest.cc b/media/blink/buffered_data_source_host_impl_unittest.cc
index 54ecf75c3b6ea6652d8af115800b0d502a868bbc..b6717d52ac0287b994b44209fc1e409879ef3e99 100644
--- a/media/blink/buffered_data_source_host_impl_unittest.cc
+++ b/media/blink/buffered_data_source_host_impl_unittest.cc
@@ -2,23 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/macros.h"
#include "media/blink/buffered_data_source_host_impl.h"
+
+#include "base/bind.h"
+#include "base/macros.h"
+#include "base/test/simple_test_tick_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class BufferedDataSourceHostImplTest : public testing::Test {
public:
- BufferedDataSourceHostImplTest() {}
+ BufferedDataSourceHostImplTest()
+ : host_(base::Bind(&BufferedDataSourceHostImplTest::ProgressCallback,
+ base::Unretained(this)),
+ &clock_) {}
void Add() {
host_.AddBufferedTimeRanges(&ranges_, base::TimeDelta::FromSeconds(10));
}
+ void ProgressCallback() { progress_callback_calls_++; }
+
protected:
+ int progress_callback_calls_ = 0;
BufferedDataSourceHostImpl host_;
Ranges<base::TimeDelta> ranges_;
+ base::SimpleTestTickClock clock_;
DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest);
};
@@ -73,4 +83,72 @@ TEST_F(BufferedDataSourceHostImplTest, DidLoadingProgress) {
EXPECT_FALSE(host_.DidLoadingProgress());
}
+TEST_F(BufferedDataSourceHostImplTest, CanPlayThrough) {
+ host_.SetTotalBytes(100000);
+ EXPECT_EQ(100000,
+ host_.UnloadedBytesInInterval(Interval<int64_t>(0, 100000)));
+ host_.AddBufferedByteRange(0, 10000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(10000, 20000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(20000, 30000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(30000, 40000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(40000, 50000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ EXPECT_EQ(50000, host_.UnloadedBytesInInterval(Interval<int64_t>(0, 100000)));
+ host_.AddBufferedByteRange(50000, 60000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(60000, 70000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(70000, 80000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ host_.AddBufferedByteRange(80000, 90000);
+ // Download rate is allowed to be estimated low, but not high.
+ EXPECT_LE(host_.DownloadRate(), 10000.0f);
+ EXPECT_GE(host_.DownloadRate(), 9000.0f);
+ EXPECT_EQ(10000, host_.UnloadedBytesInInterval(Interval<int64_t>(0, 100000)));
+ EXPECT_EQ(9, progress_callback_calls_);
+ // If the video is 0.1s we can't play through.
+ EXPECT_FALSE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(0.01), 1.0));
+ // If the video is 1000s we can play through.
+ EXPECT_TRUE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(1000.0), 1.0));
+ // No more downloads for 1000 seconds...
+ clock_.Advance(base::TimeDelta::FromSeconds(1000));
+ // Can't play through..
+ EXPECT_FALSE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(100.0), 1.0));
+ host_.AddBufferedByteRange(90000, 100000);
+ clock_.Advance(base::TimeDelta::FromSeconds(1));
+ EXPECT_EQ(0, host_.UnloadedBytesInInterval(Interval<int64_t>(0, 100000)));
+
+ // Media is fully downloaded, so we can certainly play through, even if
+ // we only have 0.01 seconds to do it.
+ EXPECT_TRUE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(0.01), 1.0));
+}
+
+TEST_F(BufferedDataSourceHostImplTest, CanPlayThroughSmallAdvances) {
+ host_.SetTotalBytes(20000);
+ EXPECT_EQ(20000, host_.UnloadedBytesInInterval(Interval<int64_t>(0, 20000)));
+ for (int j = 1; j <= 100; j++) {
+ host_.AddBufferedByteRange(0, j * 100);
+ clock_.Advance(base::TimeDelta::FromSecondsD(0.01));
+ }
+ // Download rate is allowed to be estimated low, but not high.
+ EXPECT_LE(host_.DownloadRate(), 10000.0f);
+ EXPECT_GE(host_.DownloadRate(), 9000.0f);
+ EXPECT_EQ(10000, host_.UnloadedBytesInInterval(Interval<int64_t>(0, 20000)));
+ EXPECT_EQ(100, progress_callback_calls_);
+ // If the video is 0.1s we can't play through.
+ EXPECT_FALSE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(0.01), 1.0));
+ // If the video is 1000s we can play through.
+ EXPECT_TRUE(host_.CanPlayThrough(base::TimeDelta(),
+ base::TimeDelta::FromSecondsD(1000.0), 1.0));
+}
+
} // namespace media
« no previous file with comments | « media/blink/buffered_data_source_host_impl.cc ('k') | media/blink/webmediaplayer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698