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