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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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 static bool got_frfr = false; |
| 58 |
57 // Predicate that tests that request disallows compressed data. | 59 // Predicate that tests that request disallows compressed data. |
58 static bool CorrectAcceptEncoding(const blink::WebURLRequest& request) { | 60 static bool CorrectAcceptEncodingAndProxy(const blink::WebURLRequest& request) { |
| 61 std::string chrome_proxy = |
| 62 request.HttpHeaderField(WebString::FromUTF8("chrome-proxy")).Utf8(); |
| 63 if (chrome_proxy != (got_frfr ? "" : "frfr")) { |
| 64 return false; |
| 65 } |
| 66 |
59 std::string value = request | 67 std::string value = request |
60 .HttpHeaderField(WebString::FromUTF8( | 68 .HttpHeaderField(WebString::FromUTF8( |
61 net::HttpRequestHeaders::kAcceptEncoding)) | 69 net::HttpRequestHeaders::kAcceptEncoding)) |
62 .Utf8(); | 70 .Utf8(); |
63 return (value.find("identity;q=1") != std::string::npos) && | 71 return (value.find("identity;q=1") != std::string::npos) && |
64 (value.find("*;q=0") != std::string::npos); | 72 (value.find("*;q=0") != std::string::npos); |
65 } | 73 } |
66 | 74 |
67 class ResourceMultiBufferDataProviderTest : public testing::Test { | 75 class ResourceMultiBufferDataProviderTest : public testing::Test { |
68 public: | 76 public: |
(...skipping 29 matching lines...) Expand all Loading... |
98 url_data_->multibuffer()->AddProvider(std::move(loader)); | 106 url_data_->multibuffer()->AddProvider(std::move(loader)); |
99 | 107 |
100 // |test_loader_| will be used when Start() is called. | 108 // |test_loader_| will be used when Start() is called. |
101 url_loader_ = new NiceMock<MockWebAssociatedURLLoader>(); | 109 url_loader_ = new NiceMock<MockWebAssociatedURLLoader>(); |
102 loader_->test_loader_ = | 110 loader_->test_loader_ = |
103 std::unique_ptr<blink::WebAssociatedURLLoader>(url_loader_); | 111 std::unique_ptr<blink::WebAssociatedURLLoader>(url_loader_); |
104 } | 112 } |
105 | 113 |
106 void Start() { | 114 void Start() { |
107 InSequence s; | 115 InSequence s; |
108 EXPECT_CALL(*url_loader_, | 116 got_frfr = false; |
109 LoadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); | 117 EXPECT_CALL( |
| 118 *url_loader_, |
| 119 LoadAsynchronously(Truly(CorrectAcceptEncodingAndProxy), loader_)); |
110 | 120 |
111 loader_->Start(); | 121 loader_->Start(); |
112 } | 122 } |
113 | 123 |
114 void FullResponse(int64_t instance_size, bool ok = true) { | 124 void FullResponse(int64_t instance_size, bool ok = true) { |
115 WebURLResponse response(gurl_); | 125 WebURLResponse response(gurl_); |
116 response.SetHTTPHeaderField( | 126 response.SetHTTPHeaderField( |
117 WebString::FromUTF8("Content-Length"), | 127 WebString::FromUTF8("Content-Length"), |
118 WebString::FromUTF8(base::StringPrintf("%" PRId64, instance_size))); | 128 WebString::FromUTF8(base::StringPrintf("%" PRId64, instance_size))); |
119 response.SetExpectedContentLength(instance_size); | 129 response.SetExpectedContentLength(instance_size); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { | 331 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { |
322 // Test redirect. | 332 // Test redirect. |
323 Initialize(kHttpUrl, 0); | 333 Initialize(kHttpUrl, 0); |
324 Start(); | 334 Start(); |
325 Redirect(kHttpRedirect); | 335 Redirect(kHttpRedirect); |
326 FullResponse(1024); | 336 FullResponse(1024); |
327 StopWhenLoad(); | 337 StopWhenLoad(); |
328 } | 338 } |
329 | 339 |
330 } // namespace media | 340 } // namespace media |
OLD | NEW |