| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "headless/public/util/generic_url_request_job.h" | 5 #include "headless/public/util/generic_url_request_job.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 // Return the canned response. | 85 // Return the canned response. |
| 86 std::unique_ptr<base::Value> fetch_reply( | 86 std::unique_ptr<base::Value> fetch_reply( |
| 87 base::JSONReader::Read(find_it->second, base::JSON_PARSE_RFC)); | 87 base::JSONReader::Read(find_it->second, base::JSON_PARSE_RFC)); |
| 88 CHECK(fetch_reply) << "Invalid json: " << find_it->second; | 88 CHECK(fetch_reply) << "Invalid json: " << find_it->second; |
| 89 | 89 |
| 90 base::DictionaryValue* reply_dictionary; | 90 base::DictionaryValue* reply_dictionary; |
| 91 ASSERT_TRUE(fetch_reply->GetAsDictionary(&reply_dictionary)); | 91 ASSERT_TRUE(fetch_reply->GetAsDictionary(&reply_dictionary)); |
| 92 std::string final_url; | 92 std::string final_url; |
| 93 ASSERT_TRUE(reply_dictionary->GetString("url", &final_url)); | 93 ASSERT_TRUE(reply_dictionary->GetString("url", &final_url)); |
| 94 int http_response_code; | |
| 95 ASSERT_TRUE(reply_dictionary->GetInteger("http_response_code", | |
| 96 &http_response_code)); | |
| 97 ASSERT_TRUE(reply_dictionary->GetString("data", &response_data_)); | 94 ASSERT_TRUE(reply_dictionary->GetString("data", &response_data_)); |
| 98 base::DictionaryValue* reply_headers_dictionary; | 95 base::DictionaryValue* reply_headers_dictionary; |
| 99 ASSERT_TRUE( | 96 ASSERT_TRUE( |
| 100 reply_dictionary->GetDictionary("headers", &reply_headers_dictionary)); | 97 reply_dictionary->GetDictionary("headers", &reply_headers_dictionary)); |
| 101 scoped_refptr<net::HttpResponseHeaders> response_headers( | 98 scoped_refptr<net::HttpResponseHeaders> response_headers( |
| 102 new net::HttpResponseHeaders("")); | 99 new net::HttpResponseHeaders("")); |
| 103 for (base::DictionaryValue::Iterator it(*reply_headers_dictionary); | 100 for (base::DictionaryValue::Iterator it(*reply_headers_dictionary); |
| 104 !it.IsAtEnd(); it.Advance()) { | 101 !it.IsAtEnd(); it.Advance()) { |
| 105 std::string value; | 102 std::string value; |
| 106 ASSERT_TRUE(it.value().GetAsString(&value)); | 103 ASSERT_TRUE(it.value().GetAsString(&value)); |
| 107 response_headers->AddHeader( | 104 response_headers->AddHeader( |
| 108 base::StringPrintf("%s: %s", it.key().c_str(), value.c_str())); | 105 base::StringPrintf("%s: %s", it.key().c_str(), value.c_str())); |
| 109 } | 106 } |
| 110 | 107 |
| 111 result_listener->OnFetchComplete( | 108 result_listener->OnFetchComplete( |
| 112 GURL(final_url), http_response_code, std::move(response_headers), | 109 GURL(final_url), std::move(response_headers), response_data_.c_str(), |
| 113 response_data_.c_str(), response_data_.size()); | 110 response_data_.size()); |
| 114 } | 111 } |
| 115 | 112 |
| 116 private: | 113 private: |
| 117 std::map<std::string, std::string>* json_fetch_reply_map_; // NOT OWNED | 114 std::map<std::string, std::string>* json_fetch_reply_map_; // NOT OWNED |
| 118 base::DictionaryValue* fetch_request_; // NOT OWNED | 115 base::DictionaryValue* fetch_request_; // NOT OWNED |
| 119 std::string response_data_; // Here to ensure the required lifetime. | 116 std::string response_data_; // Here to ensure the required lifetime. |
| 120 }; | 117 }; |
| 121 | 118 |
| 122 class MockProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { | 119 class MockProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
| 123 public: | 120 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 base::DictionaryValue fetch_request_; // The request sent to MockFetcher. | 183 base::DictionaryValue fetch_request_; // The request sent to MockFetcher. |
| 187 std::map<std::string, std::string> | 184 std::map<std::string, std::string> |
| 188 json_fetch_reply_map_; // Replies to be sent by MockFetcher. | 185 json_fetch_reply_map_; // Replies to be sent by MockFetcher. |
| 189 MockDelegate job_delegate_; | 186 MockDelegate job_delegate_; |
| 190 }; | 187 }; |
| 191 | 188 |
| 192 TEST_F(GenericURLRequestJobTest, BasicGetRequestParams) { | 189 TEST_F(GenericURLRequestJobTest, BasicGetRequestParams) { |
| 193 json_fetch_reply_map_["https://example.com/"] = R"( | 190 json_fetch_reply_map_["https://example.com/"] = R"( |
| 194 { | 191 { |
| 195 "url": "https://example.com", | 192 "url": "https://example.com", |
| 196 "http_response_code": 200, | |
| 197 "data": "Reply", | 193 "data": "Reply", |
| 198 "headers": { | 194 "headers": { |
| 199 "Content-Type": "text/html; charset=UTF-8" | 195 "Content-Type": "text/html; charset=UTF-8" |
| 200 } | 196 } |
| 201 })"; | 197 })"; |
| 202 | 198 |
| 203 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( | 199 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( |
| 204 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); | 200 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); |
| 205 request->SetReferrer("https://referrer.example.com"); | 201 request->SetReferrer("https://referrer.example.com"); |
| 206 request->SetExtraRequestHeaderByName("Extra-Header", "Value", true); | 202 request->SetExtraRequestHeaderByName("Extra-Header", "Value", true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 222 } | 218 } |
| 223 })"; | 219 })"; |
| 224 | 220 |
| 225 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); | 221 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); |
| 226 } | 222 } |
| 227 | 223 |
| 228 TEST_F(GenericURLRequestJobTest, BasicPostRequestParams) { | 224 TEST_F(GenericURLRequestJobTest, BasicPostRequestParams) { |
| 229 json_fetch_reply_map_["https://example.com/"] = R"( | 225 json_fetch_reply_map_["https://example.com/"] = R"( |
| 230 { | 226 { |
| 231 "url": "https://example.com", | 227 "url": "https://example.com", |
| 232 "http_response_code": 200, | |
| 233 "data": "Reply", | 228 "data": "Reply", |
| 234 "headers": { | 229 "headers": { |
| 235 "Content-Type": "text/html; charset=UTF-8" | 230 "Content-Type": "text/html; charset=UTF-8" |
| 236 } | 231 } |
| 237 })"; | 232 })"; |
| 238 | 233 |
| 239 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( | 234 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( |
| 240 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); | 235 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); |
| 241 request->SetReferrer("https://referrer.example.com"); | 236 request->SetReferrer("https://referrer.example.com"); |
| 242 request->SetExtraRequestHeaderByName("Extra-Header", "Value", true); | 237 request->SetExtraRequestHeaderByName("Extra-Header", "Value", true); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 266 } | 261 } |
| 267 })"; | 262 })"; |
| 268 | 263 |
| 269 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); | 264 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); |
| 270 } | 265 } |
| 271 | 266 |
| 272 TEST_F(GenericURLRequestJobTest, BasicRequestProperties) { | 267 TEST_F(GenericURLRequestJobTest, BasicRequestProperties) { |
| 273 std::string reply = R"( | 268 std::string reply = R"( |
| 274 { | 269 { |
| 275 "url": "https://example.com", | 270 "url": "https://example.com", |
| 276 "http_response_code": 200, | |
| 277 "data": "Reply", | 271 "data": "Reply", |
| 278 "headers": { | 272 "headers": { |
| 279 "Content-Type": "text/html; charset=UTF-8" | 273 "Content-Type": "text/html; charset=UTF-8" |
| 280 } | 274 } |
| 281 })"; | 275 })"; |
| 282 | 276 |
| 283 std::unique_ptr<net::URLRequest> request( | 277 std::unique_ptr<net::URLRequest> request( |
| 284 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 278 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 285 | 279 |
| 286 EXPECT_EQ(200, request->GetResponseCode()); | 280 EXPECT_EQ(200, request->GetResponseCode()); |
| 287 | 281 |
| 288 std::string mime_type; | 282 std::string mime_type; |
| 289 request->GetMimeType(&mime_type); | 283 request->GetMimeType(&mime_type); |
| 290 EXPECT_EQ("text/html", mime_type); | 284 EXPECT_EQ("text/html", mime_type); |
| 291 | 285 |
| 292 std::string charset; | 286 std::string charset; |
| 293 request->GetCharset(&charset); | 287 request->GetCharset(&charset); |
| 294 EXPECT_EQ("utf-8", charset); | 288 EXPECT_EQ("utf-8", charset); |
| 295 | 289 |
| 296 std::string content_type; | 290 std::string content_type; |
| 297 EXPECT_TRUE(request->response_info().headers->GetNormalizedHeader( | 291 EXPECT_TRUE(request->response_info().headers->GetNormalizedHeader( |
| 298 "Content-Type", &content_type)); | 292 "Content-Type", &content_type)); |
| 299 EXPECT_EQ("text/html; charset=UTF-8", content_type); | 293 EXPECT_EQ("text/html; charset=UTF-8", content_type); |
| 300 } | 294 } |
| 301 | 295 |
| 302 TEST_F(GenericURLRequestJobTest, BasicRequestContents) { | 296 TEST_F(GenericURLRequestJobTest, BasicRequestContents) { |
| 303 std::string reply = R"( | 297 std::string reply = R"( |
| 304 { | 298 { |
| 305 "url": "https://example.com", | 299 "url": "https://example.com", |
| 306 "http_response_code": 200, | |
| 307 "data": "Reply", | 300 "data": "Reply", |
| 308 "headers": { | 301 "headers": { |
| 309 "Content-Type": "text/html; charset=UTF-8" | 302 "Content-Type": "text/html; charset=UTF-8" |
| 310 } | 303 } |
| 311 })"; | 304 })"; |
| 312 | 305 |
| 313 std::unique_ptr<net::URLRequest> request( | 306 std::unique_ptr<net::URLRequest> request( |
| 314 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 307 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 315 | 308 |
| 316 const int kBufferSize = 256; | 309 const int kBufferSize = 256; |
| 317 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); | 310 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); |
| 318 int bytes_read; | 311 int bytes_read; |
| 319 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); | 312 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); |
| 320 EXPECT_EQ(5, bytes_read); | 313 EXPECT_EQ(5, bytes_read); |
| 321 EXPECT_EQ("Reply", std::string(buffer->data(), 5)); | 314 EXPECT_EQ("Reply", std::string(buffer->data(), 5)); |
| 322 | 315 |
| 323 net::LoadTimingInfo load_timing_info; | 316 net::LoadTimingInfo load_timing_info; |
| 324 request->GetLoadTimingInfo(&load_timing_info); | 317 request->GetLoadTimingInfo(&load_timing_info); |
| 325 EXPECT_FALSE(load_timing_info.receive_headers_end.is_null()); | 318 EXPECT_FALSE(load_timing_info.receive_headers_end.is_null()); |
| 326 } | 319 } |
| 327 | 320 |
| 328 TEST_F(GenericURLRequestJobTest, ReadInParts) { | 321 TEST_F(GenericURLRequestJobTest, ReadInParts) { |
| 329 std::string reply = R"( | 322 std::string reply = R"( |
| 330 { | 323 { |
| 331 "url": "https://example.com", | 324 "url": "https://example.com", |
| 332 "http_response_code": 200, | |
| 333 "data": "Reply", | 325 "data": "Reply", |
| 334 "headers": { | 326 "headers": { |
| 335 "Content-Type": "text/html; charset=UTF-8" | 327 "Content-Type": "text/html; charset=UTF-8" |
| 336 } | 328 } |
| 337 })"; | 329 })"; |
| 338 | 330 |
| 339 std::unique_ptr<net::URLRequest> request( | 331 std::unique_ptr<net::URLRequest> request( |
| 340 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 332 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 341 | 333 |
| 342 const int kBufferSize = 3; | 334 const int kBufferSize = 3; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 cookies->push_back(*net::CanonicalCookie::Create( | 401 cookies->push_back(*net::CanonicalCookie::Create( |
| 410 GURL("https://example.com"), "bad_path_cookie", "7", "example.com", | 402 GURL("https://example.com"), "bad_path_cookie", "7", "example.com", |
| 411 "/gadgets", base::Time(), base::Time(), | 403 "/gadgets", base::Time(), base::Time(), |
| 412 /* secure */ false, | 404 /* secure */ false, |
| 413 /* http_only */ false, net::CookieSameSite::NO_RESTRICTION, | 405 /* http_only */ false, net::CookieSameSite::NO_RESTRICTION, |
| 414 net::COOKIE_PRIORITY_DEFAULT)); | 406 net::COOKIE_PRIORITY_DEFAULT)); |
| 415 | 407 |
| 416 std::string reply = R"( | 408 std::string reply = R"( |
| 417 { | 409 { |
| 418 "url": "https://example.com", | 410 "url": "https://example.com", |
| 419 "http_response_code": 200, | |
| 420 "data": "Reply", | 411 "data": "Reply", |
| 421 "headers": { | 412 "headers": { |
| 422 "Content-Type": "text/html; charset=UTF-8" | 413 "Content-Type": "text/html; charset=UTF-8" |
| 423 } | 414 } |
| 424 })"; | 415 })"; |
| 425 | 416 |
| 426 std::unique_ptr<net::URLRequest> request( | 417 std::unique_ptr<net::URLRequest> request( |
| 427 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 418 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 428 | 419 |
| 429 std::string expected_request_json = R"( | 420 std::string expected_request_json = R"( |
| 430 { | 421 { |
| 431 "url": "https://example.com/", | 422 "url": "https://example.com/", |
| 432 "method": "GET", | 423 "method": "GET", |
| 433 "headers": { | 424 "headers": { |
| 434 "Cookie": "basic_cookie=1; secure_cookie=2; http_only_cookie=3", | 425 "Cookie": "basic_cookie=1; secure_cookie=2; http_only_cookie=3", |
| 435 "Referer": "" | 426 "Referer": "" |
| 436 } | 427 } |
| 437 })"; | 428 })"; |
| 438 | 429 |
| 439 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); | 430 EXPECT_THAT(fetch_request_, MatchesJson(expected_request_json)); |
| 440 } | 431 } |
| 441 | 432 |
| 442 TEST_F(GenericURLRequestJobTest, DelegateBlocksLoading) { | 433 TEST_F(GenericURLRequestJobTest, DelegateBlocksLoading) { |
| 443 std::string reply = R"( | 434 std::string reply = R"( |
| 444 { | 435 { |
| 445 "url": "https://example.com", | 436 "url": "https://example.com", |
| 446 "http_response_code": 200, | |
| 447 "data": "Reply", | 437 "data": "Reply", |
| 448 "headers": { | 438 "headers": { |
| 449 "Content-Type": "text/html; charset=UTF-8" | 439 "Content-Type": "text/html; charset=UTF-8" |
| 450 } | 440 } |
| 451 })"; | 441 })"; |
| 452 | 442 |
| 453 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { | 443 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { |
| 454 pending_request->BlockRequest(net::ERR_FILE_NOT_FOUND); | 444 pending_request->BlockRequest(net::ERR_FILE_NOT_FOUND); |
| 455 })); | 445 })); |
| 456 | 446 |
| 457 std::unique_ptr<net::URLRequest> request( | 447 std::unique_ptr<net::URLRequest> request( |
| 458 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 448 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 459 | 449 |
| 460 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 450 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
| 461 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); | 451 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); |
| 462 } | 452 } |
| 463 | 453 |
| 464 TEST_F(GenericURLRequestJobTest, DelegateModifiesRequest) { | 454 TEST_F(GenericURLRequestJobTest, DelegateModifiesRequest) { |
| 465 json_fetch_reply_map_["https://example.com/"] = R"( | 455 json_fetch_reply_map_["https://example.com/"] = R"( |
| 466 { | 456 { |
| 467 "url": "https://example.com", | 457 "url": "https://example.com", |
| 468 "http_response_code": 200, | |
| 469 "data": "Welcome to example.com", | 458 "data": "Welcome to example.com", |
| 470 "headers": { | 459 "headers": { |
| 471 "Content-Type": "text/html; charset=UTF-8" | 460 "Content-Type": "text/html; charset=UTF-8" |
| 472 } | 461 } |
| 473 })"; | 462 })"; |
| 474 | 463 |
| 475 json_fetch_reply_map_["https://othersite.com/"] = R"( | 464 json_fetch_reply_map_["https://othersite.com/"] = R"( |
| 476 { | 465 { |
| 477 "url": "https://example.com", | 466 "url": "https://example.com", |
| 478 "http_response_code": 200, | |
| 479 "data": "Welcome to othersite.com", | 467 "data": "Welcome to othersite.com", |
| 480 "headers": { | 468 "headers": { |
| 481 "Content-Type": "text/html; charset=UTF-8" | 469 "Content-Type": "text/html; charset=UTF-8" |
| 482 } | 470 } |
| 483 })"; | 471 })"; |
| 484 | 472 |
| 485 // Turn the GET into a POST to a different site. | 473 // Turn the GET into a POST to a different site. |
| 486 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { | 474 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { |
| 487 net::HttpRequestHeaders headers; | 475 net::HttpRequestHeaders headers; |
| 488 headers.SetHeader("TestHeader", "Hello"); | 476 headers.SetHeader("TestHeader", "Hello"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 518 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); | 506 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); |
| 519 EXPECT_EQ(24, bytes_read); | 507 EXPECT_EQ(24, bytes_read); |
| 520 EXPECT_EQ("Welcome to othersite.com", | 508 EXPECT_EQ("Welcome to othersite.com", |
| 521 std::string(buffer->data(), bytes_read)); | 509 std::string(buffer->data(), bytes_read)); |
| 522 } | 510 } |
| 523 | 511 |
| 524 TEST_F(GenericURLRequestJobTest, DelegateMocks404Response) { | 512 TEST_F(GenericURLRequestJobTest, DelegateMocks404Response) { |
| 525 std::string reply = R"( | 513 std::string reply = R"( |
| 526 { | 514 { |
| 527 "url": "https://example.com", | 515 "url": "https://example.com", |
| 528 "http_response_code": 200, | |
| 529 "data": "Reply", | 516 "data": "Reply", |
| 530 "headers": { | 517 "headers": { |
| 531 "Content-Type": "text/html; charset=UTF-8" | 518 "Content-Type": "text/html; charset=UTF-8" |
| 532 } | 519 } |
| 533 })"; | 520 })"; |
| 534 | 521 |
| 535 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { | 522 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { |
| 536 std::unique_ptr<GenericURLRequestJob::MockResponseData> mock_response_data( | 523 std::unique_ptr<GenericURLRequestJob::MockResponseData> mock_response_data( |
| 537 new GenericURLRequestJob::MockResponseData()); | 524 new GenericURLRequestJob::MockResponseData()); |
| 538 mock_response_data->http_response_code = 404; | |
| 539 mock_response_data->response_data = "HTTP/1.1 404 Not Found\r\n\r\n"; | 525 mock_response_data->response_data = "HTTP/1.1 404 Not Found\r\n\r\n"; |
| 540 pending_request->MockResponse(std::move(mock_response_data)); | 526 pending_request->MockResponse(std::move(mock_response_data)); |
| 541 })); | 527 })); |
| 542 | 528 |
| 543 std::unique_ptr<net::URLRequest> request( | 529 std::unique_ptr<net::URLRequest> request( |
| 544 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); | 530 CreateAndCompleteGetJob(GURL("https://example.com"), reply)); |
| 545 | 531 |
| 546 EXPECT_EQ(404, request->GetResponseCode()); | 532 EXPECT_EQ(404, request->GetResponseCode()); |
| 547 } | 533 } |
| 548 | 534 |
| 549 TEST_F(GenericURLRequestJobTest, DelegateMocks302Response) { | 535 TEST_F(GenericURLRequestJobTest, DelegateMocks302Response) { |
| 550 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { | 536 job_delegate_.SetPolicy(base::Bind([](PendingRequest* pending_request) { |
| 551 if (pending_request->GetRequest()->GetURLRequest()->url().spec() == | 537 if (pending_request->GetRequest()->GetURLRequest()->url().spec() == |
| 552 "https://example.com/") { | 538 "https://example.com/") { |
| 553 std::unique_ptr<GenericURLRequestJob::MockResponseData> | 539 std::unique_ptr<GenericURLRequestJob::MockResponseData> |
| 554 mock_response_data(new GenericURLRequestJob::MockResponseData()); | 540 mock_response_data(new GenericURLRequestJob::MockResponseData()); |
| 555 mock_response_data->http_response_code = 302; | |
| 556 mock_response_data->response_data = | 541 mock_response_data->response_data = |
| 557 "HTTP/1.1 302 Found\r\n" | 542 "HTTP/1.1 302 Found\r\n" |
| 558 "Location: https://foo.com/\r\n\r\n"; | 543 "Location: https://foo.com/\r\n\r\n"; |
| 559 pending_request->MockResponse(std::move(mock_response_data)); | 544 pending_request->MockResponse(std::move(mock_response_data)); |
| 560 } else { | 545 } else { |
| 561 pending_request->AllowRequest(); | 546 pending_request->AllowRequest(); |
| 562 } | 547 } |
| 563 })); | 548 })); |
| 564 | 549 |
| 565 json_fetch_reply_map_["https://example.com/"] = R"( | 550 json_fetch_reply_map_["https://example.com/"] = R"( |
| 566 { | 551 { |
| 567 "url": "https://example.com", | 552 "url": "https://example.com", |
| 568 "http_response_code": 200, | |
| 569 "data": "Welcome to example.com", | 553 "data": "Welcome to example.com", |
| 570 "headers": { | 554 "headers": { |
| 571 "Content-Type": "text/html; charset=UTF-8" | 555 "Content-Type": "text/html; charset=UTF-8" |
| 572 } | 556 } |
| 573 })"; | 557 })"; |
| 574 | 558 |
| 575 json_fetch_reply_map_["https://foo.com/"] = R"( | 559 json_fetch_reply_map_["https://foo.com/"] = R"( |
| 576 { | 560 { |
| 577 "url": "https://example.com", | 561 "url": "https://example.com", |
| 578 "http_response_code": 200, | |
| 579 "data": "Welcome to foo.com", | 562 "data": "Welcome to foo.com", |
| 580 "headers": { | 563 "headers": { |
| 581 "Content-Type": "text/html; charset=UTF-8" | 564 "Content-Type": "text/html; charset=UTF-8" |
| 582 } | 565 } |
| 583 })"; | 566 })"; |
| 584 | 567 |
| 585 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( | 568 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( |
| 586 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); | 569 GURL("https://example.com"), net::DEFAULT_PRIORITY, &request_delegate_)); |
| 587 request->Start(); | 570 request->Start(); |
| 588 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 603 OnResourceLoadFailed(_, net::ERR_ADDRESS_UNREACHABLE)); | 586 OnResourceLoadFailed(_, net::ERR_ADDRESS_UNREACHABLE)); |
| 604 | 587 |
| 605 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( | 588 std::unique_ptr<net::URLRequest> request(url_request_context_.CreateRequest( |
| 606 GURL("https://i-dont-exist.com"), net::DEFAULT_PRIORITY, | 589 GURL("https://i-dont-exist.com"), net::DEFAULT_PRIORITY, |
| 607 &request_delegate_)); | 590 &request_delegate_)); |
| 608 request->Start(); | 591 request->Start(); |
| 609 base::RunLoop().RunUntilIdle(); | 592 base::RunLoop().RunUntilIdle(); |
| 610 } | 593 } |
| 611 | 594 |
| 612 } // namespace headless | 595 } // namespace headless |
| OLD | NEW |