OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 // This test suite uses SSLClientSocket to test the implementation of | 5 // This test suite uses SSLClientSocket to test the implementation of |
6 // SSLServerSocket. In order to establish connections between the sockets | 6 // SSLServerSocket. In order to establish connections between the sockets |
7 // we need two additional classes: | 7 // we need two additional classes: |
8 // 1. FakeSocket | 8 // 1. FakeSocket |
9 // Connects SSL socket to FakeDataChannel. This class is just a stub. | 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. |
10 // | 10 // |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 virtual int Write(IOBuffer* buf, int buf_len, | 80 virtual int Write(IOBuffer* buf, int buf_len, |
81 OldCompletionCallback* callback) { | 81 OldCompletionCallback* callback) { |
82 data_.push(new net::DrainableIOBuffer(buf, buf_len)); | 82 data_.push(new net::DrainableIOBuffer(buf, buf_len)); |
83 MessageLoop::current()->PostTask( | 83 MessageLoop::current()->PostTask( |
84 FROM_HERE, task_factory_.NewRunnableMethod( | 84 FROM_HERE, task_factory_.NewRunnableMethod( |
85 &FakeDataChannel::DoReadCallback)); | 85 &FakeDataChannel::DoReadCallback)); |
86 return buf_len; | 86 return buf_len; |
87 } | 87 } |
88 virtual int Write(IOBuffer* buf, int buf_len, | |
89 const CompletionCallback& callback) { | |
90 data_.push(new net::DrainableIOBuffer(buf, buf_len)); | |
91 MessageLoop::current()->PostTask( | |
92 FROM_HERE, task_factory_.NewRunnableMethod( | |
93 &FakeDataChannel::DoReadCallback)); | |
94 return buf_len; | |
95 } | |
96 | 88 |
97 private: | 89 private: |
98 void DoReadCallback() { | 90 void DoReadCallback() { |
99 if ((!old_read_callback_ && read_callback_.is_null()) || data_.empty()) | 91 if ((!old_read_callback_ && read_callback_.is_null()) || data_.empty()) |
100 return; | 92 return; |
101 | 93 |
102 int copied = PropogateData(read_buf_, read_buf_len_); | 94 int copied = PropogateData(read_buf_, read_buf_len_); |
103 if (old_read_callback_) { | 95 if (old_read_callback_) { |
104 net::OldCompletionCallback* callback = old_read_callback_; | 96 net::OldCompletionCallback* callback = old_read_callback_; |
105 old_read_callback_ = NULL; | 97 old_read_callback_ = NULL; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 buf_len = rand() % buf_len + 1; | 153 buf_len = rand() % buf_len + 1; |
162 return incoming_->Read(buf, buf_len, callback); | 154 return incoming_->Read(buf, buf_len, callback); |
163 } | 155 } |
164 | 156 |
165 virtual int Write(IOBuffer* buf, int buf_len, | 157 virtual int Write(IOBuffer* buf, int buf_len, |
166 OldCompletionCallback* callback) { | 158 OldCompletionCallback* callback) { |
167 // Write random number of bytes. | 159 // Write random number of bytes. |
168 buf_len = rand() % buf_len + 1; | 160 buf_len = rand() % buf_len + 1; |
169 return outgoing_->Write(buf, buf_len, callback); | 161 return outgoing_->Write(buf, buf_len, callback); |
170 } | 162 } |
171 virtual int Write(IOBuffer* buf, int buf_len, | |
172 const CompletionCallback& callback) { | |
173 // Write random number of bytes. | |
174 buf_len = rand() % buf_len + 1; | |
175 return outgoing_->Write(buf, buf_len, callback); | |
176 } | |
177 | 163 |
178 virtual bool SetReceiveBufferSize(int32 size) { | 164 virtual bool SetReceiveBufferSize(int32 size) { |
179 return true; | 165 return true; |
180 } | 166 } |
181 | 167 |
182 virtual bool SetSendBufferSize(int32 size) { | 168 virtual bool SetSendBufferSize(int32 size) { |
183 return true; | 169 return true; |
184 } | 170 } |
185 | 171 |
186 virtual int Connect(OldCompletionCallback* callback) { | 172 virtual int Connect(OldCompletionCallback* callback) { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; | 496 const char* kKeyingLabelBad = "EXPERIMENTAL-server-socket-test-bad"; |
511 unsigned char client_bad[kKeyingMaterialSize]; | 497 unsigned char client_bad[kKeyingMaterialSize]; |
512 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, | 498 rv = client_socket_->ExportKeyingMaterial(kKeyingLabelBad, kKeyingContext, |
513 client_bad, sizeof(client_bad)); | 499 client_bad, sizeof(client_bad)); |
514 ASSERT_EQ(rv, net::OK); | 500 ASSERT_EQ(rv, net::OK); |
515 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); | 501 EXPECT_TRUE(memcmp(server_out, client_bad, sizeof(server_out)) != 0); |
516 } | 502 } |
517 #endif | 503 #endif |
518 | 504 |
519 } // namespace net | 505 } // namespace net |
OLD | NEW |