 Chromium Code Reviews
 Chromium Code Reviews Issue 11300020:
  Add QuicStream and friends to QUIC code.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11300020:
  Add QuicStream and friends to QUIC code.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/quic_crypto_stream.h" | |
| 6 | |
| 7 #include <map> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "net/quic/quic_utils.h" | |
| 11 #include "net/quic/test_tools/quic_test_utils.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using std::map; | |
| 16 using std::string; | |
| 17 | |
| 18 namespace net { | |
| 19 namespace test { | |
| 20 namespace { | |
| 21 | |
| 22 class MockQuicCryptoStream : public QuicCryptoStream { | |
| 23 public: | |
| 24 explicit MockQuicCryptoStream(QuicSession* session) | |
| 25 : QuicCryptoStream(session) { | |
| 26 } | |
| 27 | |
| 28 void OnHandshakeMessage(const CryptoHandshakeMessage& message) { | |
| 29 message_tags_.push_back(message.tag); | |
| 30 message_maps_.push_back(map<CryptoTag, string>()); | |
| 31 CryptoTagValueMap::const_iterator it = message.tag_value_map.begin(); | |
| 32 while (it != message.tag_value_map.end()) { | |
| 33 message_maps_.back()[it->first] = it->second.as_string(); | |
| 34 ++it; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 std::vector<CryptoTag> message_tags_; | |
| 
jar (doing other things)
2012/10/31 22:37:37
nit: I think even here in test land, members shoul
 
Ryan Hamilton
2012/11/01 22:52:20
Fixed upstream.
 | |
| 39 std::vector<map<CryptoTag, string> > message_maps_; | |
| 40 }; | |
| 
jar (doing other things)
2012/10/31 22:37:37
nit: DISALLOW_COPY_AND_ASSIGN
 
Ryan Hamilton
2012/11/01 22:52:20
Fixed upstream.
 | |
| 41 | |
| 42 class QuicCryptoStreamTest : public ::testing::Test { | |
| 43 public: | |
| 44 QuicCryptoStreamTest() | |
| 45 : addr_(IPAddressNumber(), 1), | |
| 46 connection_(new MockConnection(1, addr_)), | |
| 47 session_(connection_, true), | |
| 48 stream_(&session_) { | |
| 49 message_.tag = kSHLO; | |
| 50 message_.tag_value_map[1] = "abc"; | |
| 51 message_.tag_value_map[2] = "def"; | |
| 52 ConstructHandshakeMessage(); | |
| 53 } | |
| 54 | |
| 55 void ConstructHandshakeMessage() { | |
| 56 CryptoFramer framer; | |
| 57 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | |
| 58 } | |
| 59 | |
| 60 IPEndPoint addr_; | |
| 
jar (doing other things)
2012/10/31 22:37:37
These should probably be protected:
 
Ryan Hamilton
2012/11/01 22:52:20
Fixed upstream.
 | |
| 61 MockConnection* connection_; | |
| 62 MockSession session_; | |
| 63 MockQuicCryptoStream stream_; | |
| 64 CryptoHandshakeMessage message_; | |
| 65 scoped_ptr<QuicData> message_data_; | |
| 66 }; | |
| 67 | |
| 68 TEST_F(QuicCryptoStreamTest, NotInitiallyConected) { | |
| 69 EXPECT_FALSE(stream_.handshake_complete()); | |
| 70 } | |
| 71 | |
| 72 TEST_F(QuicCryptoStreamTest, OnErrorClosesConnection) { | |
| 73 CryptoFramer framer; | |
| 74 EXPECT_CALL(session_, ConnectionClose(QUIC_NO_ERROR, false)); | |
| 75 stream_.OnError(&framer); | |
| 76 } | |
| 77 | |
| 78 TEST_F(QuicCryptoStreamTest, ProcessData) { | |
| 79 EXPECT_EQ(message_data_->length(), | |
| 80 stream_.ProcessData(message_data_->data(), | |
| 81 message_data_->length())); | |
| 82 ASSERT_EQ(1u, stream_.message_tags_.size()); | |
| 83 EXPECT_EQ(kSHLO, stream_.message_tags_[0]); | |
| 84 EXPECT_EQ(2u, stream_.message_maps_[0].size()); | |
| 85 EXPECT_EQ("abc",stream_.message_maps_[0][1]); | |
| 86 EXPECT_EQ("def", stream_.message_maps_[0][2]); | |
| 87 } | |
| 88 | |
| 89 TEST_F(QuicCryptoStreamTest, ProcessBadData) { | |
| 90 string bad(message_data_->data(), message_data_->length()); | |
| 91 bad[6] = 0xFF; // out of order tag | |
| 92 | |
| 93 EXPECT_CALL(*connection_, | |
| 94 SendConnectionClose(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); | |
| 95 EXPECT_EQ(0u, stream_.ProcessData(bad.data(), bad.length())); | |
| 96 } | |
| 97 | |
| 98 } // namespace | |
| 99 } // namespace test | |
| 100 } // namespace net | |
| OLD | NEW |