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

Side by Side Diff: jingle/notifier/base/chrome_async_socket_unittest.cc

Issue 6833031: Changed the jingle network code in ChromeAsyncSocket to use the client socket pool. This also all... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Lint fix Created 9 years, 8 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) 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 #include "jingle/notifier/base/chrome_async_socket.h" 5 #include "jingle/notifier/base/chrome_async_socket.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/message_loop_proxy.h"
14 #include "net/base/capturing_net_log.h" 15 #include "net/base/capturing_net_log.h"
15 #include "net/base/cert_verifier.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/ssl_config_service.h" 17 #include "net/base/ssl_config_service.h"
18 #include "net/socket/socket_test_util.h" 18 #include "net/socket/socket_test_util.h"
19 #include "net/url_request/url_request_context_getter.h"
20 #include "net/url_request/url_request_test_util.h"
19 #include "talk/base/sigslot.h" 21 #include "talk/base/sigslot.h"
20 #include "talk/base/socketaddress.h" 22 #include "talk/base/socketaddress.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace notifier { 25 namespace notifier {
24 26
25 namespace { 27 namespace {
26 28
29 // Used to return a dummy context.
30 class TestURLRequestContextGetter : public net::URLRequestContextGetter {
31 public:
32 TestURLRequestContextGetter()
33 : message_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()) {
34 }
35 virtual ~TestURLRequestContextGetter() { }
36
37 // net::URLRequestContextGetter:
38 virtual net::URLRequestContext* GetURLRequestContext() {
39 if (!context_)
40 context_ = new TestURLRequestContext();
41 return context_.get();
42 }
43 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
44 return message_loop_proxy_;
45 }
46
47 private:
48 scoped_refptr<net::URLRequestContext> context_;
49 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
50 };
51
27 // Data provider that handles reads/writes for ChromeAsyncSocket. 52 // Data provider that handles reads/writes for ChromeAsyncSocket.
28 class AsyncSocketDataProvider : public net::SocketDataProvider { 53 class AsyncSocketDataProvider : public net::SocketDataProvider {
29 public: 54 public:
30 AsyncSocketDataProvider() : has_pending_read_(false) {} 55 AsyncSocketDataProvider() : has_pending_read_(false) {}
31 56
32 virtual ~AsyncSocketDataProvider() { 57 virtual ~AsyncSocketDataProvider() {
33 EXPECT_TRUE(writes_.empty()); 58 EXPECT_TRUE(writes_.empty());
34 EXPECT_TRUE(reads_.empty()); 59 EXPECT_TRUE(reads_.empty());
35 } 60 }
36 61
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 DISALLOW_COPY_AND_ASSIGN(AsyncSocketDataProvider); 120 DISALLOW_COPY_AND_ASSIGN(AsyncSocketDataProvider);
96 }; 121 };
97 122
98 class ChromeAsyncSocketTest 123 class ChromeAsyncSocketTest
99 : public testing::Test, 124 : public testing::Test,
100 public sigslot::has_slots<> { 125 public sigslot::has_slots<> {
101 protected: 126 protected:
102 ChromeAsyncSocketTest() 127 ChromeAsyncSocketTest()
103 : ssl_socket_data_provider_(true, net::OK), 128 : ssl_socket_data_provider_(true, net::OK),
104 capturing_net_log_(net::CapturingNetLog::kUnbounded), 129 capturing_net_log_(net::CapturingNetLog::kUnbounded),
130 url_request_context_getter_(new TestURLRequestContextGetter()),
105 addr_(0xaabbccdd, 35) {} 131 addr_(0xaabbccdd, 35) {}
106 132
107 virtual ~ChromeAsyncSocketTest() {} 133 virtual ~ChromeAsyncSocketTest() {}
108 134
109 virtual void SetUp() { 135 virtual void SetUp() {
110 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory( 136 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory(
111 new net::MockClientSocketFactory()); 137 new net::MockClientSocketFactory());
112 mock_client_socket_factory->AddSocketDataProvider( 138 mock_client_socket_factory->AddSocketDataProvider(
113 &async_socket_data_provider_); 139 &async_socket_data_provider_);
114 mock_client_socket_factory->AddSSLSocketDataProvider( 140 mock_client_socket_factory->AddSSLSocketDataProvider(
115 &ssl_socket_data_provider_); 141 &ssl_socket_data_provider_);
116 142
117 chrome_async_socket_.reset( 143 chrome_async_socket_.reset(
118 new ChromeAsyncSocket(mock_client_socket_factory.release(), 144 new ChromeAsyncSocket(ssl_config_, url_request_context_getter_, false,
119 ssl_config_, &cert_verifier_, 14, 20, 145 14, 20,
120 &capturing_net_log_)), 146 &capturing_net_log_));
121 147 chrome_async_socket_->set_client_socket_factory(
148 mock_client_socket_factory.release());
122 chrome_async_socket_->SignalConnected.connect( 149 chrome_async_socket_->SignalConnected.connect(
123 this, &ChromeAsyncSocketTest::OnConnect); 150 this, &ChromeAsyncSocketTest::OnConnect);
124 chrome_async_socket_->SignalSSLConnected.connect( 151 chrome_async_socket_->SignalSSLConnected.connect(
125 this, &ChromeAsyncSocketTest::OnSSLConnect); 152 this, &ChromeAsyncSocketTest::OnSSLConnect);
126 chrome_async_socket_->SignalClosed.connect( 153 chrome_async_socket_->SignalClosed.connect(
127 this, &ChromeAsyncSocketTest::OnClose); 154 this, &ChromeAsyncSocketTest::OnClose);
128 chrome_async_socket_->SignalRead.connect( 155 chrome_async_socket_->SignalRead.connect(
129 this, &ChromeAsyncSocketTest::OnRead); 156 this, &ChromeAsyncSocketTest::OnRead);
130 chrome_async_socket_->SignalError.connect( 157 chrome_async_socket_->SignalError.connect(
131 this, &ChromeAsyncSocketTest::OnError); 158 this, &ChromeAsyncSocketTest::OnError);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 393 }
367 394
368 // ChromeAsyncSocket expects a message loop. 395 // ChromeAsyncSocket expects a message loop.
369 MessageLoop message_loop_; 396 MessageLoop message_loop_;
370 397
371 AsyncSocketDataProvider async_socket_data_provider_; 398 AsyncSocketDataProvider async_socket_data_provider_;
372 net::SSLSocketDataProvider ssl_socket_data_provider_; 399 net::SSLSocketDataProvider ssl_socket_data_provider_;
373 400
374 net::CapturingNetLog capturing_net_log_; 401 net::CapturingNetLog capturing_net_log_;
375 net::SSLConfig ssl_config_; 402 net::SSLConfig ssl_config_;
376 net::CertVerifier cert_verifier_; 403 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_;
377 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; 404 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_;
378 std::deque<SignalSocketState> signal_socket_states_; 405 std::deque<SignalSocketState> signal_socket_states_;
379 const talk_base::SocketAddress addr_; 406 const talk_base::SocketAddress addr_;
380 407
381 private: 408 private:
382 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); 409 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest);
383 }; 410 };
384 411
385 TEST_F(ChromeAsyncSocketTest, InitialState) { 412 TEST_F(ChromeAsyncSocketTest, InitialState) {
386 ExpectClosed(); 413 ExpectClosed();
(...skipping 23 matching lines...) Expand all
410 EXPECT_TRUE(chrome_async_socket_->Close()); 437 EXPECT_TRUE(chrome_async_socket_->Close());
411 ExpectClosed(); 438 ExpectClosed();
412 ExpectSignalSocketState( 439 ExpectSignalSocketState(
413 SignalSocketState::NoError( 440 SignalSocketState::NoError(
414 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); 441 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED));
415 442
416 EXPECT_TRUE(chrome_async_socket_->Close()); 443 EXPECT_TRUE(chrome_async_socket_->Close());
417 ExpectClosed(); 444 ExpectClosed();
418 } 445 }
419 446
420 TEST_F(ChromeAsyncSocketTest, UnresolvedConnect) {
421 const talk_base::SocketAddress unresolved_addr(0, 0);
422 EXPECT_FALSE(chrome_async_socket_->Connect(unresolved_addr));
423 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED,
424 ChromeAsyncSocket::ERROR_DNS);
425
426 EXPECT_TRUE(chrome_async_socket_->Close());
427 ExpectClosed();
428 }
429
430 TEST_F(ChromeAsyncSocketTest, DoubleConnect) { 447 TEST_F(ChromeAsyncSocketTest, DoubleConnect) {
431 EXPECT_DEBUG_DEATH({ 448 EXPECT_DEBUG_DEATH({
432 DoOpenClosed(); 449 DoOpenClosed();
433 450
434 EXPECT_FALSE(chrome_async_socket_->Connect(addr_)); 451 EXPECT_FALSE(chrome_async_socket_->Connect(addr_));
435 ExpectErrorState(ChromeAsyncSocket::STATE_OPEN, 452 ExpectErrorState(ChromeAsyncSocket::STATE_OPEN,
436 ChromeAsyncSocket::ERROR_WRONGSTATE); 453 ChromeAsyncSocket::ERROR_WRONGSTATE);
437 454
438 DoCloseOpened( 455 DoCloseOpened(
439 SignalSocketState(SIGNAL_CLOSE, 456 SignalSocketState(SIGNAL_CLOSE,
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 message_loop_.RunAllPending(); 1031 message_loop_.RunAllPending();
1015 1032
1016 ExpectNoSignal(); 1033 ExpectNoSignal();
1017 1034
1018 DoSSLCloseOpenedNoError(); 1035 DoSSLCloseOpenedNoError();
1019 } 1036 }
1020 1037
1021 } // namespace 1038 } // namespace
1022 1039
1023 } // namespace notifier 1040 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698