OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 args.push_back("python"); | 62 args.push_back("python"); |
63 args.push_back("util/net/http_transport_test_server.py"); | 63 args.push_back("util/net/http_transport_test_server.py"); |
64 SetChildCommand(getenv("COMSPEC"), &args); | 64 SetChildCommand(getenv("COMSPEC"), &args); |
65 #endif // OS_POSIX | 65 #endif // OS_POSIX |
66 } | 66 } |
67 | 67 |
68 const HTTPHeaders& headers() { return headers_; } | 68 const HTTPHeaders& headers() { return headers_; } |
69 | 69 |
70 private: | 70 private: |
71 void MultiprocessParent() override { | 71 void MultiprocessParent() override { |
72 // Use Logging*FD() instead of Checked*FD() so that the test can fail | 72 // Use Logging*File() instead of Checked*File() so that the test can fail |
73 // gracefully with a gtest assertion if the child does not execute properly. | 73 // gracefully with a gtest assertion if the child does not execute properly. |
74 | 74 |
75 // The child will write the HTTP server port number as a packed unsigned | 75 // The child will write the HTTP server port number as a packed unsigned |
76 // short to stdout. | 76 // short to stdout. |
77 uint16_t port; | 77 uint16_t port; |
78 ASSERT_TRUE(LoggingReadFile(ReadPipeFD(), &port, sizeof(port))); | 78 ASSERT_TRUE(LoggingReadFile(ReadPipeHandle(), &port, sizeof(port))); |
79 | 79 |
80 // Then the parent will tell the web server what response code to send | 80 // Then the parent will tell the web server what response code to send |
81 // for the HTTP request. | 81 // for the HTTP request. |
82 ASSERT_TRUE(LoggingWriteFile( | 82 ASSERT_TRUE(LoggingWriteFile( |
83 WritePipeFD(), &response_code_, sizeof(response_code_))); | 83 WritePipeHandle(), &response_code_, sizeof(response_code_))); |
84 | 84 |
85 // Now execute the HTTP request. | 85 // Now execute the HTTP request. |
86 scoped_ptr<HTTPTransport> transport(HTTPTransport::Create()); | 86 scoped_ptr<HTTPTransport> transport(HTTPTransport::Create()); |
87 transport->SetMethod("POST"); | 87 transport->SetMethod("POST"); |
88 transport->SetURL(base::StringPrintf("http://127.0.0.1:%d/upload", port)); | 88 transport->SetURL(base::StringPrintf("http://127.0.0.1:%d/upload", port)); |
89 for (const auto& pair : headers_) { | 89 for (const auto& pair : headers_) { |
90 transport->SetHeader(pair.first, pair.second); | 90 transport->SetHeader(pair.first, pair.second); |
91 } | 91 } |
92 transport->SetBodyStream(body_stream_.Pass()); | 92 transport->SetBodyStream(body_stream_.Pass()); |
93 | 93 |
94 EXPECT_EQ(transport->ExecuteSynchronously(), (response_code_ == 200)); | 94 EXPECT_EQ(transport->ExecuteSynchronously(), (response_code_ == 200)); |
95 | 95 |
96 // Read until the child's stdout closes. | 96 // Read until the child's stdout closes. |
97 std::string request; | 97 std::string request; |
98 char buf[32]; | 98 char buf[32]; |
99 ssize_t bytes_read; | 99 ssize_t bytes_read; |
100 while ((bytes_read = ReadFile(ReadPipeFD(), buf, sizeof(buf))) != 0) { | 100 while ((bytes_read = ReadFile(ReadPipeHandle(), buf, sizeof(buf))) != 0) { |
101 ASSERT_GE(bytes_read, 0); | 101 ASSERT_GE(bytes_read, 0); |
102 request.append(buf, bytes_read); | 102 request.append(buf, bytes_read); |
103 } | 103 } |
104 | 104 |
105 if (request_validator_) | 105 if (request_validator_) |
106 request_validator_(this, request); | 106 request_validator_(this, request); |
107 } | 107 } |
108 | 108 |
109 HTTPHeaders headers_; | 109 HTTPHeaders headers_; |
110 scoped_ptr<HTTPBodyStream> body_stream_; | 110 scoped_ptr<HTTPBodyStream> body_stream_; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); | 249 headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); |
250 | 250 |
251 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, | 251 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, |
252 &UnchunkedPlainText); | 252 &UnchunkedPlainText); |
253 test.Run(); | 253 test.Run(); |
254 } | 254 } |
255 | 255 |
256 } // namespace | 256 } // namespace |
257 } // namespace test | 257 } // namespace test |
258 } // namespace crashpad | 258 } // namespace crashpad |
OLD | NEW |