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

Side by Side Diff: media/base/download_rate_monitor_unittest.cc

Issue 9113023: Fire canplaythrough as soon as download defers to fix autoplay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/download_rate_monitor.h" 5 #include "media/base/download_rate_monitor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 25 matching lines...) Expand all
36 int bytes_per_packet, 36 int bytes_per_packet,
37 int ms_between_packets, 37 int ms_between_packets,
38 int number_of_packets) { 38 int number_of_packets) {
39 int bytes_buffered = starting_bytes; 39 int bytes_buffered = starting_bytes;
40 base::Time packet_time = base::Time::FromDoubleT(starting_time); 40 base::Time packet_time = base::Time::FromDoubleT(starting_time);
41 41
42 monitor_.SetNetworkActivity(true); 42 monitor_.SetNetworkActivity(true);
43 // Loop executes (number_of_packets + 1) times because a packet needs a 43 // Loop executes (number_of_packets + 1) times because a packet needs a
44 // starting and end point. 44 // starting and end point.
45 for (int i = 0; i < number_of_packets + 1; ++i) { 45 for (int i = 0; i < number_of_packets + 1; ++i) {
46 monitor_.SetBufferedBytes(bytes_buffered, packet_time); 46 monitor_.SetBufferedBytes(bytes_buffered, packet_time);
acolwell GONE FROM CHROMIUM 2012/01/05 22:33:56 Consider creating a helper object that models how
vrk (LEFT CHROMIUM) 2012/01/09 19:01:18 Made two objects, a FakeFilterHost and FakeDataSou
47 packet_time += base::TimeDelta::FromMilliseconds(ms_between_packets); 47 packet_time += base::TimeDelta::FromMilliseconds(ms_between_packets);
48 bytes_buffered += bytes_per_packet; 48 bytes_buffered += bytes_per_packet;
49 } 49 }
50 monitor_.SetNetworkActivity(false);
51 return bytes_buffered; 50 return bytes_buffered;
52 } 51 }
53 52
54 void StartMonitor(int bitrate) { 53 void StartMonitor(int bitrate) {
55 StartMonitor(bitrate, false, false); 54 StartMonitor(bitrate, false, false);
56 } 55 }
57 56
58 void StartMonitor(int bitrate, bool streaming, bool local_source) { 57 void StartMonitor(int bitrate, bool streaming, bool local_source) {
59 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 58 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough,
60 base::Unretained(this)), bitrate, streaming, local_source); 59 base::Unretained(this)), bitrate, streaming, local_source);
61 } 60 }
62 61
63 DownloadRateMonitor monitor_; 62 DownloadRateMonitor monitor_;
64 63
65 private: 64 private:
66 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitorTest); 65 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitorTest);
67 }; 66 };
68 67
69 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate) { 68 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate) {
70 static const int media_bitrate = 1024 * 1024 * 8; 69 static const int media_bitrate = 1024 * 1024 * 8;
71 70
72 // Simulate downloading at double the media's bitrate. 71 // Simulate downloading at double the media's bitrate.
73 StartMonitor(media_bitrate); 72 StartMonitor(media_bitrate);
74 EXPECT_CALL(*this, CanPlayThrough()); 73 EXPECT_CALL(*this, CanPlayThrough());
75 SimulateNetwork(1, 0, 2 * media_bitrate / 8, 1000, 10); 74 SimulateNetwork(1, 0, 2 * media_bitrate / 8, 1000, 10);
76 } 75 }
77 76
78 // If the user pauses and the pipeline stops downloading data, make sure the 77 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_Defer) {
79 // DownloadRateMonitor understands that the download is not stalling.
80 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_Pause) {
acolwell GONE FROM CHROMIUM 2012/01/05 22:33:56 Based on what the comment sayd, I think this test
vrk (LEFT CHROMIUM) 2012/01/09 19:01:18 Ahhh, now I remember why I deleted this. The test
81 static const int media_bitrate = 1024 * 1024 * 8; 78 static const int media_bitrate = 1024 * 1024 * 8;
82 static const int download_byte_rate = 1.1 * media_bitrate / 8; 79 static const int download_byte_rate = 1.1 * media_bitrate / 8;
83 80
84 // Start downloading faster than the media's bitrate. 81 // Start downloading faster than the media's bitrate.
85 StartMonitor(media_bitrate); 82 StartMonitor(media_bitrate);
83 SimulateNetwork(1, 0, download_byte_rate, 1000, 2);
84
85 // Now defer download because the client has decided enough data has been
86 // buffered.
86 EXPECT_CALL(*this, CanPlayThrough()); 87 EXPECT_CALL(*this, CanPlayThrough());
87 int buffered = SimulateNetwork(1, 0, download_byte_rate, 1000, 2); 88 monitor_.SetNetworkActivity(false);
88
89 // Then "pause" for 3 minutes and continue downloading at same rate.
90 SimulateNetwork(60 * 3, buffered, download_byte_rate, 1000, 4);
91 } 89 }
92 90
93 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekForward) { 91 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekForward) {
94 static const int media_bitrate = 1024 * 1024 * 8; 92 static const int media_bitrate = 1024 * 1024 * 8;
95 static const int download_byte_rate = 1.1 * media_bitrate / 8; 93 static const int download_byte_rate = 1.1 * media_bitrate / 8;
96 94
97 // Start downloading faster than the media's bitrate. 95 // Start downloading faster than the media's bitrate.
98 EXPECT_CALL(*this, CanPlayThrough()); 96 EXPECT_CALL(*this, CanPlayThrough());
99 StartMonitor(media_bitrate); 97 StartMonitor(media_bitrate);
100 SimulateNetwork(1, 0, download_byte_rate, 1000, 2); 98 SimulateNetwork(1, 0, download_byte_rate, 1000, 2);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 static const int seconds_of_data = 20; 154 static const int seconds_of_data = 20;
157 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data; 155 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data;
158 156
159 // Simulate downloading entire video at half the bitrate of the video. 157 // Simulate downloading entire video at half the bitrate of the video.
160 StartMonitor(media_bitrate); 158 StartMonitor(media_bitrate);
161 EXPECT_CALL(*this, CanPlayThrough()); 159 EXPECT_CALL(*this, CanPlayThrough());
162 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, seconds_of_data * 2); 160 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, seconds_of_data * 2);
163 } 161 }
164 162
165 } // namespace media 163 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698