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

Side by Side Diff: remoting/protocol/authenticator_test_base.cc

Issue 10454066: Move the core state machine of SSLClientSocketNSS into a thread-safe Core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win_rel by not caching the current threads task runner. See added comment Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/protocol/authenticator_test_base.h" 5 #include "remoting/protocol/authenticator_test_base.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/test/test_timeouts.h"
11 #include "base/timer.h"
10 #include "crypto/rsa_private_key.h" 12 #include "crypto/rsa_private_key.h"
11 #include "net/base/cert_test_util.h" 13 #include "net/base/cert_test_util.h"
12 #include "remoting/protocol/authenticator.h" 14 #include "remoting/protocol/authenticator.h"
13 #include "remoting/protocol/channel_authenticator.h" 15 #include "remoting/protocol/channel_authenticator.h"
14 #include "remoting/protocol/fake_session.h" 16 #include "remoting/protocol/fake_session.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
17 19
18 using testing::_; 20 using testing::_;
19 using testing::SaveArg; 21 using testing::SaveArg;
20 22
21 namespace remoting { 23 namespace remoting {
22 namespace protocol { 24 namespace protocol {
23 25
24 AuthenticatorTestBase::MockChannelDoneCallback::MockChannelDoneCallback() { 26 namespace {
25 } 27
26 AuthenticatorTestBase::MockChannelDoneCallback::~MockChannelDoneCallback() { 28 ACTION_P(QuitThreadOnCounter, counter) {
29 --(*counter);
30 EXPECT_GE(*counter, 0);
31 if (*counter == 0)
32 MessageLoop::current()->Quit();
27 } 33 }
28 34
29 AuthenticatorTestBase::AuthenticatorTestBase() { 35 } // namespace
30 } 36
31 AuthenticatorTestBase::~AuthenticatorTestBase() { 37 AuthenticatorTestBase::MockChannelDoneCallback::MockChannelDoneCallback() {}
32 } 38
39 AuthenticatorTestBase::MockChannelDoneCallback::~MockChannelDoneCallback() {}
40
41 AuthenticatorTestBase::AuthenticatorTestBase() {}
42
43 AuthenticatorTestBase::~AuthenticatorTestBase() {}
33 44
34 void AuthenticatorTestBase::SetUp() { 45 void AuthenticatorTestBase::SetUp() {
35 FilePath certs_dir(net::GetTestCertsDirectory()); 46 FilePath certs_dir(net::GetTestCertsDirectory());
36 47
37 FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der"); 48 FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
38 ASSERT_TRUE(file_util::ReadFileToString(cert_path, &host_cert_)); 49 ASSERT_TRUE(file_util::ReadFileToString(cert_path, &host_cert_));
39 50
40 FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); 51 FilePath key_path = certs_dir.AppendASCII("unittest.key.bin");
41 std::string key_string; 52 std::string key_string;
42 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string)); 53 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 base::Unretained(this))); 103 base::Unretained(this)));
93 104
94 host_auth_->SecureAndAuthenticate( 105 host_auth_->SecureAndAuthenticate(
95 host_fake_socket_.PassAs<net::StreamSocket>(), 106 host_fake_socket_.PassAs<net::StreamSocket>(),
96 base::Bind(&AuthenticatorTestBase::OnHostConnected, 107 base::Bind(&AuthenticatorTestBase::OnHostConnected,
97 base::Unretained(this))); 108 base::Unretained(this)));
98 109
99 net::StreamSocket* client_socket = NULL; 110 net::StreamSocket* client_socket = NULL;
100 net::StreamSocket* host_socket = NULL; 111 net::StreamSocket* host_socket = NULL;
101 112
113 // Expect two callbacks to be called - the client callback and the host
114 // callback.
115 int callback_counter = 2;
116
102 EXPECT_CALL(client_callback_, OnDone(net::OK, _)) 117 EXPECT_CALL(client_callback_, OnDone(net::OK, _))
103 .WillOnce(SaveArg<1>(&client_socket)); 118 .WillOnce(DoAll(SaveArg<1>(&client_socket),
119 QuitThreadOnCounter(&callback_counter)));
104 if (expected_fail) { 120 if (expected_fail) {
105 EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL)); 121 EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL))
122 .WillOnce(QuitThreadOnCounter(&callback_counter));
106 } else { 123 } else {
107 EXPECT_CALL(host_callback_, OnDone(net::OK, _)) 124 EXPECT_CALL(host_callback_, OnDone(net::OK, _))
108 .WillOnce(SaveArg<1>(&host_socket)); 125 .WillOnce(DoAll(SaveArg<1>(&host_socket),
126 QuitThreadOnCounter(&callback_counter)));
109 } 127 }
110 128
111 message_loop_.RunAllPending(); 129 // Ensure that .Run() does not run unbounded if the callbacks are never
130 // called.
131 base::Timer shutdown_timer(false, false);
132 shutdown_timer.Start(FROM_HERE, TestTimeouts::action_timeout(),
133 MessageLoop::QuitClosure());
134 message_loop_.Run();
135 shutdown_timer.Stop();
112 136
113 testing::Mock::VerifyAndClearExpectations(&client_callback_); 137 testing::Mock::VerifyAndClearExpectations(&client_callback_);
114 testing::Mock::VerifyAndClearExpectations(&host_callback_); 138 testing::Mock::VerifyAndClearExpectations(&host_callback_);
115 139
116 client_socket_.reset(client_socket); 140 client_socket_.reset(client_socket);
117 host_socket_.reset(host_socket); 141 host_socket_.reset(host_socket);
142
143 if (!expected_fail) {
144 ASSERT_TRUE(client_socket_.get() != NULL);
145 ASSERT_TRUE(host_socket_.get() != NULL);
146 }
118 } 147 }
119 148
120 void AuthenticatorTestBase::OnHostConnected( 149 void AuthenticatorTestBase::OnHostConnected(
121 net::Error error, 150 net::Error error,
122 scoped_ptr<net::StreamSocket> socket) { 151 scoped_ptr<net::StreamSocket> socket) {
123 host_callback_.OnDone(error, socket.get()); 152 host_callback_.OnDone(error, socket.get());
124 host_socket_ = socket.Pass(); 153 host_socket_ = socket.Pass();
125 } 154 }
126 155
127 void AuthenticatorTestBase::OnClientConnected( 156 void AuthenticatorTestBase::OnClientConnected(
128 net::Error error, 157 net::Error error,
129 scoped_ptr<net::StreamSocket> socket) { 158 scoped_ptr<net::StreamSocket> socket) {
130 client_callback_.OnDone(error, socket.get()); 159 client_callback_.OnDone(error, socket.get());
131 client_socket_ = socket.Pass(); 160 client_socket_ = socket.Pass();
132 } 161 }
133 162
134 } // namespace protocol 163 } // namespace protocol
135 } // namespace remoting 164 } // namespace remoting
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/sslinfo.c ('k') | remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698