| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if (!writes_) { | 291 if (!writes_) { |
| 292 // Not using mock writes; succeed synchronously. | 292 // Not using mock writes; succeed synchronously. |
| 293 return MockWriteResult(false, data.length()); | 293 return MockWriteResult(false, data.length()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Check that what we are writing matches the expectation. | 296 // Check that what we are writing matches the expectation. |
| 297 // Then give the mocked return value. | 297 // Then give the mocked return value. |
| 298 net::MockWrite* w = &writes_[write_index_++]; | 298 net::MockWrite* w = &writes_[write_index_++]; |
| 299 int result = w->result; | 299 int result = w->result; |
| 300 if (w->data) { | 300 if (w->data) { |
| 301 // Note - we can simulate a partial write here. If the expected data |
| 302 // is a match, but shorter than the write actually written, that is legal. |
| 303 // Example: |
| 304 // Application writes "foobarbaz" (9 bytes) |
| 305 // Expected write was "foo" (3 bytes) |
| 306 // This is a success, and we return 3 to the application. |
| 301 std::string expected_data(w->data, w->data_len); | 307 std::string expected_data(w->data, w->data_len); |
| 302 EXPECT_EQ(expected_data, data); | 308 EXPECT_GE(data.length(), expected_data.length()); |
| 303 if (expected_data != data) | 309 std::string actual_data(data.substr(0, w->data_len)); |
| 310 EXPECT_EQ(expected_data, actual_data); |
| 311 if (expected_data != actual_data) |
| 304 return MockWriteResult(false, net::ERR_UNEXPECTED); | 312 return MockWriteResult(false, net::ERR_UNEXPECTED); |
| 305 if (result == net::OK) | 313 if (result == net::OK) |
| 306 result = w->data_len; | 314 result = w->data_len; |
| 307 } | 315 } |
| 308 return MockWriteResult(w->async, result); | 316 return MockWriteResult(w->async, result); |
| 309 } | 317 } |
| 310 | 318 |
| 311 void StaticSocketDataProvider::Reset() { | 319 void StaticSocketDataProvider::Reset() { |
| 312 read_index_ = 0; | 320 read_index_ = 0; |
| 313 write_index_ = 0; | 321 write_index_ = 0; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } | 459 } |
| 452 | 460 |
| 453 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { | 461 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { |
| 454 bool released_one; | 462 bool released_one; |
| 455 do { | 463 do { |
| 456 released_one = ReleaseOneConnection(keep_alive); | 464 released_one = ReleaseOneConnection(keep_alive); |
| 457 } while (released_one); | 465 } while (released_one); |
| 458 } | 466 } |
| 459 | 467 |
| 460 } // namespace net | 468 } // namespace net |
| OLD | NEW |