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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "media/base/media_log.h" | 8 #include "media/base/media_log.h" |
9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
10 #include "media/base/test_helpers.h" | 10 #include "media/base/test_helpers.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using blink::WebURLResponse; | 31 using blink::WebURLResponse; |
32 using blink::WebView; | 32 using blink::WebView; |
33 | 33 |
34 namespace media { | 34 namespace media { |
35 | 35 |
36 class MockBufferedDataSourceHost : public BufferedDataSourceHost { | 36 class MockBufferedDataSourceHost : public BufferedDataSourceHost { |
37 public: | 37 public: |
38 MockBufferedDataSourceHost() {} | 38 MockBufferedDataSourceHost() {} |
39 virtual ~MockBufferedDataSourceHost() {} | 39 virtual ~MockBufferedDataSourceHost() {} |
40 | 40 |
41 MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); | 41 MOCK_METHOD1(SetTotalBytes, void(int64_t total_bytes)); |
42 MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); | 42 MOCK_METHOD2(AddBufferedByteRange, void(int64_t start, int64_t end)); |
43 | 43 |
44 private: | 44 private: |
45 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); | 45 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); |
46 }; | 46 }; |
47 | 47 |
48 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. | 48 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. |
49 // Also keeps track of whether said MockWebURLLoader is actively loading. | 49 // Also keeps track of whether said MockWebURLLoader is actively loading. |
50 class MockBufferedDataSource : public BufferedDataSource { | 50 class MockBufferedDataSource : public BufferedDataSource { |
51 public: | 51 public: |
52 MockBufferedDataSource( | 52 MockBufferedDataSource( |
53 const GURL& url, | 53 const GURL& url, |
54 BufferedResourceLoader::CORSMode cors_mode, | 54 BufferedResourceLoader::CORSMode cors_mode, |
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
56 WebLocalFrame* frame, | 56 WebLocalFrame* frame, |
57 BufferedDataSourceHost* host) | 57 BufferedDataSourceHost* host) |
58 : BufferedDataSource(url, | 58 : BufferedDataSource(url, |
59 cors_mode, | 59 cors_mode, |
60 task_runner, | 60 task_runner, |
61 frame, | 61 frame, |
62 new media::MediaLog(), | 62 new media::MediaLog(), |
63 host, | 63 host, |
64 base::Bind(&MockBufferedDataSource::set_downloading, | 64 base::Bind(&MockBufferedDataSource::set_downloading, |
65 base::Unretained(this))), | 65 base::Unretained(this))), |
66 downloading_(false), | 66 downloading_(false), |
67 loading_(false) {} | 67 loading_(false) {} |
68 virtual ~MockBufferedDataSource() {} | 68 virtual ~MockBufferedDataSource() {} |
69 | 69 |
70 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 70 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64_t, int64_t)); |
71 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, | 71 BufferedResourceLoader* CreateMockResourceLoader(int64_t first_byte_position, |
72 int64 last_byte_position) { | 72 int64_t last_byte_position) { |
73 CHECK(!loading_) << "Previous resource load wasn't cancelled"; | 73 CHECK(!loading_) << "Previous resource load wasn't cancelled"; |
74 | 74 |
75 BufferedResourceLoader* loader = | 75 BufferedResourceLoader* loader = |
76 BufferedDataSource::CreateResourceLoader(first_byte_position, | 76 BufferedDataSource::CreateResourceLoader(first_byte_position, |
77 last_byte_position); | 77 last_byte_position); |
78 | 78 |
79 // Keep track of active loading state via loadAsynchronously() and cancel(). | 79 // Keep track of active loading state via loadAsynchronously() and cancel(). |
80 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); | 80 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); |
81 ON_CALL(*url_loader, loadAsynchronously(_, _)) | 81 ON_CALL(*url_loader, loadAsynchronously(_, _)) |
82 .WillByDefault(Assign(&loading_, true)); | 82 .WillByDefault(Assign(&loading_, true)); |
(...skipping 13 matching lines...) Expand all Loading... |
96 private: | 96 private: |
97 // Whether the resource is downloading or deferred. | 97 // Whether the resource is downloading or deferred. |
98 bool downloading_; | 98 bool downloading_; |
99 | 99 |
100 // Whether the resource load has starting loading but yet to been cancelled. | 100 // Whether the resource load has starting loading but yet to been cancelled. |
101 bool loading_; | 101 bool loading_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); | 103 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); |
104 }; | 104 }; |
105 | 105 |
106 static const int64 kFileSize = 5000000; | 106 static const int64_t kFileSize = 5000000; |
107 static const int64 kFarReadPosition = 4000000; | 107 static const int64_t kFarReadPosition = 4000000; |
108 static const int kDataSize = 1024; | 108 static const int kDataSize = 1024; |
109 | 109 |
110 static const char kHttpUrl[] = "http://localhost/foo.webm"; | 110 static const char kHttpUrl[] = "http://localhost/foo.webm"; |
111 static const char kFileUrl[] = "file:///tmp/bar.webm"; | 111 static const char kFileUrl[] = "file:///tmp/bar.webm"; |
112 static const char kHttpDifferentPathUrl[] = "http://localhost/bar.webm"; | 112 static const char kHttpDifferentPathUrl[] = "http://localhost/bar.webm"; |
113 static const char kHttpDifferentOriginUrl[] = "http://127.0.0.1/foo.webm"; | 113 static const char kHttpDifferentOriginUrl[] = "http://127.0.0.1/foo.webm"; |
114 | 114 |
115 class BufferedDataSourceTest : public testing::Test { | 115 class BufferedDataSourceTest : public testing::Test { |
116 public: | 116 public: |
117 BufferedDataSourceTest() | 117 BufferedDataSourceTest() |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 | 218 |
219 void FinishLoading() { | 219 void FinishLoading() { |
220 data_source_->set_loading(false); | 220 data_source_->set_loading(false); |
221 loader()->didFinishLoading(url_loader(), 0, -1); | 221 loader()->didFinishLoading(url_loader(), 0, -1); |
222 message_loop_.RunUntilIdle(); | 222 message_loop_.RunUntilIdle(); |
223 } | 223 } |
224 | 224 |
225 MOCK_METHOD1(ReadCallback, void(int size)); | 225 MOCK_METHOD1(ReadCallback, void(int size)); |
226 | 226 |
227 void ReadAt(int64 position) { | 227 void ReadAt(int64_t position) { |
228 data_source_->Read(position, kDataSize, buffer_, | 228 data_source_->Read(position, kDataSize, buffer_, |
229 base::Bind(&BufferedDataSourceTest::ReadCallback, | 229 base::Bind(&BufferedDataSourceTest::ReadCallback, |
230 base::Unretained(this))); | 230 base::Unretained(this))); |
231 message_loop_.RunUntilIdle(); | 231 message_loop_.RunUntilIdle(); |
232 } | 232 } |
233 | 233 |
234 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1, | 234 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1, |
235 const WebURLResponse& response2) { | 235 const WebURLResponse& response2) { |
236 EXPECT_CALL(host_, SetTotalBytes(kFileSize)); | 236 EXPECT_CALL(host_, SetTotalBytes(kFileSize)); |
237 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize * 2 - 1)); | 237 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize * 2 - 1)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 MockWebFrameClient client_; | 300 MockWebFrameClient client_; |
301 WebView* view_; | 301 WebView* view_; |
302 WebLocalFrame* frame_; | 302 WebLocalFrame* frame_; |
303 | 303 |
304 StrictMock<MockBufferedDataSourceHost> host_; | 304 StrictMock<MockBufferedDataSourceHost> host_; |
305 base::MessageLoop message_loop_; | 305 base::MessageLoop message_loop_; |
306 int bytes_received_; | 306 int bytes_received_; |
307 | 307 |
308 private: | 308 private: |
309 // Used for calling BufferedDataSource::Read(). | 309 // Used for calling BufferedDataSource::Read(). |
310 uint8 buffer_[kDataSize]; | 310 uint8_t buffer_[kDataSize]; |
311 | 311 |
312 BufferedDataSource::Preload preload_; | 312 BufferedDataSource::Preload preload_; |
313 | 313 |
314 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); | 314 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
315 }; | 315 }; |
316 | 316 |
317 TEST_F(BufferedDataSourceTest, Range_Supported) { | 317 TEST_F(BufferedDataSourceTest, Range_Supported) { |
318 InitializeWith206Response(); | 318 InitializeWith206Response(); |
319 | 319 |
320 EXPECT_TRUE(data_source_->loading()); | 320 EXPECT_TRUE(data_source_->loading()); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 InitializeWithFileResponse(); | 692 InitializeWithFileResponse(); |
693 | 693 |
694 EXPECT_TRUE(data_source_->loading()); | 694 EXPECT_TRUE(data_source_->loading()); |
695 EXPECT_FALSE(data_source_->IsStreaming()); | 695 EXPECT_FALSE(data_source_->IsStreaming()); |
696 Stop(); | 696 Stop(); |
697 } | 697 } |
698 | 698 |
699 TEST_F(BufferedDataSourceTest, StopDuringRead) { | 699 TEST_F(BufferedDataSourceTest, StopDuringRead) { |
700 InitializeWith206Response(); | 700 InitializeWith206Response(); |
701 | 701 |
702 uint8 buffer[256]; | 702 uint8_t buffer[256]; |
703 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( | 703 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( |
704 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); | 704 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); |
705 | 705 |
706 // The outstanding read should fail before the stop callback runs. | 706 // The outstanding read should fail before the stop callback runs. |
707 { | 707 { |
708 InSequence s; | 708 InSequence s; |
709 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 709 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
710 data_source_->Stop(); | 710 data_source_->Stop(); |
711 } | 711 } |
712 message_loop_.RunUntilIdle(); | 712 message_loop_.RunUntilIdle(); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 // Read a bit from the beginning. | 1017 // Read a bit from the beginning. |
1018 ReadAt(0); | 1018 ReadAt(0); |
1019 EXPECT_CALL(*this, ReadCallback(kDataSize)); | 1019 EXPECT_CALL(*this, ReadCallback(kDataSize)); |
1020 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 1020 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
1021 ReceiveData(kDataSize); | 1021 ReceiveData(kDataSize); |
1022 | 1022 |
1023 EXPECT_FALSE(active_loader()); | 1023 EXPECT_FALSE(active_loader()); |
1024 } | 1024 } |
1025 | 1025 |
1026 } // namespace media | 1026 } // namespace media |
OLD | NEW |