Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 6 #include "base/message_loop.h" |
| 7 #include "media/base/media_log.h" | 7 #include "media/base/media_log.h" |
| 8 #include "media/base/mock_callback.h" | 8 #include "media/base/mock_callback.h" |
| 9 #include "media/base/mock_data_source_host.h" | 9 #include "media/base/mock_data_source_host.h" |
| 10 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" |
| 13 #include "webkit/media/buffered_data_source.h" | 13 #include "webkit/media/buffered_data_source.h" |
| 14 #include "webkit/mocks/mock_webframeclient.h" | 14 #include "webkit/mocks/mock_webframeclient.h" |
| 15 #include "webkit/mocks/mock_weburlloader.h" | 15 #include "webkit/mocks/mock_weburlloader.h" |
| 16 #include "webkit/media/test_response_generator.h" | 16 #include "webkit/media/test_response_generator.h" |
| 17 | 17 |
| 18 using ::testing::_; | 18 using ::testing::_; |
| 19 using ::testing::Assign; | 19 using ::testing::Assign; |
| 20 using ::testing::Invoke; | 20 using ::testing::Invoke; |
| 21 using ::testing::NiceMock; | |
| 21 using ::testing::StrictMock; | 22 using ::testing::StrictMock; |
| 22 using ::testing::NiceMock; | |
| 23 | 23 |
| 24 using WebKit::WebFrame; | 24 using WebKit::WebFrame; |
| 25 using WebKit::WebString; | 25 using WebKit::WebString; |
| 26 using WebKit::WebURLLoader; | 26 using WebKit::WebURLLoader; |
| 27 using WebKit::WebURLResponse; | 27 using WebKit::WebURLResponse; |
| 28 using WebKit::WebView; | 28 using WebKit::WebView; |
| 29 | 29 |
| 30 using webkit_glue::MockWebFrameClient; | 30 using webkit_glue::MockWebFrameClient; |
| 31 using webkit_glue::MockWebURLLoader; | 31 using webkit_glue::MockWebURLLoader; |
| 32 | 32 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 view_->mainFrame()); | 89 view_->mainFrame()); |
| 90 data_source_->set_host(&host_); | 90 data_source_->set_host(&host_); |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual ~BufferedDataSourceTest() { | 93 virtual ~BufferedDataSourceTest() { |
| 94 view_->close(); | 94 view_->close(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void Initialize(media::PipelineStatus expected) { | 97 void Initialize(media::PipelineStatus expected) { |
| 98 ExpectCreateResourceLoader(); | 98 ExpectCreateResourceLoader(); |
| 99 | |
| 100 EXPECT_CALL(host_, SetNetworkActivity(true)); | |
| 99 data_source_->Initialize(response_generator_.gurl(), | 101 data_source_->Initialize(response_generator_.gurl(), |
| 100 media::NewExpectedStatusCB(expected)); | 102 media::NewExpectedStatusCB(expected)); |
| 101 message_loop_.RunAllPending(); | 103 message_loop_.RunAllPending(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 // Helper to initialize tests with a valid 206 response. | 106 // Helper to initialize tests with a valid 206 response. |
| 105 void InitializeWith206Response() { | 107 void InitializeWith206Response() { |
| 106 Initialize(media::PIPELINE_OK); | 108 Initialize(media::PIPELINE_OK); |
| 107 | 109 |
| 108 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 110 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 128 .WillOnce(Invoke(data_source_.get(), | 130 .WillOnce(Invoke(data_source_.get(), |
| 129 &MockBufferedDataSource::CreateMockResourceLoader)); | 131 &MockBufferedDataSource::CreateMockResourceLoader)); |
| 130 message_loop_.RunAllPending(); | 132 message_loop_.RunAllPending(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void Respond(const WebURLResponse& response) { | 135 void Respond(const WebURLResponse& response) { |
| 134 loader()->didReceiveResponse(url_loader(), response); | 136 loader()->didReceiveResponse(url_loader(), response); |
| 135 message_loop_.RunAllPending(); | 137 message_loop_.RunAllPending(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void FinishRead() { | 140 void ReceiveData(int size) { |
| 139 loader()->didReceiveData(url_loader(), data_, kDataSize, kDataSize); | 141 scoped_array<char> data(new char[size]); |
| 142 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. | |
| 143 | |
| 144 loader()->didReceiveData(url_loader(), data.get(), size, size); | |
| 140 message_loop_.RunAllPending(); | 145 message_loop_.RunAllPending(); |
| 141 } | 146 } |
| 142 | 147 |
| 143 void FinishLoading() { | 148 void FinishLoading() { |
| 144 data_source_->set_loading(false); | 149 data_source_->set_loading(false); |
| 145 loader()->didFinishLoading(url_loader(), 0); | 150 loader()->didFinishLoading(url_loader(), 0); |
| 146 message_loop_.RunAllPending(); | 151 message_loop_.RunAllPending(); |
| 147 } | 152 } |
| 148 | 153 |
| 149 MOCK_METHOD1(ReadCallback, void(int size)); | 154 MOCK_METHOD1(ReadCallback, void(int size)); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 179 MockWebFrameClient client_; | 184 MockWebFrameClient client_; |
| 180 WebView* view_; | 185 WebView* view_; |
| 181 | 186 |
| 182 StrictMock<media::MockDataSourceHost> host_; | 187 StrictMock<media::MockDataSourceHost> host_; |
| 183 MessageLoop message_loop_; | 188 MessageLoop message_loop_; |
| 184 | 189 |
| 185 private: | 190 private: |
| 186 // Used for calling BufferedDataSource::Read(). | 191 // Used for calling BufferedDataSource::Read(). |
| 187 uint8 buffer_[kDataSize]; | 192 uint8 buffer_[kDataSize]; |
| 188 | 193 |
| 189 // Used for calling BufferedResourceLoader::didReceiveData(). | |
| 190 char data_[kDataSize]; | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); | 194 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
| 193 }; | 195 }; |
| 194 | 196 |
| 195 TEST_F(BufferedDataSourceTest, Range_Supported) { | 197 TEST_F(BufferedDataSourceTest, Range_Supported) { |
| 196 Initialize(media::PIPELINE_OK); | 198 Initialize(media::PIPELINE_OK); |
| 197 | 199 |
| 198 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); | 200 EXPECT_CALL(host_, SetTotalBytes(response_generator_.content_length())); |
| 199 Respond(response_generator_.Generate206(0)); | 201 Respond(response_generator_.Generate206(0)); |
| 200 | 202 |
| 201 EXPECT_TRUE(data_source_->loading()); | 203 EXPECT_TRUE(data_source_->loading()); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 EXPECT_TRUE(data_source_->loading()); | 424 EXPECT_TRUE(data_source_->loading()); |
| 423 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 425 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 424 Stop(); | 426 Stop(); |
| 425 } | 427 } |
| 426 | 428 |
| 427 TEST_F(BufferedDataSourceTest, Read) { | 429 TEST_F(BufferedDataSourceTest, Read) { |
| 428 InitializeWith206Response(); | 430 InitializeWith206Response(); |
| 429 | 431 |
| 430 ReadAt(0); | 432 ReadAt(0); |
| 431 | 433 |
| 432 // When the read completes we'll update our network status. | 434 // Receive first half of the read. |
| 435 EXPECT_CALL(host_, AddBufferedByteRange(0, (kDataSize / 2) - 1)); | |
| 436 ReceiveData(kDataSize / 2); | |
| 437 | |
| 438 // Receive last half of the read. | |
| 439 EXPECT_CALL(*this, ReadCallback(kDataSize)); | |
| 433 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 440 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
| 434 EXPECT_CALL(host_, SetNetworkActivity(true)); | 441 ReceiveData(kDataSize / 2); |
| 435 EXPECT_CALL(*this, ReadCallback(kDataSize)); | |
| 436 FinishRead(); | |
| 437 | |
| 438 // During teardown we'll also report our final network status. | |
| 439 EXPECT_CALL(host_, SetNetworkActivity(false)); | |
|
Ami GONE FROM CHROMIUM
2012/07/09 00:25:46
So this is not expected to fire anymore?
scherkus (not reviewing)
2012/07/09 18:53:30
The call to Stop() below simulates page navigation
| |
| 440 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | |
| 441 | 442 |
| 442 EXPECT_TRUE(data_source_->loading()); | 443 EXPECT_TRUE(data_source_->loading()); |
| 443 Stop(); | 444 Stop(); |
| 444 } | 445 } |
| 445 | 446 |
| 446 } // namespace webkit_media | 447 } // namespace webkit_media |
| OLD | NEW |