Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/media/capture/audio_mirroring_manager.h" | 5 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 16 #include "media/audio/virtual_audio_sink.h" | |
|
miu
2016/05/06 22:29:49
You can remove this #include now that AudioPushSin
qiangchen
2016/05/10 22:36:52
Done.
| |
| 16 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using media::AudioOutputStream; | 21 using media::AudioOutputStream; |
| 21 using media::AudioParameters; | 22 using media::AudioParameters; |
| 23 using media::AudioPushSink; | |
| 22 using testing::_; | 24 using testing::_; |
| 23 using testing::Invoke; | 25 using testing::Invoke; |
| 24 using testing::NotNull; | 26 using testing::NotNull; |
| 25 using testing::Ref; | 27 using testing::Ref; |
| 26 using testing::Return; | 28 using testing::Return; |
| 27 using testing::ReturnRef; | 29 using testing::ReturnRef; |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 class MockDiverter : public AudioMirroringManager::Diverter { | 35 class MockDiverter : public AudioMirroringManager::Diverter { |
| 34 public: | 36 public: |
| 35 MOCK_METHOD0(GetAudioParameters, const AudioParameters&()); | 37 MOCK_METHOD0(GetAudioParameters, const AudioParameters&()); |
| 36 MOCK_METHOD1(StartDiverting, void(AudioOutputStream*)); | 38 MOCK_METHOD1(StartDiverting, void(AudioOutputStream*)); |
| 37 MOCK_METHOD0(StopDiverting, void()); | 39 MOCK_METHOD0(StopDiverting, void()); |
| 40 MOCK_METHOD1(StartDuplicating, void(AudioPushSink*)); | |
| 41 MOCK_METHOD1(StopDuplicating, void(AudioPushSink*)); | |
| 38 }; | 42 }; |
| 39 | 43 |
| 40 class MockMirroringDestination | 44 class MockMirroringDestination |
| 41 : public AudioMirroringManager::MirroringDestination { | 45 : public AudioMirroringManager::MirroringDestination { |
| 42 public: | 46 public: |
| 43 typedef AudioMirroringManager::SourceFrameRef SourceFrameRef; | 47 typedef AudioMirroringManager::SourceFrameRef SourceFrameRef; |
| 44 | 48 |
| 45 MockMirroringDestination(int render_process_id, int render_frame_id) | 49 MockMirroringDestination(int render_process_id, |
| 50 int render_frame_id, | |
| 51 bool is_duplication) | |
| 46 : render_process_id_(render_process_id), | 52 : render_process_id_(render_process_id), |
| 47 render_frame_id_(render_frame_id), | 53 render_frame_id_(render_frame_id), |
| 48 query_count_(0) {} | 54 query_count_(0), |
| 55 is_duplication_(is_duplication) {} | |
| 49 | 56 |
| 50 MOCK_METHOD2(QueryForMatches, | 57 MOCK_METHOD2(QueryForMatches, |
| 51 void(const std::set<SourceFrameRef>& candidates, | 58 void(const std::set<SourceFrameRef>& candidates, |
| 52 const MatchesCallback& results_callback)); | 59 const MatchesCallback& results_callback)); |
| 53 MOCK_METHOD1(AddInput, | 60 MOCK_METHOD1(AddInput, |
| 54 media::AudioOutputStream*(const media::AudioParameters& params)); | 61 media::AudioOutputStream*(const media::AudioParameters& params)); |
| 55 | 62 |
| 63 MOCK_METHOD1(AddPushInput, | |
| 64 media::AudioPushSink*(const media::AudioParameters& params)); | |
| 65 | |
| 56 void SimulateQuery(const std::set<SourceFrameRef>& candidates, | 66 void SimulateQuery(const std::set<SourceFrameRef>& candidates, |
| 57 const MatchesCallback& results_callback) { | 67 const MatchesCallback& results_callback) { |
| 58 ++query_count_; | 68 ++query_count_; |
| 59 | 69 |
| 60 std::set<SourceFrameRef> result; | 70 std::set<SourceFrameRef> result; |
| 61 if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) != | 71 if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) != |
| 62 candidates.end()) { | 72 candidates.end()) { |
| 63 result.insert(SourceFrameRef(render_process_id_, render_frame_id_)); | 73 result.insert(SourceFrameRef(render_process_id_, render_frame_id_)); |
| 64 } | 74 } |
| 65 results_callback.Run(result); | 75 results_callback.Run(result, is_duplication_); |
| 66 } | 76 } |
| 67 | 77 |
| 68 media::AudioOutputStream* SimulateAddInput( | 78 media::AudioOutputStream* SimulateAddInput( |
| 69 const media::AudioParameters& params) { | 79 const media::AudioParameters& params) { |
| 70 static AudioOutputStream* const kNonNullPointer = | 80 static AudioOutputStream* const kNonNullPointer = |
| 71 reinterpret_cast<AudioOutputStream*>(0x11111110); | 81 reinterpret_cast<AudioOutputStream*>(0x11111110); |
| 72 return kNonNullPointer; | 82 return kNonNullPointer; |
| 73 } | 83 } |
| 74 | 84 |
| 85 media::AudioPushSink* SimulateAddPushInput( | |
| 86 const media::AudioParameters& params) { | |
| 87 static AudioPushSink* const kNonNullPointer = | |
| 88 reinterpret_cast<AudioPushSink*>(0x11111110); | |
| 89 return kNonNullPointer; | |
| 90 } | |
| 91 | |
| 75 int query_count() const { | 92 int query_count() const { |
| 76 return query_count_; | 93 return query_count_; |
| 77 } | 94 } |
| 78 | 95 |
| 79 private: | 96 private: |
| 80 const int render_process_id_; | 97 const int render_process_id_; |
| 81 const int render_frame_id_; | 98 const int render_frame_id_; |
| 82 int query_count_; | 99 int query_count_; |
| 100 bool is_duplication_; | |
| 83 }; | 101 }; |
| 84 | 102 |
| 85 } // namespace | 103 } // namespace |
| 86 | 104 |
| 87 class AudioMirroringManagerTest : public testing::Test { | 105 class AudioMirroringManagerTest : public testing::Test { |
| 88 public: | 106 public: |
| 89 typedef AudioMirroringManager::Diverter Diverter; | 107 typedef AudioMirroringManager::Diverter Diverter; |
| 90 typedef AudioMirroringManager::MirroringDestination MirroringDestination; | 108 typedef AudioMirroringManager::MirroringDestination MirroringDestination; |
| 91 typedef AudioMirroringManager::StreamRoutes StreamRoutes; | 109 typedef AudioMirroringManager::StreamRoutes StreamRoutes; |
| 92 | 110 |
| 93 AudioMirroringManagerTest() | 111 AudioMirroringManagerTest() |
| 94 : io_thread_(BrowserThread::IO, &message_loop_), | 112 : io_thread_(BrowserThread::IO, &message_loop_), |
| 95 params_(AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO, | 113 params_(AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO, |
| 96 AudioParameters::kAudioCDSampleRate, 16, | 114 AudioParameters::kAudioCDSampleRate, 16, |
| 97 AudioParameters::kAudioCDSampleRate / 10) {} | 115 AudioParameters::kAudioCDSampleRate / 10) {} |
| 98 | 116 |
| 99 MockDiverter* CreateStream( | 117 MockDiverter* CreateStream(int render_process_id, |
| 100 int render_process_id, int render_frame_id, int expected_times_diverted) { | 118 int render_frame_id, |
| 119 int expected_times_diverted, | |
| 120 int expected_times_duplicated) { | |
| 101 MockDiverter* const diverter = new MockDiverter(); | 121 MockDiverter* const diverter = new MockDiverter(); |
| 122 | |
| 123 if (expected_times_diverted + expected_times_duplicated > 0) { | |
| 124 EXPECT_CALL(*diverter, GetAudioParameters()) | |
| 125 .Times(expected_times_diverted + expected_times_duplicated) | |
| 126 .WillRepeatedly(ReturnRef(params_)); | |
| 127 } | |
| 128 | |
| 102 if (expected_times_diverted > 0) { | 129 if (expected_times_diverted > 0) { |
| 103 EXPECT_CALL(*diverter, GetAudioParameters()) | |
| 104 .Times(expected_times_diverted) | |
| 105 .WillRepeatedly(ReturnRef(params_)); | |
| 106 EXPECT_CALL(*diverter, StartDiverting(NotNull())) | 130 EXPECT_CALL(*diverter, StartDiverting(NotNull())) |
| 107 .Times(expected_times_diverted); | 131 .Times(expected_times_diverted); |
| 108 EXPECT_CALL(*diverter, StopDiverting()) | 132 EXPECT_CALL(*diverter, StopDiverting()) |
| 109 .Times(expected_times_diverted); | 133 .Times(expected_times_diverted); |
| 110 } | 134 } |
| 111 | 135 |
| 136 if (expected_times_duplicated > 0) { | |
| 137 EXPECT_CALL(*diverter, StartDuplicating(NotNull())) | |
| 138 .Times(expected_times_duplicated); | |
| 139 EXPECT_CALL(*diverter, StopDuplicating(NotNull())) | |
| 140 .Times(expected_times_duplicated); | |
| 141 } | |
| 142 | |
| 112 mirroring_manager_.AddDiverter( | 143 mirroring_manager_.AddDiverter( |
| 113 render_process_id, render_frame_id, diverter); | 144 render_process_id, render_frame_id, diverter); |
| 114 | 145 |
| 115 return diverter; | 146 return diverter; |
| 116 } | 147 } |
| 117 | 148 |
| 118 void KillStream(MockDiverter* diverter) { | 149 void KillStream(MockDiverter* diverter) { |
| 119 mirroring_manager_.RemoveDiverter(diverter); | 150 mirroring_manager_.RemoveDiverter(diverter); |
| 120 delete diverter; | 151 delete diverter; |
| 121 } | 152 } |
| 122 | 153 |
| 123 void StartMirroringTo(const std::unique_ptr<MockMirroringDestination>& dest, | 154 void StartMirroringTo(const std::unique_ptr<MockMirroringDestination>& dest, |
| 124 int expected_inputs_added) { | 155 int expected_inputs_added, |
| 156 int expected_push_inputs_added) { | |
| 125 EXPECT_CALL(*dest, QueryForMatches(_, _)) | 157 EXPECT_CALL(*dest, QueryForMatches(_, _)) |
| 126 .WillRepeatedly(Invoke(dest.get(), | 158 .WillRepeatedly(Invoke(dest.get(), |
| 127 &MockMirroringDestination::SimulateQuery)); | 159 &MockMirroringDestination::SimulateQuery)); |
| 128 if (expected_inputs_added > 0) { | 160 if (expected_inputs_added > 0) { |
| 129 EXPECT_CALL(*dest, AddInput(Ref(params_))) | 161 EXPECT_CALL(*dest, AddInput(Ref(params_))) |
| 130 .Times(expected_inputs_added) | 162 .Times(expected_inputs_added) |
| 131 .WillRepeatedly(Invoke(dest.get(), | 163 .WillRepeatedly(Invoke(dest.get(), |
| 132 &MockMirroringDestination::SimulateAddInput)) | 164 &MockMirroringDestination::SimulateAddInput)) |
| 133 .RetiresOnSaturation(); | 165 .RetiresOnSaturation(); |
| 134 } | 166 } |
| 135 | 167 |
| 168 if (expected_push_inputs_added > 0) { | |
| 169 EXPECT_CALL(*dest, AddPushInput(Ref(params_))) | |
| 170 .Times(expected_push_inputs_added) | |
| 171 .WillRepeatedly(Invoke( | |
| 172 dest.get(), &MockMirroringDestination::SimulateAddPushInput)) | |
| 173 .RetiresOnSaturation(); | |
| 174 } | |
| 175 | |
| 136 mirroring_manager_.StartMirroring(dest.get()); | 176 mirroring_manager_.StartMirroring(dest.get()); |
| 137 } | 177 } |
| 138 | 178 |
| 139 void StopMirroringTo(const std::unique_ptr<MockMirroringDestination>& dest) { | 179 void StopMirroringTo(const std::unique_ptr<MockMirroringDestination>& dest) { |
| 140 mirroring_manager_.StopMirroring(dest.get()); | 180 mirroring_manager_.StopMirroring(dest.get()); |
| 141 } | 181 } |
| 142 | 182 |
| 143 int CountStreamsDivertedTo( | 183 int CountStreamsDivertedTo( |
| 144 const std::unique_ptr<MockMirroringDestination>& dest) const { | 184 const std::unique_ptr<MockMirroringDestination>& dest) const { |
| 145 int count = 0; | 185 int count = 0; |
| 146 for (StreamRoutes::const_iterator it = mirroring_manager_.routes_.begin(); | 186 for (StreamRoutes::const_iterator it = mirroring_manager_.routes_.begin(); |
| 147 it != mirroring_manager_.routes_.end(); ++it) { | 187 it != mirroring_manager_.routes_.end(); ++it) { |
| 148 if (it->destination == dest.get()) | 188 if (it->destination == dest.get()) |
| 149 ++count; | 189 ++count; |
| 150 } | 190 } |
| 151 return count; | 191 return count; |
| 152 } | 192 } |
| 153 | 193 |
| 194 int CountStreamsDuplicatedTo( | |
| 195 const std::unique_ptr<MockMirroringDestination>& dest) const { | |
| 196 int count = 0; | |
| 197 for (StreamRoutes::const_iterator it = mirroring_manager_.routes_.begin(); | |
| 198 it != mirroring_manager_.routes_.end(); ++it) { | |
| 199 if (it->duplications.find(dest.get()) != it->duplications.end()) | |
| 200 ++count; | |
| 201 } | |
| 202 return count; | |
| 203 } | |
| 204 | |
| 154 void ExpectNoLongerManagingAnything() const { | 205 void ExpectNoLongerManagingAnything() const { |
| 155 EXPECT_TRUE(mirroring_manager_.routes_.empty()); | 206 EXPECT_TRUE(mirroring_manager_.routes_.empty()); |
| 156 EXPECT_TRUE(mirroring_manager_.sessions_.empty()); | 207 EXPECT_TRUE(mirroring_manager_.sessions_.empty()); |
| 157 } | 208 } |
| 158 | 209 |
| 159 private: | 210 private: |
| 160 base::MessageLoopForIO message_loop_; | 211 base::MessageLoopForIO message_loop_; |
| 161 BrowserThreadImpl io_thread_; | 212 BrowserThreadImpl io_thread_; |
| 162 AudioParameters params_; | 213 AudioParameters params_; |
| 163 AudioMirroringManager mirroring_manager_; | 214 AudioMirroringManager mirroring_manager_; |
| 164 | 215 |
| 165 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManagerTest); | 216 DISALLOW_COPY_AND_ASSIGN(AudioMirroringManagerTest); |
| 166 }; | 217 }; |
| 167 | 218 |
| 168 namespace { | 219 namespace { |
| 169 const int kRenderProcessId = 123; | 220 const int kRenderProcessId = 123; |
| 170 const int kRenderFrameId = 456; | 221 const int kRenderFrameId = 456; |
| 171 const int kAnotherRenderProcessId = 789; | 222 const int kAnotherRenderProcessId = 789; |
| 172 const int kAnotherRenderFrameId = 1234; | 223 const int kAnotherRenderFrameId = 1234; |
| 173 const int kYetAnotherRenderProcessId = 4560; | 224 const int kYetAnotherRenderProcessId = 4560; |
| 174 const int kYetAnotherRenderFrameId = 7890; | 225 const int kYetAnotherRenderFrameId = 7890; |
| 175 } | 226 } |
| 176 | 227 |
| 177 TEST_F(AudioMirroringManagerTest, MirroringSessionOfNothing) { | 228 TEST_F(AudioMirroringManagerTest, MirroringSessionOfNothing) { |
| 178 const std::unique_ptr<MockMirroringDestination> destination( | 229 const std::unique_ptr<MockMirroringDestination> destination( |
| 179 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 230 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 180 StartMirroringTo(destination, 0); | 231 StartMirroringTo(destination, 0, 0); |
| 181 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 232 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 182 | 233 |
| 183 StopMirroringTo(destination); | 234 StopMirroringTo(destination); |
| 184 EXPECT_EQ(0, destination->query_count()); | 235 EXPECT_EQ(0, destination->query_count()); |
| 185 | 236 |
| 186 ExpectNoLongerManagingAnything(); | 237 ExpectNoLongerManagingAnything(); |
| 187 } | 238 } |
| 188 | 239 |
| 189 TEST_F(AudioMirroringManagerTest, TwoMirroringSessionsOfNothing) { | 240 TEST_F(AudioMirroringManagerTest, TwoMirroringSessionsOfNothing) { |
| 190 const std::unique_ptr<MockMirroringDestination> destination( | 241 const std::unique_ptr<MockMirroringDestination> destination( |
| 191 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 242 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 192 StartMirroringTo(destination, 0); | 243 StartMirroringTo(destination, 0, 0); |
| 193 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 244 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 194 | 245 |
| 195 StopMirroringTo(destination); | 246 StopMirroringTo(destination); |
| 196 EXPECT_EQ(0, destination->query_count()); | 247 EXPECT_EQ(0, destination->query_count()); |
| 197 | 248 |
| 198 const std::unique_ptr<MockMirroringDestination> another_destination( | 249 const std::unique_ptr<MockMirroringDestination> another_destination( |
| 199 new MockMirroringDestination(kAnotherRenderProcessId, | 250 new MockMirroringDestination(kAnotherRenderProcessId, |
| 200 kAnotherRenderFrameId)); | 251 kAnotherRenderFrameId, false)); |
| 201 StartMirroringTo(another_destination, 0); | 252 StartMirroringTo(another_destination, 0, 0); |
| 202 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 253 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 203 | 254 |
| 204 StopMirroringTo(another_destination); | 255 StopMirroringTo(another_destination); |
| 205 EXPECT_EQ(0, another_destination->query_count()); | 256 EXPECT_EQ(0, another_destination->query_count()); |
| 206 | 257 |
| 207 ExpectNoLongerManagingAnything(); | 258 ExpectNoLongerManagingAnything(); |
| 208 } | 259 } |
| 209 | 260 |
| 210 // Tests that a mirroring session starts after, and ends before, a stream that | 261 // Tests that a mirroring session starts after, and ends before, a stream that |
| 211 // will be diverted to it. | 262 // will be diverted to it. |
| 212 TEST_F(AudioMirroringManagerTest, StreamLifetimeAroundMirroringSession) { | 263 TEST_F(AudioMirroringManagerTest, StreamLifetimeAroundMirroringSession) { |
| 213 MockDiverter* const stream = | 264 MockDiverter* const stream = |
| 214 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 265 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 215 const std::unique_ptr<MockMirroringDestination> destination( | 266 const std::unique_ptr<MockMirroringDestination> destination( |
| 216 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 267 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 217 StartMirroringTo(destination, 1); | 268 StartMirroringTo(destination, 1, 0); |
| 218 EXPECT_EQ(1, destination->query_count()); | 269 EXPECT_EQ(1, destination->query_count()); |
| 219 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 270 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 220 | 271 |
| 221 StopMirroringTo(destination); | 272 StopMirroringTo(destination); |
| 222 EXPECT_EQ(1, destination->query_count()); | 273 EXPECT_EQ(1, destination->query_count()); |
| 223 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 274 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 224 | 275 |
| 225 KillStream(stream); | 276 KillStream(stream); |
| 226 EXPECT_EQ(1, destination->query_count()); | 277 EXPECT_EQ(1, destination->query_count()); |
| 227 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 278 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 228 | 279 |
| 229 ExpectNoLongerManagingAnything(); | 280 ExpectNoLongerManagingAnything(); |
| 230 } | 281 } |
| 231 | 282 |
| 232 // Tests that a mirroring session starts before, and ends after, a stream that | 283 // Tests that a mirroring session starts before, and ends after, a stream that |
| 233 // will be diverted to it. | 284 // will be diverted to it. |
| 234 TEST_F(AudioMirroringManagerTest, StreamLifetimeWithinMirroringSession) { | 285 TEST_F(AudioMirroringManagerTest, StreamLifetimeWithinMirroringSession) { |
| 235 const std::unique_ptr<MockMirroringDestination> destination( | 286 const std::unique_ptr<MockMirroringDestination> destination( |
| 236 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 287 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 237 StartMirroringTo(destination, 1); | 288 StartMirroringTo(destination, 1, 0); |
| 238 EXPECT_EQ(0, destination->query_count()); | 289 EXPECT_EQ(0, destination->query_count()); |
| 239 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 290 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 240 | 291 |
| 241 MockDiverter* const stream = | 292 MockDiverter* const stream = |
| 242 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 293 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 243 EXPECT_EQ(1, destination->query_count()); | 294 EXPECT_EQ(1, destination->query_count()); |
| 244 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 295 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 245 | 296 |
| 246 KillStream(stream); | 297 KillStream(stream); |
| 247 EXPECT_EQ(1, destination->query_count()); | 298 EXPECT_EQ(1, destination->query_count()); |
| 248 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 299 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 249 | 300 |
| 250 StopMirroringTo(destination); | 301 StopMirroringTo(destination); |
| 251 EXPECT_EQ(1, destination->query_count()); | 302 EXPECT_EQ(1, destination->query_count()); |
| 252 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 303 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 253 | 304 |
| 254 ExpectNoLongerManagingAnything(); | 305 ExpectNoLongerManagingAnything(); |
| 255 } | 306 } |
| 256 | 307 |
| 257 // Tests that a stream is diverted correctly as two mirroring sessions come and | 308 // Tests that a stream is diverted correctly as two mirroring sessions come and |
| 258 // go. | 309 // go. |
| 259 TEST_F(AudioMirroringManagerTest, StreamLifetimeAcrossTwoMirroringSessions) { | 310 TEST_F(AudioMirroringManagerTest, StreamLifetimeAcrossTwoMirroringSessions) { |
| 260 MockDiverter* const stream = | 311 MockDiverter* const stream = |
| 261 CreateStream(kRenderProcessId, kRenderFrameId, 2); | 312 CreateStream(kRenderProcessId, kRenderFrameId, 2, 0); |
| 262 | 313 |
| 263 const std::unique_ptr<MockMirroringDestination> destination( | 314 const std::unique_ptr<MockMirroringDestination> destination( |
| 264 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 315 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 265 StartMirroringTo(destination, 1); | 316 StartMirroringTo(destination, 1, 0); |
| 266 EXPECT_EQ(1, destination->query_count()); | 317 EXPECT_EQ(1, destination->query_count()); |
| 267 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 318 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 268 | 319 |
| 269 StopMirroringTo(destination); | 320 StopMirroringTo(destination); |
| 270 EXPECT_EQ(1, destination->query_count()); | 321 EXPECT_EQ(1, destination->query_count()); |
| 271 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 322 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 272 | 323 |
| 273 const std::unique_ptr<MockMirroringDestination> second_destination( | 324 const std::unique_ptr<MockMirroringDestination> second_destination( |
| 274 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 325 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 275 StartMirroringTo(second_destination, 1); | 326 StartMirroringTo(second_destination, 1, 0); |
| 276 EXPECT_EQ(1, destination->query_count()); | 327 EXPECT_EQ(1, destination->query_count()); |
| 277 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 328 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 278 EXPECT_EQ(1, second_destination->query_count()); | 329 EXPECT_EQ(1, second_destination->query_count()); |
| 279 EXPECT_EQ(1, CountStreamsDivertedTo(second_destination)); | 330 EXPECT_EQ(1, CountStreamsDivertedTo(second_destination)); |
| 280 | 331 |
| 281 StopMirroringTo(second_destination); | 332 StopMirroringTo(second_destination); |
| 282 EXPECT_EQ(1, destination->query_count()); | 333 EXPECT_EQ(1, destination->query_count()); |
| 283 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 334 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 284 EXPECT_EQ(1, second_destination->query_count()); | 335 EXPECT_EQ(1, second_destination->query_count()); |
| 285 EXPECT_EQ(0, CountStreamsDivertedTo(second_destination)); | 336 EXPECT_EQ(0, CountStreamsDivertedTo(second_destination)); |
| 286 | 337 |
| 287 KillStream(stream); | 338 KillStream(stream); |
| 288 EXPECT_EQ(1, destination->query_count()); | 339 EXPECT_EQ(1, destination->query_count()); |
| 289 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 340 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 290 EXPECT_EQ(1, second_destination->query_count()); | 341 EXPECT_EQ(1, second_destination->query_count()); |
| 291 EXPECT_EQ(0, CountStreamsDivertedTo(second_destination)); | 342 EXPECT_EQ(0, CountStreamsDivertedTo(second_destination)); |
| 292 | 343 |
| 293 ExpectNoLongerManagingAnything(); | 344 ExpectNoLongerManagingAnything(); |
| 294 } | 345 } |
| 295 | 346 |
| 296 // Tests that a stream does not flip-flop between two destinations that are a | 347 // Tests that a stream does not flip-flop between two destinations that are a |
| 297 // match for it. | 348 // match for it. |
| 298 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_1) { | 349 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_1) { |
| 299 MockDiverter* const stream = | 350 MockDiverter* const stream = |
| 300 CreateStream(kRenderProcessId, kRenderFrameId, 2); | 351 CreateStream(kRenderProcessId, kRenderFrameId, 2, 0); |
| 301 | 352 |
| 302 const std::unique_ptr<MockMirroringDestination> destination( | 353 const std::unique_ptr<MockMirroringDestination> destination( |
| 303 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 354 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 304 StartMirroringTo(destination, 1); | 355 StartMirroringTo(destination, 1, 0); |
| 305 EXPECT_EQ(1, destination->query_count()); | 356 EXPECT_EQ(1, destination->query_count()); |
| 306 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 357 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 307 | 358 |
| 308 const std::unique_ptr<MockMirroringDestination> replacement_destination( | 359 const std::unique_ptr<MockMirroringDestination> replacement_destination( |
| 309 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 360 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 310 StartMirroringTo(replacement_destination, 1); | 361 StartMirroringTo(replacement_destination, 1, 0); |
| 311 EXPECT_EQ(1, destination->query_count()); | 362 EXPECT_EQ(1, destination->query_count()); |
| 312 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 363 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 313 EXPECT_EQ(0, replacement_destination->query_count()); | 364 EXPECT_EQ(1, replacement_destination->query_count()); |
| 314 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 365 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 315 | 366 |
| 316 StopMirroringTo(destination); | 367 StopMirroringTo(destination); |
| 317 EXPECT_EQ(1, destination->query_count()); | 368 EXPECT_EQ(1, destination->query_count()); |
| 318 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 369 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 319 EXPECT_EQ(1, replacement_destination->query_count()); | 370 EXPECT_EQ(2, replacement_destination->query_count()); |
| 320 EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination)); | 371 EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination)); |
| 321 | 372 |
| 322 StopMirroringTo(replacement_destination); | 373 StopMirroringTo(replacement_destination); |
| 323 EXPECT_EQ(1, destination->query_count()); | 374 EXPECT_EQ(1, destination->query_count()); |
| 324 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 375 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 325 EXPECT_EQ(1, replacement_destination->query_count()); | 376 EXPECT_EQ(2, replacement_destination->query_count()); |
| 326 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 377 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 327 | 378 |
| 328 KillStream(stream); | 379 KillStream(stream); |
| 329 EXPECT_EQ(1, destination->query_count()); | 380 EXPECT_EQ(1, destination->query_count()); |
| 330 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 381 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 331 EXPECT_EQ(1, replacement_destination->query_count()); | 382 EXPECT_EQ(2, replacement_destination->query_count()); |
| 332 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 383 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 333 | 384 |
| 334 ExpectNoLongerManagingAnything(); | 385 ExpectNoLongerManagingAnything(); |
| 335 } | 386 } |
| 336 | 387 |
| 337 // Same as StreamDivertingStickyToOneDestination_1, with a different order of | 388 // Same as StreamDivertingStickyToOneDestination_1, with a different order of |
| 338 // operations that should have the same effects. | 389 // operations that should have the same effects. |
| 339 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_2) { | 390 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_2) { |
| 340 MockDiverter* const stream = | 391 MockDiverter* const stream = |
| 341 CreateStream(kRenderProcessId, kRenderFrameId, 2); | 392 CreateStream(kRenderProcessId, kRenderFrameId, 2, 0); |
| 342 | 393 |
| 343 const std::unique_ptr<MockMirroringDestination> destination( | 394 const std::unique_ptr<MockMirroringDestination> destination( |
| 344 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 395 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 345 StartMirroringTo(destination, 1); | 396 StartMirroringTo(destination, 1, 0); |
| 346 EXPECT_EQ(1, destination->query_count()); | 397 EXPECT_EQ(1, destination->query_count()); |
| 347 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 398 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 348 | 399 |
| 349 const std::unique_ptr<MockMirroringDestination> replacement_destination( | 400 const std::unique_ptr<MockMirroringDestination> replacement_destination( |
| 350 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 401 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 351 StartMirroringTo(replacement_destination, 1); | 402 StartMirroringTo(replacement_destination, 1, 0); |
| 352 EXPECT_EQ(1, destination->query_count()); | 403 EXPECT_EQ(1, destination->query_count()); |
| 353 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 404 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 354 EXPECT_EQ(0, replacement_destination->query_count()); | 405 EXPECT_EQ(1, replacement_destination->query_count()); |
| 355 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 406 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 356 | 407 |
| 357 StopMirroringTo(destination); | 408 StopMirroringTo(destination); |
| 358 EXPECT_EQ(1, destination->query_count()); | 409 EXPECT_EQ(1, destination->query_count()); |
| 359 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 410 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 360 EXPECT_EQ(1, replacement_destination->query_count()); | 411 EXPECT_EQ(2, replacement_destination->query_count()); |
| 361 EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination)); | 412 EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination)); |
| 362 | 413 |
| 363 KillStream(stream); | 414 KillStream(stream); |
| 364 EXPECT_EQ(1, destination->query_count()); | 415 EXPECT_EQ(1, destination->query_count()); |
| 365 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 416 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 366 EXPECT_EQ(1, replacement_destination->query_count()); | 417 EXPECT_EQ(2, replacement_destination->query_count()); |
| 367 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 418 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 368 | 419 |
| 369 StopMirroringTo(replacement_destination); | 420 StopMirroringTo(replacement_destination); |
| 370 EXPECT_EQ(1, destination->query_count()); | 421 EXPECT_EQ(1, destination->query_count()); |
| 371 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 422 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 372 EXPECT_EQ(1, replacement_destination->query_count()); | 423 EXPECT_EQ(2, replacement_destination->query_count()); |
| 373 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 424 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 374 | 425 |
| 375 ExpectNoLongerManagingAnything(); | 426 ExpectNoLongerManagingAnything(); |
| 376 } | 427 } |
| 377 | 428 |
| 378 // Same as StreamDivertingStickyToOneDestination_1, except that the stream is | 429 // Same as StreamDivertingStickyToOneDestination_1, except that the stream is |
| 379 // killed before the first destination is stopped. Therefore, the second | 430 // killed before the first destination is stopped. Therefore, the second |
| 380 // destination should never see the stream. | 431 // destination should never see the stream. |
| 381 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_3) { | 432 TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_3) { |
| 382 MockDiverter* const stream = | 433 MockDiverter* const stream = |
| 383 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 434 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 384 | 435 |
| 385 const std::unique_ptr<MockMirroringDestination> destination( | 436 const std::unique_ptr<MockMirroringDestination> destination( |
| 386 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 437 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 387 StartMirroringTo(destination, 1); | 438 StartMirroringTo(destination, 1, 0); |
| 388 EXPECT_EQ(1, destination->query_count()); | 439 EXPECT_EQ(1, destination->query_count()); |
| 389 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 440 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 390 | 441 |
| 391 const std::unique_ptr<MockMirroringDestination> replacement_destination( | 442 const std::unique_ptr<MockMirroringDestination> replacement_destination( |
| 392 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 443 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 393 StartMirroringTo(replacement_destination, 0); | 444 StartMirroringTo(replacement_destination, 0, 0); |
| 394 EXPECT_EQ(1, destination->query_count()); | 445 EXPECT_EQ(1, destination->query_count()); |
| 395 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 446 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 396 EXPECT_EQ(0, replacement_destination->query_count()); | 447 EXPECT_EQ(1, replacement_destination->query_count()); |
| 397 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 448 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 398 | 449 |
| 399 KillStream(stream); | 450 KillStream(stream); |
| 400 EXPECT_EQ(1, destination->query_count()); | 451 EXPECT_EQ(1, destination->query_count()); |
| 401 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 452 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 402 EXPECT_EQ(0, replacement_destination->query_count()); | 453 EXPECT_EQ(1, replacement_destination->query_count()); |
| 403 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 454 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 404 | 455 |
| 405 StopMirroringTo(destination); | 456 StopMirroringTo(destination); |
| 406 EXPECT_EQ(1, destination->query_count()); | 457 EXPECT_EQ(1, destination->query_count()); |
| 407 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 458 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 408 EXPECT_EQ(0, replacement_destination->query_count()); | 459 EXPECT_EQ(1, replacement_destination->query_count()); |
| 409 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 460 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 410 | 461 |
| 411 StopMirroringTo(replacement_destination); | 462 StopMirroringTo(replacement_destination); |
| 412 EXPECT_EQ(1, destination->query_count()); | 463 EXPECT_EQ(1, destination->query_count()); |
| 413 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 464 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 414 EXPECT_EQ(0, replacement_destination->query_count()); | 465 EXPECT_EQ(1, replacement_destination->query_count()); |
| 415 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); | 466 EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination)); |
| 416 | 467 |
| 417 ExpectNoLongerManagingAnything(); | 468 ExpectNoLongerManagingAnything(); |
| 418 } | 469 } |
| 419 | 470 |
| 420 // Tests that multiple streams are diverted/mixed to one destination. | 471 // Tests that multiple streams are diverted/mixed to one destination. |
| 421 TEST_F(AudioMirroringManagerTest, MultipleStreamsInOneMirroringSession) { | 472 TEST_F(AudioMirroringManagerTest, MultipleStreamsInOneMirroringSession) { |
| 422 MockDiverter* const stream1 = | 473 MockDiverter* const stream1 = |
| 423 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 474 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 424 | 475 |
| 425 const std::unique_ptr<MockMirroringDestination> destination( | 476 const std::unique_ptr<MockMirroringDestination> destination( |
| 426 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 477 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 427 StartMirroringTo(destination, 3); | 478 StartMirroringTo(destination, 3, 0); |
| 428 EXPECT_EQ(1, destination->query_count()); | 479 EXPECT_EQ(1, destination->query_count()); |
| 429 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 480 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 430 | 481 |
| 431 MockDiverter* const stream2 = | 482 MockDiverter* const stream2 = |
| 432 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 483 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 433 EXPECT_EQ(2, destination->query_count()); | 484 EXPECT_EQ(2, destination->query_count()); |
| 434 EXPECT_EQ(2, CountStreamsDivertedTo(destination)); | 485 EXPECT_EQ(2, CountStreamsDivertedTo(destination)); |
| 435 | 486 |
| 436 MockDiverter* const stream3 = | 487 MockDiverter* const stream3 = |
| 437 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 488 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 438 EXPECT_EQ(3, destination->query_count()); | 489 EXPECT_EQ(3, destination->query_count()); |
| 439 EXPECT_EQ(3, CountStreamsDivertedTo(destination)); | 490 EXPECT_EQ(3, CountStreamsDivertedTo(destination)); |
| 440 | 491 |
| 441 KillStream(stream2); | 492 KillStream(stream2); |
| 442 EXPECT_EQ(3, destination->query_count()); | 493 EXPECT_EQ(3, destination->query_count()); |
| 443 EXPECT_EQ(2, CountStreamsDivertedTo(destination)); | 494 EXPECT_EQ(2, CountStreamsDivertedTo(destination)); |
| 444 | 495 |
| 445 StopMirroringTo(destination); | 496 StopMirroringTo(destination); |
| 446 EXPECT_EQ(3, destination->query_count()); | 497 EXPECT_EQ(3, destination->query_count()); |
| 447 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 498 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 448 | 499 |
| 449 KillStream(stream3); | 500 KillStream(stream3); |
| 450 EXPECT_EQ(3, destination->query_count()); | 501 EXPECT_EQ(3, destination->query_count()); |
| 451 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 502 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 452 | 503 |
| 453 KillStream(stream1); | 504 KillStream(stream1); |
| 454 EXPECT_EQ(3, destination->query_count()); | 505 EXPECT_EQ(3, destination->query_count()); |
| 455 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 506 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 456 | 507 |
| 457 ExpectNoLongerManagingAnything(); | 508 ExpectNoLongerManagingAnything(); |
| 458 } | 509 } |
| 459 | 510 |
| 460 // A random interleaving of operations for three separate targets, each of which | 511 // A random interleaving of operations for three separate targets, each of which |
| 461 // has one stream mirrored to one destination. | 512 // has one stream mirrored to one destination. |
| 462 TEST_F(AudioMirroringManagerTest, ThreeSeparateMirroringSessions) { | 513 TEST_F(AudioMirroringManagerTest, ThreeSeparateMirroringSessions) { |
| 463 MockDiverter* const stream = | 514 MockDiverter* const stream = |
| 464 CreateStream(kRenderProcessId, kRenderFrameId, 1); | 515 CreateStream(kRenderProcessId, kRenderFrameId, 1, 0); |
| 465 | 516 |
| 466 const std::unique_ptr<MockMirroringDestination> destination( | 517 const std::unique_ptr<MockMirroringDestination> destination( |
| 467 new MockMirroringDestination(kRenderProcessId, kRenderFrameId)); | 518 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); |
| 468 StartMirroringTo(destination, 1); | 519 StartMirroringTo(destination, 1, 0); |
| 469 EXPECT_EQ(1, destination->query_count()); | 520 EXPECT_EQ(1, destination->query_count()); |
| 470 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 521 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 471 | 522 |
| 472 const std::unique_ptr<MockMirroringDestination> another_destination( | 523 const std::unique_ptr<MockMirroringDestination> another_destination( |
| 473 new MockMirroringDestination(kAnotherRenderProcessId, | 524 new MockMirroringDestination(kAnotherRenderProcessId, |
| 474 kAnotherRenderFrameId)); | 525 kAnotherRenderFrameId, false)); |
| 475 StartMirroringTo(another_destination, 1); | 526 StartMirroringTo(another_destination, 1, 0); |
| 476 EXPECT_EQ(1, destination->query_count()); | 527 EXPECT_EQ(1, destination->query_count()); |
| 477 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 528 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 478 EXPECT_EQ(0, another_destination->query_count()); | 529 EXPECT_EQ(1, another_destination->query_count()); |
| 479 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 530 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 480 | 531 |
| 481 MockDiverter* const another_stream = | 532 MockDiverter* const another_stream = |
| 482 CreateStream(kAnotherRenderProcessId, kAnotherRenderFrameId, 1); | 533 CreateStream(kAnotherRenderProcessId, kAnotherRenderFrameId, 1, 0); |
| 483 EXPECT_EQ(2, destination->query_count()); | 534 EXPECT_EQ(2, destination->query_count()); |
| 484 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | 535 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); |
| 485 EXPECT_EQ(1, another_destination->query_count()); | 536 EXPECT_EQ(2, another_destination->query_count()); |
| 486 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); | 537 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); |
| 487 | 538 |
| 488 KillStream(stream); | 539 KillStream(stream); |
| 489 EXPECT_EQ(2, destination->query_count()); | 540 EXPECT_EQ(2, destination->query_count()); |
| 490 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 541 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 491 EXPECT_EQ(1, another_destination->query_count()); | 542 EXPECT_EQ(2, another_destination->query_count()); |
| 492 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); | 543 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); |
| 493 | 544 |
| 494 MockDiverter* const yet_another_stream = | 545 MockDiverter* const yet_another_stream = |
| 495 CreateStream(kYetAnotherRenderProcessId, kYetAnotherRenderFrameId, 1); | 546 CreateStream(kYetAnotherRenderProcessId, kYetAnotherRenderFrameId, 1, 0); |
| 496 EXPECT_EQ(3, destination->query_count()); | 547 EXPECT_EQ(3, destination->query_count()); |
| 497 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 548 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 498 EXPECT_EQ(2, another_destination->query_count()); | 549 EXPECT_EQ(3, another_destination->query_count()); |
| 499 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); | 550 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); |
| 500 | 551 |
| 501 const std::unique_ptr<MockMirroringDestination> yet_another_destination( | 552 const std::unique_ptr<MockMirroringDestination> yet_another_destination( |
| 502 new MockMirroringDestination(kYetAnotherRenderProcessId, | 553 new MockMirroringDestination(kYetAnotherRenderProcessId, |
| 503 kYetAnotherRenderFrameId)); | 554 kYetAnotherRenderFrameId, false)); |
| 504 StartMirroringTo(yet_another_destination, 1); | 555 StartMirroringTo(yet_another_destination, 1, 0); |
| 505 EXPECT_EQ(3, destination->query_count()); | 556 EXPECT_EQ(3, destination->query_count()); |
| 506 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 557 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 507 EXPECT_EQ(2, another_destination->query_count()); | 558 EXPECT_EQ(3, another_destination->query_count()); |
| 508 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); | 559 EXPECT_EQ(1, CountStreamsDivertedTo(another_destination)); |
| 509 EXPECT_EQ(1, yet_another_destination->query_count()); | 560 EXPECT_EQ(1, yet_another_destination->query_count()); |
| 510 EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination)); | 561 EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination)); |
| 511 | 562 |
| 512 StopMirroringTo(another_destination); | 563 StopMirroringTo(another_destination); |
| 513 EXPECT_EQ(4, destination->query_count()); | 564 EXPECT_EQ(4, destination->query_count()); |
| 514 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 565 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 515 EXPECT_EQ(2, another_destination->query_count()); | 566 EXPECT_EQ(3, another_destination->query_count()); |
| 516 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 567 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 517 EXPECT_EQ(2, yet_another_destination->query_count()); | 568 EXPECT_EQ(2, yet_another_destination->query_count()); |
| 518 EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination)); | 569 EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination)); |
| 519 | 570 |
| 520 StopMirroringTo(yet_another_destination); | 571 StopMirroringTo(yet_another_destination); |
| 521 EXPECT_EQ(5, destination->query_count()); | 572 EXPECT_EQ(5, destination->query_count()); |
| 522 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 573 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 523 EXPECT_EQ(2, another_destination->query_count()); | 574 EXPECT_EQ(3, another_destination->query_count()); |
| 524 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 575 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 525 EXPECT_EQ(2, yet_another_destination->query_count()); | 576 EXPECT_EQ(2, yet_another_destination->query_count()); |
| 526 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); | 577 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); |
| 527 | 578 |
| 528 StopMirroringTo(destination); | 579 StopMirroringTo(destination); |
| 529 EXPECT_EQ(5, destination->query_count()); | 580 EXPECT_EQ(5, destination->query_count()); |
| 530 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 581 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 531 EXPECT_EQ(2, another_destination->query_count()); | 582 EXPECT_EQ(3, another_destination->query_count()); |
| 532 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 583 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 533 EXPECT_EQ(2, yet_another_destination->query_count()); | 584 EXPECT_EQ(2, yet_another_destination->query_count()); |
| 534 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); | 585 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); |
| 535 | 586 |
| 536 KillStream(another_stream); | 587 KillStream(another_stream); |
| 537 EXPECT_EQ(5, destination->query_count()); | 588 EXPECT_EQ(5, destination->query_count()); |
| 538 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 589 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 539 EXPECT_EQ(2, another_destination->query_count()); | 590 EXPECT_EQ(3, another_destination->query_count()); |
| 540 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 591 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 541 EXPECT_EQ(2, yet_another_destination->query_count()); | 592 EXPECT_EQ(2, yet_another_destination->query_count()); |
| 542 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); | 593 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); |
| 543 | 594 |
| 544 KillStream(yet_another_stream); | 595 KillStream(yet_another_stream); |
| 545 EXPECT_EQ(5, destination->query_count()); | 596 EXPECT_EQ(5, destination->query_count()); |
| 546 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 597 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
| 547 EXPECT_EQ(2, another_destination->query_count()); | 598 EXPECT_EQ(3, another_destination->query_count()); |
| 548 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 599 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
| 549 EXPECT_EQ(2, yet_another_destination->query_count()); | 600 EXPECT_EQ(2, yet_another_destination->query_count()); |
| 550 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); | 601 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); |
| 551 | 602 |
| 552 ExpectNoLongerManagingAnything(); | 603 ExpectNoLongerManagingAnything(); |
| 553 } | 604 } |
| 554 | 605 |
| 606 // Tests that a stream can be successfully duplicated. | |
|
miu
2016/05/06 22:29:49
Nice tests here! :)
qiangchen
2016/05/10 22:36:52
Acknowledged.
| |
| 607 TEST_F(AudioMirroringManagerTest, DuplicationToOneDestination) { | |
| 608 MockDiverter* const stream = | |
| 609 CreateStream(kRenderProcessId, kRenderFrameId, 1, 1); | |
| 610 | |
| 611 const std::unique_ptr<MockMirroringDestination> destination( | |
| 612 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); | |
| 613 StartMirroringTo(destination, 1, 0); | |
| 614 EXPECT_EQ(1, destination->query_count()); | |
| 615 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | |
| 616 | |
| 617 const std::unique_ptr<MockMirroringDestination> duplicated_destination( | |
| 618 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, true)); | |
| 619 StartMirroringTo(duplicated_destination, 0, 1); | |
| 620 EXPECT_EQ(1, destination->query_count()); | |
| 621 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | |
| 622 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 623 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 624 | |
| 625 StopMirroringTo(destination); | |
| 626 EXPECT_EQ(1, destination->query_count()); | |
| 627 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 628 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 629 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 630 | |
| 631 StopMirroringTo(duplicated_destination); | |
| 632 EXPECT_EQ(1, destination->query_count()); | |
| 633 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 634 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 635 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 636 | |
| 637 KillStream(stream); | |
| 638 EXPECT_EQ(1, destination->query_count()); | |
| 639 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 640 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 641 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 642 | |
| 643 ExpectNoLongerManagingAnything(); | |
| 644 } | |
| 645 | |
| 646 // Tests that a stream can be successfully duplicated to multiple destinations | |
| 647 // simultaneously. | |
| 648 TEST_F(AudioMirroringManagerTest, DuplicationToMultipleDestinations) { | |
| 649 MockDiverter* const stream = | |
| 650 CreateStream(kRenderProcessId, kRenderFrameId, 1, 2); | |
| 651 | |
| 652 const std::unique_ptr<MockMirroringDestination> destination( | |
| 653 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); | |
| 654 StartMirroringTo(destination, 1, 0); | |
| 655 EXPECT_EQ(1, destination->query_count()); | |
| 656 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | |
| 657 | |
| 658 const std::unique_ptr<MockMirroringDestination> duplicated_destination( | |
| 659 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, true)); | |
| 660 StartMirroringTo(duplicated_destination, 0, 1); | |
| 661 EXPECT_EQ(1, destination->query_count()); | |
| 662 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | |
| 663 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 664 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 665 | |
| 666 const std::unique_ptr<MockMirroringDestination> duplicated_destination2( | |
| 667 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, true)); | |
| 668 StartMirroringTo(duplicated_destination2, 0, 1); | |
| 669 EXPECT_EQ(1, destination->query_count()); | |
| 670 EXPECT_EQ(1, CountStreamsDivertedTo(destination)); | |
| 671 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 672 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 673 EXPECT_EQ(1, duplicated_destination2->query_count()); | |
| 674 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination2)); | |
| 675 | |
| 676 StopMirroringTo(destination); | |
| 677 EXPECT_EQ(1, destination->query_count()); | |
| 678 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 679 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 680 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 681 EXPECT_EQ(2, duplicated_destination2->query_count()); | |
| 682 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination2)); | |
| 683 | |
| 684 StopMirroringTo(duplicated_destination); | |
| 685 EXPECT_EQ(1, destination->query_count()); | |
| 686 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 687 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 688 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 689 EXPECT_EQ(2, duplicated_destination2->query_count()); | |
| 690 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination2)); | |
| 691 | |
| 692 StopMirroringTo(duplicated_destination2); | |
| 693 EXPECT_EQ(1, destination->query_count()); | |
| 694 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 695 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 696 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 697 EXPECT_EQ(2, duplicated_destination2->query_count()); | |
| 698 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination2)); | |
| 699 | |
| 700 KillStream(stream); | |
| 701 EXPECT_EQ(1, destination->query_count()); | |
| 702 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | |
| 703 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 704 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 705 EXPECT_EQ(2, duplicated_destination2->query_count()); | |
| 706 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination2)); | |
| 707 | |
| 708 ExpectNoLongerManagingAnything(); | |
| 709 } | |
| 710 | |
| 711 // Tests that duplication should not be affected when the major flow gets | |
| 712 // diverted to another destination | |
| 713 TEST_F(AudioMirroringManagerTest, DuplicationUnaffectedBySwitchingDivertion) { | |
|
miu
2016/05/06 22:29:49
nit: s/Divertion/DivertedFlow/
qiangchen
2016/05/10 22:36:52
Done.
| |
| 714 MockDiverter* const stream = | |
| 715 CreateStream(kRenderProcessId, kRenderFrameId, 2, 1); | |
| 716 | |
| 717 const std::unique_ptr<MockMirroringDestination> duplicated_destination( | |
| 718 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, true)); | |
| 719 StartMirroringTo(duplicated_destination, 0, 1); | |
| 720 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 721 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 722 | |
| 723 const std::unique_ptr<MockMirroringDestination> divert_destination( | |
| 724 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); | |
| 725 StartMirroringTo(divert_destination, 1, 0); | |
| 726 EXPECT_EQ(1, divert_destination->query_count()); | |
| 727 EXPECT_EQ(1, CountStreamsDivertedTo(divert_destination)); | |
| 728 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 729 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 730 | |
| 731 const std::unique_ptr<MockMirroringDestination> divert_destination2( | |
| 732 new MockMirroringDestination(kRenderProcessId, kRenderFrameId, false)); | |
| 733 StartMirroringTo(divert_destination2, 1, 0); | |
| 734 EXPECT_EQ(1, divert_destination->query_count()); | |
| 735 EXPECT_EQ(1, CountStreamsDivertedTo(divert_destination)); | |
| 736 EXPECT_EQ(1, duplicated_destination->query_count()); | |
| 737 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 738 EXPECT_EQ(1, divert_destination2->query_count()); | |
| 739 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination2)); | |
| 740 | |
| 741 StopMirroringTo(divert_destination); | |
| 742 EXPECT_EQ(1, divert_destination->query_count()); | |
| 743 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination)); | |
| 744 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 745 EXPECT_EQ(1, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 746 EXPECT_EQ(2, divert_destination2->query_count()); | |
| 747 EXPECT_EQ(1, CountStreamsDivertedTo(divert_destination2)); | |
| 748 | |
| 749 StopMirroringTo(duplicated_destination); | |
| 750 EXPECT_EQ(1, divert_destination->query_count()); | |
| 751 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination)); | |
| 752 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 753 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 754 EXPECT_EQ(2, divert_destination2->query_count()); | |
| 755 EXPECT_EQ(1, CountStreamsDivertedTo(divert_destination2)); | |
| 756 | |
| 757 StopMirroringTo(divert_destination2); | |
| 758 EXPECT_EQ(1, divert_destination->query_count()); | |
| 759 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination)); | |
| 760 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 761 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 762 EXPECT_EQ(2, divert_destination2->query_count()); | |
| 763 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination2)); | |
| 764 | |
| 765 KillStream(stream); | |
| 766 EXPECT_EQ(1, divert_destination->query_count()); | |
| 767 EXPECT_EQ(0, CountStreamsDivertedTo(divert_destination)); | |
| 768 EXPECT_EQ(2, duplicated_destination->query_count()); | |
| 769 EXPECT_EQ(0, CountStreamsDuplicatedTo(duplicated_destination)); | |
| 770 | |
| 771 ExpectNoLongerManagingAnything(); | |
| 772 } | |
| 773 | |
| 555 } // namespace content | 774 } // namespace content |
| OLD | NEW |