| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const char kHttpRedirect[] = "http://test/ing"; | 48 const char kHttpRedirect[] = "http://test/ing"; |
| 49 const char kEtag[] = "\"arglebargle glopy-glyf?\""; | 49 const char kEtag[] = "\"arglebargle glopy-glyf?\""; |
| 50 | 50 |
| 51 const int kDataSize = 1024; | 51 const int kDataSize = 1024; |
| 52 const int kHttpOK = 200; | 52 const int kHttpOK = 200; |
| 53 const int kHttpPartialContent = 206; | 53 const int kHttpPartialContent = 206; |
| 54 | 54 |
| 55 enum NetworkState { NONE, LOADED, LOADING }; | 55 enum NetworkState { NONE, LOADED, LOADING }; |
| 56 | 56 |
| 57 // Predicate that tests that request disallows compressed data. | 57 // Predicate that tests that request disallows compressed data. |
| 58 static bool CorrectAcceptEncodingAndEtag(const blink::WebURLRequest& request) { | 58 static bool CorrectAcceptEncoding(const blink::WebURLRequest& request) { |
| 59 std::string etag = | |
| 60 request.httpHeaderField(WebString::fromUTF8("If-Match")).utf8(); | |
| 61 EXPECT_EQ(etag, kEtag); | |
| 62 | |
| 63 std::string value = | 59 std::string value = |
| 64 request.httpHeaderField( | 60 request.httpHeaderField( |
| 65 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) | 61 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding)) |
| 66 .utf8(); | 62 .utf8(); |
| 67 return (value.find("identity;q=1") != std::string::npos) && | 63 return (value.find("identity;q=1") != std::string::npos) && |
| 68 (value.find("*;q=0") != std::string::npos); | 64 (value.find("*;q=0") != std::string::npos); |
| 69 } | 65 } |
| 70 | 66 |
| 71 class ResourceMultiBufferDataProviderTest : public testing::Test { | 67 class ResourceMultiBufferDataProviderTest : public testing::Test { |
| 72 public: | 68 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 url_data_->multibuffer()->AddProvider(std::move(loader)); | 100 url_data_->multibuffer()->AddProvider(std::move(loader)); |
| 105 | 101 |
| 106 // |test_loader_| will be used when Start() is called. | 102 // |test_loader_| will be used when Start() is called. |
| 107 url_loader_ = new NiceMock<MockWebAssociatedURLLoader>(); | 103 url_loader_ = new NiceMock<MockWebAssociatedURLLoader>(); |
| 108 loader_->test_loader_ = | 104 loader_->test_loader_ = |
| 109 std::unique_ptr<blink::WebAssociatedURLLoader>(url_loader_); | 105 std::unique_ptr<blink::WebAssociatedURLLoader>(url_loader_); |
| 110 } | 106 } |
| 111 | 107 |
| 112 void Start() { | 108 void Start() { |
| 113 InSequence s; | 109 InSequence s; |
| 114 EXPECT_CALL( | 110 EXPECT_CALL(*url_loader_, |
| 115 *url_loader_, | 111 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); |
| 116 loadAsynchronously(Truly(CorrectAcceptEncodingAndEtag), loader_)); | |
| 117 | 112 |
| 118 loader_->Start(); | 113 loader_->Start(); |
| 119 } | 114 } |
| 120 | 115 |
| 121 void FullResponse(int64_t instance_size, bool ok = true) { | 116 void FullResponse(int64_t instance_size, bool ok = true) { |
| 122 WebURLResponse response(gurl_); | 117 WebURLResponse response(gurl_); |
| 123 response.setHTTPHeaderField( | 118 response.setHTTPHeaderField( |
| 124 WebString::fromUTF8("Content-Length"), | 119 WebString::fromUTF8("Content-Length"), |
| 125 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size))); | 120 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size))); |
| 126 response.setExpectedContentLength(instance_size); | 121 response.setExpectedContentLength(instance_size); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { | 323 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { |
| 329 // Test redirect. | 324 // Test redirect. |
| 330 Initialize(kHttpUrl, 0); | 325 Initialize(kHttpUrl, 0); |
| 331 Start(); | 326 Start(); |
| 332 Redirect(kHttpRedirect); | 327 Redirect(kHttpRedirect); |
| 333 FullResponse(1024); | 328 FullResponse(1024); |
| 334 StopWhenLoad(); | 329 StopWhenLoad(); |
| 335 } | 330 } |
| 336 | 331 |
| 337 } // namespace media | 332 } // namespace media |
| OLD | NEW |