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

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

Issue 8661002: Fire CanPlayThrough immediately for local and streaming media files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase ToT Created 9 years 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 "testing/gmock/include/gmock/gmock.h" 7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using ::testing::Mock; 10 using ::testing::Mock;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // starting and end point. 42 // starting and end point.
43 for (int i = 0; i < number_of_packets + 1; ++i) { 43 for (int i = 0; i < number_of_packets + 1; ++i) {
44 monitor_.SetBufferedBytes(bytes_buffered, packet_time); 44 monitor_.SetBufferedBytes(bytes_buffered, packet_time);
45 packet_time += base::TimeDelta::FromMilliseconds(ms_between_packets); 45 packet_time += base::TimeDelta::FromMilliseconds(ms_between_packets);
46 bytes_buffered += bytes_per_packet; 46 bytes_buffered += bytes_per_packet;
47 } 47 }
48 monitor_.SetNetworkActivity(false); 48 monitor_.SetNetworkActivity(false);
49 return bytes_buffered; 49 return bytes_buffered;
50 } 50 }
51 51
52 void StartMonitor(int bitrate) {
53 StartMonitor(bitrate, false, false);
54 }
55
56 void StartMonitor(int bitrate, bool streaming, bool local_source) {
57 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough,
58 base::Unretained(this)), bitrate, streaming, local_source);
59 }
60
52 DownloadRateMonitor monitor_; 61 DownloadRateMonitor monitor_;
53 62
54 private: 63 private:
55 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitorTest); 64 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitorTest);
56 }; 65 };
57 66
58 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate) { 67 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate) {
59 static const int media_bitrate = 1024 * 1024 * 8; 68 static const int media_bitrate = 1024 * 1024 * 8;
60 69
61 // Simulate downloading at double the media's bitrate. 70 // Simulate downloading at double the media's bitrate.
62 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 71 StartMonitor(media_bitrate);
63 base::Unretained(this)), media_bitrate);
64 EXPECT_CALL(*this, CanPlayThrough()); 72 EXPECT_CALL(*this, CanPlayThrough());
65 SimulateNetwork(1, 0, 2 * media_bitrate / 8, 1000, 10); 73 SimulateNetwork(1, 0, 2 * media_bitrate / 8, 1000, 10);
66 } 74 }
67 75
68 // If the user pauses and the pipeline stops downloading data, make sure the 76 // If the user pauses and the pipeline stops downloading data, make sure the
69 // DownloadRateMonitor understands that the download is not stalling. 77 // DownloadRateMonitor understands that the download is not stalling.
70 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_Pause) { 78 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_Pause) {
71 static const int media_bitrate = 1024 * 1024 * 8; 79 static const int media_bitrate = 1024 * 1024 * 8;
72 static const int download_byte_rate = 1.1 * media_bitrate / 8; 80 static const int download_byte_rate = 1.1 * media_bitrate / 8;
73 81
74 // Start downloading faster than the media's bitrate. 82 // Start downloading faster than the media's bitrate.
75 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 83 StartMonitor(media_bitrate);
76 base::Unretained(this)), media_bitrate);
77 EXPECT_CALL(*this, CanPlayThrough()); 84 EXPECT_CALL(*this, CanPlayThrough());
78 int buffered = SimulateNetwork(1, 0, download_byte_rate, 1000, 2); 85 int buffered = SimulateNetwork(1, 0, download_byte_rate, 1000, 2);
79 86
80 // Then "pause" for 3 minutes and continue downloading at same rate. 87 // Then "pause" for 3 minutes and continue downloading at same rate.
81 SimulateNetwork(60 * 3, buffered, download_byte_rate, 1000, 4); 88 SimulateNetwork(60 * 3, buffered, download_byte_rate, 1000, 4);
82 } 89 }
83 90
84 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekForward) { 91 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekForward) {
85 static const int media_bitrate = 1024 * 1024 * 8; 92 static const int media_bitrate = 1024 * 1024 * 8;
86 static const int download_byte_rate = 1.1 * media_bitrate / 8; 93 static const int download_byte_rate = 1.1 * media_bitrate / 8;
87 94
88 // Start downloading faster than the media's bitrate. 95 // Start downloading faster than the media's bitrate.
89 EXPECT_CALL(*this, CanPlayThrough()); 96 EXPECT_CALL(*this, CanPlayThrough());
90 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 97 StartMonitor(media_bitrate);
91 base::Unretained(this)), media_bitrate);
92 SimulateNetwork(1, 0, download_byte_rate, 1000, 2); 98 SimulateNetwork(1, 0, download_byte_rate, 1000, 2);
93 99
94 // Then seek forward mid-file and continue downloading at same rate. 100 // Then seek forward mid-file and continue downloading at same rate.
95 SimulateNetwork(4, kMediaSizeInBytes / 2, download_byte_rate, 1000, 4); 101 SimulateNetwork(4, kMediaSizeInBytes / 2, download_byte_rate, 1000, 4);
96 } 102 }
97 103
98 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekBackward) { 104 TEST_F(DownloadRateMonitorTest, DownloadRateGreaterThanBitrate_SeekBackward) {
99 static const int media_bitrate = 1024 * 1024 * 8; 105 static const int media_bitrate = 1024 * 1024 * 8;
100 static const int download_byte_rate = 1.1 * media_bitrate / 8; 106 static const int download_byte_rate = 1.1 * media_bitrate / 8;
101 107
102 // Start downloading faster than the media's bitrate, in middle of file. 108 // Start downloading faster than the media's bitrate, in middle of file.
103 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 109 StartMonitor(media_bitrate);
104 base::Unretained(this)), media_bitrate);
105 SimulateNetwork(1, kMediaSizeInBytes / 2, download_byte_rate, 1000, 2); 110 SimulateNetwork(1, kMediaSizeInBytes / 2, download_byte_rate, 1000, 2);
106 111
107 // Then seek back to beginning and continue downloading at same rate. 112 // Then seek back to beginning and continue downloading at same rate.
108 EXPECT_CALL(*this, CanPlayThrough()); 113 EXPECT_CALL(*this, CanPlayThrough());
109 SimulateNetwork(4, 0, download_byte_rate, 1000, 4); 114 SimulateNetwork(4, 0, download_byte_rate, 1000, 4);
110 } 115 }
111 116
112 TEST_F(DownloadRateMonitorTest, DownloadRateLessThanBitrate) { 117 TEST_F(DownloadRateMonitorTest, DownloadRateLessThanBitrate) {
113 static const int media_bitrate = 1024 * 1024 * 8; 118 static const int media_bitrate = 1024 * 1024 * 8;
114 119
115 // Simulate downloading at half the media's bitrate. 120 // Simulate downloading at half the media's bitrate.
116 EXPECT_CALL(*this, CanPlayThrough()) 121 EXPECT_CALL(*this, CanPlayThrough())
117 .Times(0); 122 .Times(0);
118 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 123 StartMonitor(media_bitrate);
119 base::Unretained(this)), media_bitrate);
120 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, 10); 124 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, 10);
121 } 125 }
122 126
123 TEST_F(DownloadRateMonitorTest, MediaIsLoaded) { 127 TEST_F(DownloadRateMonitorTest, MediaSourceIsLocal) {
124 static const int media_bitrate = 1024 * 1024 * 8; 128 static const int media_bitrate = 1024 * 1024 * 8;
125 129
126 monitor_.set_loaded(true); 130 // Simulate no data downloaded.
131 EXPECT_CALL(*this, CanPlayThrough());
132 StartMonitor(media_bitrate, false, true);
133 }
127 134
128 // Simulate no data downloaded (source is already loaded). 135 TEST_F(DownloadRateMonitorTest, MediaSourceIsStreaming) {
136 static const int media_bitrate = 1024 * 1024 * 8;
137
138 // Simulate downloading at the media's bitrate while streaming.
129 EXPECT_CALL(*this, CanPlayThrough()); 139 EXPECT_CALL(*this, CanPlayThrough());
130 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 140 StartMonitor(media_bitrate, true, false);
131 base::Unretained(this)), media_bitrate); 141 SimulateNetwork(1, 0, media_bitrate / 8, 1000, 10);
132 SimulateNetwork(1, 0, 0, 1000, 10);
133 } 142 }
134 143
135 TEST_F(DownloadRateMonitorTest, VeryFastDownloadRate) { 144 TEST_F(DownloadRateMonitorTest, VeryFastDownloadRate) {
136 static const int media_bitrate = 1024 * 1024 * 8; 145 static const int media_bitrate = 1024 * 1024 * 8;
137 146
138 // Simulate downloading half the video very quickly in one chunk. 147 // Simulate downloading half the video very quickly in one chunk.
139 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 148 StartMonitor(media_bitrate);
140 base::Unretained(this)), media_bitrate);
141 EXPECT_CALL(*this, CanPlayThrough()); 149 EXPECT_CALL(*this, CanPlayThrough());
142 SimulateNetwork(1, 0, kMediaSizeInBytes / 2, 10, 1); 150 SimulateNetwork(1, 0, kMediaSizeInBytes / 2, 10, 1);
143 } 151 }
144 152
145 TEST_F(DownloadRateMonitorTest, DownloadEntireVideo) { 153 TEST_F(DownloadRateMonitorTest, DownloadEntireVideo) {
146 static const int seconds_of_data = 20; 154 static const int seconds_of_data = 20;
147 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data; 155 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data;
148 156
149 // Simulate downloading entire video at half the bitrate of the video. 157 // Simulate downloading entire video at half the bitrate of the video.
150 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, 158 StartMonitor(media_bitrate);
151 base::Unretained(this)), media_bitrate);
152 EXPECT_CALL(*this, CanPlayThrough()); 159 EXPECT_CALL(*this, CanPlayThrough());
153 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);
154 } 161 }
155 162
156 } // namespace media 163 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698