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

Side by Side Diff: net/websockets/websocket_frame_parser_test.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 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/websockets/websocket_basic_stream_test.cc ('k') | net/websockets/websocket_frame_test.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/websockets/websocket_frame_parser.h" 5 #include "net/websockets/websocket_frame_parser.h"
6 6
7 #include <stdint.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 #include <vector> 10 #include <vector>
9 11
10 #include "base/basictypes.h" 12 #include "base/basictypes.h"
11 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
12 #include "base/port.h"
13 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
14 #include "net/websockets/websocket_frame.h" 15 #include "net/websockets/websocket_frame.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 namespace { 20 namespace {
20 21
21 const char kHello[] = "Hello, world!"; 22 const char kHello[] = "Hello, world!";
22 const uint64 kHelloLength = arraysize(kHello) - 1; 23 const uint64 kHelloLength = arraysize(kHello) - 1;
23 const char kHelloFrame[] = "\x81\x0DHello, world!"; 24 const char kHelloFrame[] = "\x81\x0DHello, world!";
24 const uint64 kHelloFrameLength = arraysize(kHelloFrame) - 1; 25 const uint64 kHelloFrameLength = arraysize(kHelloFrame) - 1;
25 const char kMaskedHelloFrame[] = 26 const char kMaskedHelloFrame[] =
26 "\x81\x8D\xDE\xAD\xBE\xEF" 27 "\x81\x8D\xDE\xAD\xBE\xEF"
27 "\x96\xC8\xD2\x83\xB1\x81\x9E\x98\xB1\xDF\xD2\x8B\xFF"; 28 "\x96\xC8\xD2\x83\xB1\x81\x9E\x98\xB1\xDF\xD2\x8B\xFF";
28 const uint64 kMaskedHelloFrameLength = arraysize(kMaskedHelloFrame) - 1; 29 const uint64 kMaskedHelloFrameLength = arraysize(kMaskedHelloFrame) - 1;
29 30
30 struct FrameHeaderTestCase { 31 struct FrameHeaderTestCase {
31 const char* frame_header; 32 const char* frame_header;
32 size_t frame_header_length; 33 size_t frame_header_length;
33 uint64 frame_length; 34 uint64 frame_length;
34 WebSocketError error_code; 35 WebSocketError error_code;
35 }; 36 };
36 37
37 const FrameHeaderTestCase kFrameHeaderTests[] = { 38 const FrameHeaderTestCase kFrameHeaderTests[] = {
38 { "\x81\x00", 2, GG_UINT64_C(0), kWebSocketNormalClosure }, 39 {"\x81\x00", 2, UINT64_C(0), kWebSocketNormalClosure},
39 { "\x81\x7D", 2, GG_UINT64_C(125), kWebSocketNormalClosure }, 40 {"\x81\x7D", 2, UINT64_C(125), kWebSocketNormalClosure},
40 { "\x81\x7E\x00\x7E", 4, GG_UINT64_C(126), kWebSocketNormalClosure }, 41 {"\x81\x7E\x00\x7E", 4, UINT64_C(126), kWebSocketNormalClosure},
41 { "\x81\x7E\xFF\xFF", 4, GG_UINT64_C(0xFFFF), kWebSocketNormalClosure }, 42 {"\x81\x7E\xFF\xFF", 4, UINT64_C(0xFFFF), kWebSocketNormalClosure},
42 { "\x81\x7F\x00\x00\x00\x00\x00\x01\x00\x00", 10, GG_UINT64_C(0x10000), 43 {"\x81\x7F\x00\x00\x00\x00\x00\x01\x00\x00", 10, UINT64_C(0x10000),
43 kWebSocketNormalClosure }, 44 kWebSocketNormalClosure},
44 { "\x81\x7F\x00\x00\x00\x00\x7F\xFF\xFF\xFF", 10, GG_UINT64_C(0x7FFFFFFF), 45 {"\x81\x7F\x00\x00\x00\x00\x7F\xFF\xFF\xFF", 10, UINT64_C(0x7FFFFFFF),
45 kWebSocketNormalClosure }, 46 kWebSocketNormalClosure},
46 { "\x81\x7F\x00\x00\x00\x00\x80\x00\x00\x00", 10, GG_UINT64_C(0x80000000), 47 {"\x81\x7F\x00\x00\x00\x00\x80\x00\x00\x00", 10, UINT64_C(0x80000000),
47 kWebSocketErrorMessageTooBig }, 48 kWebSocketErrorMessageTooBig},
48 { "\x81\x7F\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 10, 49 {"\x81\x7F\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 10,
49 GG_UINT64_C(0x7FFFFFFFFFFFFFFF), kWebSocketErrorMessageTooBig } 50 UINT64_C(0x7FFFFFFFFFFFFFFF), kWebSocketErrorMessageTooBig}};
50 };
51 const int kNumFrameHeaderTests = arraysize(kFrameHeaderTests); 51 const int kNumFrameHeaderTests = arraysize(kFrameHeaderTests);
52 52
53 TEST(WebSocketFrameParserTest, DecodeNormalFrame) { 53 TEST(WebSocketFrameParserTest, DecodeNormalFrame) {
54 WebSocketFrameParser parser; 54 WebSocketFrameParser parser;
55 55
56 ScopedVector<WebSocketFrameChunk> frames; 56 ScopedVector<WebSocketFrameChunk> frames;
57 EXPECT_TRUE(parser.Decode(kHelloFrame, kHelloFrameLength, &frames)); 57 EXPECT_TRUE(parser.Decode(kHelloFrame, kHelloFrameLength, &frames));
58 EXPECT_EQ(kWebSocketNormalClosure, parser.websocket_error()); 58 EXPECT_EQ(kWebSocketNormalClosure, parser.websocket_error());
59 ASSERT_EQ(1u, frames.size()); 59 ASSERT_EQ(1u, frames.size());
60 WebSocketFrameChunk* frame = frames[0]; 60 WebSocketFrameChunk* frame = frames[0];
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 EXPECT_EQ(reserved3, header->reserved3); 567 EXPECT_EQ(reserved3, header->reserved3);
568 EXPECT_EQ(WebSocketFrameHeader::kOpCodeText, header->opcode); 568 EXPECT_EQ(WebSocketFrameHeader::kOpCodeText, header->opcode);
569 EXPECT_FALSE(header->masked); 569 EXPECT_FALSE(header->masked);
570 EXPECT_EQ(0u, header->payload_length); 570 EXPECT_EQ(0u, header->payload_length);
571 } 571 }
572 } 572 }
573 573
574 } // Unnamed namespace 574 } // Unnamed namespace
575 575
576 } // namespace net 576 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_basic_stream_test.cc ('k') | net/websockets/websocket_frame_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698