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_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // GoogleMock; a nested anonymous namespace will not work. | 52 // GoogleMock; a nested anonymous namespace will not work. |
53 | 53 |
54 std::ostream& operator<<(std::ostream& os, const WebSocketFrameHeader& header) { | 54 std::ostream& operator<<(std::ostream& os, const WebSocketFrameHeader& header) { |
55 return os << (header.final ? "FINAL_FRAME" : "NOT_FINAL_FRAME") << ", " | 55 return os << (header.final ? "FINAL_FRAME" : "NOT_FINAL_FRAME") << ", " |
56 << header.opcode << ", " | 56 << header.opcode << ", " |
57 << (header.masked ? "MASKED" : "NOT_MASKED"); | 57 << (header.masked ? "MASKED" : "NOT_MASKED"); |
58 } | 58 } |
59 | 59 |
60 std::ostream& operator<<(std::ostream& os, const WebSocketFrame& frame) { | 60 std::ostream& operator<<(std::ostream& os, const WebSocketFrame& frame) { |
61 os << "{" << frame.header << ", "; | 61 os << "{" << frame.header << ", "; |
62 if (frame.data) { | 62 if (frame.data.get()) { |
63 return os << "\"" << base::StringPiece(frame.data->data(), | 63 return os << "\"" << base::StringPiece(frame.data->data(), |
64 frame.header.payload_length) | 64 frame.header.payload_length) |
65 << "\"}"; | 65 << "\"}"; |
66 } | 66 } |
67 return os << "NULL}"; | 67 return os << "NULL}"; |
68 } | 68 } |
69 | 69 |
70 std::ostream& operator<<(std::ostream& os, | 70 std::ostream& operator<<(std::ostream& os, |
71 const ScopedVector<WebSocketFrame>& vector) { | 71 const ScopedVector<WebSocketFrame>& vector) { |
72 os << "{"; | 72 os << "{"; |
(...skipping 2782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2855 | 2855 |
2856 CreateChannelAndConnectSuccessfully(); | 2856 CreateChannelAndConnectSuccessfully(); |
2857 channel_->SendFrame( | 2857 channel_->SendFrame( |
2858 true, | 2858 true, |
2859 WebSocketFrameHeader::kOpCodeBinary, | 2859 WebSocketFrameHeader::kOpCodeBinary, |
2860 std::vector<char>(kBinaryBlob, kBinaryBlob + kBinaryBlobSize)); | 2860 std::vector<char>(kBinaryBlob, kBinaryBlob + kBinaryBlobSize)); |
2861 ASSERT_TRUE(frames != NULL); | 2861 ASSERT_TRUE(frames != NULL); |
2862 ASSERT_EQ(1U, frames->size()); | 2862 ASSERT_EQ(1U, frames->size()); |
2863 const WebSocketFrame* out_frame = (*frames)[0]; | 2863 const WebSocketFrame* out_frame = (*frames)[0]; |
2864 EXPECT_EQ(kBinaryBlobSize, out_frame->header.payload_length); | 2864 EXPECT_EQ(kBinaryBlobSize, out_frame->header.payload_length); |
2865 ASSERT_TRUE(out_frame->data); | 2865 ASSERT_TRUE(out_frame->data.get()); |
2866 EXPECT_EQ(0, memcmp(kBinaryBlob, out_frame->data->data(), kBinaryBlobSize)); | 2866 EXPECT_EQ(0, memcmp(kBinaryBlob, out_frame->data->data(), kBinaryBlobSize)); |
2867 } | 2867 } |
2868 | 2868 |
2869 // Test the read path for 8-bit cleanliness as well. | 2869 // Test the read path for 8-bit cleanliness as well. |
2870 TEST_F(WebSocketChannelEventInterfaceTest, ReadBinaryFramesAre8BitClean) { | 2870 TEST_F(WebSocketChannelEventInterfaceTest, ReadBinaryFramesAre8BitClean) { |
2871 scoped_ptr<WebSocketFrame> frame( | 2871 scoped_ptr<WebSocketFrame> frame( |
2872 new WebSocketFrame(WebSocketFrameHeader::kOpCodeBinary)); | 2872 new WebSocketFrame(WebSocketFrameHeader::kOpCodeBinary)); |
2873 WebSocketFrameHeader& frame_header = frame->header; | 2873 WebSocketFrameHeader& frame_header = frame->header; |
2874 frame_header.final = true; | 2874 frame_header.final = true; |
2875 frame_header.payload_length = kBinaryBlobSize; | 2875 frame_header.payload_length = kBinaryBlobSize; |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3428 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3428 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
3429 ASSERT_TRUE(read_frames); | 3429 ASSERT_TRUE(read_frames); |
3430 // Provide the "Close" message from the server. | 3430 // Provide the "Close" message from the server. |
3431 *read_frames = CreateFrameVector(frames); | 3431 *read_frames = CreateFrameVector(frames); |
3432 read_callback.Run(OK); | 3432 read_callback.Run(OK); |
3433 completion.WaitForResult(); | 3433 completion.WaitForResult(); |
3434 } | 3434 } |
3435 | 3435 |
3436 } // namespace | 3436 } // namespace |
3437 } // namespace net | 3437 } // namespace net |
OLD | NEW |