| Index: content/browser/media/capture/audio_mirroring_manager_unittest.cc
|
| diff --git a/content/browser/media/capture/audio_mirroring_manager_unittest.cc b/content/browser/media/capture/audio_mirroring_manager_unittest.cc
|
| index cd197769aa5510142be4ac9fd5e2f09dab306117..6fece29c09f14e99befd90dedec1ad40e07115c9 100644
|
| --- a/content/browser/media/capture/audio_mirroring_manager_unittest.cc
|
| +++ b/content/browser/media/capture/audio_mirroring_manager_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "content/browser/media/capture/audio_mirroring_manager.h"
|
|
|
| #include <map>
|
| +#include <utility>
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| @@ -18,6 +19,7 @@
|
| using media::AudioOutputStream;
|
| using media::AudioParameters;
|
| using testing::_;
|
| +using testing::Invoke;
|
| using testing::NotNull;
|
| using testing::Ref;
|
| using testing::Return;
|
| @@ -37,14 +39,56 @@ class MockDiverter : public AudioMirroringManager::Diverter {
|
| class MockMirroringDestination
|
| : public AudioMirroringManager::MirroringDestination {
|
| public:
|
| + typedef AudioMirroringManager::SourceFrameRef SourceFrameRef;
|
| +
|
| + MockMirroringDestination(int render_process_id, int render_frame_id)
|
| + : render_process_id_(render_process_id),
|
| + render_frame_id_(render_frame_id),
|
| + query_count_(0) {}
|
| +
|
| + MOCK_METHOD2(QueryForMatches,
|
| + void(const std::set<SourceFrameRef>& candidates,
|
| + const MatchesCallback& results_callback));
|
| MOCK_METHOD1(AddInput,
|
| media::AudioOutputStream*(const media::AudioParameters& params));
|
| +
|
| + void SimulateQuery(const std::set<SourceFrameRef>& candidates,
|
| + const MatchesCallback& results_callback) {
|
| + ++query_count_;
|
| +
|
| + std::set<SourceFrameRef> result;
|
| + if (candidates.find(SourceFrameRef(render_process_id_, render_frame_id_)) !=
|
| + candidates.end()) {
|
| + result.insert(SourceFrameRef(render_process_id_, render_frame_id_));
|
| + }
|
| + results_callback.Run(result);
|
| + }
|
| +
|
| + media::AudioOutputStream* SimulateAddInput(
|
| + const media::AudioParameters& params) {
|
| + static AudioOutputStream* const kNonNullPointer =
|
| + reinterpret_cast<AudioOutputStream*>(0x11111110);
|
| + return kNonNullPointer;
|
| + }
|
| +
|
| + int query_count() const {
|
| + return query_count_;
|
| + }
|
| +
|
| + private:
|
| + const int render_process_id_;
|
| + const int render_frame_id_;
|
| + int query_count_;
|
| };
|
|
|
| } // namespace
|
|
|
| class AudioMirroringManagerTest : public testing::Test {
|
| public:
|
| + typedef AudioMirroringManager::Diverter Diverter;
|
| + typedef AudioMirroringManager::MirroringDestination MirroringDestination;
|
| + typedef AudioMirroringManager::StreamRoutes StreamRoutes;
|
| +
|
| AudioMirroringManagerTest()
|
| : io_thread_(BrowserThread::IO, &message_loop_),
|
| params_(AudioParameters::AUDIO_FAKE, media::CHANNEL_LAYOUT_STEREO,
|
| @@ -52,7 +96,7 @@ class AudioMirroringManagerTest : public testing::Test {
|
| AudioParameters::kAudioCDSampleRate / 10) {}
|
|
|
| MockDiverter* CreateStream(
|
| - int render_process_id, int render_view_id, int expected_times_diverted) {
|
| + int render_process_id, int render_frame_id, int expected_times_diverted) {
|
| MockDiverter* const diverter = new MockDiverter();
|
| if (expected_times_diverted > 0) {
|
| EXPECT_CALL(*diverter, GetAudioParameters())
|
| @@ -64,41 +108,52 @@ class AudioMirroringManagerTest : public testing::Test {
|
| .Times(expected_times_diverted);
|
| }
|
|
|
| - mirroring_manager_.AddDiverter(render_process_id, render_view_id, diverter);
|
| + mirroring_manager_.AddDiverter(
|
| + render_process_id, render_frame_id, diverter);
|
|
|
| return diverter;
|
| }
|
|
|
| - void KillStream(
|
| - int render_process_id, int render_view_id, MockDiverter* diverter) {
|
| - mirroring_manager_.RemoveDiverter(
|
| - render_process_id, render_view_id, diverter);
|
| -
|
| + void KillStream(MockDiverter* diverter) {
|
| + mirroring_manager_.RemoveDiverter(diverter);
|
| delete diverter;
|
| }
|
|
|
| - MockMirroringDestination* StartMirroringTo(
|
| - int render_process_id, int render_view_id, int expected_inputs_added) {
|
| - MockMirroringDestination* const dest = new MockMirroringDestination();
|
| + void StartMirroringTo(const scoped_ptr<MockMirroringDestination>& dest,
|
| + int expected_inputs_added) {
|
| + EXPECT_CALL(*dest, QueryForMatches(_, _))
|
| + .WillRepeatedly(Invoke(dest.get(),
|
| + &MockMirroringDestination::SimulateQuery));
|
| if (expected_inputs_added > 0) {
|
| - static AudioOutputStream* const kNonNullPointer =
|
| - reinterpret_cast<AudioOutputStream*>(0x11111110);
|
| EXPECT_CALL(*dest, AddInput(Ref(params_)))
|
| .Times(expected_inputs_added)
|
| - .WillRepeatedly(Return(kNonNullPointer));
|
| + .WillRepeatedly(Invoke(dest.get(),
|
| + &MockMirroringDestination::SimulateAddInput))
|
| + .RetiresOnSaturation();
|
| }
|
|
|
| - mirroring_manager_.StartMirroring(render_process_id, render_view_id, dest);
|
| + mirroring_manager_.StartMirroring(dest.get());
|
| + }
|
|
|
| - return dest;
|
| + void StopMirroringTo(const scoped_ptr<MockMirroringDestination>& dest) {
|
| + mirroring_manager_.StopMirroring(dest.get());
|
| }
|
|
|
| - void StopMirroringTo(int render_process_id, int render_view_id,
|
| - MockMirroringDestination* dest) {
|
| - mirroring_manager_.StopMirroring(render_process_id, render_view_id, dest);
|
| + int CountStreamsDivertedTo(
|
| + const scoped_ptr<MockMirroringDestination>& dest) const {
|
| + int count = 0;
|
| + for (StreamRoutes::const_iterator it = mirroring_manager_.routes_.begin();
|
| + it != mirroring_manager_.routes_.end(); ++it) {
|
| + if (it->destination == dest.get())
|
| + ++count;
|
| + }
|
| + return count;
|
| + }
|
|
|
| - delete dest;
|
| -}
|
| + void ExpectNoLongerManagingAnything() const {
|
| + EXPECT_TRUE(mirroring_manager_.routes_.empty());
|
| + EXPECT_TRUE(mirroring_manager_.sessions_.empty());
|
| + }
|
|
|
| private:
|
| base::MessageLoopForIO message_loop_;
|
| @@ -111,123 +166,389 @@ class AudioMirroringManagerTest : public testing::Test {
|
|
|
| namespace {
|
| const int kRenderProcessId = 123;
|
| -const int kRenderViewId = 456;
|
| +const int kRenderFrameId = 456;
|
| const int kAnotherRenderProcessId = 789;
|
| -const int kAnotherRenderViewId = 1234;
|
| +const int kAnotherRenderFrameId = 1234;
|
| const int kYetAnotherRenderProcessId = 4560;
|
| -const int kYetAnotherRenderViewId = 7890;
|
| +const int kYetAnotherRenderFrameId = 7890;
|
| }
|
|
|
| TEST_F(AudioMirroringManagerTest, MirroringSessionOfNothing) {
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 0);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 0);
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(0, destination->query_count());
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| TEST_F(AudioMirroringManagerTest, TwoMirroringSessionsOfNothing) {
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 0);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| -
|
| - MockMirroringDestination* const another_destination =
|
| - StartMirroringTo(kAnotherRenderProcessId, kAnotherRenderViewId, 0);
|
| - StopMirroringTo(kAnotherRenderProcessId, kAnotherRenderViewId,
|
| - another_destination);
|
| -}
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 0);
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(0, destination->query_count());
|
|
|
| -TEST_F(AudioMirroringManagerTest, SwitchMirroringDestinationNoStreams) {
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 0);
|
| - MockMirroringDestination* const new_destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 0);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, new_destination);
|
| + const scoped_ptr<MockMirroringDestination> another_destination(
|
| + new MockMirroringDestination(kAnotherRenderProcessId,
|
| + kAnotherRenderFrameId));
|
| + StartMirroringTo(another_destination, 0);
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| +
|
| + StopMirroringTo(another_destination);
|
| + EXPECT_EQ(0, another_destination->query_count());
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| +// Tests that a mirroring session starts after, and ends before, a stream that
|
| +// will be diverted to it.
|
| TEST_F(AudioMirroringManagerTest, StreamLifetimeAroundMirroringSession) {
|
| - MockDiverter* const stream = CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream);
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| +// Tests that a mirroring session starts before, and ends after, a stream that
|
| +// will be diverted to it.
|
| TEST_F(AudioMirroringManagerTest, StreamLifetimeWithinMirroringSession) {
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - MockDiverter* const stream = CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(0, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| -TEST_F(AudioMirroringManagerTest, StreamLifetimeAroundTwoMirroringSessions) {
|
| - MockDiverter* const stream = CreateStream(kRenderProcessId, kRenderViewId, 2);
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| - MockMirroringDestination* const new_destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, new_destination);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream);
|
| +// Tests that a stream is diverted correctly as two mirroring sessions come and
|
| +// go.
|
| +TEST_F(AudioMirroringManagerTest, StreamLifetimeAcrossTwoMirroringSessions) {
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 2);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> second_destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(second_destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, second_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(second_destination));
|
| +
|
| + StopMirroringTo(second_destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, second_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(second_destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, second_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(second_destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| -TEST_F(AudioMirroringManagerTest, StreamLifetimeWithinTwoMirroringSessions) {
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - MockDiverter* const stream = CreateStream(kRenderProcessId, kRenderViewId, 2);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| - MockMirroringDestination* const new_destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, new_destination);
|
| +// Tests that a stream does not flip-flop between two destinations that are a
|
| +// match for it.
|
| +TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_1) {
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 2);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> replacement_destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(replacement_destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(replacement_destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| +}
|
| +
|
| +// Same as StreamDivertingStickyToOneDestination_1, with a different order of
|
| +// operations that should have the same effects.
|
| +TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_2) {
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 2);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> replacement_destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(replacement_destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(replacement_destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| +}
|
| +
|
| +// Same as StreamDivertingStickyToOneDestination_1, except that the stream is
|
| +// killed before the first destination is stopped. Therefore, the second
|
| +// destination should never see the stream.
|
| +TEST_F(AudioMirroringManagerTest, StreamDivertingStickyToOneDestination_3) {
|
| + MockDiverter* const stream =
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> replacement_destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(replacement_destination, 0);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + StopMirroringTo(replacement_destination);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, replacement_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(replacement_destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| +// Tests that multiple streams are diverted/mixed to one destination.
|
| TEST_F(AudioMirroringManagerTest, MultipleStreamsInOneMirroringSession) {
|
| MockDiverter* const stream1 =
|
| - CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 3);
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 3);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| MockDiverter* const stream2 =
|
| - CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| + EXPECT_EQ(2, destination->query_count());
|
| + EXPECT_EQ(2, CountStreamsDivertedTo(destination));
|
| +
|
| MockDiverter* const stream3 =
|
| - CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream2);
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream3);
|
| - KillStream(kRenderProcessId, kRenderViewId, stream1);
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(3, CountStreamsDivertedTo(destination));
|
| +
|
| + KillStream(stream2);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(2, CountStreamsDivertedTo(destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + KillStream(stream3);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + KillStream(stream1);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| // A random interleaving of operations for three separate targets, each of which
|
| // has one stream mirrored to one destination.
|
| TEST_F(AudioMirroringManagerTest, ThreeSeparateMirroringSessions) {
|
| MockDiverter* const stream =
|
| - CreateStream(kRenderProcessId, kRenderViewId, 1);
|
| - MockMirroringDestination* const destination =
|
| - StartMirroringTo(kRenderProcessId, kRenderViewId, 1);
|
| + CreateStream(kRenderProcessId, kRenderFrameId, 1);
|
| +
|
| + const scoped_ptr<MockMirroringDestination> destination(
|
| + new MockMirroringDestination(kRenderProcessId, kRenderFrameId));
|
| + StartMirroringTo(destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> another_destination(
|
| + new MockMirroringDestination(kAnotherRenderProcessId,
|
| + kAnotherRenderFrameId));
|
| + StartMirroringTo(another_destination, 1);
|
| + EXPECT_EQ(1, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(0, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
|
|
| - MockMirroringDestination* const another_destination =
|
| - StartMirroringTo(kAnotherRenderProcessId, kAnotherRenderViewId, 1);
|
| MockDiverter* const another_stream =
|
| - CreateStream(kAnotherRenderProcessId, kAnotherRenderViewId, 1);
|
| -
|
| - KillStream(kRenderProcessId, kRenderViewId, stream);
|
| + CreateStream(kAnotherRenderProcessId, kAnotherRenderFrameId, 1);
|
| + EXPECT_EQ(2, destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
|
| +
|
| + KillStream(stream);
|
| + EXPECT_EQ(2, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(1, another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
|
|
|
| MockDiverter* const yet_another_stream =
|
| - CreateStream(kYetAnotherRenderProcessId, kYetAnotherRenderViewId, 1);
|
| - MockMirroringDestination* const yet_another_destination =
|
| - StartMirroringTo(kYetAnotherRenderProcessId, kYetAnotherRenderViewId, 1);
|
| -
|
| - StopMirroringTo(kAnotherRenderProcessId, kAnotherRenderViewId,
|
| - another_destination);
|
| -
|
| - StopMirroringTo(kYetAnotherRenderProcessId, kYetAnotherRenderViewId,
|
| - yet_another_destination);
|
| -
|
| - StopMirroringTo(kRenderProcessId, kRenderViewId, destination);
|
| -
|
| - KillStream(kAnotherRenderProcessId, kAnotherRenderViewId, another_stream);
|
| - KillStream(kYetAnotherRenderProcessId, kYetAnotherRenderViewId,
|
| - yet_another_stream);
|
| + CreateStream(kYetAnotherRenderProcessId, kYetAnotherRenderFrameId, 1);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
|
| +
|
| + const scoped_ptr<MockMirroringDestination> yet_another_destination(
|
| + new MockMirroringDestination(kYetAnotherRenderProcessId,
|
| + kYetAnotherRenderFrameId));
|
| + StartMirroringTo(yet_another_destination, 1);
|
| + EXPECT_EQ(3, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(1, yet_another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + StopMirroringTo(another_destination);
|
| + EXPECT_EQ(4, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(2, yet_another_destination->query_count());
|
| + EXPECT_EQ(1, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + StopMirroringTo(yet_another_destination);
|
| + EXPECT_EQ(5, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(2, yet_another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + StopMirroringTo(destination);
|
| + EXPECT_EQ(5, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(2, yet_another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + KillStream(another_stream);
|
| + EXPECT_EQ(5, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(2, yet_another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + KillStream(yet_another_stream);
|
| + EXPECT_EQ(5, destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(destination));
|
| + EXPECT_EQ(2, another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(another_destination));
|
| + EXPECT_EQ(2, yet_another_destination->query_count());
|
| + EXPECT_EQ(0, CountStreamsDivertedTo(yet_another_destination));
|
| +
|
| + ExpectNoLongerManagingAnything();
|
| }
|
|
|
| } // namespace content
|
|
|