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

Side by Side Diff: net/tools/quic/test_tools/quic_test_client.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 months 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
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/test_tools/quic_test_client.h" 5 #include "net/tools/quic/test_tools/quic_test_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "net/quic/test_tools/quic_connection_peer.h" 22 #include "net/quic/test_tools/quic_connection_peer.h"
23 #include "net/quic/test_tools/quic_spdy_session_peer.h" 23 #include "net/quic/test_tools/quic_spdy_session_peer.h"
24 #include "net/quic/test_tools/quic_stream_peer.h" 24 #include "net/quic/test_tools/quic_stream_peer.h"
25 #include "net/quic/test_tools/quic_test_utils.h" 25 #include "net/quic/test_tools/quic_test_utils.h"
26 #include "net/tools/quic/quic_epoll_connection_helper.h" 26 #include "net/tools/quic/quic_epoll_connection_helper.h"
27 #include "net/tools/quic/quic_packet_writer_wrapper.h" 27 #include "net/tools/quic/quic_packet_writer_wrapper.h"
28 #include "net/tools/quic/quic_spdy_client_stream.h" 28 #include "net/tools/quic/quic_spdy_client_stream.h"
29 #include "net/tools/quic/test_tools/quic_client_peer.h" 29 #include "net/tools/quic/test_tools/quic_client_peer.h"
30 #include "third_party/boringssl/src/include/openssl/x509.h" 30 #include "third_party/boringssl/src/include/openssl/x509.h"
31 31
32 using base::StringPiece;
33 using std::string; 32 using std::string;
34 using testing::_; 33 using testing::_;
35 using testing::Invoke; 34 using testing::Invoke;
36 35
37 namespace net { 36 namespace net {
38 namespace test { 37 namespace test {
39 namespace { 38 namespace {
40 39
41 // RecordingProofVerifier accepts any certificate chain and records the common 40 // RecordingProofVerifier accepts any certificate chain and records the common
42 // name of the leaf and then delegates the actual verfication to an actual 41 // name of the leaf and then delegates the actual verfication to an actual
43 // verifier. If no optional verifier is provided, then VerifyProof will return 42 // verifier. If no optional verifier is provided, then VerifyProof will return
44 // success. 43 // success.
45 class RecordingProofVerifier : public ProofVerifier { 44 class RecordingProofVerifier : public ProofVerifier {
46 public: 45 public:
47 explicit RecordingProofVerifier(std::unique_ptr<ProofVerifier> verifier) 46 explicit RecordingProofVerifier(std::unique_ptr<ProofVerifier> verifier)
48 : verifier_(std::move(verifier)) {} 47 : verifier_(std::move(verifier)) {}
49 48
50 // ProofVerifier interface. 49 // ProofVerifier interface.
51 QuicAsyncStatus VerifyProof( 50 QuicAsyncStatus VerifyProof(
52 const string& hostname, 51 const string& hostname,
53 const uint16_t port, 52 const uint16_t port,
54 const string& server_config, 53 const string& server_config,
55 QuicVersion quic_version, 54 QuicVersion quic_version,
56 StringPiece chlo_hash, 55 QuicStringPiece chlo_hash,
57 const std::vector<string>& certs, 56 const std::vector<string>& certs,
58 const string& cert_sct, 57 const string& cert_sct,
59 const string& signature, 58 const string& signature,
60 const ProofVerifyContext* context, 59 const ProofVerifyContext* context,
61 string* error_details, 60 string* error_details,
62 std::unique_ptr<ProofVerifyDetails>* details, 61 std::unique_ptr<ProofVerifyDetails>* details,
63 std::unique_ptr<ProofVerifierCallback> callback) override { 62 std::unique_ptr<ProofVerifierCallback> callback) override {
64 common_name_.clear(); 63 common_name_.clear();
65 if (certs.empty()) { 64 if (certs.empty()) {
66 return QUIC_FAILURE; 65 return QUIC_FAILURE;
67 } 66 }
68 67
69 // Convert certs to X509Certificate. 68 // Convert certs to X509Certificate.
70 std::vector<StringPiece> cert_pieces(certs.size()); 69 std::vector<QuicStringPiece> cert_pieces(certs.size());
71 for (unsigned i = 0; i < certs.size(); i++) { 70 for (unsigned i = 0; i < certs.size(); i++) {
72 cert_pieces[i] = StringPiece(certs[i]); 71 cert_pieces[i] = QuicStringPiece(certs[i]);
73 } 72 }
74 // TODO(rtenneti): Fix after adding support for real certs. Currently, 73 // TODO(rtenneti): Fix after adding support for real certs. Currently,
75 // cert_pieces are "leaf" and "intermediate" and CreateFromDERCertChain 74 // cert_pieces are "leaf" and "intermediate" and CreateFromDERCertChain
76 // fails to return cert from these cert_pieces. 75 // fails to return cert from these cert_pieces.
77 // bssl::UniquePtr<X509> cert(d2i_X509(nullptr, &data, certs[0].size())); 76 // bssl::UniquePtr<X509> cert(d2i_X509(nullptr, &data, certs[0].size()));
78 // if (!cert.get()) { 77 // if (!cert.get()) {
79 // return QUIC_FAILURE; 78 // return QUIC_FAILURE;
80 // } 79 // }
81 // 80 //
82 // common_name_ = cert->subject().GetDisplayName(); 81 // common_name_ = cert->subject().GetDisplayName();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 for (const string& url : url_list) { 282 for (const string& url : url_list) {
284 SendRequest(url); 283 SendRequest(url);
285 } 284 }
286 while (client()->WaitForEvents()) { 285 while (client()->WaitForEvents()) {
287 } 286 }
288 return; 287 return;
289 } 288 }
290 289
291 ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest( 290 ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest(
292 const SpdyHeaderBlock* headers, 291 const SpdyHeaderBlock* headers,
293 StringPiece body, 292 QuicStringPiece body,
294 bool fin, 293 bool fin,
295 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { 294 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
296 if (headers) { 295 if (headers) {
297 QuicClientPushPromiseIndex::TryHandle* handle; 296 QuicClientPushPromiseIndex::TryHandle* handle;
298 QuicAsyncStatus rv = 297 QuicAsyncStatus rv =
299 client()->push_promise_index()->Try(*headers, this, &handle); 298 client()->push_promise_index()->Try(*headers, this, &handle);
300 if (rv == QUIC_SUCCESS) 299 if (rv == QUIC_SUCCESS)
301 return 1; 300 return 1;
302 if (rv == QUIC_PENDING) { 301 if (rv == QUIC_PENDING) {
303 // May need to retry request if asynchronous rendezvous fails. 302 // May need to retry request if asynchronous rendezvous fails.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 335 }
337 std::unique_ptr<QuicClientBase::QuicDataToResend> data_to_resend( 336 std::unique_ptr<QuicClientBase::QuicDataToResend> data_to_resend(
338 new TestClientDataToResend(std::move(new_headers), body, fin, this, 337 new TestClientDataToResend(std::move(new_headers), body, fin, this,
339 ack_listener)); 338 ack_listener));
340 client()->MaybeAddQuicDataToResend(std::move(data_to_resend)); 339 client()->MaybeAddQuicDataToResend(std::move(data_to_resend));
341 } 340 }
342 return ret; 341 return ret;
343 } 342 }
344 343
345 ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers, 344 ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers,
346 StringPiece body) { 345 QuicStringPiece body) {
347 return SendMessage(headers, body, /*fin=*/true); 346 return SendMessage(headers, body, /*fin=*/true);
348 } 347 }
349 348
350 ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers, 349 ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers,
351 StringPiece body, 350 QuicStringPiece body,
352 bool fin) { 351 bool fin) {
353 stream_ = nullptr; // Always force creation of a stream for SendMessage. 352 stream_ = nullptr; // Always force creation of a stream for SendMessage.
354 // Any response we might have received for a previous request would no longer 353 // Any response we might have received for a previous request would no longer
355 // be valid. TODO(jeffpiazza): There's probably additional client state that 354 // be valid. TODO(jeffpiazza): There's probably additional client state that
356 // should be reset here, too, if we were being more careful. 355 // should be reset here, too, if we were being more careful.
357 response_complete_ = false; 356 response_complete_ = false;
358 357
359 // If we're not connected, try to find an sni hostname. 358 // If we're not connected, try to find an sni hostname.
360 if (!connected()) { 359 if (!connected()) {
361 QuicUrl url(SpdyUtils::GetUrlFromHeaderBlock(headers)); 360 QuicUrl url(SpdyUtils::GetUrlFromHeaderBlock(headers));
362 if (override_sni_set_) { 361 if (override_sni_set_) {
363 client_->set_server_id( 362 client_->set_server_id(
364 QuicServerId(override_sni_, url.port(), PRIVACY_MODE_DISABLED)); 363 QuicServerId(override_sni_, url.port(), PRIVACY_MODE_DISABLED));
365 } 364 }
366 } 365 }
367 366
368 ssize_t ret = GetOrCreateStreamAndSendRequest(&headers, body, fin, nullptr); 367 ssize_t ret = GetOrCreateStreamAndSendRequest(&headers, body, fin, nullptr);
369 WaitForWriteToFlush(); 368 WaitForWriteToFlush();
370 return ret; 369 return ret;
371 } 370 }
372 371
373 ssize_t QuicTestClient::SendData(const string& data, bool last_data) { 372 ssize_t QuicTestClient::SendData(const string& data, bool last_data) {
374 return SendData(data, last_data, nullptr); 373 return SendData(data, last_data, nullptr);
375 } 374 }
376 375
377 ssize_t QuicTestClient::SendData( 376 ssize_t QuicTestClient::SendData(
378 const string& data, 377 const string& data,
379 bool last_data, 378 bool last_data,
380 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { 379 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
381 return GetOrCreateStreamAndSendRequest(nullptr, StringPiece(data), last_data, 380 return GetOrCreateStreamAndSendRequest(nullptr, QuicStringPiece(data),
382 std::move(ack_listener)); 381 last_data, std::move(ack_listener));
383 } 382 }
384 383
385 bool QuicTestClient::response_complete() const { 384 bool QuicTestClient::response_complete() const {
386 return response_complete_; 385 return response_complete_;
387 } 386 }
388 387
389 int64_t QuicTestClient::response_body_size() const { 388 int64_t QuicTestClient::response_body_size() const {
390 return response_body_size_; 389 return response_body_size_;
391 } 390 }
392 391
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 675 }
677 676
678 void QuicTestClient::WaitForWriteToFlush() { 677 void QuicTestClient::WaitForWriteToFlush() {
679 while (connected() && client()->session()->HasDataToWrite()) { 678 while (connected() && client()->session()->HasDataToWrite()) {
680 client_->WaitForEvents(); 679 client_->WaitForEvents();
681 } 680 }
682 } 681 }
683 682
684 QuicTestClient::TestClientDataToResend::TestClientDataToResend( 683 QuicTestClient::TestClientDataToResend::TestClientDataToResend(
685 std::unique_ptr<SpdyHeaderBlock> headers, 684 std::unique_ptr<SpdyHeaderBlock> headers,
686 base::StringPiece body, 685 QuicStringPiece body,
687 bool fin, 686 bool fin,
688 QuicTestClient* test_client, 687 QuicTestClient* test_client,
689 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) 688 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)
690 : QuicClient::QuicDataToResend(std::move(headers), body, fin), 689 : QuicClient::QuicDataToResend(std::move(headers), body, fin),
691 test_client_(test_client), 690 test_client_(test_client),
692 ack_listener_(std::move(ack_listener)) {} 691 ack_listener_(std::move(ack_listener)) {}
693 692
694 QuicTestClient::TestClientDataToResend::~TestClientDataToResend() {} 693 QuicTestClient::TestClientDataToResend::~TestClientDataToResend() {}
695 694
696 void QuicTestClient::TestClientDataToResend::Resend() { 695 void QuicTestClient::TestClientDataToResend::Resend() {
(...skipping 11 matching lines...) Expand all
708 } else if (uri[0] == '/') { 707 } else if (uri[0] == '/') {
709 url = "https://" + client_->server_id().host() + uri; 708 url = "https://" + client_->server_id().host() + uri;
710 } else { 709 } else {
711 url = "https://" + uri; 710 url = "https://" + uri;
712 } 711 }
713 return SpdyUtils::PopulateHeaderBlockFromUrl(url, headers); 712 return SpdyUtils::PopulateHeaderBlockFromUrl(url, headers);
714 } 713 }
715 714
716 } // namespace test 715 } // namespace test
717 } // namespace net 716 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698