summaryrefslogtreecommitdiff
path: root/xmpp/hangoutpubsubclient_unittest.cc
blob: 555ee5c34a5060ede17e8537a030d01c2a98d2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
// Copyright 2011 Google Inc. All Rights Reserved


#include <string>

#include "webrtc/libjingle/xmllite/qname.h"
#include "webrtc/libjingle/xmllite/xmlelement.h"
#include "talk/xmpp/constants.h"
#include "talk/xmpp/fakexmppclient.h"
#include "talk/xmpp/hangoutpubsubclient.h"
#include "talk/xmpp/jid.h"
#include "webrtc/base/faketaskrunner.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/sigslot.h"

class TestHangoutPubSubListener : public sigslot::has_slots<> {
 public:
  TestHangoutPubSubListener() :
      request_error_count(0),
      publish_audio_mute_error_count(0),
      publish_video_mute_error_count(0),
      publish_video_pause_error_count(0),
      publish_presenter_error_count(0),
      publish_recording_error_count(0),
      remote_mute_error_count(0) {
  }

  void OnPresenterStateChange(
      const std::string& nick, bool was_presenting, bool is_presenting) {
    last_presenter_nick = nick;
    last_was_presenting = was_presenting;
    last_is_presenting = is_presenting;
  }

  void OnAudioMuteStateChange(
      const std::string& nick, bool was_muted, bool is_muted) {
    last_audio_muted_nick = nick;
    last_was_audio_muted = was_muted;
    last_is_audio_muted = is_muted;
  }

  void OnVideoMuteStateChange(
      const std::string& nick, bool was_muted, bool is_muted) {
    last_video_muted_nick = nick;
    last_was_video_muted = was_muted;
    last_is_video_muted = is_muted;
  }

  void OnVideoPauseStateChange(
      const std::string& nick, bool was_paused, bool is_paused) {
    last_video_paused_nick = nick;
    last_was_video_paused = was_paused;
    last_is_video_paused = is_paused;
  }

  void OnRecordingStateChange(
      const std::string& nick, bool was_recording, bool is_recording) {
    last_recording_nick = nick;
    last_was_recording = was_recording;
    last_is_recording = is_recording;
  }

  void OnRemoteMute(
      const std::string& mutee_nick,
      const std::string& muter_nick,
      bool should_mute_locally) {
    last_mutee_nick = mutee_nick;
    last_muter_nick = muter_nick;
    last_should_mute = should_mute_locally;
  }

  void OnMediaBlock(
      const std::string& blockee_nick,
      const std::string& blocker_nick) {
    last_blockee_nick = blockee_nick;
    last_blocker_nick = blocker_nick;
  }

  void OnRequestError(const std::string& node, const buzz::XmlElement* stanza) {
    ++request_error_count;
    request_error_node = node;
  }

  void OnPublishAudioMuteError(const std::string& task_id,
                               const buzz::XmlElement* stanza) {
    ++publish_audio_mute_error_count;
    error_task_id = task_id;
  }

  void OnPublishVideoMuteError(const std::string& task_id,
                               const buzz::XmlElement* stanza) {
    ++publish_video_mute_error_count;
    error_task_id = task_id;
  }

  void OnPublishVideoPauseError(const std::string& task_id,
                               const buzz::XmlElement* stanza) {
    ++publish_video_pause_error_count;
    error_task_id = task_id;
  }

  void OnPublishPresenterError(const std::string& task_id,
                               const buzz::XmlElement* stanza) {
    ++publish_presenter_error_count;
    error_task_id = task_id;
  }

  void OnPublishRecordingError(const std::string& task_id,
                               const buzz::XmlElement* stanza) {
    ++publish_recording_error_count;
    error_task_id = task_id;
  }

  void OnRemoteMuteResult(const std::string& task_id,
                          const std::string& mutee_nick) {
    result_task_id = task_id;
    remote_mute_mutee_nick = mutee_nick;
  }

  void OnRemoteMuteError(const std::string& task_id,
                         const std::string& mutee_nick,
                         const buzz::XmlElement* stanza) {
    ++remote_mute_error_count;
    error_task_id = task_id;
    remote_mute_mutee_nick = mutee_nick;
  }

  void OnMediaBlockResult(const std::string& task_id,
                          const std::string& blockee_nick) {
    result_task_id = task_id;
    media_blockee_nick = blockee_nick;
  }

  void OnMediaBlockError(const std::string& task_id,
                         const std::string& blockee_nick,
                         const buzz::XmlElement* stanza) {
    ++media_block_error_count;
    error_task_id = task_id;
    media_blockee_nick = blockee_nick;
  }

  std::string last_presenter_nick;
  bool last_is_presenting;
  bool last_was_presenting;
  std::string last_audio_muted_nick;
  bool last_is_audio_muted;
  bool last_was_audio_muted;
  std::string last_video_muted_nick;
  bool last_is_video_muted;
  bool last_was_video_muted;
  std::string last_video_paused_nick;
  bool last_is_video_paused;
  bool last_was_video_paused;
  std::string last_recording_nick;
  bool last_is_recording;
  bool last_was_recording;
  std::string last_mutee_nick;
  std::string last_muter_nick;
  bool last_should_mute;
  std::string last_blockee_nick;
  std::string last_blocker_nick;

  int request_error_count;
  std::string request_error_node;
  int publish_audio_mute_error_count;
  int publish_video_mute_error_count;
  int publish_video_pause_error_count;
  int publish_presenter_error_count;
  int publish_recording_error_count;
  int remote_mute_error_count;
  std::string result_task_id;
  std::string error_task_id;
  std::string remote_mute_mutee_nick;
  int media_block_error_count;
  std::string media_blockee_nick;
};

class HangoutPubSubClientTest : public testing::Test {
 public:
  HangoutPubSubClientTest() :
      pubsubjid("room@domain.com"),
      nick("me") {

    runner.reset(new rtc::FakeTaskRunner());
    xmpp_client = new buzz::FakeXmppClient(runner.get());
    client.reset(new buzz::HangoutPubSubClient(xmpp_client, pubsubjid, nick));
    listener.reset(new TestHangoutPubSubListener());
    client->SignalPresenterStateChange.connect(
        listener.get(), &TestHangoutPubSubListener::OnPresenterStateChange);
    client->SignalAudioMuteStateChange.connect(
        listener.get(), &TestHangoutPubSubListener::OnAudioMuteStateChange);
    client->SignalVideoMuteStateChange.connect(
        listener.get(), &TestHangoutPubSubListener::OnVideoMuteStateChange);
    client->SignalVideoPauseStateChange.connect(
        listener.get(), &TestHangoutPubSubListener::OnVideoPauseStateChange);
    client->SignalRecordingStateChange.connect(
        listener.get(), &TestHangoutPubSubListener::OnRecordingStateChange);
    client->SignalRemoteMute.connect(
        listener.get(), &TestHangoutPubSubListener::OnRemoteMute);
    client->SignalMediaBlock.connect(
        listener.get(), &TestHangoutPubSubListener::OnMediaBlock);
    client->SignalRequestError.connect(
        listener.get(), &TestHangoutPubSubListener::OnRequestError);
    client->SignalPublishAudioMuteError.connect(
        listener.get(), &TestHangoutPubSubListener::OnPublishAudioMuteError);
    client->SignalPublishVideoMuteError.connect(
        listener.get(), &TestHangoutPubSubListener::OnPublishVideoMuteError);
    client->SignalPublishVideoPauseError.connect(
        listener.get(), &TestHangoutPubSubListener::OnPublishVideoPauseError);
    client->SignalPublishPresenterError.connect(
        listener.get(), &TestHangoutPubSubListener::OnPublishPresenterError);
    client->SignalPublishRecordingError.connect(
        listener.get(), &TestHangoutPubSubListener::OnPublishRecordingError);
    client->SignalRemoteMuteResult.connect(
        listener.get(), &TestHangoutPubSubListener::OnRemoteMuteResult);
    client->SignalRemoteMuteError.connect(
        listener.get(), &TestHangoutPubSubListener::OnRemoteMuteError);
    client->SignalMediaBlockResult.connect(
        listener.get(), &TestHangoutPubSubListener::OnMediaBlockResult);
    client->SignalMediaBlockError.connect(
        listener.get(), &TestHangoutPubSubListener::OnMediaBlockError);
  }

  rtc::scoped_ptr<rtc::FakeTaskRunner> runner;
  // xmpp_client deleted by deleting runner.
  buzz::FakeXmppClient* xmpp_client;
  rtc::scoped_ptr<buzz::HangoutPubSubClient> client;
  rtc::scoped_ptr<TestHangoutPubSubListener> listener;
  buzz::Jid pubsubjid;
  std::string nick;
};

TEST_F(HangoutPubSubClientTest, TestRequest) {
  ASSERT_EQ(0U, xmpp_client->sent_stanzas().size());

  client->RequestAll();
  std::string expected_presenter_request =
      "<cli:iq type=\"get\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pub:pubsub xmlns:pub=\"http://jabber.org/protocol/pubsub\">"
          "<pub:items node=\"google:presenter\"/>"
        "</pub:pubsub>"
      "</cli:iq>";

  std::string expected_media_request =
      "<cli:iq type=\"get\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pub:pubsub xmlns:pub=\"http://jabber.org/protocol/pubsub\">"
          "<pub:items node=\"google:muc#media\"/>"
        "</pub:pubsub>"
      "</cli:iq>";

  ASSERT_EQ(2U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_presenter_request, xmpp_client->sent_stanzas()[0]->Str());
  EXPECT_EQ(expected_media_request, xmpp_client->sent_stanzas()[1]->Str());

  std::string presenter_response =
      "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'>"
      "  <pubsub xmlns='http://jabber.org/protocol/pubsub'>"
      "    <items node='google:presenter'>"
      "      <item id='12344'>"
      "        <presenter xmlns='google:presenter' nick='presenting-nick2'/>"
      "        <pre:presentation-item xmlns:pre='google:presenter'"
      "          pre:presentation-type='s'/>"
      "      </item>"
      "      <item id='12345'>"
      "        <presenter xmlns='google:presenter' nick='presenting-nick'/>"
      "        <pre:presentation-item xmlns:pre='google:presenter'"
      "          pre:presentation-type='o'/>"
      "      </item>"
      // Some clients are "bad" in that they'll jam multiple states in
      // all at once.  We have to deal with it.
      "      <item id='12346'>"
      "        <presenter xmlns='google:presenter' nick='presenting-nick'/>"
      "        <pre:presentation-item xmlns:pre='google:presenter'"
      "          pre:presentation-type='s'/>"
      "      </item>"
      "    </items>"
      "  </pubsub>"
      "</iq>";

  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(presenter_response));
  EXPECT_EQ("presenting-nick", listener->last_presenter_nick);
  EXPECT_FALSE(listener->last_was_presenting);
  EXPECT_TRUE(listener->last_is_presenting);

  std::string media_response =
      "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'>"
      "  <pubsub xmlns='http://jabber.org/protocol/pubsub'>"
      "    <items node='google:muc#media'>"
      "      <item id='audio-mute:muted-nick'>"
      "        <audio-mute nick='muted-nick' xmlns='google:muc#media'/>"
      "      </item>"
      "      <item id='video-mute:video-muted-nick'>"
      "        <video-mute nick='video-muted-nick' xmlns='google:muc#media'/>"
      "      </item>"
      "      <item id='video-pause:video-paused-nick'>"
      "        <video-pause nick='video-paused-nick' xmlns='google:muc#media'/>"
      "      </item>"
      "      <item id='recording:recording-nick'>"
      "        <recording nick='recording-nick' xmlns='google:muc#media'/>"
      "      </item>"
      "    </items>"
      "  </pubsub>"
      "</iq>";

  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(media_response));
  EXPECT_EQ("muted-nick", listener->last_audio_muted_nick);
  EXPECT_FALSE(listener->last_was_audio_muted);
  EXPECT_TRUE(listener->last_is_audio_muted);

  EXPECT_EQ("video-muted-nick", listener->last_video_muted_nick);
  EXPECT_FALSE(listener->last_was_video_muted);
  EXPECT_TRUE(listener->last_is_video_muted);

  EXPECT_EQ("video-paused-nick", listener->last_video_paused_nick);
  EXPECT_FALSE(listener->last_was_video_paused);
  EXPECT_TRUE(listener->last_is_video_paused);

  EXPECT_EQ("recording-nick", listener->last_recording_nick);
  EXPECT_FALSE(listener->last_was_recording);
  EXPECT_TRUE(listener->last_is_recording);

  std::string incoming_presenter_resets_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:presenter'>"
      "      <item id='12348'>"
      "        <presenter xmlns='google:presenter' nick='presenting-nick'/>"
      "        <pre:presentation-item xmlns:pre='google:presenter'"
      "          pre:presentation-type='o'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_presenter_resets_message));
  EXPECT_EQ("presenting-nick", listener->last_presenter_nick);
  //EXPECT_TRUE(listener->last_was_presenting);
  EXPECT_FALSE(listener->last_is_presenting);

  std::string incoming_presenter_retracts_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:presenter'>"
      "      <retract id='12344'/>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_presenter_retracts_message));
  EXPECT_EQ("presenting-nick2", listener->last_presenter_nick);
  EXPECT_TRUE(listener->last_was_presenting);
  EXPECT_FALSE(listener->last_is_presenting);

  std::string incoming_media_retracts_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:muc#media'>"
      "      <item id='audio-mute:muted-nick'>"
      "      </item>"
      "      <retract id='video-mute:video-muted-nick'/>"
      "      <retract id='video-pause:video-paused-nick'/>"
      "      <retract id='recording:recording-nick'/>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_media_retracts_message));
  EXPECT_EQ("muted-nick", listener->last_audio_muted_nick);
  EXPECT_TRUE(listener->last_was_audio_muted);
  EXPECT_FALSE(listener->last_is_audio_muted);

  EXPECT_EQ("video-paused-nick", listener->last_video_paused_nick);
  EXPECT_TRUE(listener->last_was_video_paused);
  EXPECT_FALSE(listener->last_is_video_paused);

  EXPECT_EQ("recording-nick", listener->last_recording_nick);
  EXPECT_TRUE(listener->last_was_recording);
  EXPECT_FALSE(listener->last_is_recording);

  std::string incoming_presenter_changes_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:presenter'>"
      "      <item id='presenting-nick2'>"
      "        <presenter xmlns='google:presenter' nick='presenting-nick2'/>"
      "        <pre:presentation-item xmlns:pre='google:presenter'"
      "          pre:presentation-type='s'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_presenter_changes_message));
  EXPECT_EQ("presenting-nick2", listener->last_presenter_nick);
  EXPECT_FALSE(listener->last_was_presenting);
  EXPECT_TRUE(listener->last_is_presenting);

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_presenter_changes_message));
  EXPECT_EQ("presenting-nick2", listener->last_presenter_nick);
  EXPECT_TRUE(listener->last_was_presenting);
  EXPECT_TRUE(listener->last_is_presenting);

  std::string incoming_media_changes_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:muc#media'>"
      "      <item id='audio-mute:muted-nick2'>"
      "        <audio-mute nick='muted-nick2' xmlns='google:muc#media'/>"
      "      </item>"
      "      <item id='video-pause:video-paused-nick2'>"
      "        <video-pause nick='video-paused-nick2' xmlns='google:muc#media'/>"
      "      </item>"
      "      <item id='recording:recording-nick2'>"
      "        <recording nick='recording-nick2' xmlns='google:muc#media'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_media_changes_message));
  EXPECT_EQ("muted-nick2", listener->last_audio_muted_nick);
  EXPECT_FALSE(listener->last_was_audio_muted);
  EXPECT_TRUE(listener->last_is_audio_muted);

  EXPECT_EQ("video-paused-nick2", listener->last_video_paused_nick);
  EXPECT_FALSE(listener->last_was_video_paused);
  EXPECT_TRUE(listener->last_is_video_paused);

  EXPECT_EQ("recording-nick2", listener->last_recording_nick);
  EXPECT_FALSE(listener->last_was_recording);
  EXPECT_TRUE(listener->last_is_recording);

  std::string incoming_remote_mute_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:muc#media'>"
      "      <item id='audio-mute:mutee' publisher='room@domain.com/muter'>"
      "        <audio-mute nick='mutee' xmlns='google:muc#media'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  listener->last_is_audio_muted = false;
  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_remote_mute_message));
  EXPECT_EQ("mutee", listener->last_mutee_nick);
  EXPECT_EQ("muter", listener->last_muter_nick);
  EXPECT_FALSE(listener->last_should_mute);
  EXPECT_EQ("mutee", listener->last_audio_muted_nick);
  EXPECT_TRUE(listener->last_is_audio_muted);

  std::string incoming_remote_mute_me_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:muc#media'>"
      "      <item id='audio-mute:me' publisher='room@domain.com/muter'>"
      "        <audio-mute nick='me' xmlns='google:muc#media'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  listener->last_is_audio_muted = false;
  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_remote_mute_me_message));
  EXPECT_EQ("me", listener->last_mutee_nick);
  EXPECT_EQ("muter", listener->last_muter_nick);
  EXPECT_TRUE(listener->last_should_mute);
  EXPECT_EQ("me", listener->last_audio_muted_nick);
  EXPECT_TRUE(listener->last_is_audio_muted);

  std::string incoming_media_block_message =
      "<message xmlns='jabber:client' from='room@domain.com'>"
      "  <event xmlns='http://jabber.org/protocol/pubsub#event'>"
      "    <items node='google:muc#media'>"
      "      <item id='block:blocker:blockee'"
      "            publisher='room@domain.com/blocker'>"
      "        <block nick='blockee' xmlns='google:muc#media'/>"
      "      </item>"
      "    </items>"
      "  </event>"
      "</message>";

  xmpp_client->HandleStanza(
      buzz::XmlElement::ForStr(incoming_media_block_message));
  EXPECT_EQ("blockee", listener->last_blockee_nick);
  EXPECT_EQ("blocker", listener->last_blocker_nick);
}

TEST_F(HangoutPubSubClientTest, TestRequestError) {
  client->RequestAll();
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'>"
      "  <error type='auth'>"
      "    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
      "  </error>"
      "</iq>";

  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->request_error_count);
  EXPECT_EQ("google:presenter", listener->request_error_node);
}

TEST_F(HangoutPubSubClientTest, TestPublish) {
  client->PublishPresenterState(true);
  std::string expected_presenter_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:presenter\">"
            "<item id=\"me\">"
              "<presenter xmlns=\"google:presenter\""
              " nick=\"me\"/>"
              "<pre:presentation-item"
              " pre:presentation-type=\"s\" xmlns:pre=\"google:presenter\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(1U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_presenter_iq,
            xmpp_client->sent_stanzas()[0]->Str());

  client->PublishAudioMuteState(true);
  std::string expected_audio_mute_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:muc#media\">"
            "<item id=\"audio-mute:me\">"
              "<audio-mute xmlns=\"google:muc#media\" nick=\"me\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(2U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_audio_mute_iq, xmpp_client->sent_stanzas()[1]->Str());

  client->PublishVideoPauseState(true);
  std::string expected_video_pause_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:muc#media\">"
            "<item id=\"video-pause:me\">"
              "<video-pause xmlns=\"google:muc#media\" nick=\"me\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(3U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_video_pause_iq, xmpp_client->sent_stanzas()[2]->Str());

  client->PublishRecordingState(true);
  std::string expected_recording_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:muc#media\">"
            "<item id=\"recording:me\">"
              "<recording xmlns=\"google:muc#media\" nick=\"me\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(4U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_recording_iq, xmpp_client->sent_stanzas()[3]->Str());

  client->RemoteMute("mutee");
  std::string expected_remote_mute_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:muc#media\">"
            "<item id=\"audio-mute:mutee\">"
              "<audio-mute xmlns=\"google:muc#media\" nick=\"mutee\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(5U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_remote_mute_iq, xmpp_client->sent_stanzas()[4]->Str());

  client->PublishPresenterState(false);
  std::string expected_presenter_retract_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:presenter\">"
            "<item id=\"me\">"
              "<presenter xmlns=\"google:presenter\""
              " nick=\"me\"/>"
              "<pre:presentation-item"
              " pre:presentation-type=\"o\" xmlns:pre=\"google:presenter\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(6U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_presenter_retract_iq,
            xmpp_client->sent_stanzas()[5]->Str());

  client->PublishAudioMuteState(false);
  std::string expected_audio_mute_retract_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<retract node=\"google:muc#media\" notify=\"true\">"
            "<item id=\"audio-mute:me\"/>"
          "</retract>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(7U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_audio_mute_retract_iq,
            xmpp_client->sent_stanzas()[6]->Str());

  client->PublishVideoPauseState(false);
  std::string expected_video_pause_retract_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<retract node=\"google:muc#media\" notify=\"true\">"
            "<item id=\"video-pause:me\"/>"
          "</retract>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(8U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_video_pause_retract_iq,
            xmpp_client->sent_stanzas()[7]->Str());

  client->BlockMedia("blockee");
  std::string expected_media_block_iq =
      "<cli:iq type=\"set\" to=\"room@domain.com\" id=\"0\" "
        "xmlns:cli=\"jabber:client\">"
        "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">"
          "<publish node=\"google:muc#media\">"
            "<item id=\"block:me:blockee\">"
              "<block xmlns=\"google:muc#media\" nick=\"blockee\"/>"
            "</item>"
          "</publish>"
        "</pubsub>"
      "</cli:iq>";

  ASSERT_EQ(9U, xmpp_client->sent_stanzas().size());
  EXPECT_EQ(expected_media_block_iq, xmpp_client->sent_stanzas()[8]->Str());
}

TEST_F(HangoutPubSubClientTest, TestPublishPresenterError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->PublishPresenterState(true);
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->publish_presenter_error_count);
  EXPECT_EQ("0", listener->error_task_id);
}


TEST_F(HangoutPubSubClientTest, TestPublishAudioMuteError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->PublishAudioMuteState(true);
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->publish_audio_mute_error_count);
  EXPECT_EQ("0", listener->error_task_id);
}

TEST_F(HangoutPubSubClientTest, TestPublishVideoPauseError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->PublishVideoPauseState(true);
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->publish_video_pause_error_count);
  EXPECT_EQ("0", listener->error_task_id);
}

TEST_F(HangoutPubSubClientTest, TestPublishRecordingError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->PublishRecordingState(true);
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->publish_recording_error_count);
  EXPECT_EQ("0", listener->error_task_id);
}

TEST_F(HangoutPubSubClientTest, TestPublishRemoteMuteResult) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'/>";

  client->RemoteMute("joe");
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ("joe", listener->remote_mute_mutee_nick);
  EXPECT_EQ("0", listener->result_task_id);
}

TEST_F(HangoutPubSubClientTest, TestRemoteMuteError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->RemoteMute("joe");
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->remote_mute_error_count);
  EXPECT_EQ("joe", listener->remote_mute_mutee_nick);
  EXPECT_EQ("0", listener->error_task_id);
}

TEST_F(HangoutPubSubClientTest, TestPublishMediaBlockResult) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='result' from='room@domain.com'/>";

  client->BlockMedia("joe");
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ("joe", listener->media_blockee_nick);
  EXPECT_EQ("0", listener->result_task_id);
}

TEST_F(HangoutPubSubClientTest, TestMediaBlockError) {
  std::string result_iq =
      "<iq xmlns='jabber:client' id='0' type='error' from='room@domain.com'/>";

  client->BlockMedia("joe");
  xmpp_client->HandleStanza(buzz::XmlElement::ForStr(result_iq));
  EXPECT_EQ(1, listener->remote_mute_error_count);
  EXPECT_EQ("joe", listener->media_blockee_nick);
  EXPECT_EQ("0", listener->error_task_id);
}