1 // Copyright 2014 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.
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "base/threading/thread.h"
9 #include "content/renderer/media/webrtc/media_stream_track_metrics.h"
10 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
15 using webrtc::AudioSourceInterface
;
16 using webrtc::AudioTrackInterface
;
17 using webrtc::AudioTrackSinkInterface
;
18 using webrtc::MediaStreamInterface
;
19 using webrtc::ObserverInterface
;
20 using webrtc::PeerConnectionInterface
;
21 using webrtc::VideoRendererInterface
;
22 using webrtc::VideoSourceInterface
;
23 using webrtc::VideoTrackInterface
;
27 // A very simple mock that implements only the id() method.
28 class MockAudioTrackInterface
: public AudioTrackInterface
{
30 explicit MockAudioTrackInterface(const std::string
& id
) : id_(id
) {}
31 virtual ~MockAudioTrackInterface() {}
33 virtual std::string
id() const override
{ return id_
; }
35 MOCK_METHOD1(RegisterObserver
, void(ObserverInterface
*));
36 MOCK_METHOD1(UnregisterObserver
, void(ObserverInterface
*));
37 MOCK_CONST_METHOD0(kind
, std::string());
38 MOCK_CONST_METHOD0(enabled
, bool());
39 MOCK_CONST_METHOD0(state
, TrackState());
40 MOCK_METHOD1(set_enabled
, bool(bool));
41 MOCK_METHOD1(set_state
, bool(TrackState
));
42 MOCK_CONST_METHOD0(GetSource
, AudioSourceInterface
*());
43 MOCK_METHOD1(AddSink
, void(AudioTrackSinkInterface
*));
44 MOCK_METHOD1(RemoveSink
, void(AudioTrackSinkInterface
*));
50 // A very simple mock that implements only the id() method.
51 class MockVideoTrackInterface
: public VideoTrackInterface
{
53 explicit MockVideoTrackInterface(const std::string
& id
) : id_(id
) {}
54 virtual ~MockVideoTrackInterface() {}
56 virtual std::string
id() const override
{ return id_
; }
58 MOCK_METHOD1(RegisterObserver
, void(ObserverInterface
*));
59 MOCK_METHOD1(UnregisterObserver
, void(ObserverInterface
*));
60 MOCK_CONST_METHOD0(kind
, std::string());
61 MOCK_CONST_METHOD0(enabled
, bool());
62 MOCK_CONST_METHOD0(state
, TrackState());
63 MOCK_METHOD1(set_enabled
, bool(bool));
64 MOCK_METHOD1(set_state
, bool(TrackState
));
65 MOCK_METHOD1(AddRenderer
, void(VideoRendererInterface
*));
66 MOCK_METHOD1(RemoveRenderer
, void(VideoRendererInterface
*));
67 MOCK_CONST_METHOD0(GetSource
, VideoSourceInterface
*());
73 class MockMediaStreamTrackMetrics
: public MediaStreamTrackMetrics
{
75 virtual ~MockMediaStreamTrackMetrics() {}
77 MOCK_METHOD4(SendLifetimeMessage
,
78 void(const std::string
&, TrackType
, LifetimeEvent
, StreamType
));
80 using MediaStreamTrackMetrics::MakeUniqueIdImpl
;
83 class MediaStreamTrackMetricsTest
: public testing::Test
{
85 MediaStreamTrackMetricsTest() : signaling_thread_("signaling_thread") {}
86 void SetUp() override
{
87 metrics_
.reset(new MockMediaStreamTrackMetrics());
88 stream_
= new rtc::RefCountedObject
<MockMediaStream
>("stream");
89 signaling_thread_
.Start();
92 void TearDown() override
{
93 signaling_thread_
.Stop();
98 // Adds an audio track to |stream_| on the signaling thread to simulate how
99 // notifications will be fired in Chrome.
100 template <typename TrackType
>
101 void AddTrack(TrackType
* track
) {
102 // Explicitly casting to this type is necessary since the
103 // MediaStreamInterface has two methods with the same name.
104 typedef bool (MediaStreamInterface::*AddTrack
)(TrackType
*);
105 base::RunLoop run_loop
;
106 signaling_thread_
.task_runner()->PostTaskAndReply(FROM_HERE
,
108 base::IgnoreResult
<AddTrack
>(&MediaStreamInterface::AddTrack
),
110 run_loop
.QuitClosure());
114 template <typename TrackType
>
115 void RemoveTrack(TrackType
* track
) {
116 // Explicitly casting to this type is necessary since the
117 // MediaStreamInterface has two methods with the same name.
118 typedef bool (MediaStreamInterface::*RemoveTrack
)(TrackType
*);
119 base::RunLoop run_loop
;
120 signaling_thread_
.task_runner()->PostTaskAndReply(FROM_HERE
,
122 base::IgnoreResult
<RemoveTrack
>(&MediaStreamInterface::RemoveTrack
),
124 run_loop
.QuitClosure());
128 // Convenience methods to cast the mock track types into their webrtc
130 void AddAudioTrack(AudioTrackInterface
* track
) { AddTrack(track
); }
131 void RemoveAudioTrack(AudioTrackInterface
* track
) { RemoveTrack(track
); }
132 void AddVideoTrack(VideoTrackInterface
* track
) { AddTrack(track
); }
133 void RemoveVideoTrack(VideoTrackInterface
* track
) { RemoveTrack(track
); }
135 scoped_refptr
<MockAudioTrackInterface
> MakeAudioTrack(std::string id
) {
136 return new rtc::RefCountedObject
<MockAudioTrackInterface
>(id
);
139 scoped_refptr
<MockVideoTrackInterface
> MakeVideoTrack(std::string id
) {
140 return new rtc::RefCountedObject
<MockVideoTrackInterface
>(id
);
143 scoped_ptr
<MockMediaStreamTrackMetrics
> metrics_
;
144 scoped_refptr
<MediaStreamInterface
> stream_
;
146 base::MessageLoopForUI message_loop_
;
147 base::Thread signaling_thread_
;
150 TEST_F(MediaStreamTrackMetricsTest
, MakeUniqueId
) {
151 // The important testable properties of the unique ID are that it
152 // should differ when any of the three constituents differ
153 // (PeerConnection pointer, track ID, remote or not. Also, testing
154 // that the implementation does not discard the upper 32 bits of the
155 // PeerConnection pointer is important.
157 // The important hard-to-test property is that the ID be generated
158 // using a hash function with virtually zero chance of
159 // collisions. We don't test this, we rely on MD5 having this
162 // Lower 32 bits the same, upper 32 differ.
164 metrics_
->MakeUniqueIdImpl(
165 0x1000000000000001, "x", MediaStreamTrackMetrics::RECEIVED_STREAM
),
166 metrics_
->MakeUniqueIdImpl(
167 0x2000000000000001, "x", MediaStreamTrackMetrics::RECEIVED_STREAM
));
170 EXPECT_NE(metrics_
->MakeUniqueIdImpl(
171 42, "x", MediaStreamTrackMetrics::RECEIVED_STREAM
),
172 metrics_
->MakeUniqueIdImpl(
173 42, "y", MediaStreamTrackMetrics::RECEIVED_STREAM
));
175 // Remove vs. local track differs.
176 EXPECT_NE(metrics_
->MakeUniqueIdImpl(
177 42, "x", MediaStreamTrackMetrics::RECEIVED_STREAM
),
178 metrics_
->MakeUniqueIdImpl(
179 42, "x", MediaStreamTrackMetrics::SENT_STREAM
));
182 TEST_F(MediaStreamTrackMetricsTest
, BasicRemoteStreams
) {
183 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
184 scoped_refptr
<MockVideoTrackInterface
> video(MakeVideoTrack("video"));
185 stream_
->AddTrack(audio
.get());
186 stream_
->AddTrack(video
.get());
187 metrics_
->AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM
, stream_
.get());
189 EXPECT_CALL(*metrics_
,
190 SendLifetimeMessage("audio",
191 MediaStreamTrackMetrics::AUDIO_TRACK
,
192 MediaStreamTrackMetrics::CONNECTED
,
193 MediaStreamTrackMetrics::RECEIVED_STREAM
));
194 EXPECT_CALL(*metrics_
,
195 SendLifetimeMessage("video",
196 MediaStreamTrackMetrics::VIDEO_TRACK
,
197 MediaStreamTrackMetrics::CONNECTED
,
198 MediaStreamTrackMetrics::RECEIVED_STREAM
));
199 metrics_
->IceConnectionChange(
200 PeerConnectionInterface::kIceConnectionConnected
);
202 EXPECT_CALL(*metrics_
,
203 SendLifetimeMessage("audio",
204 MediaStreamTrackMetrics::AUDIO_TRACK
,
205 MediaStreamTrackMetrics::DISCONNECTED
,
206 MediaStreamTrackMetrics::RECEIVED_STREAM
));
207 EXPECT_CALL(*metrics_
,
208 SendLifetimeMessage("video",
209 MediaStreamTrackMetrics::VIDEO_TRACK
,
210 MediaStreamTrackMetrics::DISCONNECTED
,
211 MediaStreamTrackMetrics::RECEIVED_STREAM
));
212 metrics_
->IceConnectionChange(
213 PeerConnectionInterface::kIceConnectionDisconnected
);
216 TEST_F(MediaStreamTrackMetricsTest
, BasicLocalStreams
) {
217 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
218 scoped_refptr
<MockVideoTrackInterface
> video(MakeVideoTrack("video"));
219 stream_
->AddTrack(audio
.get());
220 stream_
->AddTrack(video
.get());
221 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
223 EXPECT_CALL(*metrics_
,
224 SendLifetimeMessage("audio",
225 MediaStreamTrackMetrics::AUDIO_TRACK
,
226 MediaStreamTrackMetrics::CONNECTED
,
227 MediaStreamTrackMetrics::SENT_STREAM
));
228 EXPECT_CALL(*metrics_
,
229 SendLifetimeMessage("video",
230 MediaStreamTrackMetrics::VIDEO_TRACK
,
231 MediaStreamTrackMetrics::CONNECTED
,
232 MediaStreamTrackMetrics::SENT_STREAM
));
233 metrics_
->IceConnectionChange(
234 PeerConnectionInterface::kIceConnectionConnected
);
236 EXPECT_CALL(*metrics_
,
237 SendLifetimeMessage("audio",
238 MediaStreamTrackMetrics::AUDIO_TRACK
,
239 MediaStreamTrackMetrics::DISCONNECTED
,
240 MediaStreamTrackMetrics::SENT_STREAM
));
241 EXPECT_CALL(*metrics_
,
242 SendLifetimeMessage("video",
243 MediaStreamTrackMetrics::VIDEO_TRACK
,
244 MediaStreamTrackMetrics::DISCONNECTED
,
245 MediaStreamTrackMetrics::SENT_STREAM
));
246 metrics_
->IceConnectionChange(PeerConnectionInterface::kIceConnectionFailed
);
249 TEST_F(MediaStreamTrackMetricsTest
, LocalStreamAddedAferIceConnect
) {
250 metrics_
->IceConnectionChange(
251 PeerConnectionInterface::kIceConnectionConnected
);
253 EXPECT_CALL(*metrics_
,
254 SendLifetimeMessage("audio",
255 MediaStreamTrackMetrics::AUDIO_TRACK
,
256 MediaStreamTrackMetrics::CONNECTED
,
257 MediaStreamTrackMetrics::SENT_STREAM
));
258 EXPECT_CALL(*metrics_
,
259 SendLifetimeMessage("video",
260 MediaStreamTrackMetrics::VIDEO_TRACK
,
261 MediaStreamTrackMetrics::CONNECTED
,
262 MediaStreamTrackMetrics::SENT_STREAM
));
264 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
265 scoped_refptr
<MockVideoTrackInterface
> video(MakeVideoTrack("video"));
266 stream_
->AddTrack(audio
.get());
267 stream_
->AddTrack(video
.get());
268 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
271 TEST_F(MediaStreamTrackMetricsTest
, RemoteStreamAddedAferIceConnect
) {
272 metrics_
->IceConnectionChange(
273 PeerConnectionInterface::kIceConnectionConnected
);
275 EXPECT_CALL(*metrics_
,
276 SendLifetimeMessage("audio",
277 MediaStreamTrackMetrics::AUDIO_TRACK
,
278 MediaStreamTrackMetrics::CONNECTED
,
279 MediaStreamTrackMetrics::RECEIVED_STREAM
));
280 EXPECT_CALL(*metrics_
,
281 SendLifetimeMessage("video",
282 MediaStreamTrackMetrics::VIDEO_TRACK
,
283 MediaStreamTrackMetrics::CONNECTED
,
284 MediaStreamTrackMetrics::RECEIVED_STREAM
));
286 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
287 scoped_refptr
<MockVideoTrackInterface
> video(MakeVideoTrack("video"));
288 stream_
->AddTrack(audio
.get());
289 stream_
->AddTrack(video
.get());
290 metrics_
->AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM
, stream_
.get());
293 TEST_F(MediaStreamTrackMetricsTest
, RemoteStreamTrackAdded
) {
294 scoped_refptr
<MockAudioTrackInterface
> initial(MakeAudioTrack("initial"));
295 scoped_refptr
<MockAudioTrackInterface
> added(MakeAudioTrack("added"));
296 stream_
->AddTrack(initial
.get());
297 metrics_
->AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM
, stream_
.get());
299 EXPECT_CALL(*metrics_
,
300 SendLifetimeMessage("initial",
301 MediaStreamTrackMetrics::AUDIO_TRACK
,
302 MediaStreamTrackMetrics::CONNECTED
,
303 MediaStreamTrackMetrics::RECEIVED_STREAM
));
304 metrics_
->IceConnectionChange(
305 PeerConnectionInterface::kIceConnectionConnected
);
307 EXPECT_CALL(*metrics_
,
308 SendLifetimeMessage("added",
309 MediaStreamTrackMetrics::AUDIO_TRACK
,
310 MediaStreamTrackMetrics::CONNECTED
,
311 MediaStreamTrackMetrics::RECEIVED_STREAM
));
312 AddAudioTrack(added
.get());
314 EXPECT_CALL(*metrics_
,
315 SendLifetimeMessage("initial",
316 MediaStreamTrackMetrics::AUDIO_TRACK
,
317 MediaStreamTrackMetrics::DISCONNECTED
,
318 MediaStreamTrackMetrics::RECEIVED_STREAM
));
319 EXPECT_CALL(*metrics_
,
320 SendLifetimeMessage("added",
321 MediaStreamTrackMetrics::AUDIO_TRACK
,
322 MediaStreamTrackMetrics::DISCONNECTED
,
323 MediaStreamTrackMetrics::RECEIVED_STREAM
));
324 metrics_
->IceConnectionChange(PeerConnectionInterface::kIceConnectionFailed
);
327 TEST_F(MediaStreamTrackMetricsTest
, LocalStreamTrackRemoved
) {
328 scoped_refptr
<MockAudioTrackInterface
> first(MakeAudioTrack("first"));
329 scoped_refptr
<MockAudioTrackInterface
> second(MakeAudioTrack("second"));
330 stream_
->AddTrack(first
.get());
331 stream_
->AddTrack(second
.get());
332 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
334 EXPECT_CALL(*metrics_
,
335 SendLifetimeMessage("first",
336 MediaStreamTrackMetrics::AUDIO_TRACK
,
337 MediaStreamTrackMetrics::CONNECTED
,
338 MediaStreamTrackMetrics::SENT_STREAM
));
339 EXPECT_CALL(*metrics_
,
340 SendLifetimeMessage("second",
341 MediaStreamTrackMetrics::AUDIO_TRACK
,
342 MediaStreamTrackMetrics::CONNECTED
,
343 MediaStreamTrackMetrics::SENT_STREAM
));
344 metrics_
->IceConnectionChange(
345 PeerConnectionInterface::kIceConnectionConnected
);
347 EXPECT_CALL(*metrics_
,
348 SendLifetimeMessage("first",
349 MediaStreamTrackMetrics::AUDIO_TRACK
,
350 MediaStreamTrackMetrics::DISCONNECTED
,
351 MediaStreamTrackMetrics::SENT_STREAM
));
352 stream_
->RemoveTrack(first
.get());
354 EXPECT_CALL(*metrics_
,
355 SendLifetimeMessage("second",
356 MediaStreamTrackMetrics::AUDIO_TRACK
,
357 MediaStreamTrackMetrics::DISCONNECTED
,
358 MediaStreamTrackMetrics::SENT_STREAM
));
359 metrics_
->IceConnectionChange(PeerConnectionInterface::kIceConnectionFailed
);
362 TEST_F(MediaStreamTrackMetricsTest
, LocalStreamModificationsBeforeAndAfter
) {
363 scoped_refptr
<MockAudioTrackInterface
> first(MakeAudioTrack("first"));
364 scoped_refptr
<MockAudioTrackInterface
> second(MakeAudioTrack("second"));
365 stream_
->AddTrack(first
.get());
366 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
368 // This gets added after we start observing, but no lifetime message
369 // should be sent at this point since the call is not connected. It
370 // should get sent only once it gets connected.
371 AddAudioTrack(second
.get());
373 EXPECT_CALL(*metrics_
,
374 SendLifetimeMessage("first",
375 MediaStreamTrackMetrics::AUDIO_TRACK
,
376 MediaStreamTrackMetrics::CONNECTED
,
377 MediaStreamTrackMetrics::SENT_STREAM
));
378 EXPECT_CALL(*metrics_
,
379 SendLifetimeMessage("second",
380 MediaStreamTrackMetrics::AUDIO_TRACK
,
381 MediaStreamTrackMetrics::CONNECTED
,
382 MediaStreamTrackMetrics::SENT_STREAM
));
383 metrics_
->IceConnectionChange(
384 PeerConnectionInterface::kIceConnectionConnected
);
386 EXPECT_CALL(*metrics_
,
387 SendLifetimeMessage("first",
388 MediaStreamTrackMetrics::AUDIO_TRACK
,
389 MediaStreamTrackMetrics::DISCONNECTED
,
390 MediaStreamTrackMetrics::SENT_STREAM
));
391 EXPECT_CALL(*metrics_
,
392 SendLifetimeMessage("second",
393 MediaStreamTrackMetrics::AUDIO_TRACK
,
394 MediaStreamTrackMetrics::DISCONNECTED
,
395 MediaStreamTrackMetrics::SENT_STREAM
));
396 metrics_
->IceConnectionChange(PeerConnectionInterface::kIceConnectionFailed
);
398 // This happens after the call is disconnected so no lifetime
399 // message should be sent.
400 RemoveAudioTrack(first
.get());
403 TEST_F(MediaStreamTrackMetricsTest
, RemoteStreamMultipleDisconnects
) {
404 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
405 stream_
->AddTrack(audio
.get());
406 metrics_
->AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM
, stream_
.get());
408 EXPECT_CALL(*metrics_
,
409 SendLifetimeMessage("audio",
410 MediaStreamTrackMetrics::AUDIO_TRACK
,
411 MediaStreamTrackMetrics::CONNECTED
,
412 MediaStreamTrackMetrics::RECEIVED_STREAM
));
413 metrics_
->IceConnectionChange(
414 PeerConnectionInterface::kIceConnectionConnected
);
416 EXPECT_CALL(*metrics_
,
417 SendLifetimeMessage("audio",
418 MediaStreamTrackMetrics::AUDIO_TRACK
,
419 MediaStreamTrackMetrics::DISCONNECTED
,
420 MediaStreamTrackMetrics::RECEIVED_STREAM
));
421 metrics_
->IceConnectionChange(
422 PeerConnectionInterface::kIceConnectionDisconnected
);
423 metrics_
->IceConnectionChange(PeerConnectionInterface::kIceConnectionFailed
);
424 RemoveAudioTrack(audio
.get());
427 TEST_F(MediaStreamTrackMetricsTest
, RemoteStreamConnectDisconnectTwice
) {
428 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
429 stream_
->AddTrack(audio
.get());
430 metrics_
->AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM
, stream_
.get());
432 for (size_t i
= 0; i
< 2; ++i
) {
433 EXPECT_CALL(*metrics_
,
434 SendLifetimeMessage("audio",
435 MediaStreamTrackMetrics::AUDIO_TRACK
,
436 MediaStreamTrackMetrics::CONNECTED
,
437 MediaStreamTrackMetrics::RECEIVED_STREAM
));
438 metrics_
->IceConnectionChange(
439 PeerConnectionInterface::kIceConnectionConnected
);
441 EXPECT_CALL(*metrics_
,
442 SendLifetimeMessage("audio",
443 MediaStreamTrackMetrics::AUDIO_TRACK
,
444 MediaStreamTrackMetrics::DISCONNECTED
,
445 MediaStreamTrackMetrics::RECEIVED_STREAM
));
446 metrics_
->IceConnectionChange(
447 PeerConnectionInterface::kIceConnectionDisconnected
);
450 RemoveAudioTrack(audio
.get());
453 TEST_F(MediaStreamTrackMetricsTest
, LocalStreamRemovedNoDisconnect
) {
454 scoped_refptr
<MockAudioTrackInterface
> audio(MakeAudioTrack("audio"));
455 scoped_refptr
<MockVideoTrackInterface
> video(MakeVideoTrack("video"));
456 stream_
->AddTrack(audio
.get());
457 stream_
->AddTrack(video
.get());
458 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
460 EXPECT_CALL(*metrics_
,
461 SendLifetimeMessage("audio",
462 MediaStreamTrackMetrics::AUDIO_TRACK
,
463 MediaStreamTrackMetrics::CONNECTED
,
464 MediaStreamTrackMetrics::SENT_STREAM
));
465 EXPECT_CALL(*metrics_
,
466 SendLifetimeMessage("video",
467 MediaStreamTrackMetrics::VIDEO_TRACK
,
468 MediaStreamTrackMetrics::CONNECTED
,
469 MediaStreamTrackMetrics::SENT_STREAM
));
470 metrics_
->IceConnectionChange(
471 PeerConnectionInterface::kIceConnectionConnected
);
473 EXPECT_CALL(*metrics_
,
474 SendLifetimeMessage("audio",
475 MediaStreamTrackMetrics::AUDIO_TRACK
,
476 MediaStreamTrackMetrics::DISCONNECTED
,
477 MediaStreamTrackMetrics::SENT_STREAM
));
478 EXPECT_CALL(*metrics_
,
479 SendLifetimeMessage("video",
480 MediaStreamTrackMetrics::VIDEO_TRACK
,
481 MediaStreamTrackMetrics::DISCONNECTED
,
482 MediaStreamTrackMetrics::SENT_STREAM
));
483 metrics_
->RemoveStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
486 TEST_F(MediaStreamTrackMetricsTest
, LocalStreamLargerTest
) {
487 scoped_refptr
<MockAudioTrackInterface
> audio1(MakeAudioTrack("audio1"));
488 scoped_refptr
<MockAudioTrackInterface
> audio2(MakeAudioTrack("audio2"));
489 scoped_refptr
<MockAudioTrackInterface
> audio3(MakeAudioTrack("audio3"));
490 scoped_refptr
<MockVideoTrackInterface
> video1(MakeVideoTrack("video1"));
491 scoped_refptr
<MockVideoTrackInterface
> video2(MakeVideoTrack("video2"));
492 scoped_refptr
<MockVideoTrackInterface
> video3(MakeVideoTrack("video3"));
493 stream_
->AddTrack(audio1
.get());
494 stream_
->AddTrack(video1
.get());
495 metrics_
->AddStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
497 EXPECT_CALL(*metrics_
,
498 SendLifetimeMessage("audio1",
499 MediaStreamTrackMetrics::AUDIO_TRACK
,
500 MediaStreamTrackMetrics::CONNECTED
,
501 MediaStreamTrackMetrics::SENT_STREAM
));
502 EXPECT_CALL(*metrics_
,
503 SendLifetimeMessage("video1",
504 MediaStreamTrackMetrics::VIDEO_TRACK
,
505 MediaStreamTrackMetrics::CONNECTED
,
506 MediaStreamTrackMetrics::SENT_STREAM
));
507 metrics_
->IceConnectionChange(
508 PeerConnectionInterface::kIceConnectionConnected
);
510 EXPECT_CALL(*metrics_
,
511 SendLifetimeMessage("audio2",
512 MediaStreamTrackMetrics::AUDIO_TRACK
,
513 MediaStreamTrackMetrics::CONNECTED
,
514 MediaStreamTrackMetrics::SENT_STREAM
));
515 AddAudioTrack(audio2
.get());
516 EXPECT_CALL(*metrics_
,
517 SendLifetimeMessage("video2",
518 MediaStreamTrackMetrics::VIDEO_TRACK
,
519 MediaStreamTrackMetrics::CONNECTED
,
520 MediaStreamTrackMetrics::SENT_STREAM
));
521 AddVideoTrack(video2
.get());
523 EXPECT_CALL(*metrics_
,
524 SendLifetimeMessage("audio1",
525 MediaStreamTrackMetrics::AUDIO_TRACK
,
526 MediaStreamTrackMetrics::DISCONNECTED
,
527 MediaStreamTrackMetrics::SENT_STREAM
));
528 RemoveAudioTrack(audio1
.get());
530 EXPECT_CALL(*metrics_
,
531 SendLifetimeMessage("audio3",
532 MediaStreamTrackMetrics::AUDIO_TRACK
,
533 MediaStreamTrackMetrics::CONNECTED
,
534 MediaStreamTrackMetrics::SENT_STREAM
));
535 AddAudioTrack(audio3
.get());
536 EXPECT_CALL(*metrics_
,
537 SendLifetimeMessage("video3",
538 MediaStreamTrackMetrics::VIDEO_TRACK
,
539 MediaStreamTrackMetrics::CONNECTED
,
540 MediaStreamTrackMetrics::SENT_STREAM
));
541 AddVideoTrack(video3
.get());
544 EXPECT_CALL(*metrics_
,
545 SendLifetimeMessage("audio1",
546 MediaStreamTrackMetrics::AUDIO_TRACK
,
547 MediaStreamTrackMetrics::CONNECTED
,
548 MediaStreamTrackMetrics::SENT_STREAM
));
549 AddAudioTrack(audio1
.get());
551 EXPECT_CALL(*metrics_
,
552 SendLifetimeMessage("audio2",
553 MediaStreamTrackMetrics::AUDIO_TRACK
,
554 MediaStreamTrackMetrics::DISCONNECTED
,
555 MediaStreamTrackMetrics::SENT_STREAM
));
556 RemoveAudioTrack(audio2
.get());
557 EXPECT_CALL(*metrics_
,
558 SendLifetimeMessage("video2",
559 MediaStreamTrackMetrics::VIDEO_TRACK
,
560 MediaStreamTrackMetrics::DISCONNECTED
,
561 MediaStreamTrackMetrics::SENT_STREAM
));
562 RemoveVideoTrack(video2
.get());
564 EXPECT_CALL(*metrics_
,
565 SendLifetimeMessage("audio1",
566 MediaStreamTrackMetrics::AUDIO_TRACK
,
567 MediaStreamTrackMetrics::DISCONNECTED
,
568 MediaStreamTrackMetrics::SENT_STREAM
));
569 RemoveAudioTrack(audio1
.get());
570 EXPECT_CALL(*metrics_
,
571 SendLifetimeMessage("video1",
572 MediaStreamTrackMetrics::VIDEO_TRACK
,
573 MediaStreamTrackMetrics::DISCONNECTED
,
574 MediaStreamTrackMetrics::SENT_STREAM
));
575 RemoveVideoTrack(video1
.get());
577 EXPECT_CALL(*metrics_
,
578 SendLifetimeMessage("audio3",
579 MediaStreamTrackMetrics::AUDIO_TRACK
,
580 MediaStreamTrackMetrics::DISCONNECTED
,
581 MediaStreamTrackMetrics::SENT_STREAM
));
582 EXPECT_CALL(*metrics_
,
583 SendLifetimeMessage("video3",
584 MediaStreamTrackMetrics::VIDEO_TRACK
,
585 MediaStreamTrackMetrics::DISCONNECTED
,
586 MediaStreamTrackMetrics::SENT_STREAM
));
587 metrics_
->RemoveStream(MediaStreamTrackMetrics::SENT_STREAM
, stream_
.get());
590 } // namespace content