| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" |
| 11 #include "net/websockets/websocket_handshake.h" | 12 #include "net/websockets/websocket_handshake.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 class WebSocketHandshakeTest : public testing::Test { | 19 class WebSocketHandshakeTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 static void SetUpParameter(WebSocketHandshake* handshake, | 21 static void SetUpParameter(WebSocketHandshake* handshake, |
| 21 uint32 number_1, uint32 number_2, | 22 uint32 number_1, uint32 number_2, |
| 22 const std::string& key_1, const std::string& key_2, | 23 const std::string& key_1, const std::string& key_2, |
| 23 const std::string& key_3) { | 24 const std::string& key_3) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const char* actual_key3 = actual.data() + actual.size() - 12; | 80 const char* actual_key3 = actual.data() + actual.size() - 12; |
| 80 EXPECT_TRUE(memcmp(expected_key3, actual_key3, 12) == 0) | 81 EXPECT_TRUE(memcmp(expected_key3, actual_key3, 12) == 0) |
| 81 << "expected_key3:" << DumpKey(expected_key3, 12) | 82 << "expected_key3:" << DumpKey(expected_key3, 12) |
| 82 << ", actual_key3:" << DumpKey(actual_key3, 12); | 83 << ", actual_key3:" << DumpKey(actual_key3, 12); |
| 83 } | 84 } |
| 84 | 85 |
| 85 static std::string DumpKey(const char* buf, int len) { | 86 static std::string DumpKey(const char* buf, int len) { |
| 86 std::string s; | 87 std::string s; |
| 87 for (int i = 0; i < len; i++) { | 88 for (int i = 0; i < len; i++) { |
| 88 if (isprint(buf[i])) | 89 if (isprint(buf[i])) |
| 89 s += StringPrintf("%c", buf[i]); | 90 s += base::StringPrintf("%c", buf[i]); |
| 90 else | 91 else |
| 91 s += StringPrintf("\\x%02x", buf[i]); | 92 s += base::StringPrintf("\\x%02x", buf[i]); |
| 92 } | 93 } |
| 93 return s; | 94 return s; |
| 94 } | 95 } |
| 95 | 96 |
| 96 static std::string GetResourceName(WebSocketHandshake* handshake) { | 97 static std::string GetResourceName(WebSocketHandshake* handshake) { |
| 97 return handshake->GetResourceName(); | 98 return handshake->GetResourceName(); |
| 98 } | 99 } |
| 99 static std::string GetHostFieldValue(WebSocketHandshake* handshake) { | 100 static std::string GetHostFieldValue(WebSocketHandshake* handshake) { |
| 100 return handshake->GetHostFieldValue(); | 101 return handshake->GetHostFieldValue(); |
| 101 } | 102 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 scoped_ptr<WebSocketHandshake> handshake( | 321 scoped_ptr<WebSocketHandshake> handshake( |
| 321 new WebSocketHandshake(GURL("wss://example.com:80/demo"), | 322 new WebSocketHandshake(GURL("wss://example.com:80/demo"), |
| 322 "http://example.com", | 323 "http://example.com", |
| 323 "wss://example.com/demo", | 324 "wss://example.com/demo", |
| 324 "sample")); | 325 "sample")); |
| 325 // :80 should be preserved as it's not the default port for wss://. | 326 // :80 should be preserved as it's not the default port for wss://. |
| 326 EXPECT_EQ("example.com:80", GetHostFieldValue(handshake.get())); | 327 EXPECT_EQ("example.com:80", GetHostFieldValue(handshake.get())); |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace net | 330 } // namespace net |
| OLD | NEW |