| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 reply_dictionary->GetDictionary("headers", &reply_headers_dictionary)); | 79 reply_dictionary->GetDictionary("headers", &reply_headers_dictionary)); |
| 80 scoped_refptr<net::HttpResponseHeaders> response_headers( | 80 scoped_refptr<net::HttpResponseHeaders> response_headers( |
| 81 new net::HttpResponseHeaders("")); | 81 new net::HttpResponseHeaders("")); |
| 82 for (base::DictionaryValue::Iterator it(*reply_headers_dictionary); | 82 for (base::DictionaryValue::Iterator it(*reply_headers_dictionary); |
| 83 !it.IsAtEnd(); it.Advance()) { | 83 !it.IsAtEnd(); it.Advance()) { |
| 84 std::string value; | 84 std::string value; |
| 85 ASSERT_TRUE(it.value().GetAsString(&value)); | 85 ASSERT_TRUE(it.value().GetAsString(&value)); |
| 86 response_headers->AddHeader( | 86 response_headers->AddHeader( |
| 87 base::StringPrintf("%s: %s", it.key().c_str(), value.c_str())); | 87 base::StringPrintf("%s: %s", it.key().c_str(), value.c_str())); |
| 88 } | 88 } |
| 89 |
| 89 result_listener->OnFetchComplete( | 90 result_listener->OnFetchComplete( |
| 90 GURL(final_url), http_response_code, std::move(response_headers), | 91 GURL(final_url), http_response_code, std::move(response_headers), |
| 91 response_data_.c_str(), response_data_.size()); | 92 response_data_.c_str(), response_data_.size()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 std::unique_ptr<base::Value> fetch_reply_; | 96 std::unique_ptr<base::Value> fetch_reply_; |
| 96 base::DictionaryValue* fetch_request_; // NOT OWNED | 97 base::DictionaryValue* fetch_request_; // NOT OWNED |
| 97 std::string response_data_; // Here to ensure the required lifetime. | 98 std::string response_data_; // Here to ensure the required lifetime. |
| 98 }; | 99 }; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 234 |
| 234 std::unique_ptr<net::URLRequest> request( | 235 std::unique_ptr<net::URLRequest> request( |
| 235 CreateAndCompleteJob(GURL("https://example.com"), reply)); | 236 CreateAndCompleteJob(GURL("https://example.com"), reply)); |
| 236 | 237 |
| 237 const int kBufferSize = 256; | 238 const int kBufferSize = 256; |
| 238 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); | 239 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); |
| 239 int bytes_read; | 240 int bytes_read; |
| 240 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); | 241 EXPECT_TRUE(request->Read(buffer.get(), kBufferSize, &bytes_read)); |
| 241 EXPECT_EQ(5, bytes_read); | 242 EXPECT_EQ(5, bytes_read); |
| 242 EXPECT_EQ("Reply", std::string(buffer->data(), 5)); | 243 EXPECT_EQ("Reply", std::string(buffer->data(), 5)); |
| 244 |
| 245 net::LoadTimingInfo load_timing_info; |
| 246 request->GetLoadTimingInfo(&load_timing_info); |
| 247 EXPECT_FALSE(load_timing_info.receive_headers_end.is_null()); |
| 243 } | 248 } |
| 244 | 249 |
| 245 TEST_F(GenericURLRequestJobTest, ReadInParts) { | 250 TEST_F(GenericURLRequestJobTest, ReadInParts) { |
| 246 std::string reply = | 251 std::string reply = |
| 247 "{\"url\":\"https://example.com\"," | 252 "{\"url\":\"https://example.com\"," |
| 248 " \"http_response_code\":200," | 253 " \"http_response_code\":200," |
| 249 " \"data\":\"Reply\"," | 254 " \"data\":\"Reply\"," |
| 250 " \"headers\":{\"Content-Type\":\"text/html; charset=UTF-8\"}}"; | 255 " \"headers\":{\"Content-Type\":\"text/html; charset=UTF-8\"}}"; |
| 251 | 256 |
| 252 std::unique_ptr<net::URLRequest> request( | 257 std::unique_ptr<net::URLRequest> request( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 job_delegate_.SetShouldBlock(true); | 362 job_delegate_.SetShouldBlock(true); |
| 358 | 363 |
| 359 std::unique_ptr<net::URLRequest> request( | 364 std::unique_ptr<net::URLRequest> request( |
| 360 CreateAndCompleteJob(GURL("https://example.com"), reply)); | 365 CreateAndCompleteJob(GURL("https://example.com"), reply)); |
| 361 | 366 |
| 362 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); | 367 EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status()); |
| 363 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); | 368 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request->status().error()); |
| 364 } | 369 } |
| 365 | 370 |
| 366 } // namespace headless | 371 } // namespace headless |
| OLD | NEW |