Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: media/blink/resource_multibuffer_data_provider_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 void Start() { 101 void Start() {
102 InSequence s; 102 InSequence s;
103 EXPECT_CALL(*url_loader_, 103 EXPECT_CALL(*url_loader_,
104 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); 104 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_));
105 105
106 loader_->Start(); 106 loader_->Start();
107 } 107 }
108 108
109 void FullResponse(int64 instance_size, bool ok = true) { 109 void FullResponse(int64_t instance_size, bool ok = true) {
110 WebURLResponse response(gurl_); 110 WebURLResponse response(gurl_);
111 response.setHTTPHeaderField( 111 response.setHTTPHeaderField(
112 WebString::fromUTF8("Content-Length"), 112 WebString::fromUTF8("Content-Length"),
113 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size))); 113 WebString::fromUTF8(base::StringPrintf("%" PRId64, instance_size)));
114 response.setExpectedContentLength(instance_size); 114 response.setExpectedContentLength(instance_size);
115 response.setHTTPStatusCode(kHttpOK); 115 response.setHTTPStatusCode(kHttpOK);
116 loader_->didReceiveResponse(url_loader_, response); 116 loader_->didReceiveResponse(url_loader_, response);
117 117
118 if (ok) { 118 if (ok) {
119 EXPECT_EQ(instance_size, url_data_->length()); 119 EXPECT_EQ(instance_size, url_data_->length());
120 } 120 }
121 121
122 EXPECT_FALSE(url_data_->range_supported()); 122 EXPECT_FALSE(url_data_->range_supported());
123 } 123 }
124 124
125 void PartialResponse(int64 first_position, 125 void PartialResponse(int64_t first_position,
126 int64 last_position, 126 int64_t last_position,
127 int64 instance_size) { 127 int64_t instance_size) {
128 PartialResponse(first_position, last_position, instance_size, false, true); 128 PartialResponse(first_position, last_position, instance_size, false, true);
129 } 129 }
130 130
131 void PartialResponse(int64 first_position, 131 void PartialResponse(int64_t first_position,
132 int64 last_position, 132 int64_t last_position,
133 int64 instance_size, 133 int64_t instance_size,
134 bool chunked, 134 bool chunked,
135 bool accept_ranges) { 135 bool accept_ranges) {
136 WebURLResponse response(gurl_); 136 WebURLResponse response(gurl_);
137 response.setHTTPHeaderField( 137 response.setHTTPHeaderField(
138 WebString::fromUTF8("Content-Range"), 138 WebString::fromUTF8("Content-Range"),
139 WebString::fromUTF8( 139 WebString::fromUTF8(
140 base::StringPrintf("bytes " 140 base::StringPrintf("bytes "
141 "%" PRId64 "-%" PRId64 "/%" PRId64, 141 "%" PRId64 "-%" PRId64 "/%" PRId64,
142 first_position, last_position, instance_size))); 142 first_position, last_position, instance_size)));
143 143
144 // HTTP 1.1 doesn't permit Content-Length with Transfer-Encoding: chunked. 144 // HTTP 1.1 doesn't permit Content-Length with Transfer-Encoding: chunked.
145 int64 content_length = -1; 145 int64_t content_length = -1;
146 if (chunked) { 146 if (chunked) {
147 response.setHTTPHeaderField(WebString::fromUTF8("Transfer-Encoding"), 147 response.setHTTPHeaderField(WebString::fromUTF8("Transfer-Encoding"),
148 WebString::fromUTF8("chunked")); 148 WebString::fromUTF8("chunked"));
149 } else { 149 } else {
150 content_length = last_position - first_position + 1; 150 content_length = last_position - first_position + 1;
151 } 151 }
152 response.setExpectedContentLength(content_length); 152 response.setExpectedContentLength(content_length);
153 153
154 // A server isn't required to return Accept-Ranges even though it might. 154 // A server isn't required to return Accept-Ranges even though it might.
155 if (accept_ranges) { 155 if (accept_ranges) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 loader_->didReceiveData( 192 loader_->didReceiveData(
193 url_loader_, reinterpret_cast<char*>(data_ + position), size, size); 193 url_loader_, reinterpret_cast<char*>(data_ + position), size, size);
194 } 194 }
195 195
196 void WriteData(int size) { 196 void WriteData(int size) {
197 scoped_ptr<char[]> data(new char[size]); 197 scoped_ptr<char[]> data(new char[size]);
198 loader_->didReceiveData(url_loader_, data.get(), size, size); 198 loader_->didReceiveData(url_loader_, data.get(), size, size);
199 } 199 }
200 200
201 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size]. 201 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size].
202 void VerifyBuffer(uint8* buffer, int pos, int size) { 202 void VerifyBuffer(uint8_t* buffer, int pos, int size) {
203 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size)); 203 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size));
204 } 204 }
205 205
206 bool HasActiveLoader() { return loader_->active_loader_; } 206 bool HasActiveLoader() { return loader_->active_loader_; }
207 MOCK_METHOD1(RedirectCallback, void(const scoped_refptr<UrlData>&)); 207 MOCK_METHOD1(RedirectCallback, void(const scoped_refptr<UrlData>&));
208 208
209 void SetUrlData(const scoped_refptr<UrlData>& new_url_data) { 209 void SetUrlData(const scoped_refptr<UrlData>& new_url_data) {
210 url_data_ = new_url_data; 210 url_data_ = new_url_data;
211 } 211 }
212 212
213 protected: 213 protected:
214 GURL gurl_; 214 GURL gurl_;
215 int64 first_position_; 215 int64_t first_position_;
216 216
217 scoped_ptr<UrlIndex> url_index_; 217 scoped_ptr<UrlIndex> url_index_;
218 scoped_refptr<UrlData> url_data_; 218 scoped_refptr<UrlData> url_data_;
219 scoped_refptr<UrlData> redirected_to_; 219 scoped_refptr<UrlData> redirected_to_;
220 // The loader is owned by the UrlData above. 220 // The loader is owned by the UrlData above.
221 ResourceMultiBufferDataProvider* loader_; 221 ResourceMultiBufferDataProvider* loader_;
222 NiceMock<MockWebURLLoader>* url_loader_; 222 NiceMock<MockWebURLLoader>* url_loader_;
223 223
224 MockWebFrameClient client_; 224 MockWebFrameClient client_;
225 WebView* view_; 225 WebView* view_;
226 WebLocalFrame* frame_; 226 WebLocalFrame* frame_;
227 227
228 base::MessageLoop message_loop_; 228 base::MessageLoop message_loop_;
229 229
230 uint8 data_[kDataSize]; 230 uint8_t data_[kDataSize];
231 231
232 private: 232 private:
233 DISALLOW_COPY_AND_ASSIGN(ResourceMultiBufferDataProviderTest); 233 DISALLOW_COPY_AND_ASSIGN(ResourceMultiBufferDataProviderTest);
234 }; 234 };
235 235
236 TEST_F(ResourceMultiBufferDataProviderTest, StartStop) { 236 TEST_F(ResourceMultiBufferDataProviderTest, StartStop) {
237 Initialize(kHttpUrl, 0); 237 Initialize(kHttpUrl, 0);
238 Start(); 238 Start();
239 StopWhenLoad(); 239 StopWhenLoad();
240 } 240 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { 321 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) {
322 // Test redirect. 322 // Test redirect.
323 Initialize(kHttpUrl, 0); 323 Initialize(kHttpUrl, 0);
324 Start(); 324 Start();
325 Redirect(kHttpRedirect); 325 Redirect(kHttpRedirect);
326 FullResponse(1024); 326 FullResponse(1024);
327 StopWhenLoad(); 327 StopWhenLoad();
328 } 328 }
329 329
330 } // namespace media 330 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698