Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / media / capture / audio_mirroring_manager_unittest.cc
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/capture/audio_mirroring_manager.h"
6
7 #include <map>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "content/browser/browser_thread_impl.h"
15 #include "media/audio/audio_parameters.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using media::AudioOutputStream;
20 using media::AudioParameters;
21 using testing::_;
22 using testing::Invoke;
23 using testing::NotNull;
24 using testing::Ref;
25 using testing::Return;
26 using testing::ReturnRef;
27
28 namespace content {
29
30 namespace {
31
32 class MockDiverter : public AudioMirroringManager::Diverter {
33  public:
34   MOCK_METHOD0(GetAudioParameters, const AudioParameters&());
35   MOCK_METHOD1(StartDiverting, void(AudioOutputStream*));
36   MOCK_METHOD0(StopDiverting, void());
37 };
38
39 class MockMirroringDestination
40     : public AudioMirroringManager::MirroringDestination {
41  public:
42   typedef AudioMirroringManager::SourceFrameRef SourceFrameRef;
43
44   MockMirroringDestination(int render_process_id, int render_frame_id)
45       : render_process_id_(render_process_id),
46         render_frame_id_(render_frame_id),
47         query_count_(0) {}
48
49   MOCK_METHOD2(QueryForMatches,
50                void(const std::set<SourceFrameRef>& candidates,
51                     const MatchesCallback& results_callback));
52   MOCK_METHOD1(AddInput,
53                media::AudioOutputStream*(const media::AudioParameters& params));
54
55   void SimulateQuery(const std::set<SourceFrameRef>& candidates,
56                      const MatchesCallback& results_callback) {
57     ++query_count_;
58
59     std::set<SourceFrameRef> result;
60     if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) !=
61             candidates.end()) {
62       result.insert(SourceFrameRef(render_process_id_, render_frame_id_));
63     }
64     results_callback.Run(result);
65   }
66
67   media::AudioOutputStream* SimulateAddInput(
68       const media::AudioParameters& params) {
69     static AudioOutputStream* const kNonNullPointer =
70         reinterpret_cast<AudioOutputStream*>(0x11111110);
71     return kNonNullPointer;
72   }
73
74   int query_count() const {
75     return query_count_;
76   }
77
78  private:
79   const int render_process_id_;
80   const int render_frame_id_;
81   int query_count_;
82 };
83
84 }  // namespace
85
86 class AudioMirroringManagerTest : public testing::Test {
87  public:
88   typedef AudioMirroringManager::Diverter Diverter;
89   typedef AudioMirroringManager::MirroringDestination MirroringDestination;
90   typedef AudioMirroringManager::StreamRoutes StreamRoutes;
91
92   AudioMirroringManagerTest()
93       : io_thread_(BrowserThread::IO, &message_loop_),
94         params_(AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO,
95                 AudioParameters::kAudioCDSampleRate, 16,
96                 AudioParameters::kAudioCDSampleRate / 10) {}
97
98   MockDiverter* CreateStream(
99       int render_process_id, int render_frame_id, int expected_times_diverted) {
100     MockDiverter* const diverter = new MockDiverter();
101     if (expected_times_diverted > 0) {
102       EXPECT_CALL(*diverter, GetAudioParameters())
103           .Times(expected_times_diverted)
104           .WillRepeatedly(ReturnRef(params_));
105       EXPECT_CALL(*diverter, StartDiverting(NotNull()))
106           .Times(expected_times_diverted);
107       EXPECT_CALL(*diverter, StopDiverting())
108           .Times(expected_times_diverted);
109     }
110
111     mirroring_manager_.AddDiverter(
112         render_process_id, render_frame_id, diverter);
113
114     return diverter;
115   }
116
117   void KillStream(MockDiverter* diverter) {
118     mirroring_manager_.RemoveDiverter(diverter);
119     delete diverter;
120   }
121
122   void StartMirroringTo(const scoped_ptr<MockMirroringDestination>& dest,
123                         int expected_inputs_added) {
124     EXPECT_CALL(*dest, QueryForMatches(_, _))
125         .WillRepeatedly(Invoke(dest.get(),
126                                &MockMirroringDestination::SimulateQuery));
127     if (expected_inputs_added > 0) {
128       EXPECT_CALL(*dest, AddInput(Ref(params_)))
129           .Times(expected_inputs_added)
130           .WillRepeatedly(Invoke(dest.get(),
131                                  &MockMirroringDestination::SimulateAddInput))
132           .RetiresOnSaturation();
133     }
134
135     mirroring_manager_.StartMirroring(dest.get());
136   }
137
138   void StopMirroringTo(const scoped_ptr<MockMirroringDestination>& dest) {
139     mirroring_manager_.StopMirroring(dest.get());
140   }
141
142   int CountStreamsDivertedTo(
143       const scoped_ptr<MockMirroringDestination>& dest) const {
144     int count = 0;
145     for (StreamRoutes::const_iterator it = mirroring_manager_.routes_.begin();
146          it != mirroring_manager_.routes_.end(); ++it) {
147       if (it->destination == dest.get())
148         ++count;
149     }
150     return count;
151   }
152
153   void ExpectNoLongerManagingAnything() const {
154     EXPECT_TRUE(mirroring_manager_.routes_.empty());
155     EXPECT_TRUE(mirroring_manager_.sessions_.empty());
156   }
157
158  private:
159   base::MessageLoopForIO message_loop_;
160   BrowserThreadImpl io_thread_;
161   AudioParameters params_;
162   AudioMirroringManager mirroring_manager_;
163
164   DISALLOW_COPY_AND_ASSIGN(AudioMirroringManagerTest);
165 };
166
167 namespace {
168 const int kRenderProcessId = 123;
169 const int kRenderFrameId = 456;
170 const int kAnotherRenderProcessId = 789;
171 const int kAnotherRenderFrameId = 1234;
172 const int kYetAnotherRenderProcessId = 4560;
173 const int kYetAnotherRenderFrameId = 7890;
174 }
175
176 TEST_F(AudioMirroringManagerTest, MirroringSessionOfNothing) {
177   const scoped_ptr<MockMirroringDestination> destination(
178       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
179   StartMirroringTo(destination, 0);
180   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
181
182   StopMirroringTo(destination);
183   EXPECT_EQ(0, destination->query_count());
184
185   ExpectNoLongerManagingAnything();
186 }
187
188 TEST_F(AudioMirroringManagerTest, TwoMirroringSessionsOfNothing) {
189   const scoped_ptr<MockMirroringDestination> destination(
190       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
191   StartMirroringTo(destination, 0);
192   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
193
194   StopMirroringTo(destination);
195   EXPECT_EQ(0, destination->query_count());
196
197   const scoped_ptr<MockMirroringDestination> another_destination(
198       new MockMirroringDestination(kAnotherRenderProcessId,
199                                    kAnotherRenderFrameId));
200   StartMirroringTo(another_destination, 0);
201   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
202
203   StopMirroringTo(another_destination);
204   EXPECT_EQ(0, another_destination->query_count());
205
206   ExpectNoLongerManagingAnything();
207 }
208
209 // Tests that a mirroring session starts after, and ends before, a stream that
210 // will be diverted to it.
211 TEST_F(AudioMirroringManagerTest, StreamLifetimeAroundMirroringSession) {
212   MockDiverter* const stream =
213       CreateStream(kRenderProcessId, kRenderFrameId, 1);
214   const scoped_ptr<MockMirroringDestination> destination(
215       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
216   StartMirroringTo(destination, 1);
217   EXPECT_EQ(1, destination->query_count());
218   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
219
220   StopMirroringTo(destination);
221   EXPECT_EQ(1, destination->query_count());
222   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
223
224   KillStream(stream);
225   EXPECT_EQ(1, destination->query_count());
226   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
227
228   ExpectNoLongerManagingAnything();
229 }
230
231 // Tests that a mirroring session starts before, and ends after, a stream that
232 // will be diverted to it.
233 TEST_F(AudioMirroringManagerTest, StreamLifetimeWithinMirroringSession) {
234   const scoped_ptr<MockMirroringDestination> destination(
235       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
236   StartMirroringTo(destination, 1);
237   EXPECT_EQ(0, destination->query_count());
238   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
239
240   MockDiverter* const stream =
241       CreateStream(kRenderProcessId, kRenderFrameId, 1);
242   EXPECT_EQ(1, destination->query_count());
243   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
244
245   KillStream(stream);
246   EXPECT_EQ(1, destination->query_count());
247   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
248
249   StopMirroringTo(destination);
250   EXPECT_EQ(1, destination->query_count());
251   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
252
253   ExpectNoLongerManagingAnything();
254 }
255
256 // Tests that a stream is diverted correctly as two mirroring sessions come and
257 // go.
258 TEST_F(AudioMirroringManagerTest, StreamLifetimeAcrossTwoMirroringSessions) {
259   MockDiverter* const stream =
260       CreateStream(kRenderProcessId, kRenderFrameId, 2);
261
262   const scoped_ptr<MockMirroringDestination> destination(
263       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
264   StartMirroringTo(destination, 1);
265   EXPECT_EQ(1, destination->query_count());
266   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
267
268   StopMirroringTo(destination);
269   EXPECT_EQ(1, destination->query_count());
270   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
271
272   const scoped_ptr<MockMirroringDestination> second_destination(
273       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
274   StartMirroringTo(second_destination, 1);
275   EXPECT_EQ(1, destination->query_count());
276   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
277   EXPECT_EQ(1, second_destination->query_count());
278   EXPECT_EQ(1, CountStreamsDivertedTo(second_destination));
279
280   StopMirroringTo(second_destination);
281   EXPECT_EQ(1, destination->query_count());
282   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
283   EXPECT_EQ(1, second_destination->query_count());
284   EXPECT_EQ(0, CountStreamsDivertedTo(second_destination));
285
286   KillStream(stream);
287   EXPECT_EQ(1, destination->query_count());
288   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
289   EXPECT_EQ(1, second_destination->query_count());
290   EXPECT_EQ(0, CountStreamsDivertedTo(second_destination));
291
292   ExpectNoLongerManagingAnything();
293 }
294
295 // Tests that a stream does not flip-flop between two destinations that are a
296 // match for it.
297 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_1) {
298   MockDiverter* const stream =
299       CreateStream(kRenderProcessId, kRenderFrameId, 2);
300
301   const scoped_ptr<MockMirroringDestination> destination(
302       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
303   StartMirroringTo(destination, 1);
304   EXPECT_EQ(1, destination->query_count());
305   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
306
307   const scoped_ptr<MockMirroringDestination> replacement_destination(
308       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
309   StartMirroringTo(replacement_destination, 1);
310   EXPECT_EQ(1, destination->query_count());
311   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
312   EXPECT_EQ(0, replacement_destination->query_count());
313   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
314
315   StopMirroringTo(destination);
316   EXPECT_EQ(1, destination->query_count());
317   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
318   EXPECT_EQ(1, replacement_destination->query_count());
319   EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination));
320
321   StopMirroringTo(replacement_destination);
322   EXPECT_EQ(1, destination->query_count());
323   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
324   EXPECT_EQ(1, replacement_destination->query_count());
325   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
326
327   KillStream(stream);
328   EXPECT_EQ(1, destination->query_count());
329   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
330   EXPECT_EQ(1, replacement_destination->query_count());
331   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
332
333   ExpectNoLongerManagingAnything();
334 }
335
336 // Same as StreamDivertingStickyToOneDestination_1, with a different order of
337 // operations that should have the same effects.
338 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_2) {
339   MockDiverter* const stream =
340       CreateStream(kRenderProcessId, kRenderFrameId, 2);
341
342   const scoped_ptr<MockMirroringDestination> destination(
343       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
344   StartMirroringTo(destination, 1);
345   EXPECT_EQ(1, destination->query_count());
346   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
347
348   const scoped_ptr<MockMirroringDestination> replacement_destination(
349       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
350   StartMirroringTo(replacement_destination, 1);
351   EXPECT_EQ(1, destination->query_count());
352   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
353   EXPECT_EQ(0, replacement_destination->query_count());
354   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
355
356   StopMirroringTo(destination);
357   EXPECT_EQ(1, destination->query_count());
358   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
359   EXPECT_EQ(1, replacement_destination->query_count());
360   EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination));
361
362   KillStream(stream);
363   EXPECT_EQ(1, destination->query_count());
364   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
365   EXPECT_EQ(1, replacement_destination->query_count());
366   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
367
368   StopMirroringTo(replacement_destination);
369   EXPECT_EQ(1, destination->query_count());
370   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
371   EXPECT_EQ(1, replacement_destination->query_count());
372   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
373
374   ExpectNoLongerManagingAnything();
375 }
376
377 // Same as StreamDivertingStickyToOneDestination_1, except that the stream is
378 // killed before the first destination is stopped.  Therefore, the second
379 // destination should never see the stream.
380 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_3) {
381   MockDiverter* const stream =
382       CreateStream(kRenderProcessId, kRenderFrameId, 1);
383
384   const scoped_ptr<MockMirroringDestination> destination(
385       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
386   StartMirroringTo(destination, 1);
387   EXPECT_EQ(1, destination->query_count());
388   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
389
390   const scoped_ptr<MockMirroringDestination> replacement_destination(
391       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
392   StartMirroringTo(replacement_destination, 0);
393   EXPECT_EQ(1, destination->query_count());
394   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
395   EXPECT_EQ(0, replacement_destination->query_count());
396   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
397
398   KillStream(stream);
399   EXPECT_EQ(1, destination->query_count());
400   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
401   EXPECT_EQ(0, replacement_destination->query_count());
402   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
403
404   StopMirroringTo(destination);
405   EXPECT_EQ(1, destination->query_count());
406   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
407   EXPECT_EQ(0, replacement_destination->query_count());
408   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
409
410   StopMirroringTo(replacement_destination);
411   EXPECT_EQ(1, destination->query_count());
412   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
413   EXPECT_EQ(0, replacement_destination->query_count());
414   EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
415
416   ExpectNoLongerManagingAnything();
417 }
418
419 // Tests that multiple streams are diverted/mixed to one destination.
420 TEST_F(AudioMirroringManagerTest, MultipleStreamsInOneMirroringSession) {
421   MockDiverter* const stream1 =
422       CreateStream(kRenderProcessId, kRenderFrameId, 1);
423
424   const scoped_ptr<MockMirroringDestination> destination(
425       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
426   StartMirroringTo(destination, 3);
427   EXPECT_EQ(1, destination->query_count());
428   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
429
430   MockDiverter* const stream2 =
431       CreateStream(kRenderProcessId, kRenderFrameId, 1);
432   EXPECT_EQ(2, destination->query_count());
433   EXPECT_EQ(2, CountStreamsDivertedTo(destination));
434
435   MockDiverter* const stream3 =
436       CreateStream(kRenderProcessId, kRenderFrameId, 1);
437   EXPECT_EQ(3, destination->query_count());
438   EXPECT_EQ(3, CountStreamsDivertedTo(destination));
439
440   KillStream(stream2);
441   EXPECT_EQ(3, destination->query_count());
442   EXPECT_EQ(2, CountStreamsDivertedTo(destination));
443
444   StopMirroringTo(destination);
445   EXPECT_EQ(3, destination->query_count());
446   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
447
448   KillStream(stream3);
449   EXPECT_EQ(3, destination->query_count());
450   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
451
452   KillStream(stream1);
453   EXPECT_EQ(3, destination->query_count());
454   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
455
456   ExpectNoLongerManagingAnything();
457 }
458
459 // A random interleaving of operations for three separate targets, each of which
460 // has one stream mirrored to one destination.
461 TEST_F(AudioMirroringManagerTest, ThreeSeparateMirroringSessions) {
462   MockDiverter* const stream =
463       CreateStream(kRenderProcessId, kRenderFrameId, 1);
464
465   const scoped_ptr<MockMirroringDestination> destination(
466       new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
467   StartMirroringTo(destination, 1);
468   EXPECT_EQ(1, destination->query_count());
469   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
470
471   const scoped_ptr<MockMirroringDestination> another_destination(
472       new MockMirroringDestination(kAnotherRenderProcessId,
473                                    kAnotherRenderFrameId));
474   StartMirroringTo(another_destination, 1);
475   EXPECT_EQ(1, destination->query_count());
476   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
477   EXPECT_EQ(0, another_destination->query_count());
478   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
479
480   MockDiverter* const another_stream =
481       CreateStream(kAnotherRenderProcessId, kAnotherRenderFrameId, 1);
482   EXPECT_EQ(2, destination->query_count());
483   EXPECT_EQ(1, CountStreamsDivertedTo(destination));
484   EXPECT_EQ(1, another_destination->query_count());
485   EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
486
487   KillStream(stream);
488   EXPECT_EQ(2, destination->query_count());
489   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
490   EXPECT_EQ(1, another_destination->query_count());
491   EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
492
493   MockDiverter* const yet_another_stream =
494       CreateStream(kYetAnotherRenderProcessId, kYetAnotherRenderFrameId, 1);
495   EXPECT_EQ(3, destination->query_count());
496   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
497   EXPECT_EQ(2, another_destination->query_count());
498   EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
499
500   const scoped_ptr<MockMirroringDestination> yet_another_destination(
501       new MockMirroringDestination(kYetAnotherRenderProcessId,
502                                    kYetAnotherRenderFrameId));
503   StartMirroringTo(yet_another_destination, 1);
504   EXPECT_EQ(3, destination->query_count());
505   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
506   EXPECT_EQ(2, another_destination->query_count());
507   EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
508   EXPECT_EQ(1, yet_another_destination->query_count());
509   EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination));
510
511   StopMirroringTo(another_destination);
512   EXPECT_EQ(4, destination->query_count());
513   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
514   EXPECT_EQ(2, another_destination->query_count());
515   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
516   EXPECT_EQ(2, yet_another_destination->query_count());
517   EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination));
518
519   StopMirroringTo(yet_another_destination);
520   EXPECT_EQ(5, destination->query_count());
521   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
522   EXPECT_EQ(2, another_destination->query_count());
523   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
524   EXPECT_EQ(2, yet_another_destination->query_count());
525   EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
526
527   StopMirroringTo(destination);
528   EXPECT_EQ(5, destination->query_count());
529   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
530   EXPECT_EQ(2, another_destination->query_count());
531   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
532   EXPECT_EQ(2, yet_another_destination->query_count());
533   EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
534
535   KillStream(another_stream);
536   EXPECT_EQ(5, destination->query_count());
537   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
538   EXPECT_EQ(2, another_destination->query_count());
539   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
540   EXPECT_EQ(2, yet_another_destination->query_count());
541   EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
542
543   KillStream(yet_another_stream);
544   EXPECT_EQ(5, destination->query_count());
545   EXPECT_EQ(0, CountStreamsDivertedTo(destination));
546   EXPECT_EQ(2, another_destination->query_count());
547   EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
548   EXPECT_EQ(2, yet_another_destination->query_count());
549   EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
550
551   ExpectNoLongerManagingAnything();
552 }
553
554 }  // namespace content