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

Side by Side Diff: content/common/net/url_fetcher_impl_unittest.cc

Issue 10386063: Move URLFetcherDelegate to net/ and split URLFetcher between net/ and content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head, fix win component build Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/speech/google_one_shot_remote_engine.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/net/url_fetcher_impl.h" 5 #include "content/common/net/url_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 static int GetNumFetcherCores() { 81 static int GetNumFetcherCores() {
82 return URLFetcherImpl::GetNumFetcherCores(); 82 return URLFetcherImpl::GetNumFetcherCores();
83 } 83 }
84 84
85 // Creates a URLFetcher, using the program's main thread to do IO. 85 // Creates a URLFetcher, using the program's main thread to do IO.
86 virtual void CreateFetcher(const GURL& url); 86 virtual void CreateFetcher(const GURL& url);
87 87
88 // content::URLFetcherDelegate 88 // content::URLFetcherDelegate
89 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 89 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
90 90
91 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { 91 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() {
92 return io_message_loop_proxy_; 92 return io_message_loop_proxy_;
93 } 93 }
94 94
95 TestURLRequestContext* request_context() { 95 TestURLRequestContext* request_context() {
96 return context_.get(); 96 return context_.get();
97 } 97 }
98 98
99 protected: 99 protected:
(...skipping 25 matching lines...) Expand all
125 const scoped_ptr<TestURLRequestContext> context_; 125 const scoped_ptr<TestURLRequestContext> context_;
126 }; 126 };
127 127
128 void URLFetcherTest::CreateFetcher(const GURL& url) { 128 void URLFetcherTest::CreateFetcher(const GURL& url) {
129 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 129 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
130 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 130 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
131 io_message_loop_proxy(), request_context())); 131 io_message_loop_proxy(), request_context()));
132 fetcher_->Start(); 132 fetcher_->Start();
133 } 133 }
134 134
135 void URLFetcherTest::OnURLFetchComplete(const content::URLFetcher* source) { 135 void URLFetcherTest::OnURLFetchComplete(const net::URLFetcher* source) {
136 EXPECT_TRUE(source->GetStatus().is_success()); 136 EXPECT_TRUE(source->GetStatus().is_success());
137 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 137 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
138 138
139 std::string data; 139 std::string data;
140 EXPECT_TRUE(source->GetResponseAsString(&data)); 140 EXPECT_TRUE(source->GetResponseAsString(&data));
141 EXPECT_FALSE(data.empty()); 141 EXPECT_FALSE(data.empty());
142 142
143 delete fetcher_; // Have to delete this here and not in the destructor, 143 delete fetcher_; // Have to delete this here and not in the destructor,
144 // because the destructor won't necessarily run on the 144 // because the destructor won't necessarily run on the
145 // same thread that CreateFetcher() did. 145 // same thread that CreateFetcher() did.
146 146
147 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 147 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
148 // If the current message loop is not the IO loop, it will be shut down when 148 // If the current message loop is not the IO loop, it will be shut down when
149 // the main loop returns and this thread subsequently goes out of scope. 149 // the main loop returns and this thread subsequently goes out of scope.
150 } 150 }
151 151
152 namespace { 152 namespace {
153 153
154 // Version of URLFetcherTest that does a POST instead 154 // Version of URLFetcherTest that does a POST instead
155 class URLFetcherPostTest : public URLFetcherTest { 155 class URLFetcherPostTest : public URLFetcherTest {
156 public: 156 public:
157 // URLFetcherTest override. 157 // URLFetcherTest override.
158 virtual void CreateFetcher(const GURL& url) OVERRIDE; 158 virtual void CreateFetcher(const GURL& url) OVERRIDE;
159 159
160 // content::URLFetcherDelegate 160 // content::URLFetcherDelegate
161 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 161 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
162 }; 162 };
163 163
164 // Version of URLFetcherTest that tests download progress reports. 164 // Version of URLFetcherTest that tests download progress reports.
165 class URLFetcherDownloadProgressTest : public URLFetcherTest { 165 class URLFetcherDownloadProgressTest : public URLFetcherTest {
166 public: 166 public:
167 // URLFetcherTest override. 167 // URLFetcherTest override.
168 virtual void CreateFetcher(const GURL& url) OVERRIDE; 168 virtual void CreateFetcher(const GURL& url) OVERRIDE;
169 169
170 // content::URLFetcherDelegate 170 // content::URLFetcherDelegate
171 virtual void OnURLFetchDownloadProgress(const content::URLFetcher* source, 171 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
172 int64 current, int64 total) OVERRIDE; 172 int64 current, int64 total) OVERRIDE;
173 protected: 173 protected:
174 int64 previous_progress_; 174 int64 previous_progress_;
175 int64 expected_total_; 175 int64 expected_total_;
176 }; 176 };
177 177
178 /// Version of URLFetcherTest that tests progress reports at cancellation. 178 /// Version of URLFetcherTest that tests progress reports at cancellation.
179 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { 179 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest {
180 public: 180 public:
181 // URLFetcherTest override. 181 // URLFetcherTest override.
182 virtual void CreateFetcher(const GURL& url) OVERRIDE; 182 virtual void CreateFetcher(const GURL& url) OVERRIDE;
183 183
184 // content::URLFetcherDelegate 184 // content::URLFetcherDelegate
185 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 185 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
186 virtual void OnURLFetchDownloadProgress(const content::URLFetcher* source, 186 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
187 int64 current, int64 total) OVERRIDE; 187 int64 current, int64 total) OVERRIDE;
188 protected: 188 protected:
189 bool cancelled_; 189 bool cancelled_;
190 }; 190 };
191 191
192 // Version of URLFetcherTest that tests upload progress reports. 192 // Version of URLFetcherTest that tests upload progress reports.
193 class URLFetcherUploadProgressTest : public URLFetcherTest { 193 class URLFetcherUploadProgressTest : public URLFetcherTest {
194 public: 194 public:
195 virtual void CreateFetcher(const GURL& url); 195 virtual void CreateFetcher(const GURL& url);
196 196
197 // content::URLFetcherDelegate 197 // content::URLFetcherDelegate
198 virtual void OnURLFetchUploadProgress(const content::URLFetcher* source, 198 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
199 int64 current, int64 total); 199 int64 current, int64 total);
200 protected: 200 protected:
201 int64 previous_progress_; 201 int64 previous_progress_;
202 std::string chunk_; 202 std::string chunk_;
203 int64 number_of_chunks_added_; 203 int64 number_of_chunks_added_;
204 }; 204 };
205 205
206 // Version of URLFetcherTest that tests headers. 206 // Version of URLFetcherTest that tests headers.
207 class URLFetcherHeadersTest : public URLFetcherTest { 207 class URLFetcherHeadersTest : public URLFetcherTest {
208 public: 208 public:
209 // content::URLFetcherDelegate 209 // content::URLFetcherDelegate
210 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 210 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
211 }; 211 };
212 212
213 // Version of URLFetcherTest that tests SocketAddress. 213 // Version of URLFetcherTest that tests SocketAddress.
214 class URLFetcherSocketAddressTest : public URLFetcherTest { 214 class URLFetcherSocketAddressTest : public URLFetcherTest {
215 public: 215 public:
216 // content::URLFetcherDelegate 216 // content::URLFetcherDelegate
217 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 217 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
218 protected: 218 protected:
219 std::string expected_host_; 219 std::string expected_host_;
220 uint16 expected_port_; 220 uint16 expected_port_;
221 }; 221 };
222 222
223 // Version of URLFetcherTest that tests overload protection. 223 // Version of URLFetcherTest that tests overload protection.
224 class URLFetcherProtectTest : public URLFetcherTest { 224 class URLFetcherProtectTest : public URLFetcherTest {
225 public: 225 public:
226 // URLFetcherTest override. 226 // URLFetcherTest override.
227 virtual void CreateFetcher(const GURL& url) OVERRIDE; 227 virtual void CreateFetcher(const GURL& url) OVERRIDE;
228 // content::URLFetcherDelegate 228 // content::URLFetcherDelegate
229 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 229 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
230 private: 230 private:
231 Time start_time_; 231 Time start_time_;
232 }; 232 };
233 233
234 // Version of URLFetcherTest that tests overload protection, when responses 234 // Version of URLFetcherTest that tests overload protection, when responses
235 // passed through. 235 // passed through.
236 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { 236 class URLFetcherProtectTestPassedThrough : public URLFetcherTest {
237 public: 237 public:
238 // URLFetcherTest override. 238 // URLFetcherTest override.
239 virtual void CreateFetcher(const GURL& url) OVERRIDE; 239 virtual void CreateFetcher(const GURL& url) OVERRIDE;
240 // content::URLFetcherDelegate 240 // content::URLFetcherDelegate
241 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 241 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
242 private: 242 private:
243 Time start_time_; 243 Time start_time_;
244 }; 244 };
245 245
246 // Version of URLFetcherTest that tests bad HTTPS requests. 246 // Version of URLFetcherTest that tests bad HTTPS requests.
247 class URLFetcherBadHTTPSTest : public URLFetcherTest { 247 class URLFetcherBadHTTPSTest : public URLFetcherTest {
248 public: 248 public:
249 URLFetcherBadHTTPSTest(); 249 URLFetcherBadHTTPSTest();
250 250
251 // content::URLFetcherDelegate 251 // content::URLFetcherDelegate
252 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 252 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
253 253
254 private: 254 private:
255 FilePath cert_dir_; 255 FilePath cert_dir_;
256 }; 256 };
257 257
258 // Version of URLFetcherTest that tests request cancellation on shutdown. 258 // Version of URLFetcherTest that tests request cancellation on shutdown.
259 class URLFetcherCancelTest : public URLFetcherTest { 259 class URLFetcherCancelTest : public URLFetcherTest {
260 public: 260 public:
261 // URLFetcherTest override. 261 // URLFetcherTest override.
262 virtual void CreateFetcher(const GURL& url) OVERRIDE; 262 virtual void CreateFetcher(const GURL& url) OVERRIDE;
263 // content::URLFetcherDelegate 263 // content::URLFetcherDelegate
264 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 264 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
265 265
266 void CancelRequest(); 266 void CancelRequest();
267 }; 267 };
268 268
269 // Version of TestURLRequestContext that posts a Quit task to the IO 269 // Version of TestURLRequestContext that posts a Quit task to the IO
270 // thread once it is deleted. 270 // thread once it is deleted.
271 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { 271 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext {
272 public: 272 public:
273 explicit CancelTestURLRequestContext() { 273 explicit CancelTestURLRequestContext() {
274 } 274 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 scoped_ptr<TestURLRequestContext> context_; 326 scoped_ptr<TestURLRequestContext> context_;
327 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 327 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
328 base::WaitableEvent context_created_; 328 base::WaitableEvent context_created_;
329 GURL throttle_for_url_; 329 GURL throttle_for_url_;
330 }; 330 };
331 331
332 // Version of URLFetcherTest that tests retying the same request twice. 332 // Version of URLFetcherTest that tests retying the same request twice.
333 class URLFetcherMultipleAttemptTest : public URLFetcherTest { 333 class URLFetcherMultipleAttemptTest : public URLFetcherTest {
334 public: 334 public:
335 // content::URLFetcherDelegate 335 // content::URLFetcherDelegate
336 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 336 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
337 private: 337 private:
338 std::string data_; 338 std::string data_;
339 }; 339 };
340 340
341 class URLFetcherFileTest : public URLFetcherTest { 341 class URLFetcherFileTest : public URLFetcherTest {
342 public: 342 public:
343 URLFetcherFileTest() : take_ownership_of_file_(false), 343 URLFetcherFileTest() : take_ownership_of_file_(false),
344 expected_file_error_(base::PLATFORM_FILE_OK) {} 344 expected_file_error_(base::PLATFORM_FILE_OK) {}
345 345
346 void CreateFetcherForFile(const GURL& url, const FilePath& file_path); 346 void CreateFetcherForFile(const GURL& url, const FilePath& file_path);
347 void CreateFetcherForTempFile(const GURL& url); 347 void CreateFetcherForTempFile(const GURL& url);
348 348
349 // content::URLFetcherDelegate 349 // content::URLFetcherDelegate
350 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 350 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
351 351
352 protected: 352 protected:
353 FilePath expected_file_; 353 FilePath expected_file_;
354 FilePath file_path_; 354 FilePath file_path_;
355 355
356 // Set by the test. Used in OnURLFetchComplete() to decide if 356 // Set by the test. Used in OnURLFetchComplete() to decide if
357 // the URLFetcher should own the temp file, so that we can test 357 // the URLFetcher should own the temp file, so that we can test
358 // disowning prevents the file from being deleted. 358 // disowning prevents the file from being deleted.
359 bool take_ownership_of_file_; 359 bool take_ownership_of_file_;
360 360
361 // Expected file error code for the test. 361 // Expected file error code for the test.
362 // PLATFORM_FILE_OK when expecting success. 362 // PLATFORM_FILE_OK when expecting success.
363 base::PlatformFileError expected_file_error_; 363 base::PlatformFileError expected_file_error_;
364 }; 364 };
365 365
366 void URLFetcherPostTest::CreateFetcher(const GURL& url) { 366 void URLFetcherPostTest::CreateFetcher(const GURL& url) {
367 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); 367 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this);
368 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 368 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
369 io_message_loop_proxy(), request_context())); 369 io_message_loop_proxy(), request_context()));
370 fetcher_->SetUploadData("application/x-www-form-urlencoded", 370 fetcher_->SetUploadData("application/x-www-form-urlencoded",
371 "bobsyeruncle"); 371 "bobsyeruncle");
372 fetcher_->Start(); 372 fetcher_->Start();
373 } 373 }
374 374
375 void URLFetcherPostTest::OnURLFetchComplete(const content::URLFetcher* source) { 375 void URLFetcherPostTest::OnURLFetchComplete(const net::URLFetcher* source) {
376 std::string data; 376 std::string data;
377 EXPECT_TRUE(source->GetResponseAsString(&data)); 377 EXPECT_TRUE(source->GetResponseAsString(&data));
378 EXPECT_EQ(std::string("bobsyeruncle"), data); 378 EXPECT_EQ(std::string("bobsyeruncle"), data);
379 URLFetcherTest::OnURLFetchComplete(source); 379 URLFetcherTest::OnURLFetchComplete(source);
380 } 380 }
381 381
382 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { 382 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) {
383 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 383 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
384 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 384 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
385 io_message_loop_proxy(), request_context())); 385 io_message_loop_proxy(), request_context()));
386 previous_progress_ = 0; 386 previous_progress_ = 0;
387 fetcher_->Start(); 387 fetcher_->Start();
388 } 388 }
389 389
390 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( 390 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress(
391 const content::URLFetcher* source, int64 current, int64 total) { 391 const net::URLFetcher* source, int64 current, int64 total) {
392 // Increasing between 0 and total. 392 // Increasing between 0 and total.
393 EXPECT_LE(0, current); 393 EXPECT_LE(0, current);
394 EXPECT_GE(total, current); 394 EXPECT_GE(total, current);
395 EXPECT_LE(previous_progress_, current); 395 EXPECT_LE(previous_progress_, current);
396 previous_progress_ = current; 396 previous_progress_ = current;
397 EXPECT_EQ(expected_total_, total); 397 EXPECT_EQ(expected_total_, total);
398 } 398 }
399 399
400 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { 400 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) {
401 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 401 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
402 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 402 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
403 io_message_loop_proxy(), request_context())); 403 io_message_loop_proxy(), request_context()));
404 cancelled_ = false; 404 cancelled_ = false;
405 fetcher_->Start(); 405 fetcher_->Start();
406 } 406 }
407 407
408 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( 408 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress(
409 const content::URLFetcher* source, int64 current, int64 total) { 409 const net::URLFetcher* source, int64 current, int64 total) {
410 EXPECT_FALSE(cancelled_); 410 EXPECT_FALSE(cancelled_);
411 if (!cancelled_) { 411 if (!cancelled_) {
412 delete fetcher_; 412 delete fetcher_;
413 cancelled_ = true; 413 cancelled_ = true;
414 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 414 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
415 } 415 }
416 } 416 }
417 417
418 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( 418 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete(
419 const content::URLFetcher* source) { 419 const net::URLFetcher* source) {
420 // Should have been cancelled. 420 // Should have been cancelled.
421 ADD_FAILURE(); 421 ADD_FAILURE();
422 delete fetcher_; 422 delete fetcher_;
423 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 423 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
424 } 424 }
425 425
426 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { 426 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) {
427 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); 427 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this);
428 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 428 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
429 io_message_loop_proxy(), request_context())); 429 io_message_loop_proxy(), request_context()));
430 previous_progress_ = 0; 430 previous_progress_ = 0;
431 // Large enough data to require more than one read from UploadDataStream. 431 // Large enough data to require more than one read from UploadDataStream.
432 chunk_.assign(1<<16, 'a'); 432 chunk_.assign(1<<16, 'a');
433 // Use chunked upload to wait for a timer event of progress notification. 433 // Use chunked upload to wait for a timer event of progress notification.
434 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); 434 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded");
435 fetcher_->Start(); 435 fetcher_->Start();
436 number_of_chunks_added_ = 1; 436 number_of_chunks_added_ = 1;
437 fetcher_->AppendChunkToUpload(chunk_, false); 437 fetcher_->AppendChunkToUpload(chunk_, false);
438 } 438 }
439 439
440 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( 440 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress(
441 const content::URLFetcher* source, int64 current, int64 total) { 441 const net::URLFetcher* source, int64 current, int64 total) {
442 // Increasing between 0 and total. 442 // Increasing between 0 and total.
443 EXPECT_LE(0, current); 443 EXPECT_LE(0, current);
444 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, 444 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_,
445 current); 445 current);
446 EXPECT_LE(previous_progress_, current); 446 EXPECT_LE(previous_progress_, current);
447 previous_progress_ = current; 447 previous_progress_ = current;
448 EXPECT_EQ(-1, total); 448 EXPECT_EQ(-1, total);
449 449
450 if (number_of_chunks_added_ < 2) { 450 if (number_of_chunks_added_ < 2) {
451 number_of_chunks_added_ += 1; 451 number_of_chunks_added_ += 1;
452 fetcher_->AppendChunkToUpload(chunk_, true); 452 fetcher_->AppendChunkToUpload(chunk_, true);
453 } 453 }
454 } 454 }
455 455
456 void URLFetcherHeadersTest::OnURLFetchComplete( 456 void URLFetcherHeadersTest::OnURLFetchComplete(
457 const content::URLFetcher* source) { 457 const net::URLFetcher* source) {
458 std::string header; 458 std::string header;
459 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control", 459 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control",
460 &header)); 460 &header));
461 EXPECT_EQ("private", header); 461 EXPECT_EQ("private", header);
462 URLFetcherTest::OnURLFetchComplete(source); 462 URLFetcherTest::OnURLFetchComplete(source);
463 } 463 }
464 464
465 void URLFetcherSocketAddressTest::OnURLFetchComplete( 465 void URLFetcherSocketAddressTest::OnURLFetchComplete(
466 const content::URLFetcher* source) { 466 const net::URLFetcher* source) {
467 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host()); 467 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host());
468 EXPECT_EQ(expected_port_, source->GetSocketAddress().port()); 468 EXPECT_EQ(expected_port_, source->GetSocketAddress().port());
469 URLFetcherTest::OnURLFetchComplete(source); 469 URLFetcherTest::OnURLFetchComplete(source);
470 } 470 }
471 471
472 void URLFetcherProtectTest::CreateFetcher(const GURL& url) { 472 void URLFetcherProtectTest::CreateFetcher(const GURL& url) {
473 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 473 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
474 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 474 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
475 io_message_loop_proxy(), request_context())); 475 io_message_loop_proxy(), request_context()));
476 start_time_ = Time::Now(); 476 start_time_ = Time::Now();
477 fetcher_->SetMaxRetries(11); 477 fetcher_->SetMaxRetries(11);
478 fetcher_->Start(); 478 fetcher_->Start();
479 } 479 }
480 480
481 void URLFetcherProtectTest::OnURLFetchComplete( 481 void URLFetcherProtectTest::OnURLFetchComplete(
482 const content::URLFetcher* source) { 482 const net::URLFetcher* source) {
483 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); 483 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000);
484 if (source->GetResponseCode() >= 500) { 484 if (source->GetResponseCode() >= 500) {
485 // Now running ServerUnavailable test. 485 // Now running ServerUnavailable test.
486 // It takes more than 1 second to finish all 11 requests. 486 // It takes more than 1 second to finish all 11 requests.
487 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); 487 EXPECT_TRUE(Time::Now() - start_time_ >= one_second);
488 EXPECT_TRUE(source->GetStatus().is_success()); 488 EXPECT_TRUE(source->GetStatus().is_success());
489 std::string data; 489 std::string data;
490 EXPECT_TRUE(source->GetResponseAsString(&data)); 490 EXPECT_TRUE(source->GetResponseAsString(&data));
491 EXPECT_FALSE(data.empty()); 491 EXPECT_FALSE(data.empty());
492 delete fetcher_; 492 delete fetcher_;
(...skipping 20 matching lines...) Expand all
513 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 513 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
514 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 514 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
515 io_message_loop_proxy(), request_context())); 515 io_message_loop_proxy(), request_context()));
516 fetcher_->SetAutomaticallyRetryOn5xx(false); 516 fetcher_->SetAutomaticallyRetryOn5xx(false);
517 start_time_ = Time::Now(); 517 start_time_ = Time::Now();
518 fetcher_->SetMaxRetries(11); 518 fetcher_->SetMaxRetries(11);
519 fetcher_->Start(); 519 fetcher_->Start();
520 } 520 }
521 521
522 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete( 522 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete(
523 const content::URLFetcher* source) { 523 const net::URLFetcher* source) {
524 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000); 524 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000);
525 if (source->GetResponseCode() >= 500) { 525 if (source->GetResponseCode() >= 500) {
526 // Now running ServerUnavailable test. 526 // Now running ServerUnavailable test.
527 // It should get here on the first attempt, so almost immediately and 527 // It should get here on the first attempt, so almost immediately and
528 // *not* to attempt to execute all 11 requests (2.5 minutes). 528 // *not* to attempt to execute all 11 requests (2.5 minutes).
529 EXPECT_TRUE(Time::Now() - start_time_ < one_minute); 529 EXPECT_TRUE(Time::Now() - start_time_ < one_minute);
530 EXPECT_TRUE(source->GetStatus().is_success()); 530 EXPECT_TRUE(source->GetStatus().is_success());
531 // Check that suggested back off time is bigger than 0. 531 // Check that suggested back off time is bigger than 0.
532 EXPECT_GT(fetcher_->GetBackoffDelay().InMicroseconds(), 0); 532 EXPECT_GT(fetcher_->GetBackoffDelay().InMicroseconds(), 0);
533 std::string data; 533 std::string data;
(...skipping 15 matching lines...) Expand all
549 cert_dir_ = cert_dir_.AppendASCII("test"); 549 cert_dir_ = cert_dir_.AppendASCII("test");
550 cert_dir_ = cert_dir_.AppendASCII("data"); 550 cert_dir_ = cert_dir_.AppendASCII("data");
551 cert_dir_ = cert_dir_.AppendASCII("ssl"); 551 cert_dir_ = cert_dir_.AppendASCII("ssl");
552 cert_dir_ = cert_dir_.AppendASCII("certificates"); 552 cert_dir_ = cert_dir_.AppendASCII("certificates");
553 } 553 }
554 554
555 // The "server certificate expired" error should result in automatic 555 // The "server certificate expired" error should result in automatic
556 // cancellation of the request by 556 // cancellation of the request by
557 // net::URLRequest::Delegate::OnSSLCertificateError. 557 // net::URLRequest::Delegate::OnSSLCertificateError.
558 void URLFetcherBadHTTPSTest::OnURLFetchComplete( 558 void URLFetcherBadHTTPSTest::OnURLFetchComplete(
559 const content::URLFetcher* source) { 559 const net::URLFetcher* source) {
560 // This part is different from URLFetcherTest::OnURLFetchComplete 560 // This part is different from URLFetcherTest::OnURLFetchComplete
561 // because this test expects the request to be cancelled. 561 // because this test expects the request to be cancelled.
562 EXPECT_EQ(net::URLRequestStatus::CANCELED, source->GetStatus().status()); 562 EXPECT_EQ(net::URLRequestStatus::CANCELED, source->GetStatus().status());
563 EXPECT_EQ(net::ERR_ABORTED, source->GetStatus().error()); 563 EXPECT_EQ(net::ERR_ABORTED, source->GetStatus().error());
564 EXPECT_EQ(-1, source->GetResponseCode()); 564 EXPECT_EQ(-1, source->GetResponseCode());
565 EXPECT_TRUE(source->GetCookies().empty()); 565 EXPECT_TRUE(source->GetCookies().empty());
566 std::string data; 566 std::string data;
567 EXPECT_TRUE(source->GetResponseAsString(&data)); 567 EXPECT_TRUE(source->GetResponseAsString(&data));
568 EXPECT_TRUE(data.empty()); 568 EXPECT_TRUE(data.empty());
569 569
(...skipping 10 matching lines...) Expand all
580 fetcher_->SetRequestContext(context_getter); 580 fetcher_->SetRequestContext(context_getter);
581 fetcher_->SetMaxRetries(2); 581 fetcher_->SetMaxRetries(2);
582 fetcher_->Start(); 582 fetcher_->Start();
583 // We need to wait for the creation of the net::URLRequestContext, since we 583 // We need to wait for the creation of the net::URLRequestContext, since we
584 // rely on it being destroyed as a signal to end the test. 584 // rely on it being destroyed as a signal to end the test.
585 context_getter->WaitForContextCreation(); 585 context_getter->WaitForContextCreation();
586 CancelRequest(); 586 CancelRequest();
587 } 587 }
588 588
589 void URLFetcherCancelTest::OnURLFetchComplete( 589 void URLFetcherCancelTest::OnURLFetchComplete(
590 const content::URLFetcher* source) { 590 const net::URLFetcher* source) {
591 // We should have cancelled the request before completion. 591 // We should have cancelled the request before completion.
592 ADD_FAILURE(); 592 ADD_FAILURE();
593 delete fetcher_; 593 delete fetcher_;
594 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 594 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
595 } 595 }
596 596
597 void URLFetcherCancelTest::CancelRequest() { 597 void URLFetcherCancelTest::CancelRequest() {
598 delete fetcher_; 598 delete fetcher_;
599 // The URLFetcher's test context will post a Quit task once it is 599 // The URLFetcher's test context will post a Quit task once it is
600 // deleted. So if this test simply hangs, it means cancellation 600 // deleted. So if this test simply hangs, it means cancellation
601 // did not work. 601 // did not work.
602 } 602 }
603 603
604 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( 604 void URLFetcherMultipleAttemptTest::OnURLFetchComplete(
605 const content::URLFetcher* source) { 605 const net::URLFetcher* source) {
606 EXPECT_TRUE(source->GetStatus().is_success()); 606 EXPECT_TRUE(source->GetStatus().is_success());
607 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK 607 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK
608 std::string data; 608 std::string data;
609 EXPECT_TRUE(source->GetResponseAsString(&data)); 609 EXPECT_TRUE(source->GetResponseAsString(&data));
610 EXPECT_FALSE(data.empty()); 610 EXPECT_FALSE(data.empty());
611 if (!data.empty() && data_.empty()) { 611 if (!data.empty() && data_.empty()) {
612 data_ = data; 612 data_ = data;
613 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 613 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
614 io_message_loop_proxy(), request_context())); 614 io_message_loop_proxy(), request_context()));
615 fetcher_->Start(); 615 fetcher_->Start();
(...skipping 23 matching lines...) Expand all
639 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { 639 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) {
640 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); 640 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this);
641 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( 641 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
642 io_message_loop_proxy(), request_context())); 642 io_message_loop_proxy(), request_context()));
643 643
644 // Use the IO message loop to do the file operations in this test. 644 // Use the IO message loop to do the file operations in this test.
645 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); 645 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy());
646 fetcher_->Start(); 646 fetcher_->Start();
647 } 647 }
648 648
649 void URLFetcherFileTest::OnURLFetchComplete(const content::URLFetcher* source) { 649 void URLFetcherFileTest::OnURLFetchComplete(const net::URLFetcher* source) {
650 if (expected_file_error_ == base::PLATFORM_FILE_OK) { 650 if (expected_file_error_ == base::PLATFORM_FILE_OK) {
651 EXPECT_TRUE(source->GetStatus().is_success()); 651 EXPECT_TRUE(source->GetStatus().is_success());
652 EXPECT_EQ(source->GetResponseCode(), 200); 652 EXPECT_EQ(source->GetResponseCode(), 200);
653 653
654 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 654 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
655 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code)); 655 EXPECT_FALSE(fetcher_->FileErrorOccurred(&error_code));
656 656
657 EXPECT_TRUE(source->GetResponseAsFilePath( 657 EXPECT_TRUE(source->GetResponseAsFilePath(
658 take_ownership_of_file_, &file_path_)); 658 take_ownership_of_file_, &file_path_));
659 659
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 std::string(kTestServerFilePrefix) + kFileToFetch)); 1146 std::string(kTestServerFilePrefix) + kFileToFetch));
1147 1147
1148 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1148 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1149 1149
1150 MessageLoop::current()->RunAllPending(); 1150 MessageLoop::current()->RunAllPending();
1151 ASSERT_FALSE(file_util::PathExists(file_path_)) 1151 ASSERT_FALSE(file_util::PathExists(file_path_))
1152 << file_path_.value() << " not removed."; 1152 << file_path_.value() << " not removed.";
1153 } 1153 }
1154 1154
1155 } // namespace. 1155 } // namespace.
OLDNEW
« no previous file with comments | « content/browser/speech/google_one_shot_remote_engine.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698