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

Side by Side Diff: net/quic/crypto/crypto_framer_test.cc

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_framer.cc ('k') | net/quic/crypto/crypto_handshake.h » ('j') | 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 <map> 5 #include <map>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/quic/crypto/crypto_framer.h" 10 #include "net/quic/crypto/crypto_framer.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const CryptoHandshakeMessage& message) OVERRIDE { 42 const CryptoHandshakeMessage& message) OVERRIDE {
43 messages_.push_back(message); 43 messages_.push_back(message);
44 } 44 }
45 45
46 // Counters from the visitor callbacks. 46 // Counters from the visitor callbacks.
47 int error_count_; 47 int error_count_;
48 48
49 vector<CryptoHandshakeMessage> messages_; 49 vector<CryptoHandshakeMessage> messages_;
50 }; 50 };
51 51
52 TEST(CryptoFramerTest, MakeCryptoTag) {
53 CryptoTag tag = MakeQuicTag('A', 'B', 'C', 'D');
54 char bytes[4];
55 memcpy(bytes, &tag, 4);
56 EXPECT_EQ('A', bytes[0]);
57 EXPECT_EQ('B', bytes[1]);
58 EXPECT_EQ('C', bytes[2]);
59 EXPECT_EQ('D', bytes[3]);
60 }
61
62 TEST(CryptoFramerTest, ConstructHandshakeMessage) { 52 TEST(CryptoFramerTest, ConstructHandshakeMessage) {
63 CryptoHandshakeMessage message; 53 CryptoHandshakeMessage message;
64 message.set_tag(0xFFAA7733); 54 message.set_tag(0xFFAA7733);
65 message.SetStringPiece(0x12345678, "abcdef"); 55 message.SetStringPiece(0x12345678, "abcdef");
66 message.SetStringPiece(0x12345679, "ghijk"); 56 message.SetStringPiece(0x12345679, "ghijk");
67 message.SetStringPiece(0x1234567A, "lmnopqr"); 57 message.SetStringPiece(0x1234567A, "lmnopqr");
68 58
69 unsigned char packet[] = { 59 unsigned char packet[] = {
70 // tag 60 // tag
71 0x33, 0x77, 0xAA, 0xFF, 61 0x33, 0x77, 0xAA, 0xFF,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // tag 1 339 // tag 1
350 0x79, 0x56, 0x34, 0x12, 340 0x79, 0x56, 0x34, 0x12,
351 // end offset 1 341 // end offset 1
352 0x01, 0x00, 0x00, 0x00, 342 0x01, 0x00, 0x00, 0x00,
353 // tag 2 343 // tag 2
354 0x78, 0x56, 0x34, 0x13, 344 0x78, 0x56, 0x34, 0x13,
355 // end offset 2 345 // end offset 2
356 0x00, 0x00, 0x00, 0x00, 346 0x00, 0x00, 0x00, 0x00,
357 }; 347 };
358 348
359 EXPECT_FALSE(framer.ProcessInput(StringPiece(AsChars(input), 349 EXPECT_FALSE(
360 arraysize(input)))); 350 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input))));
361 EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error()); 351 EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error());
362 } 352 }
363 353
364 TEST(CryptoFramerTest, ProcessInputTooManyEntries) { 354 TEST(CryptoFramerTest, ProcessInputTooManyEntries) {
365 test::TestCryptoVisitor visitor; 355 test::TestCryptoVisitor visitor;
366 CryptoFramer framer; 356 CryptoFramer framer;
367 framer.set_visitor(&visitor); 357 framer.set_visitor(&visitor);
368 358
369 unsigned char input[] = { 359 unsigned char input[] = {
370 // tag 360 // tag
371 0x33, 0x77, 0xAA, 0xFF, 361 0x33, 0x77, 0xAA, 0xFF,
372 // num entries 362 // num entries
373 0xA0, 0x00, 363 0xA0, 0x00,
374 // padding 364 // padding
375 0x00, 0x00, 365 0x00, 0x00,
376 }; 366 };
377 367
378 EXPECT_FALSE(framer.ProcessInput(StringPiece(AsChars(input), 368 EXPECT_FALSE(
379 arraysize(input)))); 369 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input))));
380 EXPECT_EQ(QUIC_CRYPTO_TOO_MANY_ENTRIES, framer.error()); 370 EXPECT_EQ(QUIC_CRYPTO_TOO_MANY_ENTRIES, framer.error());
381 } 371 }
382 372
383 TEST(CryptoFramerTest, ProcessInputZeroLength) { 373 TEST(CryptoFramerTest, ProcessInputZeroLength) {
384 test::TestCryptoVisitor visitor; 374 test::TestCryptoVisitor visitor;
385 CryptoFramer framer; 375 CryptoFramer framer;
386 framer.set_visitor(&visitor); 376 framer.set_visitor(&visitor);
387 377
388 unsigned char input[] = { 378 unsigned char input[] = {
389 // tag 379 // tag
390 0x33, 0x77, 0xAA, 0xFF, 380 0x33, 0x77, 0xAA, 0xFF,
391 // num entries 381 // num entries
392 0x02, 0x00, 382 0x02, 0x00,
393 // padding 383 // padding
394 0x00, 0x00, 384 0x00, 0x00,
395 // tag 1 385 // tag 1
396 0x78, 0x56, 0x34, 0x12, 386 0x78, 0x56, 0x34, 0x12,
397 // end offset 1 387 // end offset 1
398 0x00, 0x00, 0x00, 0x00, 388 0x00, 0x00, 0x00, 0x00,
399 // tag 2 389 // tag 2
400 0x79, 0x56, 0x34, 0x12, 390 0x79, 0x56, 0x34, 0x12,
401 // end offset 2 391 // end offset 2
402 0x05, 0x00, 0x00, 0x00, 392 0x05, 0x00, 0x00, 0x00,
403 }; 393 };
404 394
405 EXPECT_TRUE(framer.ProcessInput(StringPiece(AsChars(input), 395 EXPECT_TRUE(
406 arraysize(input)))); 396 framer.ProcessInput(StringPiece(AsChars(input), arraysize(input))));
407 } 397 }
408 398
409 } // namespace test 399 } // namespace test
410 400
411 } // namespace net 401 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_framer.cc ('k') | net/quic/crypto/crypto_handshake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698