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/audio/audio_parameters.h" |
17 #include "media/audio/virtual_audio_sink.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, int render_frame_id) |
46 : render_process_id_(render_process_id), | 50 : render_process_id_(render_process_id), |
47 render_frame_id_(render_frame_id), | 51 render_frame_id_(render_frame_id), |
48 query_count_(0) {} | 52 query_count_(0) {} |
49 | 53 |
50 MOCK_METHOD2(QueryForMatches, | 54 MOCK_METHOD2(QueryForMatches, |
51 void(const std::set<SourceFrameRef>& candidates, | 55 void(const std::set<SourceFrameRef>& candidates, |
52 const MatchesCallback& results_callback)); | 56 const MatchesCallback& results_callback)); |
53 MOCK_METHOD1(AddInput, | 57 MOCK_METHOD1(AddInput, |
54 media::AudioOutputStream*(const media::AudioParameters& params)); | 58 media::AudioOutputStream*(const media::AudioParameters& params)); |
55 | 59 |
60 MOCK_METHOD1(AddPushInput, | |
61 media::AudioPushSink*(const media::AudioParameters& params)); | |
62 | |
56 void SimulateQuery(const std::set<SourceFrameRef>& candidates, | 63 void SimulateQuery(const std::set<SourceFrameRef>& candidates, |
57 const MatchesCallback& results_callback) { | 64 const MatchesCallback& results_callback) { |
58 ++query_count_; | 65 ++query_count_; |
59 | 66 |
60 std::set<SourceFrameRef> result; | 67 std::set<SourceFrameRef> result; |
61 if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) != | 68 if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) != |
62 candidates.end()) { | 69 candidates.end()) { |
63 result.insert(SourceFrameRef(render_process_id_, render_frame_id_)); | 70 result.insert(SourceFrameRef(render_process_id_, render_frame_id_)); |
64 } | 71 } |
65 results_callback.Run(result); | 72 results_callback.Run(result); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 KillStream(yet_another_stream); | 551 KillStream(yet_another_stream); |
545 EXPECT_EQ(5, destination->query_count()); | 552 EXPECT_EQ(5, destination->query_count()); |
546 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); | 553 EXPECT_EQ(0, CountStreamsDivertedTo(destination)); |
547 EXPECT_EQ(2, another_destination->query_count()); | 554 EXPECT_EQ(2, another_destination->query_count()); |
548 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); | 555 EXPECT_EQ(0, CountStreamsDivertedTo(another_destination)); |
549 EXPECT_EQ(2, yet_another_destination->query_count()); | 556 EXPECT_EQ(2, yet_another_destination->query_count()); |
550 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); | 557 EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination)); |
551 | 558 |
552 ExpectNoLongerManagingAnything(); | 559 ExpectNoLongerManagingAnything(); |
553 } | 560 } |
554 | 561 |
miu
2016/05/02 20:06:13
Need unit tests for the new functionality.
qiangchen
2016/05/04 22:36:46
Done.
| |
555 } // namespace content | 562 } // namespace content |
OLD | NEW |