Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: util/net/http_transport_test.cc

Issue 811823003: Cross platform low level file IO wrappers (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string.h> 18 #include <string.h>
19 19
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "gtest/gtest.h" 26 #include "gtest/gtest.h"
27 #include "util/file/fd_io.h" 27 #include "util/file/file_io.h"
28 #include "util/net/http_body.h" 28 #include "util/net/http_body.h"
29 #include "util/net/http_headers.h" 29 #include "util/net/http_headers.h"
30 #include "util/net/http_multipart_builder.h" 30 #include "util/net/http_multipart_builder.h"
31 #include "util/test/multiprocess_exec.h" 31 #include "util/test/multiprocess_exec.h"
32 32
33 namespace crashpad { 33 namespace crashpad {
34 namespace test { 34 namespace test {
35 namespace { 35 namespace {
36 36
37 class HTTPTransportTestFixture : public MultiprocessExec { 37 class HTTPTransportTestFixture : public MultiprocessExec {
(...skipping 18 matching lines...) Expand all
56 const HTTPHeaders& headers() { return headers_; } 56 const HTTPHeaders& headers() { return headers_; }
57 57
58 private: 58 private:
59 void MultiprocessParent() override { 59 void MultiprocessParent() override {
60 // Use Logging*FD() instead of Checked*FD() so that the test can fail 60 // Use Logging*FD() instead of Checked*FD() so that the test can fail
61 // gracefully with a gtest assertion if the child does not execute properly. 61 // gracefully with a gtest assertion if the child does not execute properly.
62 62
63 // The child will write the HTTP server port number as a packed unsigned 63 // The child will write the HTTP server port number as a packed unsigned
64 // short to stdout. 64 // short to stdout.
65 uint16_t port; 65 uint16_t port;
66 ASSERT_TRUE(LoggingReadFD(ReadPipeFD(), &port, sizeof(port))); 66 ASSERT_TRUE(LoggingReadFile(ReadPipeFD(), &port, sizeof(port)));
67 67
68 // Then the parent will tell the web server what response code to send 68 // Then the parent will tell the web server what response code to send
69 // for the HTTP request. 69 // for the HTTP request.
70 ASSERT_TRUE( 70 ASSERT_TRUE(LoggingWriteFile(
71 LoggingWriteFD(WritePipeFD(), &response_code_, sizeof(response_code_))); 71 WritePipeFD(), &response_code_, sizeof(response_code_)));
72 72
73 // Now execute the HTTP request. 73 // Now execute the HTTP request.
74 scoped_ptr<HTTPTransport> transport(HTTPTransport::Create()); 74 scoped_ptr<HTTPTransport> transport(HTTPTransport::Create());
75 transport->SetMethod("POST"); 75 transport->SetMethod("POST");
76 transport->SetURL(base::StringPrintf("http://127.0.0.1:%d/upload", port)); 76 transport->SetURL(base::StringPrintf("http://127.0.0.1:%d/upload", port));
77 for (const auto& pair : headers_) { 77 for (const auto& pair : headers_) {
78 transport->SetHeader(pair.first, pair.second); 78 transport->SetHeader(pair.first, pair.second);
79 } 79 }
80 transport->SetBodyStream(body_stream_.Pass()); 80 transport->SetBodyStream(body_stream_.Pass());
81 81
82 EXPECT_EQ(transport->ExecuteSynchronously(), (response_code_ == 200)); 82 EXPECT_EQ(transport->ExecuteSynchronously(), (response_code_ == 200));
83 83
84 // Read until the child's stdout closes. 84 // Read until the child's stdout closes.
85 std::string request; 85 std::string request;
86 char buf[32]; 86 char buf[32];
87 ssize_t bytes_read; 87 ssize_t bytes_read;
88 while ((bytes_read = ReadFD(ReadPipeFD(), buf, sizeof(buf))) != 0) { 88 while ((bytes_read = ReadFile(ReadPipeFD(), buf, sizeof(buf))) != 0) {
89 ASSERT_GE(bytes_read, 0); 89 ASSERT_GE(bytes_read, 0);
90 request.append(buf, bytes_read); 90 request.append(buf, bytes_read);
91 } 91 }
92 92
93 if (request_validator_) 93 if (request_validator_)
94 request_validator_(this, request); 94 request_validator_(this, request);
95 } 95 }
96 96
97 HTTPHeaders headers_; 97 HTTPHeaders headers_;
98 scoped_ptr<HTTPBodyStream> body_stream_; 98 scoped_ptr<HTTPBodyStream> body_stream_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 headers[kContentLength] = base::StringPrintf("%zu", strlen(kTextBody)); 237 headers[kContentLength] = base::StringPrintf("%zu", strlen(kTextBody));
238 238
239 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200, 239 HTTPTransportTestFixture test(headers, body_stream.Pass(), 200,
240 &UnchunkedPlainText); 240 &UnchunkedPlainText);
241 test.Run(); 241 test.Run();
242 } 242 }
243 243
244 } // namespace 244 } // namespace
245 } // namespace test 245 } // namespace test
246 } // namespace crashpad 246 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698