| OLD | NEW |
| 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 "jingle/notifier/base/xmpp_connection.h" | 5 #include "jingle/notifier/base/xmpp_connection.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "talk/xmpp/prexmppauth.h" | 21 #include "talk/xmpp/prexmppauth.h" |
| 22 #include "talk/xmpp/xmppclientsettings.h" | 22 #include "talk/xmpp/xmppclientsettings.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 namespace buzz { | 26 namespace buzz { |
| 27 class CaptchaChallenge; | 27 class CaptchaChallenge; |
| 28 class Jid; | 28 class Jid; |
| 29 } // namespace buzz | 29 } // namespace buzz |
| 30 | 30 |
| 31 namespace talk_base { | 31 namespace rtc { |
| 32 class CryptString; | 32 class CryptString; |
| 33 class SocketAddress; | 33 class SocketAddress; |
| 34 class Task; | 34 class Task; |
| 35 } // namespace talk_base | 35 } // namespace rtc |
| 36 | 36 |
| 37 namespace notifier { | 37 namespace notifier { |
| 38 | 38 |
| 39 using ::testing::_; | 39 using ::testing::_; |
| 40 using ::testing::Return; | 40 using ::testing::Return; |
| 41 using ::testing::SaveArg; | 41 using ::testing::SaveArg; |
| 42 | 42 |
| 43 class MockPreXmppAuth : public buzz::PreXmppAuth { | 43 class MockPreXmppAuth : public buzz::PreXmppAuth { |
| 44 public: | 44 public: |
| 45 virtual ~MockPreXmppAuth() {} | 45 virtual ~MockPreXmppAuth() {} |
| 46 | 46 |
| 47 MOCK_METHOD2(ChooseBestSaslMechanism, | 47 MOCK_METHOD2(ChooseBestSaslMechanism, |
| 48 std::string(const std::vector<std::string>&, bool)); | 48 std::string(const std::vector<std::string>&, bool)); |
| 49 MOCK_METHOD1(CreateSaslMechanism, | 49 MOCK_METHOD1(CreateSaslMechanism, |
| 50 buzz::SaslMechanism*(const std::string&)); | 50 buzz::SaslMechanism*(const std::string&)); |
| 51 MOCK_METHOD5(StartPreXmppAuth, | 51 MOCK_METHOD5(StartPreXmppAuth, |
| 52 void(const buzz::Jid&, | 52 void(const buzz::Jid&, |
| 53 const talk_base::SocketAddress&, | 53 const rtc::SocketAddress&, |
| 54 const talk_base::CryptString&, | 54 const rtc::CryptString&, |
| 55 const std::string&, | 55 const std::string&, |
| 56 const std::string&)); | 56 const std::string&)); |
| 57 MOCK_CONST_METHOD0(IsAuthDone, bool()); | 57 MOCK_CONST_METHOD0(IsAuthDone, bool()); |
| 58 MOCK_CONST_METHOD0(IsAuthorized, bool()); | 58 MOCK_CONST_METHOD0(IsAuthorized, bool()); |
| 59 MOCK_CONST_METHOD0(HadError, bool()); | 59 MOCK_CONST_METHOD0(HadError, bool()); |
| 60 MOCK_CONST_METHOD0(GetError, int()); | 60 MOCK_CONST_METHOD0(GetError, int()); |
| 61 MOCK_CONST_METHOD0(GetCaptchaChallenge, buzz::CaptchaChallenge()); | 61 MOCK_CONST_METHOD0(GetCaptchaChallenge, buzz::CaptchaChallenge()); |
| 62 MOCK_CONST_METHOD0(GetAuthToken, std::string()); | 62 MOCK_CONST_METHOD0(GetAuthToken, std::string()); |
| 63 MOCK_CONST_METHOD0(GetAuthMechanism, std::string()); | 63 MOCK_CONST_METHOD0(GetAuthMechanism, std::string()); |
| 64 }; | 64 }; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 165 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
| 166 url_request_context_getter_, | 166 url_request_context_getter_, |
| 167 &mock_xmpp_connection_delegate_, NULL); | 167 &mock_xmpp_connection_delegate_, NULL); |
| 168 | 168 |
| 169 xmpp_connection.weak_xmpp_client_-> | 169 xmpp_connection.weak_xmpp_client_-> |
| 170 SignalStateChange(buzz::XmppEngine::STATE_CLOSED); | 170 SignalStateChange(buzz::XmppEngine::STATE_CLOSED); |
| 171 } | 171 } |
| 172 #endif | 172 #endif |
| 173 | 173 |
| 174 TEST_F(XmppConnectionTest, Connect) { | 174 TEST_F(XmppConnectionTest, Connect) { |
| 175 base::WeakPtr<talk_base::Task> weak_ptr; | 175 base::WeakPtr<rtc::Task> weak_ptr; |
| 176 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). | 176 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). |
| 177 WillOnce(SaveArg<0>(&weak_ptr)); | 177 WillOnce(SaveArg<0>(&weak_ptr)); |
| 178 | 178 |
| 179 { | 179 { |
| 180 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 180 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
| 181 url_request_context_getter_, | 181 url_request_context_getter_, |
| 182 &mock_xmpp_connection_delegate_, NULL); | 182 &mock_xmpp_connection_delegate_, NULL); |
| 183 | 183 |
| 184 xmpp_connection.weak_xmpp_client_-> | 184 xmpp_connection.weak_xmpp_client_-> |
| 185 SignalStateChange(buzz::XmppEngine::STATE_OPEN); | 185 SignalStateChange(buzz::XmppEngine::STATE_OPEN); |
| 186 EXPECT_EQ(xmpp_connection.weak_xmpp_client_.get(), weak_ptr.get()); | 186 EXPECT_EQ(xmpp_connection.weak_xmpp_client_.get(), weak_ptr.get()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 EXPECT_EQ(NULL, weak_ptr.get()); | 189 EXPECT_EQ(NULL, weak_ptr.get()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(XmppConnectionTest, MultipleConnect) { | 192 TEST_F(XmppConnectionTest, MultipleConnect) { |
| 193 EXPECT_DEBUG_DEATH({ | 193 EXPECT_DEBUG_DEATH({ |
| 194 base::WeakPtr<talk_base::Task> weak_ptr; | 194 base::WeakPtr<rtc::Task> weak_ptr; |
| 195 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). | 195 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). |
| 196 WillOnce(SaveArg<0>(&weak_ptr)); | 196 WillOnce(SaveArg<0>(&weak_ptr)); |
| 197 | 197 |
| 198 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 198 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
| 199 url_request_context_getter_, | 199 url_request_context_getter_, |
| 200 &mock_xmpp_connection_delegate_, NULL); | 200 &mock_xmpp_connection_delegate_, NULL); |
| 201 | 201 |
| 202 xmpp_connection.weak_xmpp_client_-> | 202 xmpp_connection.weak_xmpp_client_-> |
| 203 SignalStateChange(buzz::XmppEngine::STATE_OPEN); | 203 SignalStateChange(buzz::XmppEngine::STATE_OPEN); |
| 204 for (int i = 0; i < 3; ++i) { | 204 for (int i = 0; i < 3; ++i) { |
| 205 xmpp_connection.weak_xmpp_client_-> | 205 xmpp_connection.weak_xmpp_client_-> |
| 206 SignalStateChange(buzz::XmppEngine::STATE_OPEN); | 206 SignalStateChange(buzz::XmppEngine::STATE_OPEN); |
| 207 } | 207 } |
| 208 | 208 |
| 209 EXPECT_EQ(xmpp_connection.weak_xmpp_client_.get(), weak_ptr.get()); | 209 EXPECT_EQ(xmpp_connection.weak_xmpp_client_.get(), weak_ptr.get()); |
| 210 }, "more than once"); | 210 }, "more than once"); |
| 211 } | 211 } |
| 212 | 212 |
| 213 #if !defined(_MSC_VER) || _MSC_VER < 1700 // http://crbug.com/158570 | 213 #if !defined(_MSC_VER) || _MSC_VER < 1700 // http://crbug.com/158570 |
| 214 TEST_F(XmppConnectionTest, ConnectThenError) { | 214 TEST_F(XmppConnectionTest, ConnectThenError) { |
| 215 base::WeakPtr<talk_base::Task> weak_ptr; | 215 base::WeakPtr<rtc::Task> weak_ptr; |
| 216 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). | 216 EXPECT_CALL(mock_xmpp_connection_delegate_, OnConnect(_)). |
| 217 WillOnce(SaveArg<0>(&weak_ptr)); | 217 WillOnce(SaveArg<0>(&weak_ptr)); |
| 218 EXPECT_CALL(mock_xmpp_connection_delegate_, | 218 EXPECT_CALL(mock_xmpp_connection_delegate_, |
| 219 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); | 219 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); |
| 220 | 220 |
| 221 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 221 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
| 222 url_request_context_getter_, | 222 url_request_context_getter_, |
| 223 &mock_xmpp_connection_delegate_, NULL); | 223 &mock_xmpp_connection_delegate_, NULL); |
| 224 | 224 |
| 225 xmpp_connection.weak_xmpp_client_-> | 225 xmpp_connection.weak_xmpp_client_-> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 // should still not run any more tasks. | 236 // should still not run any more tasks. |
| 237 TEST_F(XmppConnectionTest, TasksDontRunAfterXmppConnectionDestructor) { | 237 TEST_F(XmppConnectionTest, TasksDontRunAfterXmppConnectionDestructor) { |
| 238 { | 238 { |
| 239 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 239 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
| 240 url_request_context_getter_, | 240 url_request_context_getter_, |
| 241 &mock_xmpp_connection_delegate_, NULL); | 241 &mock_xmpp_connection_delegate_, NULL); |
| 242 | 242 |
| 243 jingle_glue::MockTask* task = | 243 jingle_glue::MockTask* task = |
| 244 new jingle_glue::MockTask(xmpp_connection.task_pump_.get()); | 244 new jingle_glue::MockTask(xmpp_connection.task_pump_.get()); |
| 245 // We have to do this since the state enum is protected in | 245 // We have to do this since the state enum is protected in |
| 246 // talk_base::Task. | 246 // rtc::Task. |
| 247 const int TASK_STATE_ERROR = 3; | 247 const int TASK_STATE_ERROR = 3; |
| 248 ON_CALL(*task, ProcessStart()) | 248 ON_CALL(*task, ProcessStart()) |
| 249 .WillByDefault(Return(TASK_STATE_ERROR)); | 249 .WillByDefault(Return(TASK_STATE_ERROR)); |
| 250 EXPECT_CALL(*task, ProcessStart()).Times(0); | 250 EXPECT_CALL(*task, ProcessStart()).Times(0); |
| 251 task->Start(); | 251 task->Start(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 // This should destroy |task_pump|, but |task| still shouldn't run. | 254 // This should destroy |task_pump|, but |task| still shouldn't run. |
| 255 message_loop_->RunUntilIdle(); | 255 message_loop_->RunUntilIdle(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace notifier | 258 } // namespace notifier |
| OLD | NEW |