Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Unified Diff: net/socket/websocket_transport_client_socket_pool_unittest.cc

Issue 1132313004: Clean up weird ClientSocketPoolBase and WebSocket unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/client_socket_pool_base_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/websocket_transport_client_socket_pool_unittest.cc
diff --git a/net/socket/websocket_transport_client_socket_pool_unittest.cc b/net/socket/websocket_transport_client_socket_pool_unittest.cc
index 2df660633168450d7c601f566b0eb9452831f3dc..cd67dc0e3f8b8d55b542fcf2d308f38c175f9e33 100644
--- a/net/socket/websocket_transport_client_socket_pool_unittest.cc
+++ b/net/socket/websocket_transport_client_socket_pool_unittest.cc
@@ -374,60 +374,38 @@ TEST_F(WebSocketTransportClientSocketPoolTest, CancelRequest) {
EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(7));
}
-class RequestSocketCallback : public TestCompletionCallbackBase {
- public:
- RequestSocketCallback(ClientSocketHandle* handle,
- WebSocketTransportClientSocketPool* pool)
- : handle_(handle),
- pool_(pool),
- within_callback_(false),
- callback_(base::Bind(&RequestSocketCallback::OnComplete,
- base::Unretained(this))) {}
+// Function to be used as a callback on socket request completion. It first
+// disconnects the successfully connected socket from the first request, and
+// then reuses the ClientSocketHandle to request another socket. The second
+// request is expected to succeed asynchronously.
+//
+// |nested_callback| is called with the result of the second socket request.
+void RequestSocketOnComplete(ClientSocketHandle* handle,
+ WebSocketTransportClientSocketPool* pool,
+ const CompletionCallback& nested_callback,
+ int first_request_result) {
+ EXPECT_EQ(OK, first_request_result);
+
+ // Don't allow reuse of the socket. Disconnect it and then release it.
+ handle->socket()->Disconnect();
+ handle->Reset();
- ~RequestSocketCallback() override {}
-
- const CompletionCallback& callback() const { return callback_; }
-
- private:
- void OnComplete(int result) {
- SetResult(result);
- ASSERT_EQ(OK, result);
-
- if (!within_callback_) {
- // Don't allow reuse of the socket. Disconnect it and then release it and
- // run through the MessageLoop once to get it completely released.
- handle_->socket()->Disconnect();
- handle_->Reset();
- {
- base::MessageLoop::ScopedNestableTaskAllower allow(
- base::MessageLoop::current());
- base::MessageLoop::current()->RunUntilIdle();
- }
- within_callback_ = true;
- scoped_refptr<TransportSocketParams> dest(
- new TransportSocketParams(
- HostPortPair("www.google.com", 80),
- false,
- false,
- OnHostResolutionCallback(),
- TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
- int rv =
- handle_->Init("a", dest, LOWEST, callback(), pool_, BoundNetLog());
- EXPECT_EQ(OK, rv);
- }
- }
-
- ClientSocketHandle* const handle_;
- WebSocketTransportClientSocketPool* const pool_;
- bool within_callback_;
- CompletionCallback callback_;
-
- DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback);
-};
+ scoped_refptr<TransportSocketParams> dest(new TransportSocketParams(
+ HostPortPair("www.google.com", 80), false, false,
+ OnHostResolutionCallback(),
+ TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
+ int rv =
+ handle->Init("a", dest, LOWEST, nested_callback, pool, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
mmenke 2015/05/18 21:07:55 The old test was synchronous, but it was relying o
+ if (ERR_IO_PENDING != rv)
+ nested_callback.Run(rv);
+}
+// Tests the case where a second socket is requested in a completion callback,
+// and the second socket connects synchronously. Reuses the same
+// ClientSocketHandle for the second socket, after disconnecting the first.
TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) {
ClientSocketHandle handle;
- RequestSocketCallback callback(&handle, &pool_);
scoped_refptr<TransportSocketParams> dest(
new TransportSocketParams(
HostPortPair("www.google.com", 80),
@@ -435,15 +413,13 @@ TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) {
false,
OnHostResolutionCallback(),
TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
- int rv = handle.Init(
- "a", dest, LOWEST, callback.callback(), &pool_, BoundNetLog());
+ TestCompletionCallback second_result_callback;
+ int rv = handle.Init("a", dest, LOWEST,
+ base::Bind(&RequestSocketOnComplete, &handle, &pool_,
+ second_result_callback.callback()),
+ &pool_, BoundNetLog());
ASSERT_EQ(ERR_IO_PENDING, rv);
-
- // The callback is going to request "www.google.com". We want it to complete
- // synchronously this time.
- host_resolver_->set_synchronous_mode(true);
-
- EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(OK, second_result_callback.WaitForResult());
handle.Reset();
}
« no previous file with comments | « net/socket/client_socket_pool_base_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698