2014-10-31 12:17:32 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "util/net/http_transport.h"
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2015-01-26 13:31:35 -08:00
|
|
|
|
#include <stdlib.h>
|
2014-10-31 12:17:32 -04:00
|
|
|
|
#include <string.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include <sys/types.h>
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2015-12-09 17:36:32 -05:00
|
|
|
|
#include <utility>
|
2014-10-31 12:17:32 -04:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-03-09 15:13:13 -04:00
|
|
|
|
#include "base/files/file_path.h"
|
2015-01-26 13:31:35 -08:00
|
|
|
|
#include "base/format_macros.h"
|
2014-10-31 12:17:32 -04:00
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
#include "base/strings/stringprintf.h"
|
2015-03-09 15:13:13 -04:00
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-10-31 12:17:32 -04:00
|
|
|
|
#include "build/build_config.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.
In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.
BUG=crashpad:33
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00
|
|
|
|
#include "test/multiprocess_exec.h"
|
2017-04-03 13:53:11 -04:00
|
|
|
|
#include "test/test_paths.h"
|
2014-12-17 14:35:18 -08:00
|
|
|
|
#include "util/file/file_io.h"
|
2015-11-16 13:39:01 -05:00
|
|
|
|
#include "util/misc/random_string.h"
|
2014-10-31 12:17:32 -04:00
|
|
|
|
#include "util/net/http_body.h"
|
|
|
|
|
#include "util/net/http_headers.h"
|
|
|
|
|
#include "util/net/http_multipart_builder.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class HTTPTransportTestFixture : public MultiprocessExec {
|
|
|
|
|
public:
|
|
|
|
|
using RequestValidator =
|
|
|
|
|
void(*)(HTTPTransportTestFixture*, const std::string&);
|
|
|
|
|
|
|
|
|
|
HTTPTransportTestFixture(const HTTPHeaders& headers,
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<HTTPBodyStream> body_stream,
|
2014-10-31 12:17:32 -04:00
|
|
|
|
uint16_t http_response_code,
|
|
|
|
|
RequestValidator request_validator)
|
|
|
|
|
: MultiprocessExec(),
|
|
|
|
|
headers_(headers),
|
2015-12-09 17:36:32 -05:00
|
|
|
|
body_stream_(std::move(body_stream)),
|
2014-10-31 12:17:32 -04:00
|
|
|
|
response_code_(http_response_code),
|
|
|
|
|
request_validator_(request_validator) {
|
2017-04-03 13:53:11 -04:00
|
|
|
|
base::FilePath server_path = TestPaths::TestDataRoot().Append(
|
2015-03-09 15:13:13 -04:00
|
|
|
|
FILE_PATH_LITERAL("util/net/http_transport_test_server.py"));
|
2015-01-26 13:31:35 -08:00
|
|
|
|
#if defined(OS_POSIX)
|
2015-03-09 15:13:13 -04:00
|
|
|
|
SetChildCommand(server_path.value(), nullptr);
|
2015-01-26 13:31:35 -08:00
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
|
// Explicitly invoke a shell and python so that python can be found in the
|
|
|
|
|
// path, and run the test script.
|
|
|
|
|
std::vector<std::string> args;
|
|
|
|
|
args.push_back("/c");
|
|
|
|
|
args.push_back("python");
|
2015-03-09 15:13:13 -04:00
|
|
|
|
args.push_back(base::UTF16ToUTF8(server_path.value()));
|
2015-01-26 13:31:35 -08:00
|
|
|
|
SetChildCommand(getenv("COMSPEC"), &args);
|
|
|
|
|
#endif // OS_POSIX
|
2014-10-31 12:17:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const HTTPHeaders& headers() { return headers_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void MultiprocessParent() override {
|
2015-01-28 14:49:42 -08:00
|
|
|
|
// Use Logging*File() instead of Checked*File() so that the test can fail
|
2014-12-15 16:40:16 -05:00
|
|
|
|
// gracefully with a gtest assertion if the child does not execute properly.
|
|
|
|
|
|
2014-10-31 12:17:32 -04:00
|
|
|
|
// The child will write the HTTP server port number as a packed unsigned
|
|
|
|
|
// short to stdout.
|
|
|
|
|
uint16_t port;
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
|
ASSERT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &port, sizeof(port)));
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
// Then the parent will tell the web server what response code to send
|
|
|
|
|
// for the HTTP request.
|
2014-12-17 14:35:18 -08:00
|
|
|
|
ASSERT_TRUE(LoggingWriteFile(
|
2015-01-28 14:49:42 -08:00
|
|
|
|
WritePipeHandle(), &response_code_, sizeof(response_code_)));
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
2015-02-05 18:05:40 -05:00
|
|
|
|
// The parent will also tell the web server what response body to send back.
|
|
|
|
|
// The web server will only send the response body if the response code is
|
|
|
|
|
// 200.
|
2015-11-16 13:39:01 -05:00
|
|
|
|
const std::string random_string = RandomString();
|
2015-02-05 18:05:40 -05:00
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(LoggingWriteFile(WritePipeHandle(),
|
2015-11-16 13:39:01 -05:00
|
|
|
|
random_string.c_str(),
|
|
|
|
|
random_string.size()));
|
2015-02-05 18:05:40 -05:00
|
|
|
|
|
2014-10-31 12:17:32 -04:00
|
|
|
|
// Now execute the HTTP request.
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<HTTPTransport> transport(HTTPTransport::Create());
|
2014-10-31 12:17:32 -04:00
|
|
|
|
transport->SetMethod("POST");
|
|
|
|
|
transport->SetURL(base::StringPrintf("http://127.0.0.1:%d/upload", port));
|
|
|
|
|
for (const auto& pair : headers_) {
|
|
|
|
|
transport->SetHeader(pair.first, pair.second);
|
|
|
|
|
}
|
2015-12-09 17:36:32 -05:00
|
|
|
|
transport->SetBodyStream(std::move(body_stream_));
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
2015-02-05 18:05:40 -05:00
|
|
|
|
std::string response_body;
|
|
|
|
|
bool success = transport->ExecuteSynchronously(&response_body);
|
|
|
|
|
if (response_code_ == 200) {
|
|
|
|
|
EXPECT_TRUE(success);
|
2015-11-16 13:39:01 -05:00
|
|
|
|
std::string expect_response_body = random_string + "\r\n";
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(response_body, expect_response_body);
|
2015-02-05 18:05:40 -05:00
|
|
|
|
} else {
|
|
|
|
|
EXPECT_FALSE(success);
|
|
|
|
|
EXPECT_TRUE(response_body.empty());
|
|
|
|
|
}
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
// Read until the child's stdout closes.
|
|
|
|
|
std::string request;
|
|
|
|
|
char buf[32];
|
2015-10-22 16:14:18 -07:00
|
|
|
|
FileOperationResult bytes_read;
|
2015-01-28 14:49:42 -08:00
|
|
|
|
while ((bytes_read = ReadFile(ReadPipeHandle(), buf, sizeof(buf))) != 0) {
|
2014-10-31 12:17:32 -04:00
|
|
|
|
ASSERT_GE(bytes_read, 0);
|
|
|
|
|
request.append(buf, bytes_read);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request_validator_)
|
|
|
|
|
request_validator_(this, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HTTPHeaders headers_;
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<HTTPBodyStream> body_stream_;
|
2014-10-31 12:17:32 -04:00
|
|
|
|
uint16_t response_code_;
|
|
|
|
|
RequestValidator request_validator_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char kMultipartFormData[] = "multipart/form-data";
|
|
|
|
|
|
|
|
|
|
void GetHeaderField(const std::string& request,
|
|
|
|
|
const std::string& header,
|
|
|
|
|
std::string* value) {
|
|
|
|
|
size_t index = request.find(header);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(index, std::string::npos);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
// Since the header is never the first line of the request, it should always
|
|
|
|
|
// be preceded by a CRLF.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request[index - 1], '\n');
|
|
|
|
|
EXPECT_EQ(request[index - 2], '\r');
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
index += header.length();
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request[index++], ':');
|
2014-10-31 12:17:32 -04:00
|
|
|
|
// Per RFC 7230 §3.2, there can be one or more spaces or horizontal tabs.
|
|
|
|
|
// For testing purposes, just assume one space.
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request[index++], ' ');
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
size_t header_end = request.find('\r', index);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(header_end, std::string::npos);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
*value = request.substr(index, header_end - index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetMultipartBoundary(const std::string& request,
|
|
|
|
|
std::string* multipart_boundary) {
|
|
|
|
|
std::string content_type;
|
|
|
|
|
GetHeaderField(request, kContentType, &content_type);
|
|
|
|
|
|
|
|
|
|
ASSERT_GE(content_type.length(), strlen(kMultipartFormData));
|
|
|
|
|
size_t index = strlen(kMultipartFormData);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(content_type.substr(0, index), kMultipartFormData);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(content_type[index++], ';');
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
size_t boundary_begin = content_type.find('=', index);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(boundary_begin, std::string::npos);
|
|
|
|
|
EXPECT_EQ(content_type[boundary_begin++], '=');
|
2014-10-31 12:17:32 -04:00
|
|
|
|
if (multipart_boundary) {
|
|
|
|
|
*multipart_boundary = content_type.substr(boundary_begin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char kBoundaryEq[] = "boundary=";
|
|
|
|
|
|
|
|
|
|
void ValidFormData(HTTPTransportTestFixture* fixture,
|
|
|
|
|
const std::string& request) {
|
|
|
|
|
std::string actual_boundary;
|
|
|
|
|
GetMultipartBoundary(request, &actual_boundary);
|
|
|
|
|
|
|
|
|
|
const auto& content_type = fixture->headers().find(kContentType);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(content_type, fixture->headers().end());
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
size_t boundary = content_type->second.find(kBoundaryEq);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(boundary, std::string::npos);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
std::string expected_boundary =
|
|
|
|
|
content_type->second.substr(boundary + strlen(kBoundaryEq));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(actual_boundary, expected_boundary);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
size_t body_start = request.find("\r\n\r\n");
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(body_start, std::string::npos);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
body_start += 4;
|
|
|
|
|
|
|
|
|
|
std::string expected = "--" + expected_boundary + "\r\n";
|
|
|
|
|
expected += "Content-Disposition: form-data; name=\"key1\"\r\n\r\n";
|
|
|
|
|
expected += "test\r\n";
|
|
|
|
|
ASSERT_LT(body_start + expected.length(), request.length());
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request.substr(body_start, expected.length()), expected);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
body_start += expected.length();
|
|
|
|
|
|
|
|
|
|
expected = "--" + expected_boundary + "\r\n";
|
|
|
|
|
expected += "Content-Disposition: form-data; name=\"key2\"\r\n\r\n";
|
|
|
|
|
expected += "--abcdefg123\r\n";
|
|
|
|
|
expected += "--" + expected_boundary + "--\r\n";
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_EQ(request.length(), body_start + expected.length());
|
|
|
|
|
EXPECT_EQ(request.substr(body_start), expected);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HTTPTransport, ValidFormData) {
|
|
|
|
|
HTTPMultipartBuilder builder;
|
|
|
|
|
builder.SetFormData("key1", "test");
|
|
|
|
|
builder.SetFormData("key2", "--abcdefg123");
|
|
|
|
|
|
|
|
|
|
HTTPHeaders headers;
|
2017-02-15 19:54:19 -05:00
|
|
|
|
builder.PopulateContentHeaders(&headers);
|
|
|
|
|
|
|
|
|
|
HTTPTransportTestFixture test(
|
|
|
|
|
headers, builder.GetBodyStream(), 200, &ValidFormData);
|
|
|
|
|
test.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HTTPTransport, ValidFormData_Gzip) {
|
|
|
|
|
HTTPMultipartBuilder builder;
|
|
|
|
|
builder.SetGzipEnabled(true);
|
|
|
|
|
builder.SetFormData("key1", "test");
|
|
|
|
|
builder.SetFormData("key2", "--abcdefg123");
|
|
|
|
|
|
|
|
|
|
HTTPHeaders headers;
|
|
|
|
|
builder.PopulateContentHeaders(&headers);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
HTTPTransportTestFixture test(headers, builder.GetBodyStream(), 200,
|
|
|
|
|
&ValidFormData);
|
|
|
|
|
test.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char kTextPlain[] = "text/plain";
|
|
|
|
|
|
|
|
|
|
void ErrorResponse(HTTPTransportTestFixture* fixture,
|
|
|
|
|
const std::string& request) {
|
|
|
|
|
std::string content_type;
|
|
|
|
|
GetHeaderField(request, kContentType, &content_type);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(content_type, kTextPlain);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HTTPTransport, ErrorResponse) {
|
|
|
|
|
HTTPMultipartBuilder builder;
|
|
|
|
|
HTTPHeaders headers;
|
|
|
|
|
headers[kContentType] = kTextPlain;
|
|
|
|
|
HTTPTransportTestFixture test(headers, builder.GetBodyStream(),
|
|
|
|
|
404, &ErrorResponse);
|
|
|
|
|
test.Run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char kTextBody[] = "hello world";
|
|
|
|
|
|
|
|
|
|
void UnchunkedPlainText(HTTPTransportTestFixture* fixture,
|
|
|
|
|
const std::string& request) {
|
|
|
|
|
std::string header_value;
|
|
|
|
|
GetHeaderField(request, kContentType, &header_value);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(header_value, kTextPlain);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
GetHeaderField(request, kContentLength, &header_value);
|
|
|
|
|
const auto& content_length = fixture->headers().find(kContentLength);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(content_length, fixture->headers().end());
|
|
|
|
|
EXPECT_EQ(header_value, content_length->second);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
size_t body_start = request.rfind("\r\n");
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
ASSERT_NE(body_start, std::string::npos);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request.substr(body_start + 2), kTextBody);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HTTPTransport, UnchunkedPlainText) {
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<HTTPBodyStream> body_stream(
|
|
|
|
|
new StringHTTPBodyStream(kTextBody));
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
|
|
|
|
HTTPHeaders headers;
|
|
|
|
|
headers[kContentType] = kTextPlain;
|
2015-01-26 13:31:35 -08:00
|
|
|
|
headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody));
|
2014-10-31 12:17:32 -04:00
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
|
HTTPTransportTestFixture test(
|
|
|
|
|
headers, std::move(body_stream), 200, &UnchunkedPlainText);
|
2014-10-31 12:17:32 -04:00
|
|
|
|
test.Run();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 17:52:12 -04:00
|
|
|
|
void RunUpload33k(bool has_content_length) {
|
2016-11-07 09:01:20 -05:00
|
|
|
|
// On macOS, NSMutableURLRequest winds up calling into a CFReadStream’s Read()
|
2015-08-18 15:42:34 -04:00
|
|
|
|
// callback with a 32kB buffer. Make sure that it’s able to get everything
|
|
|
|
|
// when enough is available to fill this buffer, requiring more than one
|
|
|
|
|
// Read().
|
|
|
|
|
|
|
|
|
|
std::string request_string(33 * 1024, 'a');
|
2016-04-25 12:13:07 -07:00
|
|
|
|
std::unique_ptr<HTTPBodyStream> body_stream(
|
2015-08-18 15:42:34 -04:00
|
|
|
|
new StringHTTPBodyStream(request_string));
|
|
|
|
|
|
|
|
|
|
HTTPHeaders headers;
|
|
|
|
|
headers[kContentType] = "application/octet-stream";
|
2015-08-18 17:52:12 -04:00
|
|
|
|
if (has_content_length) {
|
|
|
|
|
headers[kContentLength] =
|
|
|
|
|
base::StringPrintf("%" PRIuS, request_string.size());
|
|
|
|
|
}
|
2015-12-09 17:36:32 -05:00
|
|
|
|
HTTPTransportTestFixture test(
|
|
|
|
|
headers,
|
|
|
|
|
std::move(body_stream),
|
|
|
|
|
200,
|
2015-08-18 15:42:34 -04:00
|
|
|
|
[](HTTPTransportTestFixture* fixture, const std::string& request) {
|
|
|
|
|
size_t body_start = request.rfind("\r\n");
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(request.size() - body_start, 33 * 1024u + 2);
|
2015-08-18 15:42:34 -04:00
|
|
|
|
});
|
|
|
|
|
test.Run();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 17:52:12 -04:00
|
|
|
|
TEST(HTTPTransport, Upload33k) {
|
|
|
|
|
RunUpload33k(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HTTPTransport, Upload33k_LengthUnknown) {
|
|
|
|
|
// The same as Upload33k, but without declaring Content-Length ahead of time.
|
|
|
|
|
RunUpload33k(false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 12:17:32 -04:00
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|