| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/blink/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "media/base/media_log.h" | 18 #include "media/base/media_log.h" |
| 19 #include "media/base/seekable_buffer.h" | 19 #include "media/base/seekable_buffer.h" |
| 20 #include "media/blink/mock_webframeclient.h" |
| 20 #include "media/blink/mock_weburlloader.h" | 21 #include "media/blink/mock_weburlloader.h" |
| 21 #include "media/blink/url_index.h" | 22 #include "media/blink/url_index.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/http/http_request_headers.h" | 24 #include "net/http/http_request_headers.h" |
| 24 #include "net/http/http_util.h" | 25 #include "net/http/http_util.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 26 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "third_party/WebKit/public/platform/WebURLError.h" | 27 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 27 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 28 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 28 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 29 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 29 #include "third_party/WebKit/public/web/WebFrameClient.h" | |
| 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
| 32 | 32 |
| 33 using ::testing::_; | 33 using ::testing::_; |
| 34 using ::testing::InSequence; | 34 using ::testing::InSequence; |
| 35 using ::testing::Return; | 35 using ::testing::Return; |
| 36 using ::testing::Truly; | 36 using ::testing::Truly; |
| 37 using ::testing::NiceMock; | 37 using ::testing::NiceMock; |
| 38 | 38 |
| 39 using blink::WebLocalFrame; | 39 using blink::WebLocalFrame; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 64 request.httpHeaderField( | 64 request.httpHeaderField( |
| 65 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) | 65 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) |
| 66 .utf8(); | 66 .utf8(); |
| 67 return (value.find("identity;q=1") != std::string::npos) && | 67 return (value.find("identity;q=1") != std::string::npos) && |
| 68 (value.find("*;q=0") != std::string::npos); | 68 (value.find("*;q=0") != std::string::npos); |
| 69 } | 69 } |
| 70 | 70 |
| 71 class ResourceMultiBufferDataProviderTest : public testing::Test { | 71 class ResourceMultiBufferDataProviderTest : public testing::Test { |
| 72 public: | 72 public: |
| 73 ResourceMultiBufferDataProviderTest() | 73 ResourceMultiBufferDataProviderTest() |
| 74 : view_(WebView::create(nullptr, blink::WebPageVisibilityStateVisible)) { | 74 : view_(WebView::create(nullptr, blink::WebPageVisibilityStateVisible)), |
| 75 WebLocalFrame* frame = | 75 frame_(WebLocalFrame::create(blink::WebTreeScopeType::Document, |
| 76 WebLocalFrame::create(blink::WebTreeScopeType::Document, &client_); | 76 &client_)) { |
| 77 view_->setMainFrame(frame); | 77 view_->setMainFrame(frame_); |
| 78 url_index_.reset(new UrlIndex(frame, 0)); | 78 url_index_.reset(new UrlIndex(frame_, 0)); |
| 79 | 79 |
| 80 for (int i = 0; i < kDataSize; ++i) { | 80 for (int i = 0; i < kDataSize; ++i) { |
| 81 data_[i] = i; | 81 data_[i] = i; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual ~ResourceMultiBufferDataProviderTest() { | 85 virtual ~ResourceMultiBufferDataProviderTest() { |
| 86 view_->close(); | 86 view_->close(); |
| 87 frame_->close(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void Initialize(const char* url, int first_position) { | 90 void Initialize(const char* url, int first_position) { |
| 90 gurl_ = GURL(url); | 91 gurl_ = GURL(url); |
| 91 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); | 92 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); |
| 92 url_data_->set_etag(kEtag); | 93 url_data_->set_etag(kEtag); |
| 93 DCHECK(url_data_); | 94 DCHECK(url_data_); |
| 94 DCHECK(url_data_->frame()); | 95 DCHECK(url_data_->frame()); |
| 95 url_data_->OnRedirect( | 96 url_data_->OnRedirect( |
| 96 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, | 97 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 GURL gurl_; | 227 GURL gurl_; |
| 227 int64_t first_position_; | 228 int64_t first_position_; |
| 228 | 229 |
| 229 std::unique_ptr<UrlIndex> url_index_; | 230 std::unique_ptr<UrlIndex> url_index_; |
| 230 scoped_refptr<UrlData> url_data_; | 231 scoped_refptr<UrlData> url_data_; |
| 231 scoped_refptr<UrlData> redirected_to_; | 232 scoped_refptr<UrlData> redirected_to_; |
| 232 // The loader is owned by the UrlData above. | 233 // The loader is owned by the UrlData above. |
| 233 ResourceMultiBufferDataProvider* loader_; | 234 ResourceMultiBufferDataProvider* loader_; |
| 234 NiceMock<MockWebURLLoader>* url_loader_; | 235 NiceMock<MockWebURLLoader>* url_loader_; |
| 235 | 236 |
| 236 blink::WebFrameClient client_; | 237 MockWebFrameClient client_; |
| 237 WebView* view_; | 238 WebView* view_; |
| 239 WebLocalFrame* frame_; |
| 238 | 240 |
| 239 base::MessageLoop message_loop_; | 241 base::MessageLoop message_loop_; |
| 240 | 242 |
| 241 uint8_t data_[kDataSize]; | 243 uint8_t data_[kDataSize]; |
| 242 | 244 |
| 243 private: | 245 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(ResourceMultiBufferDataProviderTest); | 246 DISALLOW_COPY_AND_ASSIGN(ResourceMultiBufferDataProviderTest); |
| 245 }; | 247 }; |
| 246 | 248 |
| 247 TEST_F(ResourceMultiBufferDataProviderTest, StartStop) { | 249 TEST_F(ResourceMultiBufferDataProviderTest, StartStop) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { | 331 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { |
| 330 // Test redirect. | 332 // Test redirect. |
| 331 Initialize(kHttpUrl, 0); | 333 Initialize(kHttpUrl, 0); |
| 332 Start(); | 334 Start(); |
| 333 Redirect(kHttpRedirect); | 335 Redirect(kHttpRedirect); |
| 334 FullResponse(1024); | 336 FullResponse(1024); |
| 335 StopWhenLoad(); | 337 StopWhenLoad(); |
| 336 } | 338 } |
| 337 | 339 |
| 338 } // namespace media | 340 } // namespace media |
| OLD | NEW |