OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 last_byte_position); | 80 last_byte_position); |
81 | 81 |
82 // Keep track of active loading state via loadAsynchronously() and cancel(). | 82 // Keep track of active loading state via loadAsynchronously() and cancel(). |
83 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); | 83 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); |
84 ON_CALL(*url_loader, loadAsynchronously(_, _)) | 84 ON_CALL(*url_loader, loadAsynchronously(_, _)) |
85 .WillByDefault(Assign(&loading_, true)); | 85 .WillByDefault(Assign(&loading_, true)); |
86 ON_CALL(*url_loader, cancel()) | 86 ON_CALL(*url_loader, cancel()) |
87 .WillByDefault(Assign(&loading_, false)); | 87 .WillByDefault(Assign(&loading_, false)); |
88 | 88 |
89 // |test_loader_| will be used when Start() is called. | 89 // |test_loader_| will be used when Start() is called. |
90 loader->test_loader_ = scoped_ptr<WebURLLoader>(url_loader); | 90 loader->test_loader_ = std::unique_ptr<WebURLLoader>(url_loader); |
91 return loader; | 91 return loader; |
92 } | 92 } |
93 | 93 |
94 bool loading() { return loading_; } | 94 bool loading() { return loading_; } |
95 void set_loading(bool loading) { loading_ = loading; } | 95 void set_loading(bool loading) { loading_ = loading; } |
96 bool downloading() { return downloading_; } | 96 bool downloading() { return downloading_; } |
97 void set_downloading(bool downloading) { downloading_ = downloading; } | 97 void set_downloading(bool downloading) { downloading_ = downloading; } |
98 | 98 |
99 private: | 99 private: |
100 // Whether the resource is downloading or deferred. | 100 // Whether the resource is downloading or deferred. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 message_loop_.RunUntilIdle(); | 203 message_loop_.RunUntilIdle(); |
204 bytes_received_ = 0; | 204 bytes_received_ = 0; |
205 } | 205 } |
206 | 206 |
207 void Respond(const WebURLResponse& response) { | 207 void Respond(const WebURLResponse& response) { |
208 loader()->didReceiveResponse(url_loader(), response); | 208 loader()->didReceiveResponse(url_loader(), response); |
209 message_loop_.RunUntilIdle(); | 209 message_loop_.RunUntilIdle(); |
210 } | 210 } |
211 | 211 |
212 void ReceiveData(int size) { | 212 void ReceiveData(int size) { |
213 scoped_ptr<char[]> data(new char[size]); | 213 std::unique_ptr<char[]> data(new char[size]); |
214 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. | 214 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. |
215 | 215 |
216 loader()->didReceiveData(url_loader(), data.get(), size, size); | 216 loader()->didReceiveData(url_loader(), data.get(), size, size); |
217 message_loop_.RunUntilIdle(); | 217 message_loop_.RunUntilIdle(); |
218 bytes_received_ += size; | 218 bytes_received_ += size; |
219 EXPECT_EQ(bytes_received_, data_source_->GetMemoryUsage()); | 219 EXPECT_EQ(bytes_received_, data_source_->GetMemoryUsage()); |
220 } | 220 } |
221 | 221 |
222 void FinishLoading() { | 222 void FinishLoading() { |
223 data_source_->set_loading(false); | 223 data_source_->set_loading(false); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 int data_source_bitrate() { return data_source_->bitrate_; } | 291 int data_source_bitrate() { return data_source_->bitrate_; } |
292 double data_source_playback_rate() { return data_source_->playback_rate_; } | 292 double data_source_playback_rate() { return data_source_->playback_rate_; } |
293 int loader_bitrate() { return loader()->bitrate_; } | 293 int loader_bitrate() { return loader()->bitrate_; } |
294 double loader_playback_rate() { return loader()->playback_rate_; } | 294 double loader_playback_rate() { return loader()->playback_rate_; } |
295 bool is_local_source() { return data_source_->assume_fully_buffered(); } | 295 bool is_local_source() { return data_source_->assume_fully_buffered(); } |
296 void set_might_be_reused_from_cache_in_future(bool value) { | 296 void set_might_be_reused_from_cache_in_future(bool value) { |
297 loader()->might_be_reused_from_cache_in_future_ = value; | 297 loader()->might_be_reused_from_cache_in_future_ = value; |
298 } | 298 } |
299 | 299 |
300 scoped_ptr<MockBufferedDataSource> data_source_; | 300 std::unique_ptr<MockBufferedDataSource> data_source_; |
301 | 301 |
302 scoped_ptr<TestResponseGenerator> response_generator_; | 302 std::unique_ptr<TestResponseGenerator> response_generator_; |
303 MockWebFrameClient client_; | 303 MockWebFrameClient client_; |
304 WebView* view_; | 304 WebView* view_; |
305 WebLocalFrame* frame_; | 305 WebLocalFrame* frame_; |
306 | 306 |
307 StrictMock<MockBufferedDataSourceHost> host_; | 307 StrictMock<MockBufferedDataSourceHost> host_; |
308 base::MessageLoop message_loop_; | 308 base::MessageLoop message_loop_; |
309 int bytes_received_; | 309 int bytes_received_; |
310 | 310 |
311 private: | 311 private: |
312 // Used for calling BufferedDataSource::Read(). | 312 // Used for calling BufferedDataSource::Read(). |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 while (active_loader() && !active_loader()->deferred()) { | 1043 while (active_loader() && !active_loader()->deferred()) { |
1044 ReceiveData(kDataSize); | 1044 ReceiveData(kDataSize); |
1045 bytes_received += kDataSize; | 1045 bytes_received += kDataSize; |
1046 } | 1046 } |
1047 EXPECT_GT(bytes_received, 0); | 1047 EXPECT_GT(bytes_received, 0); |
1048 EXPECT_LT(bytes_received + kDataSize, kFileSize); | 1048 EXPECT_LT(bytes_received + kDataSize, kFileSize); |
1049 EXPECT_FALSE(active_loader()); | 1049 EXPECT_FALSE(active_loader()); |
1050 } | 1050 } |
1051 | 1051 |
1052 } // namespace media | 1052 } // namespace media |
OLD | NEW |