diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-22 16:16:34 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-22 16:16:34 +0000 |
commit | 3669d7d8f64445139731e73da773dbd2d4a81afb (patch) | |
tree | 639c3b714cdab1f82c7b2fb473e24fa88b1e4168 /jingle | |
parent | 4ec1228218bfc88889f0214324493b927c4b356b (diff) | |
download | chromium_src-3669d7d8f64445139731e73da773dbd2d4a81afb.zip chromium_src-3669d7d8f64445139731e73da773dbd2d4a81afb.tar.gz chromium_src-3669d7d8f64445139731e73da773dbd2d4a81afb.tar.bz2 |
Reland change to use a native MessagePump instead of a MessagePumpDefault.
Original CL: https://codereview.chromium.org/331513002/
The previous CL caused a bunch of LibJingle unit tests to fail because the tests
were using a gtest death test which runs in the context of a fork()ed but not
execu()ed process.
A CF Message loop can't live in this environment. Explicitly construct a
MessagePumpDefault for these tests.
BUG=356804,385604
Review URL: https://codereview.chromium.org/331983002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279013 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/glue/chrome_async_socket_unittest.cc | 87 |
1 files changed, 48 insertions, 39 deletions
diff --git a/jingle/glue/chrome_async_socket_unittest.cc b/jingle/glue/chrome_async_socket_unittest.cc index db3d2b0..b3c81b1 100644 --- a/jingle/glue/chrome_async_socket_unittest.cc +++ b/jingle/glue/chrome_async_socket_unittest.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" +#include "base/message_loop/message_pump_default.h" #include "jingle/glue/resolving_client_socket_factory.h" #include "net/base/address_list.h" #include "net/base/net_errors.h" @@ -143,7 +144,15 @@ class ChromeAsyncSocketTest protected: ChromeAsyncSocketTest() : ssl_socket_data_provider_(net::ASYNC, net::OK), - addr_("localhost", 35) {} + addr_("localhost", 35) { + // GTest death tests execute in a fork()ed but not exec()ed process. + // On OS X a CoreFoundation-backed message loop will exit with a + // __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__ + // when called. + // Explicitly create a MessagePumpDefault which can run in this enivronment. + scoped_ptr<base::MessagePump> pump(new base::MessagePumpDefault()); + message_loop_.reset(new base::MessageLoop(pump.Pass())); + } virtual ~ChromeAsyncSocketTest() {} @@ -182,7 +191,7 @@ class ChromeAsyncSocketTest virtual void TearDown() { // Run any tasks that we forgot to pump. - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectClosed(); ExpectNoSignal(); chrome_async_socket_.reset(); @@ -342,7 +351,7 @@ class ChromeAsyncSocketTest EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); // We may not necessarily be open; may have been other events // queued up. ExpectSignalSocketState( @@ -372,7 +381,7 @@ class ChromeAsyncSocketTest EXPECT_EQ(kDummyData, DrainRead(1)); EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLConnectSignal(); ExpectNoSignal(); ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); @@ -415,7 +424,7 @@ class ChromeAsyncSocketTest } // ChromeAsyncSocket expects a message loop. - base::MessageLoop message_loop_; + scoped_ptr<base::MessageLoop> message_loop_; AsyncSocketDataProvider async_socket_data_provider_; net::SSLSocketDataProvider ssl_socket_data_provider_; @@ -510,7 +519,7 @@ TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { SignalSocketState::NoError( SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); } TEST_F(ChromeAsyncSocketTest, HangingConnect) { @@ -532,14 +541,14 @@ TEST_F(ChromeAsyncSocketTest, PendingConnect) { ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); ExpectNoSignal(); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); ExpectSignalSocketState( SignalSocketState::NoError( SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); ExpectNoSignal(); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoCloseOpenedNoError(); } @@ -552,14 +561,14 @@ TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { net::MockConnect(net::ASYNC, net::OK)); EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSignalSocketState( SignalSocketState::NoError( SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); DoCloseOpenedNoError(); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); } TEST_F(ChromeAsyncSocketTest, PendingConnectError) { @@ -567,7 +576,7 @@ TEST_F(ChromeAsyncSocketTest, PendingConnectError) { net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSignalSocketState( SignalSocketState( @@ -629,7 +638,7 @@ TEST_F(ChromeAsyncSocketTest, Read) { EXPECT_EQ(kReadData, DrainRead(1)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoCloseOpenedNoError(); } @@ -643,7 +652,7 @@ TEST_F(ChromeAsyncSocketTest, ReadTwice) { EXPECT_EQ(kReadData, DrainRead(1)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); const char kReadData2[] = "mydatatoread2"; async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); @@ -665,7 +674,7 @@ TEST_F(ChromeAsyncSocketTest, ReadError) { EXPECT_EQ(kReadData, DrainRead(1)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); async_socket_data_provider_.AddRead( net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); @@ -699,7 +708,7 @@ TEST_F(ChromeAsyncSocketTest, PendingRead) { EXPECT_EQ(kReadData, DrainRead(1)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoCloseOpenedNoError(); } @@ -755,12 +764,12 @@ TEST_F(ChromeAsyncSocketTest, SyncWrite) { DoOpenClosed(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, arraysize(kWriteData) - 8)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectNoSignal(); @@ -778,12 +787,12 @@ TEST_F(ChromeAsyncSocketTest, AsyncWrite) { net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, arraysize(kWriteData) - 8)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectNoSignal(); @@ -801,12 +810,12 @@ TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, arraysize(kWriteData) - 8)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSignalSocketState( SignalSocketState( @@ -874,7 +883,7 @@ TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { ExpectReadSignal(); EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLConnectSignal(); ExpectNoSignal(); ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); @@ -889,7 +898,7 @@ TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { ExpectReadSignal(); EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLConnectSignal(); ExpectNoSignal(); ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); @@ -913,7 +922,7 @@ TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { ExpectReadSignal(); EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSignalSocketState( SignalSocketState( SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, @@ -941,7 +950,7 @@ TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); EXPECT_EQ(0U, len_read); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLConnectSignal(); ExpectSSLReadSignal(); ExpectNoSignal(); @@ -972,11 +981,11 @@ TEST_F(ChromeAsyncSocketTest, WriteDuringSSLConnecting) { // TODO(akalin): Figure out how to test that the write happens // *after* the SSL connect. - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLConnectSignal(); ExpectNoSignal(); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoSSLCloseOpenedNoError(); } @@ -1005,7 +1014,7 @@ TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoCloseOpened( SignalSocketState(SIGNAL_CLOSE, @@ -1020,14 +1029,14 @@ TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { TEST_F(ChromeAsyncSocketTest, SSLRead) { DoSSLOpenClosed(); async_socket_data_provider_.AddRead(net::MockRead(kReadData)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectSSLReadSignal(); ExpectNoSignal(); EXPECT_EQ(kReadData, DrainRead(1)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); DoSSLCloseOpenedNoError(); } @@ -1043,12 +1052,12 @@ TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { DoSSLOpenClosed(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, arraysize(kWriteData) - 8)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectNoSignal(); @@ -1066,12 +1075,12 @@ TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, arraysize(kWriteData) - 8)); - message_loop_.RunUntilIdle(); + message_loop_->RunUntilIdle(); ExpectNoSignal(); |