| OLD | NEW |
| 1 // Copyright (c) 2011 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" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "jingle/notifier/base/mock_task.h" | 14 #include "jingle/notifier/base/mock_task.h" |
| 14 #include "jingle/notifier/base/task_pump.h" | 15 #include "jingle/notifier/base/task_pump.h" |
| 15 #include "jingle/notifier/base/weak_xmpp_client.h" | 16 #include "jingle/notifier/base/weak_xmpp_client.h" |
| 16 #include "net/base/cert_verifier.h" | 17 #include "net/base/cert_verifier.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "talk/xmpp/prexmppauth.h" | 20 #include "talk/xmpp/prexmppauth.h" |
| 20 #include "talk/xmpp/xmppclientsettings.h" | 21 #include "talk/xmpp/xmppclientsettings.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace buzz { | 25 namespace buzz { |
| 25 class CaptchaChallenge; | 26 class CaptchaChallenge; |
| 26 class Jid; | 27 class Jid; |
| 27 } // namespace buzz | 28 } // namespace buzz |
| 28 | 29 |
| 29 namespace talk_base { | 30 namespace talk_base { |
| 30 class CryptString; | 31 class CryptString; |
| 31 class SocketAddress; | 32 class SocketAddress; |
| 32 class Task; | 33 class Task; |
| 33 } // namespace talk_base | 34 } // namespace talk_base |
| 34 | 35 |
| 35 namespace { | |
| 36 // TODO(sanjeevr): Move this to net_test_support. | |
| 37 // Used to return a dummy context. | |
| 38 class TestURLRequestContextGetter : public net::URLRequestContextGetter { | |
| 39 public: | |
| 40 TestURLRequestContextGetter() | |
| 41 : message_loop_proxy_(base::MessageLoopProxy::current()) { | |
| 42 } | |
| 43 virtual ~TestURLRequestContextGetter() { } | |
| 44 | |
| 45 // net::URLRequestContextGetter: | |
| 46 virtual net::URLRequestContext* GetURLRequestContext() { | |
| 47 if (!context_) | |
| 48 context_ = new TestURLRequestContext(); | |
| 49 return context_.get(); | |
| 50 } | |
| 51 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | |
| 52 return message_loop_proxy_; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 scoped_refptr<net::URLRequestContext> context_; | |
| 57 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 58 }; | |
| 59 } // namespace | |
| 60 | |
| 61 namespace notifier { | 36 namespace notifier { |
| 62 | 37 |
| 63 using ::testing::_; | 38 using ::testing::_; |
| 64 using ::testing::Return; | 39 using ::testing::Return; |
| 65 using ::testing::SaveArg; | 40 using ::testing::SaveArg; |
| 66 | 41 |
| 67 class MockPreXmppAuth : public buzz::PreXmppAuth { | 42 class MockPreXmppAuth : public buzz::PreXmppAuth { |
| 68 public: | 43 public: |
| 69 virtual ~MockPreXmppAuth() {} | 44 virtual ~MockPreXmppAuth() {} |
| 70 | 45 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 | 66 |
| 92 MOCK_METHOD1(OnConnect, void(base::WeakPtr<buzz::XmppTaskParentInterface>)); | 67 MOCK_METHOD1(OnConnect, void(base::WeakPtr<buzz::XmppTaskParentInterface>)); |
| 93 MOCK_METHOD3(OnError, | 68 MOCK_METHOD3(OnError, |
| 94 void(buzz::XmppEngine::Error, int, const buzz::XmlElement*)); | 69 void(buzz::XmppEngine::Error, int, const buzz::XmlElement*)); |
| 95 }; | 70 }; |
| 96 | 71 |
| 97 class XmppConnectionTest : public testing::Test { | 72 class XmppConnectionTest : public testing::Test { |
| 98 protected: | 73 protected: |
| 99 XmppConnectionTest() | 74 XmppConnectionTest() |
| 100 : mock_pre_xmpp_auth_(new MockPreXmppAuth()), | 75 : mock_pre_xmpp_auth_(new MockPreXmppAuth()), |
| 101 url_request_context_getter_(new TestURLRequestContextGetter()) {} | 76 url_request_context_getter_(new TestURLRequestContextGetter( |
| 77 message_loop_.message_loop_proxy())) {} |
| 102 | 78 |
| 103 virtual ~XmppConnectionTest() {} | 79 virtual ~XmppConnectionTest() {} |
| 104 | 80 |
| 105 virtual void TearDown() { | 81 virtual void TearDown() { |
| 106 // Clear out any messages posted by XmppConnection's destructor. | 82 // Clear out any messages posted by XmppConnection's destructor. |
| 107 message_loop_.RunAllPending(); | 83 message_loop_.RunAllPending(); |
| 108 } | 84 } |
| 109 | 85 |
| 110 // Needed by XmppConnection. | 86 // Needed by XmppConnection. |
| 111 MessageLoop message_loop_; | 87 MessageLoop message_loop_; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 .WillByDefault(Return(TASK_STATE_ERROR)); | 236 .WillByDefault(Return(TASK_STATE_ERROR)); |
| 261 EXPECT_CALL(*task, ProcessStart()).Times(0); | 237 EXPECT_CALL(*task, ProcessStart()).Times(0); |
| 262 task->Start(); | 238 task->Start(); |
| 263 } | 239 } |
| 264 | 240 |
| 265 // This should destroy |task_pump|, but |task| still shouldn't run. | 241 // This should destroy |task_pump|, but |task| still shouldn't run. |
| 266 message_loop_.RunAllPending(); | 242 message_loop_.RunAllPending(); |
| 267 } | 243 } |
| 268 | 244 |
| 269 } // namespace notifier | 245 } // namespace notifier |
| OLD | NEW |