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

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

Issue 23623008: Implement WebSocketDeflater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/websockets/websocket_deflater.h"
6
7 #include <string>
8
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/io_buffer.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace net {
16
17 TEST(WebSocketDeflaterTest, Construct) {
18 WebSocketDeflater deflater(8, WebSocketDeflater::TAKE_OVER_CONTEXT);
19 std::string expected("\x02\x00", 2);
20
21 scoped_refptr<IOBufferWithSize> actual = deflater.Finish();
22 ASSERT_TRUE(actual);
23 EXPECT_EQ(expected, std::string(actual->data(), actual->size()));
Adam Rice 2013/08/29 12:04:33 My preference would be to construct the expected s
yhirano 2013/08/30 06:20:35 Done.
24 }
25
26 TEST(WebSocketDeflaterTest, DeflateHelloTakeOverContext) {
27 WebSocketDeflater deflater(15, WebSocketDeflater::TAKE_OVER_CONTEXT);
28 scoped_refptr<IOBufferWithSize> actual1, actual2;
29 std::string expected1("\xf2\x48\xcd\xc9\xc9\x07\x00", 7);
30 std::string expected2("\xf2\x00\x11\x00\x00", 5);
31
32 ASSERT_TRUE(deflater.AddBytes("Hello", strlen("Hello")));
33 actual1 = deflater.Finish();
34 ASSERT_TRUE(actual1);
35 EXPECT_EQ(expected1, std::string(actual1->data(), actual1->size()));
36
37 ASSERT_TRUE(deflater.AddBytes("Hello", strlen("Hello")));
38 actual2 = deflater.Finish();
39 ASSERT_TRUE(actual2);
40 EXPECT_EQ(expected2, std::string(actual2->data(), actual2->size()));
41 }
42
43 TEST(WebSocketDeflaterTest, DeflateHelloDoNotTakeOverContext) {
44 WebSocketDeflater deflater(15, WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT);
45 scoped_refptr<IOBufferWithSize> actual1, actual2;
46 std::string expected1("\xf2\x48\xcd\xc9\xc9\x07\x00", 7);
47 std::string expected2("\xf2\x48\xcd\xc9\xc9\x07\x00", 7);
48
49 ASSERT_TRUE(deflater.AddBytes("Hello", strlen("Hello")));
50 actual1 = deflater.Finish();
51 ASSERT_TRUE(actual1);
52 EXPECT_EQ(expected1, std::string(actual1->data(), actual1->size()));
53
54 ASSERT_TRUE(deflater.AddBytes("Hello", strlen("Hello")));
55 actual2 = deflater.Finish();
56 ASSERT_TRUE(actual2);
57 EXPECT_EQ(expected2, std::string(actual2->data(), actual2->size()));
58 }
59
60 TEST(WebSocketDeflaterTest, MultipleAddBytesCalls) {
61 WebSocketDeflater deflater(15, WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT);
62 std::vector<char> input(32, 'a');
63 scoped_refptr<IOBufferWithSize> actual;
64 std::string expected("\x4a\x4c\xc4\x0f\x00\x00", 6);
65
66 for (size_t i = 0; i < input.size(); ++i) {
67 ASSERT_TRUE(deflater.AddBytes(&input[i], 1));
68 }
69 actual = deflater.Finish();
70 ASSERT_TRUE(actual);
71 EXPECT_EQ(expected, std::string(actual->data(), actual->size()));
72 }
73
74 TEST(WebSocketDeflaterTest, WindowBits8And15) {
Adam Rice 2013/08/29 12:04:33 If it was me I would split this into two tests, "W
yhirano 2013/08/30 06:20:35 Done.
75 WebSocketDeflater deflater8(8, WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT);
76 WebSocketDeflater deflater15(15, WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT);
77 std::vector<char> input(1024 + 64 * 2, 'a');
78 // Modify the head and tail of |input| so that back-reference
79 // can be used if the window size is sufficiently-large.
80 for (size_t j = 0; j < 64; ++j) {
81 input[j] = 'b';
82 input[input.size() - j - 1] = 'b';
83 }
84 scoped_refptr<IOBufferWithSize> actual8;
85 scoped_refptr<IOBufferWithSize> actual15;
86 std::string expected8("JJ\xa2\x0c$\x8e\x82Q0\nF,H\xa2\x10\x00\x00", 17);
87 std::string expected15("JJ\xa2\x0c$\x8e\x82Q0\nF,\xa0\xb0\xf8H\x02\x00", 18);
88
89 ASSERT_TRUE(deflater8.AddBytes(input.data(), input.size()));
90 ASSERT_TRUE(deflater15.AddBytes(input.data(), input.size()));
91 actual8 = deflater8.Finish();
92 actual15 = deflater15.Finish();
93 ASSERT_TRUE(actual8);
94 ASSERT_TRUE(actual15);
95 EXPECT_EQ(expected8, std::string(actual8->data(), actual8->size()));
96 EXPECT_EQ(expected15, std::string(actual15->data(), actual15->size()));
97 }
98
99 } // namespace net
OLDNEW
« net/websockets/websocket_deflater.cc ('K') | « net/websockets/websocket_deflater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698