| 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> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 using blink::WebLocalFrame; | 39 using blink::WebLocalFrame; |
| 40 using blink::WebString; | 40 using blink::WebString; |
| 41 using blink::WebURLError; | 41 using blink::WebURLError; |
| 42 using blink::WebURLResponse; | 42 using blink::WebURLResponse; |
| 43 using blink::WebView; | 43 using blink::WebView; |
| 44 | 44 |
| 45 namespace media { | 45 namespace media { |
| 46 | 46 |
| 47 const char kHttpUrl[] = "http://test"; | 47 const char kHttpUrl[] = "http://test"; |
| 48 const char kHttpRedirect[] = "http://test/ing"; | 48 const char kHttpRedirect[] = "http://test/ing"; |
| 49 const char kEtag[] = "\"arglebargle glopy-glyf?\""; |
| 49 | 50 |
| 50 const int kDataSize = 1024; | 51 const int kDataSize = 1024; |
| 51 const int kHttpOK = 200; | 52 const int kHttpOK = 200; |
| 52 const int kHttpPartialContent = 206; | 53 const int kHttpPartialContent = 206; |
| 53 | 54 |
| 54 enum NetworkState { NONE, LOADED, LOADING }; | 55 enum NetworkState { NONE, LOADED, LOADING }; |
| 55 | 56 |
| 56 // Predicate that tests that request disallows compressed data. | 57 // Predicate that tests that request disallows compressed data. |
| 57 static bool CorrectAcceptEncoding(const blink::WebURLRequest& request) { | 58 static bool CorrectAcceptEncodingAndEtag(const blink::WebURLRequest& request) { |
| 59 std::string etag = |
| 60 request.httpHeaderField(WebString::fromUTF8("If-Match")).utf8(); |
| 61 EXPECT_EQ(etag, kEtag); |
| 62 |
| 58 std::string value = | 63 std::string value = |
| 59 request.httpHeaderField( | 64 request.httpHeaderField( |
| 60 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) | 65 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) |
| 61 .utf8(); | 66 .utf8(); |
| 62 return (value.find("identity;q=1") != std::string::npos) && | 67 return (value.find("identity;q=1") != std::string::npos) && |
| 63 (value.find("*;q=0") != std::string::npos); | 68 (value.find("*;q=0") != std::string::npos); |
| 64 } | 69 } |
| 65 | 70 |
| 66 class ResourceMultiBufferDataProviderTest : public testing::Test { | 71 class ResourceMultiBufferDataProviderTest : public testing::Test { |
| 67 public: | 72 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 } | 83 } |
| 79 | 84 |
| 80 virtual ~ResourceMultiBufferDataProviderTest() { | 85 virtual ~ResourceMultiBufferDataProviderTest() { |
| 81 view_->close(); | 86 view_->close(); |
| 82 frame_->close(); | 87 frame_->close(); |
| 83 } | 88 } |
| 84 | 89 |
| 85 void Initialize(const char* url, int first_position) { | 90 void Initialize(const char* url, int first_position) { |
| 86 gurl_ = GURL(url); | 91 gurl_ = GURL(url); |
| 87 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); | 92 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); |
| 93 url_data_->set_etag(kEtag); |
| 88 DCHECK(url_data_); | 94 DCHECK(url_data_); |
| 89 DCHECK(url_data_->frame()); | 95 DCHECK(url_data_->frame()); |
| 90 url_data_->OnRedirect( | 96 url_data_->OnRedirect( |
| 91 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, | 97 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, |
| 92 base::Unretained(this))); | 98 base::Unretained(this))); |
| 93 | 99 |
| 94 first_position_ = first_position; | 100 first_position_ = first_position; |
| 95 | 101 |
| 96 std::unique_ptr<ResourceMultiBufferDataProvider> loader( | 102 std::unique_ptr<ResourceMultiBufferDataProvider> loader( |
| 97 new ResourceMultiBufferDataProvider(url_data_.get(), first_position_)); | 103 new ResourceMultiBufferDataProvider(url_data_.get(), first_position_)); |
| 98 loader_ = loader.get(); | 104 loader_ = loader.get(); |
| 99 url_data_->multibuffer()->AddProvider(std::move(loader)); | 105 url_data_->multibuffer()->AddProvider(std::move(loader)); |
| 100 | 106 |
| 101 // |test_loader_| will be used when Start() is called. | 107 // |test_loader_| will be used when Start() is called. |
| 102 url_loader_ = new NiceMock<MockWebURLLoader>(); | 108 url_loader_ = new NiceMock<MockWebURLLoader>(); |
| 103 loader_->test_loader_ = std::unique_ptr<blink::WebURLLoader>(url_loader_); | 109 loader_->test_loader_ = std::unique_ptr<blink::WebURLLoader>(url_loader_); |
| 104 } | 110 } |
| 105 | 111 |
| 106 void Start() { | 112 void Start() { |
| 107 InSequence s; | 113 InSequence s; |
| 108 EXPECT_CALL(*url_loader_, | 114 EXPECT_CALL( |
| 109 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); | 115 *url_loader_, |
| 116 loadAsynchronously(Truly(CorrectAcceptEncodingAndEtag), loader_)); |
| 110 | 117 |
| 111 loader_->Start(); | 118 loader_->Start(); |
| 112 } | 119 } |
| 113 | 120 |
| 114 void FullResponse(int64_t instance_size, bool ok = true) { | 121 void FullResponse(int64_t instance_size, bool ok = true) { |
| 115 WebURLResponse response(gurl_); | 122 WebURLResponse response(gurl_); |
| 116 response.setHTTPHeaderField( | 123 response.setHTTPHeaderField( |
| 117 WebString::fromUTF8("Content-Length"), | 124 WebString::fromUTF8("Content-Length"), |
| 118 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size))); | 125 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size))); |
| 119 response.setExpectedContentLength(instance_size); | 126 response.setExpectedContentLength(instance_size); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { | 331 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { |
| 325 // Test redirect. | 332 // Test redirect. |
| 326 Initialize(kHttpUrl, 0); | 333 Initialize(kHttpUrl, 0); |
| 327 Start(); | 334 Start(); |
| 328 Redirect(kHttpRedirect); | 335 Redirect(kHttpRedirect); |
| 329 FullResponse(1024); | 336 FullResponse(1024); |
| 330 StopWhenLoad(); | 337 StopWhenLoad(); |
| 331 } | 338 } |
| 332 | 339 |
| 333 } // namespace media | 340 } // namespace media |
| OLD | NEW |