| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/net/http_transport.h" | 15 #include "util/net/http_transport.h" |
| 16 | 16 |
| 17 #include <stdint.h> | 17 #include <stdint.h> |
| 18 #include <stdlib.h> |
| 18 #include <string.h> | 19 #include <string.h> |
| 19 | 20 |
| 20 #include <vector> | 21 #include <vector> |
| 21 | 22 |
| 23 #include "base/format_macros.h" |
| 22 #include "base/logging.h" | 24 #include "base/logging.h" |
| 23 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 24 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 25 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 26 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
| 27 #include "util/file/file_io.h" | 29 #include "util/file/file_io.h" |
| 28 #include "util/net/http_body.h" | 30 #include "util/net/http_body.h" |
| 29 #include "util/net/http_headers.h" | 31 #include "util/net/http_headers.h" |
| 30 #include "util/net/http_multipart_builder.h" | 32 #include "util/net/http_multipart_builder.h" |
| 31 #include "util/test/multiprocess_exec.h" | 33 #include "util/test/multiprocess_exec.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 scoped_ptr<HTTPBodyStream> body_stream, | 45 scoped_ptr<HTTPBodyStream> body_stream, |
| 44 uint16_t http_response_code, | 46 uint16_t http_response_code, |
| 45 RequestValidator request_validator) | 47 RequestValidator request_validator) |
| 46 : MultiprocessExec(), | 48 : MultiprocessExec(), |
| 47 headers_(headers), | 49 headers_(headers), |
| 48 body_stream_(body_stream.Pass()), | 50 body_stream_(body_stream.Pass()), |
| 49 response_code_(http_response_code), | 51 response_code_(http_response_code), |
| 50 request_validator_(request_validator) { | 52 request_validator_(request_validator) { |
| 51 // TODO(rsesek): Use a more robust mechanism to locate testdata | 53 // TODO(rsesek): Use a more robust mechanism to locate testdata |
| 52 // <https://code.google.com/p/crashpad/issues/detail?id=4>. | 54 // <https://code.google.com/p/crashpad/issues/detail?id=4>. |
| 55 #if defined(OS_POSIX) |
| 53 SetChildCommand("util/net/http_transport_test_server.py", nullptr); | 56 SetChildCommand("util/net/http_transport_test_server.py", nullptr); |
| 57 #elif defined(OS_WIN) |
| 58 // Explicitly invoke a shell and python so that python can be found in the |
| 59 // path, and run the test script. |
| 60 std::vector<std::string> args; |
| 61 args.push_back("/c"); |
| 62 args.push_back("python"); |
| 63 args.push_back("util/net/http_transport_test_server.py"); |
| 64 SetChildCommand(getenv("COMSPEC"), &args); |
| 65 #endif // OS_POSIX |
| 54 } | 66 } |
| 55 | 67 |
| 56 const HTTPHeaders& headers() { return headers_; } | 68 const HTTPHeaders& headers() { return headers_; } |
| 57 | 69 |
| 58 private: | 70 private: |
| 59 void MultiprocessParent() override { | 71 void MultiprocessParent() override { |
| 60 // Use Logging*File() instead of Checked*File() so that the test can fail | 72 // Use Logging*File() instead of Checked*File() so that the test can fail |
| 61 // 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. |
| 62 | 74 |
| 63 // 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 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ASSERT_NE(std::string::npos, body_start); | 239 ASSERT_NE(std::string::npos, body_start); |
| 228 | 240 |
| 229 EXPECT_EQ(kTextBody, request.substr(body_start + 2)); | 241 EXPECT_EQ(kTextBody, request.substr(body_start + 2)); |
| 230 } | 242 } |
| 231 | 243 |
| 232 TEST(HTTPTransport, UnchunkedPlainText) { | 244 TEST(HTTPTransport, UnchunkedPlainText) { |
| 233 scoped_ptr<HTTPBodyStream> body_stream(new StringHTTPBodyStream(kTextBody)); | 245 scoped_ptr<HTTPBodyStream> body_stream(new StringHTTPBodyStream(kTextBody)); |
| 234 | 246 |
| 235 HTTPHeaders headers; | 247 HTTPHeaders headers; |
| 236 headers[kContentType] = kTextPlain; | 248 headers[kContentType] = kTextPlain; |
| 237 headers[kContentLength] = base::StringPrintf("%zu", strlen(kTextBody)); | 249 headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); |
| 238 | 250 |
| 239 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, | 251 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, |
| 240 &UnchunkedPlainText); | 252 &UnchunkedPlainText); |
| 241 test.Run(); | 253 test.Run(); |
| 242 } | 254 } |
| 243 | 255 |
| 244 } // namespace | 256 } // namespace |
| 245 } // namespace test | 257 } // namespace test |
| 246 } // namespace crashpad | 258 } // namespace crashpad |
| OLD | NEW |