OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <memory> |
| 12 #include <string> |
| 13 |
| 14 #include "webrtc/libjingle/xmllite/qname.h" |
| 15 #include "webrtc/libjingle/xmllite/xmlelement.h" |
| 16 #include "webrtc/libjingle/xmpp/constants.h" |
| 17 #include "webrtc/libjingle/xmpp/fakexmppclient.h" |
| 18 #include "webrtc/libjingle/xmpp/hangoutpubsubclient.h" |
| 19 #include "webrtc/libjingle/xmpp/jid.h" |
| 20 #include "webrtc/base/faketaskrunner.h" |
| 21 #include "webrtc/base/gunit.h" |
| 22 #include "webrtc/base/sigslot.h" |
| 23 |
| 24 class TestHangoutPubSubListener : public sigslot::has_slots<> { |
| 25 public: |
| 26 TestHangoutPubSubListener() : |
| 27 request_error_count(0), |
| 28 publish_audio_mute_error_count(0), |
| 29 publish_video_mute_error_count(0), |
| 30 publish_video_pause_error_count(0), |
| 31 publish_presenter_error_count(0), |
| 32 publish_recording_error_count(0), |
| 33 remote_mute_error_count(0) { |
| 34 } |
| 35 |
| 36 void OnPresenterStateChange( |
| 37 const std::string& nick, bool was_presenting, bool is_presenting) { |
| 38 last_presenter_nick = nick; |
| 39 last_was_presenting = was_presenting; |
| 40 last_is_presenting = is_presenting; |
| 41 } |
| 42 |
| 43 void OnAudioMuteStateChange( |
| 44 const std::string& nick, bool was_muted, bool is_muted) { |
| 45 last_audio_muted_nick = nick; |
| 46 last_was_audio_muted = was_muted; |
| 47 last_is_audio_muted = is_muted; |
| 48 } |
| 49 |
| 50 void OnVideoMuteStateChange( |
| 51 const std::string& nick, bool was_muted, bool is_muted) { |
| 52 last_video_muted_nick = nick; |
| 53 last_was_video_muted = was_muted; |
| 54 last_is_video_muted = is_muted; |
| 55 } |
| 56 |
| 57 void OnVideoPauseStateChange( |
| 58 const std::string& nick, bool was_paused, bool is_paused) { |
| 59 last_video_paused_nick = nick; |
| 60 last_was_video_paused = was_paused; |
| 61 last_is_video_paused = is_paused; |
| 62 } |
| 63 |
| 64 void OnRecordingStateChange( |
| 65 const std::string& nick, bool was_recording, bool is_recording) { |
| 66 last_recording_nick = nick; |
| 67 last_was_recording = was_recording; |
| 68 last_is_recording = is_recording; |
| 69 } |
| 70 |
| 71 void OnRemoteMute( |
| 72 const std::string& mutee_nick, |
| 73 const std::string& muter_nick, |
| 74 bool should_mute_locally) { |
| 75 last_mutee_nick = mutee_nick; |
| 76 last_muter_nick = muter_nick; |
| 77 last_should_mute = should_mute_locally; |
| 78 } |
| 79 |
| 80 void OnMediaBlock( |
| 81 const std::string& blockee_nick, |
| 82 const std::string& blocker_nick) { |
| 83 last_blockee_nick = blockee_nick; |
| 84 last_blocker_nick = blocker_nick; |
| 85 } |
| 86 |
| 87 void OnRequestError(const std::string& node, const buzz::XmlElement* stanza) { |
| 88 ++request_error_count; |
| 89 request_error_node = node; |
| 90 } |
| 91 |
| 92 void OnPublishAudioMuteError(const std::string& task_id, |
| 93 const buzz::XmlElement* stanza) { |
| 94 ++publish_audio_mute_error_count; |
| 95 error_task_id = task_id; |
| 96 } |
| 97 |
| 98 void OnPublishVideoMuteError(const std::string& task_id, |
| 99 const buzz::XmlElement* stanza) { |
| 100 ++publish_video_mute_error_count; |
| 101 error_task_id = task_id; |
| 102 } |
| 103 |
| 104 void OnPublishVideoPauseError(const std::string& task_id, |
| 105 const buzz::XmlElement* stanza) { |
| 106 ++publish_video_pause_error_count; |
| 107 error_task_id = task_id; |
| 108 } |
| 109 |
| 110 void OnPublishPresenterError(const std::string& task_id, |
| 111 const buzz::XmlElement* stanza) { |
| 112 ++publish_presenter_error_count; |
| 113 error_task_id = task_id; |
| 114 } |
| 115 |
| 116 void OnPublishRecordingError(const std::string& task_id, |
| 117 const buzz::XmlElement* stanza) { |
| 118 ++publish_recording_error_count; |
| 119 error_task_id = task_id; |
| 120 } |
| 121 |
| 122 void OnRemoteMuteResult(const std::string& task_id, |
| 123 const std::string& mutee_nick) { |
| 124 result_task_id = task_id; |
| 125 remote_mute_mutee_nick = mutee_nick; |
| 126 } |
| 127 |
| 128 void OnRemoteMuteError(const std::string& task_id, |
| 129 const std::string& mutee_nick, |
| 130 const buzz::XmlElement* stanza) { |
| 131 ++remote_mute_error_count; |
| 132 error_task_id = task_id; |
| 133 remote_mute_mutee_nick = mutee_nick; |
| 134 } |
| 135 |
| 136 void OnMediaBlockResult(const std::string& task_id, |
| 137 const std::string& blockee_nick) { |
| 138 result_task_id = task_id; |
| 139 media_blockee_nick = blockee_nick; |
| 140 } |
| 141 |
| 142 void OnMediaBlockError(const std::string& task_id, |
| 143 const std::string& blockee_nick, |
| 144 const buzz::XmlElement* stanza) { |
| 145 ++media_block_error_count; |
| 146 error_task_id = task_id; |
| 147 media_blockee_nick = blockee_nick; |
| 148 } |
| 149 |
| 150 std::string last_presenter_nick; |
| 151 bool last_is_presenting; |
| 152 bool last_was_presenting; |
| 153 std::string last_audio_muted_nick; |
| 154 bool last_is_audio_muted; |
| 155 bool last_was_audio_muted; |
| 156 std::string last_video_muted_nick; |
| 157 bool last_is_video_muted; |
| 158 bool last_was_video_muted; |
| 159 std::string last_video_paused_nick; |
| 160 bool last_is_video_paused; |
| 161 bool last_was_video_paused; |
| 162 std::string last_recording_nick; |
| 163 bool last_is_recording; |
| 164 bool last_was_recording; |
| 165 std::string last_mutee_nick; |
| 166 std::string last_muter_nick; |
| 167 bool last_should_mute; |
| 168 std::string last_blockee_nick; |
| 169 std::string last_blocker_nick; |
| 170 |
| 171 int request_error_count; |
| 172 std::string request_error_node; |
| 173 int publish_audio_mute_error_count; |
| 174 int publish_video_mute_error_count; |
| 175 int publish_video_pause_error_count; |
| 176 int publish_presenter_error_count; |
| 177 int publish_recording_error_count; |
| 178 int remote_mute_error_count; |
| 179 std::string result_task_id; |
| 180 std::string error_task_id; |
| 181 std::string remote_mute_mutee_nick; |
| 182 int media_block_error_count; |
| 183 std::string media_blockee_nick; |
| 184 }; |
| 185 |
| 186 class HangoutPubSubClientTest : public testing::Test { |
| 187 public: |
| 188 HangoutPubSubClientTest() : |
| 189 pubsubjid("room@domain.com"), |
| 190 nick("me") { |
| 191 |
| 192 runner.reset(new rtc::FakeTaskRunner()); |
| 193 xmpp_client = new buzz::FakeXmppClient(runner.get()); |
| 194 client.reset(new buzz::HangoutPubSubClient(xmpp_client, pubsubjid, nick)); |
| 195 listener.reset(new TestHangoutPubSubListener()); |
| 196 client->SignalPresenterStateChange.connect( |
| 197 listener.get(), &TestHangoutPubSubListener::OnPresenterStateChange); |
| 198 client->SignalAudioMuteStateChange.connect( |
| 199 listener.get(), &TestHangoutPubSubListener::OnAudioMuteStateChange); |
| 200 client->SignalVideoMuteStateChange.connect( |
| 201 listener.get(), &TestHangoutPubSubListener::OnVideoMuteStateChange); |
| 202 client->SignalVideoPauseStateChange.connect( |
| 203 listener.get(), &TestHangoutPubSubListener::OnVideoPauseStateChange); |
| 204 client->SignalRecordingStateChange.connect( |
| 205 listener.get(), &TestHangoutPubSubListener::OnRecordingStateChange); |
| 206 client->SignalRemoteMute.connect( |
| 207 listener.get(), &TestHangoutPubSubListener::OnRemoteMute); |
| 208 client->SignalMediaBlock.connect( |
| 209 listener.get(), &TestHangoutPubSubListener::OnMediaBlock); |
| 210 client->SignalRequestError.connect( |
| 211 listener.get(), &TestHangoutPubSubListener::OnRequestError); |
| 212 client->SignalPublishAudioMuteError.connect( |
| 213 listener.get(), &TestHangoutPubSubListener::OnPublishAudioMuteError); |
| 214 client->SignalPublishVideoMuteError.connect( |
| 215 listener.get(), &TestHangoutPubSubListener::OnPublishVideoMuteError); |
| 216 client->SignalPublishVideoPauseError.connect( |
| 217 listener.get(), &TestHangoutPubSubListener::OnPublishVideoPauseError); |
| 218 client->SignalPublishPresenterError.connect( |
| 219 listener.get(), &TestHangoutPubSubListener::OnPublishPresenterError); |
| 220 client->SignalPublishRecordingError.connect( |
| 221 listener.get(), &TestHangoutPubSubListener::OnPublishRecordingError); |
| 222 client->SignalRemoteMuteResult.connect( |
| 223 listener.get(), &TestHangoutPubSubListener::OnRemoteMuteResult); |
| 224 client->SignalRemoteMuteError.connect( |
| 225 listener.get(), &TestHangoutPubSubListener::OnRemoteMuteError); |
| 226 client->SignalMediaBlockResult.connect( |
| 227 listener.get(), &TestHangoutPubSubListener::OnMediaBlockResult); |
| 228 client->SignalMediaBlockError.connect( |
| 229 listener.get(), &TestHangoutPubSubListener::OnMediaBlockError); |
| 230 } |
| 231 |
| 232 std::unique_ptr<rtc::FakeTaskRunner> runner; |
| 233 // xmpp_client deleted by deleting runner. |
| 234 buzz::FakeXmppClient* xmpp_client; |
| 235 std::unique_ptr<buzz::HangoutPubSubClient> client; |
| 236 std::unique_ptr<TestHangoutPubSubListener> listener; |
| 237 buzz::Jid pubsubjid; |
| 238 std::string nick; |
| 239 }; |
| 240 |
| 241 TEST_F(HangoutPubSubClientTest, TestRequest) { |
| 242 ASSERT_EQ(0U, xmpp_client->sent_stanzas().size()); |
| 243 |
| 244 client->RequestAll(); |
| 245 std::string expected_presenter_request = |
| 246 "<cli:iq type=\"get\" to=\"room@domain.com\" id=\"0\" " |
| 247 "xmlns:cli=\"jabber:client\">" |
| 248 "<pub:pubsub xmlns:pub=\"http://jabber.org/protocol/pubsub\">" |
| 249 "<pub:items node=\"google:presenter\"/>" |
| 250 "</pub:pubsub>" |
| 251 "</cli:iq>"; |
| 252 |
| 253 std::string expected_media_request = |
| 254 "<cli:iq type=\"get\" to=\"room@domain.com\" id=\"0\" " |
| 255 "xmlns:cli=\"jabber:client\">" |
| 256 "<pub:pubsub xmlns:pub=\"http://jabber.org/protocol/pubsub\">" |
| 257 "<pub:items node=\"google:muc#media\"/>" |
| 258 "</pub:pubsub>" |
| 259 "</cli:iq>"; |
| 260 |
| 261 ASSERT_EQ(2U, xmpp_client->sent_stanzas().size()); |
| 262 EXPECT_EQ(expected_presenter_request, xmpp_client->sent_stanzas()[0]->Str()); |
| 263 EXPECT_EQ(expected_media_request, xmpp_client->sent_stanzas()[1]->Str()); |
| 264 |
| 265 std::string presenter_response = |
| 266 "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'>" |
| 267 " <pubsub xmlns='http://jabber.org/protocol/pubsub'>" |
| 268 " <items node='google:presenter'>" |
| 269 " <item id='12344'>" |
| 270 " <presenter xmlns='google:presenter' nick='presenting-nick2'/>" |
| 271 " <pre:presentation-item xmlns:pre='google:presenter'" |
| 272 " pre:presentation-type='s'/>" |
| 273 " </item>" |
| 274 " <item id='12345'>" |
| 275 " <presenter xmlns='google:presenter' nick='presenting-nick'/>" |
| 276 " <pre:presentation-item xmlns:pre='google:presenter'" |
| 277 " pre:presentation-type='o'/>" |
| 278 " </item>" |
| 279 // Some clients are "bad" in that they'll jam multiple states in |
| 280 // all at once. We have to deal with it. |
| 281 " <item id='12346'>" |
| 282 " <presenter xmlns='google:presenter' nick='presenting-nick'/>" |
| 283 " <pre:presentation-item xmlns:pre='google:presenter'" |
| 284 " pre:presentation-type='s'/>" |
| 285 " </item>" |
| 286 " </items>" |
| 287 " </pubsub>" |
| 288 "</iq>"; |
| 289 |
| 290 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(presenter_response)); |
| 291 EXPECT_EQ("presenting-nick", listener->last_presenter_nick); |
| 292 EXPECT_FALSE(listener->last_was_presenting); |
| 293 EXPECT_TRUE(listener->last_is_presenting); |
| 294 |
| 295 std::string media_response = |
| 296 "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'>" |
| 297 " <pubsub xmlns='http://jabber.org/protocol/pubsub'>" |
| 298 " <items node='google:muc#media'>" |
| 299 " <item id='audio-mute:muted-nick'>" |
| 300 " <audio-mute nick='muted-nick' xmlns='google:muc#media'/>" |
| 301 " </item>" |
| 302 " <item id='video-mute:video-muted-nick'>" |
| 303 " <video-mute nick='video-muted-nick' xmlns='google:muc#media'/>" |
| 304 " </item>" |
| 305 " <item id='video-pause:video-paused-nick'>" |
| 306 " <video-pause nick='video-paused-nick' xmlns='google:muc#media'/>" |
| 307 " </item>" |
| 308 " <item id='recording:recording-nick'>" |
| 309 " <recording nick='recording-nick' xmlns='google:muc#media'/>" |
| 310 " </item>" |
| 311 " </items>" |
| 312 " </pubsub>" |
| 313 "</iq>"; |
| 314 |
| 315 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(media_response)); |
| 316 EXPECT_EQ("muted-nick", listener->last_audio_muted_nick); |
| 317 EXPECT_FALSE(listener->last_was_audio_muted); |
| 318 EXPECT_TRUE(listener->last_is_audio_muted); |
| 319 |
| 320 EXPECT_EQ("video-muted-nick", listener->last_video_muted_nick); |
| 321 EXPECT_FALSE(listener->last_was_video_muted); |
| 322 EXPECT_TRUE(listener->last_is_video_muted); |
| 323 |
| 324 EXPECT_EQ("video-paused-nick", listener->last_video_paused_nick); |
| 325 EXPECT_FALSE(listener->last_was_video_paused); |
| 326 EXPECT_TRUE(listener->last_is_video_paused); |
| 327 |
| 328 EXPECT_EQ("recording-nick", listener->last_recording_nick); |
| 329 EXPECT_FALSE(listener->last_was_recording); |
| 330 EXPECT_TRUE(listener->last_is_recording); |
| 331 |
| 332 std::string incoming_presenter_resets_message = |
| 333 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 334 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 335 " <items node='google:presenter'>" |
| 336 " <item id='12348'>" |
| 337 " <presenter xmlns='google:presenter' nick='presenting-nick'/>" |
| 338 " <pre:presentation-item xmlns:pre='google:presenter'" |
| 339 " pre:presentation-type='o'/>" |
| 340 " </item>" |
| 341 " </items>" |
| 342 " </event>" |
| 343 "</message>"; |
| 344 |
| 345 xmpp_client->HandleStanza( |
| 346 buzz::XmlElement::ForStr(incoming_presenter_resets_message)); |
| 347 EXPECT_EQ("presenting-nick", listener->last_presenter_nick); |
| 348 //EXPECT_TRUE(listener->last_was_presenting); |
| 349 EXPECT_FALSE(listener->last_is_presenting); |
| 350 |
| 351 std::string incoming_presenter_retracts_message = |
| 352 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 353 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 354 " <items node='google:presenter'>" |
| 355 " <retract id='12344'/>" |
| 356 " </items>" |
| 357 " </event>" |
| 358 "</message>"; |
| 359 |
| 360 xmpp_client->HandleStanza( |
| 361 buzz::XmlElement::ForStr(incoming_presenter_retracts_message)); |
| 362 EXPECT_EQ("presenting-nick2", listener->last_presenter_nick); |
| 363 EXPECT_TRUE(listener->last_was_presenting); |
| 364 EXPECT_FALSE(listener->last_is_presenting); |
| 365 |
| 366 std::string incoming_media_retracts_message = |
| 367 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 368 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 369 " <items node='google:muc#media'>" |
| 370 " <item id='audio-mute:muted-nick'>" |
| 371 " </item>" |
| 372 " <retract id='video-mute:video-muted-nick'/>" |
| 373 " <retract id='video-pause:video-paused-nick'/>" |
| 374 " <retract id='recording:recording-nick'/>" |
| 375 " </items>" |
| 376 " </event>" |
| 377 "</message>"; |
| 378 |
| 379 xmpp_client->HandleStanza( |
| 380 buzz::XmlElement::ForStr(incoming_media_retracts_message)); |
| 381 EXPECT_EQ("muted-nick", listener->last_audio_muted_nick); |
| 382 EXPECT_TRUE(listener->last_was_audio_muted); |
| 383 EXPECT_FALSE(listener->last_is_audio_muted); |
| 384 |
| 385 EXPECT_EQ("video-paused-nick", listener->last_video_paused_nick); |
| 386 EXPECT_TRUE(listener->last_was_video_paused); |
| 387 EXPECT_FALSE(listener->last_is_video_paused); |
| 388 |
| 389 EXPECT_EQ("recording-nick", listener->last_recording_nick); |
| 390 EXPECT_TRUE(listener->last_was_recording); |
| 391 EXPECT_FALSE(listener->last_is_recording); |
| 392 |
| 393 std::string incoming_presenter_changes_message = |
| 394 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 395 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 396 " <items node='google:presenter'>" |
| 397 " <item id='presenting-nick2'>" |
| 398 " <presenter xmlns='google:presenter' nick='presenting-nick2'/>" |
| 399 " <pre:presentation-item xmlns:pre='google:presenter'" |
| 400 " pre:presentation-type='s'/>" |
| 401 " </item>" |
| 402 " </items>" |
| 403 " </event>" |
| 404 "</message>"; |
| 405 |
| 406 xmpp_client->HandleStanza( |
| 407 buzz::XmlElement::ForStr(incoming_presenter_changes_message)); |
| 408 EXPECT_EQ("presenting-nick2", listener->last_presenter_nick); |
| 409 EXPECT_FALSE(listener->last_was_presenting); |
| 410 EXPECT_TRUE(listener->last_is_presenting); |
| 411 |
| 412 xmpp_client->HandleStanza( |
| 413 buzz::XmlElement::ForStr(incoming_presenter_changes_message)); |
| 414 EXPECT_EQ("presenting-nick2", listener->last_presenter_nick); |
| 415 EXPECT_TRUE(listener->last_was_presenting); |
| 416 EXPECT_TRUE(listener->last_is_presenting); |
| 417 |
| 418 std::string incoming_media_changes_message = |
| 419 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 420 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 421 " <items node='google:muc#media'>" |
| 422 " <item id='audio-mute:muted-nick2'>" |
| 423 " <audio-mute nick='muted-nick2' xmlns='google:muc#media'/>" |
| 424 " </item>" |
| 425 " <item id='video-pause:video-paused-nick2'>" |
| 426 " <video-pause nick='video-paused-nick2' xmlns='google:muc#media'/>
" |
| 427 " </item>" |
| 428 " <item id='recording:recording-nick2'>" |
| 429 " <recording nick='recording-nick2' xmlns='google:muc#media'/>" |
| 430 " </item>" |
| 431 " </items>" |
| 432 " </event>" |
| 433 "</message>"; |
| 434 |
| 435 xmpp_client->HandleStanza( |
| 436 buzz::XmlElement::ForStr(incoming_media_changes_message)); |
| 437 EXPECT_EQ("muted-nick2", listener->last_audio_muted_nick); |
| 438 EXPECT_FALSE(listener->last_was_audio_muted); |
| 439 EXPECT_TRUE(listener->last_is_audio_muted); |
| 440 |
| 441 EXPECT_EQ("video-paused-nick2", listener->last_video_paused_nick); |
| 442 EXPECT_FALSE(listener->last_was_video_paused); |
| 443 EXPECT_TRUE(listener->last_is_video_paused); |
| 444 |
| 445 EXPECT_EQ("recording-nick2", listener->last_recording_nick); |
| 446 EXPECT_FALSE(listener->last_was_recording); |
| 447 EXPECT_TRUE(listener->last_is_recording); |
| 448 |
| 449 std::string incoming_remote_mute_message = |
| 450 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 451 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 452 " <items node='google:muc#media'>" |
| 453 " <item id='audio-mute:mutee' publisher='room@domain.com/muter'>" |
| 454 " <audio-mute nick='mutee' xmlns='google:muc#media'/>" |
| 455 " </item>" |
| 456 " </items>" |
| 457 " </event>" |
| 458 "</message>"; |
| 459 |
| 460 listener->last_is_audio_muted = false; |
| 461 xmpp_client->HandleStanza( |
| 462 buzz::XmlElement::ForStr(incoming_remote_mute_message)); |
| 463 EXPECT_EQ("mutee", listener->last_mutee_nick); |
| 464 EXPECT_EQ("muter", listener->last_muter_nick); |
| 465 EXPECT_FALSE(listener->last_should_mute); |
| 466 EXPECT_EQ("mutee", listener->last_audio_muted_nick); |
| 467 EXPECT_TRUE(listener->last_is_audio_muted); |
| 468 |
| 469 std::string incoming_remote_mute_me_message = |
| 470 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 471 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 472 " <items node='google:muc#media'>" |
| 473 " <item id='audio-mute:me' publisher='room@domain.com/muter'>" |
| 474 " <audio-mute nick='me' xmlns='google:muc#media'/>" |
| 475 " </item>" |
| 476 " </items>" |
| 477 " </event>" |
| 478 "</message>"; |
| 479 |
| 480 listener->last_is_audio_muted = false; |
| 481 xmpp_client->HandleStanza( |
| 482 buzz::XmlElement::ForStr(incoming_remote_mute_me_message)); |
| 483 EXPECT_EQ("me", listener->last_mutee_nick); |
| 484 EXPECT_EQ("muter", listener->last_muter_nick); |
| 485 EXPECT_TRUE(listener->last_should_mute); |
| 486 EXPECT_EQ("me", listener->last_audio_muted_nick); |
| 487 EXPECT_TRUE(listener->last_is_audio_muted); |
| 488 |
| 489 std::string incoming_media_block_message = |
| 490 "<message xmlns='jabber:client' from='room@domain.com'>" |
| 491 " <event xmlns='http://jabber.org/protocol/pubsub#event'>" |
| 492 " <items node='google:muc#media'>" |
| 493 " <item id='block:blocker:blockee'" |
| 494 " publisher='room@domain.com/blocker'>" |
| 495 " <block nick='blockee' xmlns='google:muc#media'/>" |
| 496 " </item>" |
| 497 " </items>" |
| 498 " </event>" |
| 499 "</message>"; |
| 500 |
| 501 xmpp_client->HandleStanza( |
| 502 buzz::XmlElement::ForStr(incoming_media_block_message)); |
| 503 EXPECT_EQ("blockee", listener->last_blockee_nick); |
| 504 EXPECT_EQ("blocker", listener->last_blocker_nick); |
| 505 } |
| 506 |
| 507 TEST_F(HangoutPubSubClientTest, TestRequestError) { |
| 508 client->RequestAll(); |
| 509 std::string result_iq = |
| 510 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'>" |
| 511 " <error type='auth'>" |
| 512 " <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" |
| 513 " </error>" |
| 514 "</iq>"; |
| 515 |
| 516 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 517 EXPECT_EQ(1, listener->request_error_count); |
| 518 EXPECT_EQ("google:presenter", listener->request_error_node); |
| 519 } |
| 520 |
| 521 TEST_F(HangoutPubSubClientTest, TestPublish) { |
| 522 client->PublishPresenterState(true); |
| 523 std::string expected_presenter_iq = |
| 524 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 525 "xmlns:cli=\"jabber:client\">" |
| 526 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 527 "<publish node=\"google:presenter\">" |
| 528 "<item id=\"me\">" |
| 529 "<presenter xmlns=\"google:presenter\"" |
| 530 " nick=\"me\"/>" |
| 531 "<pre:presentation-item" |
| 532 " pre:presentation-type=\"s\" xmlns:pre=\"google:presenter\"/>" |
| 533 "</item>" |
| 534 "</publish>" |
| 535 "</pubsub>" |
| 536 "</cli:iq>"; |
| 537 |
| 538 ASSERT_EQ(1U, xmpp_client->sent_stanzas().size()); |
| 539 EXPECT_EQ(expected_presenter_iq, |
| 540 xmpp_client->sent_stanzas()[0]->Str()); |
| 541 |
| 542 client->PublishAudioMuteState(true); |
| 543 std::string expected_audio_mute_iq = |
| 544 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 545 "xmlns:cli=\"jabber:client\">" |
| 546 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 547 "<publish node=\"google:muc#media\">" |
| 548 "<item id=\"audio-mute:me\">" |
| 549 "<audio-mute xmlns=\"google:muc#media\" nick=\"me\"/>" |
| 550 "</item>" |
| 551 "</publish>" |
| 552 "</pubsub>" |
| 553 "</cli:iq>"; |
| 554 |
| 555 ASSERT_EQ(2U, xmpp_client->sent_stanzas().size()); |
| 556 EXPECT_EQ(expected_audio_mute_iq, xmpp_client->sent_stanzas()[1]->Str()); |
| 557 |
| 558 client->PublishVideoPauseState(true); |
| 559 std::string expected_video_pause_iq = |
| 560 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 561 "xmlns:cli=\"jabber:client\">" |
| 562 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 563 "<publish node=\"google:muc#media\">" |
| 564 "<item id=\"video-pause:me\">" |
| 565 "<video-pause xmlns=\"google:muc#media\" nick=\"me\"/>" |
| 566 "</item>" |
| 567 "</publish>" |
| 568 "</pubsub>" |
| 569 "</cli:iq>"; |
| 570 |
| 571 ASSERT_EQ(3U, xmpp_client->sent_stanzas().size()); |
| 572 EXPECT_EQ(expected_video_pause_iq, xmpp_client->sent_stanzas()[2]->Str()); |
| 573 |
| 574 client->PublishRecordingState(true); |
| 575 std::string expected_recording_iq = |
| 576 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 577 "xmlns:cli=\"jabber:client\">" |
| 578 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 579 "<publish node=\"google:muc#media\">" |
| 580 "<item id=\"recording:me\">" |
| 581 "<recording xmlns=\"google:muc#media\" nick=\"me\"/>" |
| 582 "</item>" |
| 583 "</publish>" |
| 584 "</pubsub>" |
| 585 "</cli:iq>"; |
| 586 |
| 587 ASSERT_EQ(4U, xmpp_client->sent_stanzas().size()); |
| 588 EXPECT_EQ(expected_recording_iq, xmpp_client->sent_stanzas()[3]->Str()); |
| 589 |
| 590 client->RemoteMute("mutee"); |
| 591 std::string expected_remote_mute_iq = |
| 592 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 593 "xmlns:cli=\"jabber:client\">" |
| 594 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 595 "<publish node=\"google:muc#media\">" |
| 596 "<item id=\"audio-mute:mutee\">" |
| 597 "<audio-mute xmlns=\"google:muc#media\" nick=\"mutee\"/>" |
| 598 "</item>" |
| 599 "</publish>" |
| 600 "</pubsub>" |
| 601 "</cli:iq>"; |
| 602 |
| 603 ASSERT_EQ(5U, xmpp_client->sent_stanzas().size()); |
| 604 EXPECT_EQ(expected_remote_mute_iq, xmpp_client->sent_stanzas()[4]->Str()); |
| 605 |
| 606 client->PublishPresenterState(false); |
| 607 std::string expected_presenter_retract_iq = |
| 608 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 609 "xmlns:cli=\"jabber:client\">" |
| 610 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 611 "<publish node=\"google:presenter\">" |
| 612 "<item id=\"me\">" |
| 613 "<presenter xmlns=\"google:presenter\"" |
| 614 " nick=\"me\"/>" |
| 615 "<pre:presentation-item" |
| 616 " pre:presentation-type=\"o\" xmlns:pre=\"google:presenter\"/>" |
| 617 "</item>" |
| 618 "</publish>" |
| 619 "</pubsub>" |
| 620 "</cli:iq>"; |
| 621 |
| 622 ASSERT_EQ(6U, xmpp_client->sent_stanzas().size()); |
| 623 EXPECT_EQ(expected_presenter_retract_iq, |
| 624 xmpp_client->sent_stanzas()[5]->Str()); |
| 625 |
| 626 client->PublishAudioMuteState(false); |
| 627 std::string expected_audio_mute_retract_iq = |
| 628 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 629 "xmlns:cli=\"jabber:client\">" |
| 630 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 631 "<retract node=\"google:muc#media\" notify=\"true\">" |
| 632 "<item id=\"audio-mute:me\"/>" |
| 633 "</retract>" |
| 634 "</pubsub>" |
| 635 "</cli:iq>"; |
| 636 |
| 637 ASSERT_EQ(7U, xmpp_client->sent_stanzas().size()); |
| 638 EXPECT_EQ(expected_audio_mute_retract_iq, |
| 639 xmpp_client->sent_stanzas()[6]->Str()); |
| 640 |
| 641 client->PublishVideoPauseState(false); |
| 642 std::string expected_video_pause_retract_iq = |
| 643 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 644 "xmlns:cli=\"jabber:client\">" |
| 645 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 646 "<retract node=\"google:muc#media\" notify=\"true\">" |
| 647 "<item id=\"video-pause:me\"/>" |
| 648 "</retract>" |
| 649 "</pubsub>" |
| 650 "</cli:iq>"; |
| 651 |
| 652 ASSERT_EQ(8U, xmpp_client->sent_stanzas().size()); |
| 653 EXPECT_EQ(expected_video_pause_retract_iq, |
| 654 xmpp_client->sent_stanzas()[7]->Str()); |
| 655 |
| 656 client->BlockMedia("blockee"); |
| 657 std::string expected_media_block_iq = |
| 658 "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" " |
| 659 "xmlns:cli=\"jabber:client\">" |
| 660 "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" |
| 661 "<publish node=\"google:muc#media\">" |
| 662 "<item id=\"block:me:blockee\">" |
| 663 "<block xmlns=\"google:muc#media\" nick=\"blockee\"/>" |
| 664 "</item>" |
| 665 "</publish>" |
| 666 "</pubsub>" |
| 667 "</cli:iq>"; |
| 668 |
| 669 ASSERT_EQ(9U, xmpp_client->sent_stanzas().size()); |
| 670 EXPECT_EQ(expected_media_block_iq, xmpp_client->sent_stanzas()[8]->Str()); |
| 671 } |
| 672 |
| 673 TEST_F(HangoutPubSubClientTest, TestPublishPresenterError) { |
| 674 std::string result_iq = |
| 675 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 676 |
| 677 client->PublishPresenterState(true); |
| 678 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 679 EXPECT_EQ(1, listener->publish_presenter_error_count); |
| 680 EXPECT_EQ("0", listener->error_task_id); |
| 681 } |
| 682 |
| 683 |
| 684 TEST_F(HangoutPubSubClientTest, TestPublishAudioMuteError) { |
| 685 std::string result_iq = |
| 686 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 687 |
| 688 client->PublishAudioMuteState(true); |
| 689 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 690 EXPECT_EQ(1, listener->publish_audio_mute_error_count); |
| 691 EXPECT_EQ("0", listener->error_task_id); |
| 692 } |
| 693 |
| 694 TEST_F(HangoutPubSubClientTest, TestPublishVideoPauseError) { |
| 695 std::string result_iq = |
| 696 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 697 |
| 698 client->PublishVideoPauseState(true); |
| 699 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 700 EXPECT_EQ(1, listener->publish_video_pause_error_count); |
| 701 EXPECT_EQ("0", listener->error_task_id); |
| 702 } |
| 703 |
| 704 TEST_F(HangoutPubSubClientTest, TestPublishRecordingError) { |
| 705 std::string result_iq = |
| 706 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 707 |
| 708 client->PublishRecordingState(true); |
| 709 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 710 EXPECT_EQ(1, listener->publish_recording_error_count); |
| 711 EXPECT_EQ("0", listener->error_task_id); |
| 712 } |
| 713 |
| 714 TEST_F(HangoutPubSubClientTest, TestPublishRemoteMuteResult) { |
| 715 std::string result_iq = |
| 716 "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'/>"; |
| 717 |
| 718 client->RemoteMute("joe"); |
| 719 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 720 EXPECT_EQ("joe", listener->remote_mute_mutee_nick); |
| 721 EXPECT_EQ("0", listener->result_task_id); |
| 722 } |
| 723 |
| 724 TEST_F(HangoutPubSubClientTest, TestRemoteMuteError) { |
| 725 std::string result_iq = |
| 726 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 727 |
| 728 client->RemoteMute("joe"); |
| 729 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 730 EXPECT_EQ(1, listener->remote_mute_error_count); |
| 731 EXPECT_EQ("joe", listener->remote_mute_mutee_nick); |
| 732 EXPECT_EQ("0", listener->error_task_id); |
| 733 } |
| 734 |
| 735 TEST_F(HangoutPubSubClientTest, TestPublishMediaBlockResult) { |
| 736 std::string result_iq = |
| 737 "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'/>"; |
| 738 |
| 739 client->BlockMedia("joe"); |
| 740 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 741 EXPECT_EQ("joe", listener->media_blockee_nick); |
| 742 EXPECT_EQ("0", listener->result_task_id); |
| 743 } |
| 744 |
| 745 TEST_F(HangoutPubSubClientTest, TestMediaBlockError) { |
| 746 std::string result_iq = |
| 747 "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>"; |
| 748 |
| 749 client->BlockMedia("joe"); |
| 750 xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq)); |
| 751 EXPECT_EQ(1, listener->remote_mute_error_count); |
| 752 EXPECT_EQ("joe", listener->media_blockee_nick); |
| 753 EXPECT_EQ("0", listener->error_task_id); |
| 754 } |
OLD | NEW |