| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/scoped_task_environment.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "content/renderer/media/webrtc/media_stream_track_metrics.h" | 11 #include "content/renderer/media/webrtc/media_stream_track_metrics.h" |
| 12 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 12 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/webrtc/api/mediastreaminterface.h" | 15 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 16 | 16 |
| 17 using webrtc::AudioSourceInterface; | 17 using webrtc::AudioSourceInterface; |
| 18 using webrtc::AudioTrackInterface; | 18 using webrtc::AudioTrackInterface; |
| 19 using webrtc::AudioTrackSinkInterface; | 19 using webrtc::AudioTrackSinkInterface; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 virtual ~MockMediaStreamTrackMetrics() {} | 78 virtual ~MockMediaStreamTrackMetrics() {} |
| 79 | 79 |
| 80 MOCK_METHOD4(SendLifetimeMessage, | 80 MOCK_METHOD4(SendLifetimeMessage, |
| 81 void(const std::string&, TrackType, LifetimeEvent, StreamType)); | 81 void(const std::string&, TrackType, LifetimeEvent, StreamType)); |
| 82 | 82 |
| 83 using MediaStreamTrackMetrics::MakeUniqueIdImpl; | 83 using MediaStreamTrackMetrics::MakeUniqueIdImpl; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class MediaStreamTrackMetricsTest : public testing::Test { | 86 class MediaStreamTrackMetricsTest : public testing::Test { |
| 87 public: | 87 public: |
| 88 MediaStreamTrackMetricsTest() : signaling_thread_("signaling_thread") {} | 88 MediaStreamTrackMetricsTest() |
| 89 : scoped_task_environment_( |
| 90 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 91 signaling_thread_("signaling_thread") {} |
| 92 |
| 89 void SetUp() override { | 93 void SetUp() override { |
| 90 metrics_.reset(new MockMediaStreamTrackMetrics()); | 94 metrics_.reset(new MockMediaStreamTrackMetrics()); |
| 91 stream_ = new rtc::RefCountedObject<MockMediaStream>("stream"); | 95 stream_ = new rtc::RefCountedObject<MockMediaStream>("stream"); |
| 92 signaling_thread_.Start(); | 96 signaling_thread_.Start(); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void TearDown() override { | 99 void TearDown() override { |
| 96 signaling_thread_.Stop(); | 100 signaling_thread_.Stop(); |
| 97 metrics_.reset(); | 101 metrics_.reset(); |
| 98 stream_ = NULL; | 102 stream_ = NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return new rtc::RefCountedObject<MockAudioTrackInterface>(id); | 143 return new rtc::RefCountedObject<MockAudioTrackInterface>(id); |
| 140 } | 144 } |
| 141 | 145 |
| 142 scoped_refptr<MockVideoTrackInterface> MakeVideoTrack(const std::string& id) { | 146 scoped_refptr<MockVideoTrackInterface> MakeVideoTrack(const std::string& id) { |
| 143 return new rtc::RefCountedObject<MockVideoTrackInterface>(id); | 147 return new rtc::RefCountedObject<MockVideoTrackInterface>(id); |
| 144 } | 148 } |
| 145 | 149 |
| 146 std::unique_ptr<MockMediaStreamTrackMetrics> metrics_; | 150 std::unique_ptr<MockMediaStreamTrackMetrics> metrics_; |
| 147 scoped_refptr<MediaStreamInterface> stream_; | 151 scoped_refptr<MediaStreamInterface> stream_; |
| 148 | 152 |
| 149 base::MessageLoopForUI message_loop_; | 153 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 150 base::Thread signaling_thread_; | 154 base::Thread signaling_thread_; |
| 151 }; | 155 }; |
| 152 | 156 |
| 153 TEST_F(MediaStreamTrackMetricsTest, MakeUniqueId) { | 157 TEST_F(MediaStreamTrackMetricsTest, MakeUniqueId) { |
| 154 // The important testable properties of the unique ID are that it | 158 // The important testable properties of the unique ID are that it |
| 155 // should differ when any of the three constituents differ | 159 // should differ when any of the three constituents differ |
| 156 // (PeerConnection pointer, track ID, remote or not. Also, testing | 160 // (PeerConnection pointer, track ID, remote or not. Also, testing |
| 157 // that the implementation does not discard the upper 32 bits of the | 161 // that the implementation does not discard the upper 32 bits of the |
| 158 // PeerConnection pointer is important. | 162 // PeerConnection pointer is important. |
| 159 // | 163 // |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 MediaStreamTrackMetrics::SENT_STREAM)); | 588 MediaStreamTrackMetrics::SENT_STREAM)); |
| 585 EXPECT_CALL(*metrics_, | 589 EXPECT_CALL(*metrics_, |
| 586 SendLifetimeMessage("video3", | 590 SendLifetimeMessage("video3", |
| 587 MediaStreamTrackMetrics::VIDEO_TRACK, | 591 MediaStreamTrackMetrics::VIDEO_TRACK, |
| 588 MediaStreamTrackMetrics::DISCONNECTED, | 592 MediaStreamTrackMetrics::DISCONNECTED, |
| 589 MediaStreamTrackMetrics::SENT_STREAM)); | 593 MediaStreamTrackMetrics::SENT_STREAM)); |
| 590 metrics_->RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, stream_.get()); | 594 metrics_->RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, stream_.get()); |
| 591 } | 595 } |
| 592 | 596 |
| 593 } // namespace content | 597 } // namespace content |
| OLD | NEW |