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
3 // found in the LICENSE file.
5 #include "net/websockets/websocket_net_log_params.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(NetLogWebSocketHandshakeParameterTest
, ToValue
) {
15 ListValue
* list
= new ListValue();
16 list
->Append(new StringValue("GET /demo HTTP/1.1"));
17 list
->Append(new StringValue("Host: example.com"));
18 list
->Append(new StringValue("Connection: Upgrade"));
19 list
->Append(new StringValue("Sec-WebSocket-Key2: 12998 5 Y3 1 .P00"));
20 list
->Append(new StringValue("Sec-WebSocket-Protocol: sample"));
21 list
->Append(new StringValue("Upgrade: WebSocket"));
22 list
->Append(new StringValue("Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5"));
23 list
->Append(new StringValue("Origin: http://example.com"));
24 list
->Append(new StringValue(""));
25 list
->Append(new StringValue("\\x00\\x01\\x0a\\x0d\\xff\\xfe\\x0d\\x0a"));
27 DictionaryValue expected
;
28 expected
.Set("headers", list
);
30 const std::string
key("\x00\x01\x0a\x0d\xff\xfe\x0d\x0a", 8);
31 const std::string testInput
=
32 "GET /demo HTTP/1.1\r\n"
33 "Host: example.com\r\n"
34 "Connection: Upgrade\r\n"
35 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n"
36 "Sec-WebSocket-Protocol: sample\r\n"
37 "Upgrade: WebSocket\r\n"
38 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"
39 "Origin: http://example.com\r\n"
43 scoped_ptr
<Value
> actual(
44 net::NetLogWebSocketHandshakeCallback(&testInput
,
45 net::NetLog::LOG_BASIC
));
47 EXPECT_TRUE(expected
.Equals(actual
.get()));