| 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 <stdlib.h> |
| 19 #include <string.h> | 19 #include <string.h> |
| 20 | 20 |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/files/file_path.h" |
| 23 #include "base/format_macros.h" | 24 #include "base/format_macros.h" |
| 24 #include "base/logging.h" | 25 #include "base/logging.h" |
| 25 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
| 26 #include "base/rand_util.h" | 27 #include "base/rand_util.h" |
| 27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/strings/utf_string_conversions.h" |
| 28 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 29 #include "gtest/gtest.h" | 31 #include "gtest/gtest.h" |
| 30 #include "util/file/file_io.h" | 32 #include "util/file/file_io.h" |
| 31 #include "util/net/http_body.h" | 33 #include "util/net/http_body.h" |
| 32 #include "util/net/http_headers.h" | 34 #include "util/net/http_headers.h" |
| 33 #include "util/net/http_multipart_builder.h" | 35 #include "util/net/http_multipart_builder.h" |
| 34 #include "util/test/multiprocess_exec.h" | 36 #include "util/test/multiprocess_exec.h" |
| 37 #include "util/test/paths.h" |
| 35 | 38 |
| 36 namespace crashpad { | 39 namespace crashpad { |
| 37 namespace test { | 40 namespace test { |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 class HTTPTransportTestFixture : public MultiprocessExec { | 43 class HTTPTransportTestFixture : public MultiprocessExec { |
| 41 public: | 44 public: |
| 42 using RequestValidator = | 45 using RequestValidator = |
| 43 void(*)(HTTPTransportTestFixture*, const std::string&); | 46 void(*)(HTTPTransportTestFixture*, const std::string&); |
| 44 | 47 |
| 45 HTTPTransportTestFixture(const HTTPHeaders& headers, | 48 HTTPTransportTestFixture(const HTTPHeaders& headers, |
| 46 scoped_ptr<HTTPBodyStream> body_stream, | 49 scoped_ptr<HTTPBodyStream> body_stream, |
| 47 uint16_t http_response_code, | 50 uint16_t http_response_code, |
| 48 RequestValidator request_validator) | 51 RequestValidator request_validator) |
| 49 : MultiprocessExec(), | 52 : MultiprocessExec(), |
| 50 headers_(headers), | 53 headers_(headers), |
| 51 body_stream_(body_stream.Pass()), | 54 body_stream_(body_stream.Pass()), |
| 52 response_code_(http_response_code), | 55 response_code_(http_response_code), |
| 53 request_validator_(request_validator) { | 56 request_validator_(request_validator) { |
| 54 // TODO(rsesek): Use a more robust mechanism to locate testdata | 57 base::FilePath server_path = Paths::TestDataRoot().Append( |
| 55 // <https://code.google.com/p/crashpad/issues/detail?id=4>. | 58 FILE_PATH_LITERAL("util/net/http_transport_test_server.py")); |
| 56 #if defined(OS_POSIX) | 59 #if defined(OS_POSIX) |
| 57 SetChildCommand("util/net/http_transport_test_server.py", nullptr); | 60 SetChildCommand(server_path.value(), nullptr); |
| 58 #elif defined(OS_WIN) | 61 #elif defined(OS_WIN) |
| 59 // Explicitly invoke a shell and python so that python can be found in the | 62 // Explicitly invoke a shell and python so that python can be found in the |
| 60 // path, and run the test script. | 63 // path, and run the test script. |
| 61 std::vector<std::string> args; | 64 std::vector<std::string> args; |
| 62 args.push_back("/c"); | 65 args.push_back("/c"); |
| 63 args.push_back("python"); | 66 args.push_back("python"); |
| 64 args.push_back("util/net/http_transport_test_server.py"); | 67 args.push_back(base::UTF16ToUTF8(server_path.value())); |
| 65 SetChildCommand(getenv("COMSPEC"), &args); | 68 SetChildCommand(getenv("COMSPEC"), &args); |
| 66 #endif // OS_POSIX | 69 #endif // OS_POSIX |
| 67 } | 70 } |
| 68 | 71 |
| 69 const HTTPHeaders& headers() { return headers_; } | 72 const HTTPHeaders& headers() { return headers_; } |
| 70 | 73 |
| 71 private: | 74 private: |
| 72 void MultiprocessParent() override { | 75 void MultiprocessParent() override { |
| 73 // Use Logging*File() instead of Checked*File() so that the test can fail | 76 // Use Logging*File() instead of Checked*File() so that the test can fail |
| 74 // gracefully with a gtest assertion if the child does not execute properly. | 77 // gracefully with a gtest assertion if the child does not execute properly. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); | 274 headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); |
| 272 | 275 |
| 273 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, | 276 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, |
| 274 &UnchunkedPlainText); | 277 &UnchunkedPlainText); |
| 275 test.Run(); | 278 test.Run(); |
| 276 } | 279 } |
| 277 | 280 |
| 278 } // namespace | 281 } // namespace |
| 279 } // namespace test | 282 } // namespace test |
| 280 } // namespace crashpad | 283 } // namespace crashpad |
| OLD | NEW |