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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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_handshake_handler.h" 5 #include "net/websockets/websocket_handshake_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
14 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char* const kCookieHeaders[] = { 21 const char* const kCookieHeaders[] = {"cookie", "cookie2"};
22 "cookie", "cookie2"
23 };
24 22
25 const char* const kSetCookieHeaders[] = { 23 const char* const kSetCookieHeaders[] = {"set-cookie", "set-cookie2"};
26 "set-cookie", "set-cookie2"
27 };
28 24
29 } // namespace 25 } // namespace
30 26
31 namespace net { 27 namespace net {
32 28
33 TEST(WebSocketHandshakeRequestHandlerTest, SimpleRequest) { 29 TEST(WebSocketHandshakeRequestHandlerTest, SimpleRequest) {
34 WebSocketHandshakeRequestHandler handler; 30 WebSocketHandshakeRequestHandler handler;
35 31
36 static const char kHandshakeRequestMessage[] = 32 static const char kHandshakeRequestMessage[] =
37 "GET /demo HTTP/1.1\r\n" 33 "GET /demo HTTP/1.1\r\n"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 request_handler.GetRequestInfo(url, &challenge); 184 request_handler.GetRequestInfo(url, &challenge);
189 185
190 EXPECT_EQ(url, request_info.url); 186 EXPECT_EQ(url, request_info.url);
191 EXPECT_EQ("GET", request_info.method); 187 EXPECT_EQ("GET", request_info.method);
192 EXPECT_FALSE(request_info.extra_headers.HasHeader("Upgrade")); 188 EXPECT_FALSE(request_info.extra_headers.HasHeader("Upgrade"));
193 EXPECT_FALSE(request_info.extra_headers.HasHeader("Connection")); 189 EXPECT_FALSE(request_info.extra_headers.HasHeader("Connection"));
194 EXPECT_FALSE(request_info.extra_headers.HasHeader("Sec-WebSocket-Key")); 190 EXPECT_FALSE(request_info.extra_headers.HasHeader("Sec-WebSocket-Key"));
195 std::string value; 191 std::string value;
196 EXPECT_TRUE(request_info.extra_headers.GetHeader("Host", &value)); 192 EXPECT_TRUE(request_info.extra_headers.GetHeader("Host", &value));
197 EXPECT_EQ("example.com", value); 193 EXPECT_EQ("example.com", value);
198 EXPECT_TRUE(request_info.extra_headers.GetHeader("Sec-WebSocket-Origin", 194 EXPECT_TRUE(
199 &value)); 195 request_info.extra_headers.GetHeader("Sec-WebSocket-Origin", &value));
200 EXPECT_EQ("http://example.com", value); 196 EXPECT_EQ("http://example.com", value);
201 EXPECT_TRUE(request_info.extra_headers.GetHeader("Sec-WebSocket-Protocol", 197 EXPECT_TRUE(
202 &value)); 198 request_info.extra_headers.GetHeader("Sec-WebSocket-Protocol", &value));
203 EXPECT_EQ("sample", value); 199 EXPECT_EQ("sample", value);
204 200
205 EXPECT_EQ("dGhlIHNhbXBsZSBub25jZQ==", challenge); 201 EXPECT_EQ("dGhlIHNhbXBsZSBub25jZQ==", challenge);
206 202
207 static const char kHandshakeResponseHeader[] = 203 static const char kHandshakeResponseHeader[] =
208 "HTTP/1.1 101 Switching Protocols\r\n" 204 "HTTP/1.1 101 Switching Protocols\r\n"
209 "Sec-WebSocket-Protocol: sample\r\n"; 205 "Sec-WebSocket-Protocol: sample\r\n";
210 206
211 std::string raw_headers = 207 std::string raw_headers = HttpUtil::AssembleRawHeaders(
212 HttpUtil::AssembleRawHeaders(kHandshakeResponseHeader, 208 kHandshakeResponseHeader, strlen(kHandshakeResponseHeader));
213 strlen(kHandshakeResponseHeader));
214 HttpResponseInfo response_info; 209 HttpResponseInfo response_info;
215 response_info.headers = new HttpResponseHeaders(raw_headers); 210 response_info.headers = new HttpResponseHeaders(raw_headers);
216 211
217 EXPECT_TRUE(StartsWithASCII(response_info.headers->GetStatusLine(), 212 EXPECT_TRUE(StartsWithASCII(
218 "HTTP/1.1 101 ", false)); 213 response_info.headers->GetStatusLine(), "HTTP/1.1 101 ", false));
219 EXPECT_FALSE(response_info.headers->HasHeader("Upgrade")); 214 EXPECT_FALSE(response_info.headers->HasHeader("Upgrade"));
220 EXPECT_FALSE(response_info.headers->HasHeader("Connection")); 215 EXPECT_FALSE(response_info.headers->HasHeader("Connection"));
221 EXPECT_FALSE(response_info.headers->HasHeader("Sec-WebSocket-Accept")); 216 EXPECT_FALSE(response_info.headers->HasHeader("Sec-WebSocket-Accept"));
222 EXPECT_TRUE(response_info.headers->HasHeaderValue("Sec-WebSocket-Protocol", 217 EXPECT_TRUE(response_info.headers->HasHeaderValue("Sec-WebSocket-Protocol",
223 "sample")); 218 "sample"));
224 219
225 WebSocketHandshakeResponseHandler response_handler; 220 WebSocketHandshakeResponseHandler response_handler;
226 221
227 EXPECT_TRUE(response_handler.ParseResponseInfo(response_info, challenge)); 222 EXPECT_TRUE(response_handler.ParseResponseInfo(response_info, challenge));
228 EXPECT_TRUE(response_handler.HasResponse()); 223 EXPECT_TRUE(response_handler.HasResponse());
229 224
230 static const char kHandshakeResponseExpectedMessage[] = 225 static const char kHandshakeResponseExpectedMessage[] =
231 "HTTP/1.1 101 Switching Protocols\r\n" 226 "HTTP/1.1 101 Switching Protocols\r\n"
232 "Upgrade: websocket\r\n" 227 "Upgrade: websocket\r\n"
233 "Connection: Upgrade\r\n" 228 "Connection: Upgrade\r\n"
234 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 229 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
235 "Sec-WebSocket-Protocol: sample\r\n" 230 "Sec-WebSocket-Protocol: sample\r\n"
236 "\r\n"; 231 "\r\n";
237 232
238 EXPECT_EQ(kHandshakeResponseExpectedMessage, response_handler.GetResponse()); 233 EXPECT_EQ(kHandshakeResponseExpectedMessage, response_handler.GetResponse());
239 } 234 }
240 235
241 } // namespace net 236 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698