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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_pump_default.h" | 14 #include "base/message_loop/message_pump_default.h" |
| 15 #include "base/run_loop.h" |
15 #include "jingle/glue/mock_task.h" | 16 #include "jingle/glue/mock_task.h" |
16 #include "jingle/glue/task_pump.h" | 17 #include "jingle/glue/task_pump.h" |
17 #include "jingle/notifier/base/weak_xmpp_client.h" | 18 #include "jingle/notifier/base/weak_xmpp_client.h" |
18 #include "net/cert/cert_verifier.h" | 19 #include "net/cert/cert_verifier.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.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 #include "webrtc/libjingle/xmpp/prexmppauth.h" | 24 #include "webrtc/libjingle/xmpp/prexmppauth.h" |
24 #include "webrtc/libjingle/xmpp/xmppclientsettings.h" | 25 #include "webrtc/libjingle/xmpp/xmppclientsettings.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 message_loop_.reset(new base::MessageLoop(std::move(pump))); | 81 message_loop_.reset(new base::MessageLoop(std::move(pump))); |
81 | 82 |
82 url_request_context_getter_ = new net::TestURLRequestContextGetter( | 83 url_request_context_getter_ = new net::TestURLRequestContextGetter( |
83 message_loop_->task_runner()); | 84 message_loop_->task_runner()); |
84 } | 85 } |
85 | 86 |
86 ~XmppConnectionTest() override {} | 87 ~XmppConnectionTest() override {} |
87 | 88 |
88 void TearDown() override { | 89 void TearDown() override { |
89 // Clear out any messages posted by XmppConnection's destructor. | 90 // Clear out any messages posted by XmppConnection's destructor. |
90 message_loop_->RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
91 } | 92 } |
92 | 93 |
93 // Needed by XmppConnection. | 94 // Needed by XmppConnection. |
94 std::unique_ptr<base::MessageLoop> message_loop_; | 95 std::unique_ptr<base::MessageLoop> message_loop_; |
95 MockXmppConnectionDelegate mock_xmpp_connection_delegate_; | 96 MockXmppConnectionDelegate mock_xmpp_connection_delegate_; |
96 std::unique_ptr<MockPreXmppAuth> mock_pre_xmpp_auth_; | 97 std::unique_ptr<MockPreXmppAuth> mock_pre_xmpp_auth_; |
97 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 98 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
98 }; | 99 }; |
99 | 100 |
100 TEST_F(XmppConnectionTest, CreateDestroy) { | 101 TEST_F(XmppConnectionTest, CreateDestroy) { |
101 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 102 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
102 url_request_context_getter_, | 103 url_request_context_getter_, |
103 &mock_xmpp_connection_delegate_, NULL); | 104 &mock_xmpp_connection_delegate_, NULL); |
104 } | 105 } |
105 | 106 |
106 #if !defined(_MSC_VER) // http://crbug.com/158570 | 107 #if !defined(_MSC_VER) // http://crbug.com/158570 |
107 TEST_F(XmppConnectionTest, ImmediateFailure) { | 108 TEST_F(XmppConnectionTest, ImmediateFailure) { |
108 // ChromeAsyncSocket::Connect() will always return false since we're | 109 // ChromeAsyncSocket::Connect() will always return false since we're |
109 // not setting a valid host, but this gets bubbled up as ERROR_NONE | 110 // not setting a valid host, but this gets bubbled up as ERROR_NONE |
110 // due to XmppClient's inconsistent error-handling. | 111 // due to XmppClient's inconsistent error-handling. |
111 EXPECT_CALL(mock_xmpp_connection_delegate_, | 112 EXPECT_CALL(mock_xmpp_connection_delegate_, |
112 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); | 113 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); |
113 | 114 |
114 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 115 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
115 url_request_context_getter_, | 116 url_request_context_getter_, |
116 &mock_xmpp_connection_delegate_, NULL); | 117 &mock_xmpp_connection_delegate_, NULL); |
117 | 118 |
118 // We need to do this *before* |xmpp_connection| gets destroyed or | 119 // We need to do this *before* |xmpp_connection| gets destroyed or |
119 // our delegate won't be called. | 120 // our delegate won't be called. |
120 message_loop_->RunUntilIdle(); | 121 base::RunLoop().RunUntilIdle(); |
121 } | 122 } |
122 | 123 |
123 TEST_F(XmppConnectionTest, PreAuthFailure) { | 124 TEST_F(XmppConnectionTest, PreAuthFailure) { |
124 EXPECT_CALL(*mock_pre_xmpp_auth_, StartPreXmppAuth(_, _, _, _,_)); | 125 EXPECT_CALL(*mock_pre_xmpp_auth_, StartPreXmppAuth(_, _, _, _,_)); |
125 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthDone()).WillOnce(Return(true)); | 126 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthDone()).WillOnce(Return(true)); |
126 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthorized()).WillOnce(Return(false)); | 127 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthorized()).WillOnce(Return(false)); |
127 EXPECT_CALL(*mock_pre_xmpp_auth_, HadError()).WillOnce(Return(true)); | 128 EXPECT_CALL(*mock_pre_xmpp_auth_, HadError()).WillOnce(Return(true)); |
128 EXPECT_CALL(*mock_pre_xmpp_auth_, GetError()).WillOnce(Return(5)); | 129 EXPECT_CALL(*mock_pre_xmpp_auth_, GetError()).WillOnce(Return(5)); |
129 | 130 |
130 EXPECT_CALL(mock_xmpp_connection_delegate_, | 131 EXPECT_CALL(mock_xmpp_connection_delegate_, |
131 OnError(buzz::XmppEngine::ERROR_AUTH, 5, NULL)); | 132 OnError(buzz::XmppEngine::ERROR_AUTH, 5, NULL)); |
132 | 133 |
133 XmppConnection xmpp_connection( | 134 XmppConnection xmpp_connection( |
134 buzz::XmppClientSettings(), url_request_context_getter_, | 135 buzz::XmppClientSettings(), url_request_context_getter_, |
135 &mock_xmpp_connection_delegate_, mock_pre_xmpp_auth_.release()); | 136 &mock_xmpp_connection_delegate_, mock_pre_xmpp_auth_.release()); |
136 | 137 |
137 // We need to do this *before* |xmpp_connection| gets destroyed or | 138 // We need to do this *before* |xmpp_connection| gets destroyed or |
138 // our delegate won't be called. | 139 // our delegate won't be called. |
139 message_loop_->RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
140 } | 141 } |
141 | 142 |
142 TEST_F(XmppConnectionTest, FailureAfterPreAuth) { | 143 TEST_F(XmppConnectionTest, FailureAfterPreAuth) { |
143 EXPECT_CALL(*mock_pre_xmpp_auth_, StartPreXmppAuth(_, _, _, _,_)); | 144 EXPECT_CALL(*mock_pre_xmpp_auth_, StartPreXmppAuth(_, _, _, _,_)); |
144 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthDone()).WillOnce(Return(true)); | 145 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthDone()).WillOnce(Return(true)); |
145 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthorized()).WillOnce(Return(true)); | 146 EXPECT_CALL(*mock_pre_xmpp_auth_, IsAuthorized()).WillOnce(Return(true)); |
146 EXPECT_CALL(*mock_pre_xmpp_auth_, GetAuthMechanism()).WillOnce(Return("")); | 147 EXPECT_CALL(*mock_pre_xmpp_auth_, GetAuthMechanism()).WillOnce(Return("")); |
147 EXPECT_CALL(*mock_pre_xmpp_auth_, GetAuthToken()).WillOnce(Return("")); | 148 EXPECT_CALL(*mock_pre_xmpp_auth_, GetAuthToken()).WillOnce(Return("")); |
148 | 149 |
149 EXPECT_CALL(mock_xmpp_connection_delegate_, | 150 EXPECT_CALL(mock_xmpp_connection_delegate_, |
150 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); | 151 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); |
151 | 152 |
152 XmppConnection xmpp_connection( | 153 XmppConnection xmpp_connection( |
153 buzz::XmppClientSettings(), url_request_context_getter_, | 154 buzz::XmppClientSettings(), url_request_context_getter_, |
154 &mock_xmpp_connection_delegate_, mock_pre_xmpp_auth_.release()); | 155 &mock_xmpp_connection_delegate_, mock_pre_xmpp_auth_.release()); |
155 | 156 |
156 // We need to do this *before* |xmpp_connection| gets destroyed or | 157 // We need to do this *before* |xmpp_connection| gets destroyed or |
157 // our delegate won't be called. | 158 // our delegate won't be called. |
158 message_loop_->RunUntilIdle(); | 159 base::RunLoop().RunUntilIdle(); |
159 } | 160 } |
160 | 161 |
161 TEST_F(XmppConnectionTest, RaisedError) { | 162 TEST_F(XmppConnectionTest, RaisedError) { |
162 EXPECT_CALL(mock_xmpp_connection_delegate_, | 163 EXPECT_CALL(mock_xmpp_connection_delegate_, |
163 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); | 164 OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL)); |
164 | 165 |
165 XmppConnection xmpp_connection(buzz::XmppClientSettings(), | 166 XmppConnection xmpp_connection(buzz::XmppClientSettings(), |
166 url_request_context_getter_, | 167 url_request_context_getter_, |
167 &mock_xmpp_connection_delegate_, NULL); | 168 &mock_xmpp_connection_delegate_, NULL); |
168 | 169 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // We have to do this since the state enum is protected in | 246 // We have to do this since the state enum is protected in |
246 // rtc::Task. | 247 // rtc::Task. |
247 const int TASK_STATE_ERROR = 3; | 248 const int TASK_STATE_ERROR = 3; |
248 ON_CALL(*task, ProcessStart()) | 249 ON_CALL(*task, ProcessStart()) |
249 .WillByDefault(Return(TASK_STATE_ERROR)); | 250 .WillByDefault(Return(TASK_STATE_ERROR)); |
250 EXPECT_CALL(*task, ProcessStart()).Times(0); | 251 EXPECT_CALL(*task, ProcessStart()).Times(0); |
251 task->Start(); | 252 task->Start(); |
252 } | 253 } |
253 | 254 |
254 // This should destroy |task_pump|, but |task| still shouldn't run. | 255 // This should destroy |task_pump|, but |task| still shouldn't run. |
255 message_loop_->RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
256 } | 257 } |
257 | 258 |
258 } // namespace notifier | 259 } // namespace notifier |
OLD | NEW |