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