OLD | NEW |
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_deflater.h" | 5 #include "net/websockets/websocket_deflater.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 ASSERT_TRUE(deflater.AddBytes("Hello", 5)); | 86 ASSERT_TRUE(deflater.AddBytes("Hello", 5)); |
87 ASSERT_TRUE(deflater.Finish()); | 87 ASSERT_TRUE(deflater.Finish()); |
88 deflater.PushSyncMark(); | 88 deflater.PushSyncMark(); |
89 ASSERT_TRUE(deflater.Finish()); | 89 ASSERT_TRUE(deflater.Finish()); |
90 deflater.PushSyncMark(); | 90 deflater.PushSyncMark(); |
91 ASSERT_TRUE(deflater.AddBytes("Hello", 5)); | 91 ASSERT_TRUE(deflater.AddBytes("Hello", 5)); |
92 ASSERT_TRUE(deflater.Finish()); | 92 ASSERT_TRUE(deflater.Finish()); |
93 | 93 |
94 actual = deflater.GetOutput(deflater.CurrentOutputSize()); | 94 actual = deflater.GetOutput(deflater.CurrentOutputSize()); |
95 EXPECT_EQ(std::string("\xf2\x48\xcd\xc9\xc9\x07\x00\x00\x00\xff\xff" | 95 EXPECT_EQ(std::string( |
96 "\x00\x00\x00\xff\xff" | 96 "\xf2\x48\xcd\xc9\xc9\x07\x00\x00\x00\xff\xff" |
97 "\xf2\x00\x11\x00\x00", 21), | 97 "\x00\x00\x00\xff\xff" |
| 98 "\xf2\x00\x11\x00\x00", |
| 99 21), |
98 ToString(actual.get())); | 100 ToString(actual.get())); |
99 ASSERT_EQ(0u, deflater.CurrentOutputSize()); | 101 ASSERT_EQ(0u, deflater.CurrentOutputSize()); |
100 } | 102 } |
101 | 103 |
102 TEST(WebSocketDeflaterTest, WindowBits8) { | 104 TEST(WebSocketDeflaterTest, WindowBits8) { |
103 WebSocketDeflater deflater(WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT); | 105 WebSocketDeflater deflater(WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT); |
104 deflater.Initialize(8); | 106 deflater.Initialize(8); |
105 // Set the head and tail of |input| so that back-reference | 107 // Set the head and tail of |input| so that back-reference |
106 // can be used if the window size is sufficiently-large. | 108 // can be used if the window size is sufficiently-large. |
107 const std::string word = "Chromium"; | 109 const std::string word = "Chromium"; |
108 std::string input = word + std::string(256, 'a') + word; | 110 std::string input = word + std::string(256, 'a') + word; |
109 scoped_refptr<IOBufferWithSize> actual; | 111 scoped_refptr<IOBufferWithSize> actual; |
110 | 112 |
111 ASSERT_TRUE(deflater.AddBytes(input.data(), input.size())); | 113 ASSERT_TRUE(deflater.AddBytes(input.data(), input.size())); |
112 ASSERT_TRUE(deflater.Finish()); | 114 ASSERT_TRUE(deflater.Finish()); |
113 actual = deflater.GetOutput(deflater.CurrentOutputSize()); | 115 actual = deflater.GetOutput(deflater.CurrentOutputSize()); |
114 EXPECT_EQ(std::string("r\xce(\xca\xcf\xcd,\xcdM\x1c\xe1\xc0\x39\xa3" | 116 EXPECT_EQ(std::string( |
115 "(?7\xb3\x34\x17\x00", 21), | 117 "r\xce(\xca\xcf\xcd,\xcdM\x1c\xe1\xc0\x39\xa3" |
| 118 "(?7\xb3\x34\x17\x00", |
| 119 21), |
116 ToString(actual.get())); | 120 ToString(actual.get())); |
117 } | 121 } |
118 | 122 |
119 TEST(WebSocketDeflaterTest, WindowBits10) { | 123 TEST(WebSocketDeflaterTest, WindowBits10) { |
120 WebSocketDeflater deflater(WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT); | 124 WebSocketDeflater deflater(WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT); |
121 deflater.Initialize(10); | 125 deflater.Initialize(10); |
122 // Set the head and tail of |input| so that back-reference | 126 // Set the head and tail of |input| so that back-reference |
123 // can be used if the window size is sufficiently-large. | 127 // can be used if the window size is sufficiently-large. |
124 const std::string word = "Chromium"; | 128 const std::string word = "Chromium"; |
125 std::string input = word + std::string(256, 'a') + word; | 129 std::string input = word + std::string(256, 'a') + word; |
126 scoped_refptr<IOBufferWithSize> actual; | 130 scoped_refptr<IOBufferWithSize> actual; |
127 | 131 |
128 ASSERT_TRUE(deflater.AddBytes(input.data(), input.size())); | 132 ASSERT_TRUE(deflater.AddBytes(input.data(), input.size())); |
129 ASSERT_TRUE(deflater.Finish()); | 133 ASSERT_TRUE(deflater.Finish()); |
130 actual = deflater.GetOutput(deflater.CurrentOutputSize()); | 134 actual = deflater.GetOutput(deflater.CurrentOutputSize()); |
131 EXPECT_EQ( | 135 EXPECT_EQ( |
132 std::string("r\xce(\xca\xcf\xcd,\xcdM\x1c\xe1\xc0\x19\x1a\x0e\0\0", 17), | 136 std::string("r\xce(\xca\xcf\xcd,\xcdM\x1c\xe1\xc0\x19\x1a\x0e\0\0", 17), |
133 ToString(actual.get())); | 137 ToString(actual.get())); |
134 } | 138 } |
135 | 139 |
136 } // namespace | 140 } // namespace |
137 | 141 |
138 } // namespace net | 142 } // namespace net |
OLD | NEW |