diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 19:24:14 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 19:24:14 +0000 |
commit | 06f924615240a1ca2fca8fd1886b0b1c39a64a92 (patch) | |
tree | 6d7bd6f82202303e8b9f55972e1209e79163cb1b /net/socket/client_socket_pool_base_unittest.cc | |
parent | 1e1fd49cfd5b770a7bdba08bfbba321748325f31 (diff) | |
download | chromium_src-06f924615240a1ca2fca8fd1886b0b1c39a64a92.zip chromium_src-06f924615240a1ca2fca8fd1886b0b1c39a64a92.tar.gz chromium_src-06f924615240a1ca2fca8fd1886b0b1c39a64a92.tar.bz2 |
Abort ConnectJobs with ERR_ABORTED when network changes.
BUG=50665
TEST=ClientSocketPoolBaseTest.AbortAllRequestsOnFlush
Review URL: http://codereview.chromium.org/3255005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_pool_base_unittest.cc')
-rw-r--r-- | net/socket/client_socket_pool_base_unittest.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 71074a9..006d4e81 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -1933,6 +1933,63 @@ TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); } +class ConnectWithinCallback : public CallbackRunner< Tuple1<int> > { + public: + ConnectWithinCallback( + const std::string& group_name, + const scoped_refptr<TestSocketParams>& params, + const scoped_refptr<TestClientSocketPool>& pool) + : group_name_(group_name), params_(params), pool_(pool) {} + + ~ConnectWithinCallback() {} + + virtual void RunWithParams(const Tuple1<int>& params) { + callback_.RunWithParams(params); + EXPECT_EQ(ERR_IO_PENDING, + handle_.Init(group_name_, + params_, + kDefaultPriority, + &nested_callback_, + pool_, + BoundNetLog())); + } + + int WaitForResult() { + return callback_.WaitForResult(); + } + + int WaitForNestedResult() { + return nested_callback_.WaitForResult(); + } + + private: + const std::string group_name_; + const scoped_refptr<TestSocketParams> params_; + const scoped_refptr<TestClientSocketPool> pool_; + ClientSocketHandle handle_; + TestCompletionCallback callback_; + TestCompletionCallback nested_callback_; +}; + +TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { + CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); + + // First job will be waiting until it gets aborted. + connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); + + ClientSocketHandle handle; + ConnectWithinCallback callback("a", params_, pool_); + EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, + &callback, pool_, BoundNetLog())); + + // Second job will be started during the first callback, and will + // asynchronously complete with OK. + connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); + pool_->Flush(); + EXPECT_EQ(ERR_ABORTED, callback.WaitForResult()); + EXPECT_EQ(OK, callback.WaitForNestedResult()); +} + // Cancel a pending socket request while we're at max sockets, // and verify that the backup socket firing doesn't cause a crash. TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { |