-// Ensures the methods used to fix audio output wedges are working correctly.
-TEST_F(AudioOutputResamplerTest, WedgeFix) {
- MockAudioOutputStream stream1(&manager_, params_);
- MockAudioOutputStream stream2(&manager_, params_);
- MockAudioOutputStream stream3(&manager_, params_);
-
- // Setup the mock such that all three streams are successfully created.
- EXPECT_CALL(manager(), MakeAudioOutputStream(_, _))
- .WillOnce(Return(&stream1))
- .WillOnce(Return(&stream2))
- .WillOnce(Return(&stream3));
-
- // Stream1 should be able to successfully open and start.
- EXPECT_CALL(stream1, Open())
- .WillOnce(Return(true));
- EXPECT_CALL(stream1, SetVolume(_));
- EXPECT_CALL(stream2, Open())
- .WillOnce(Return(true));
- EXPECT_CALL(stream2, SetVolume(_));
-
- // Open and start the first proxy and stream.
- AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_.get());
- EXPECT_TRUE(proxy1->Open());
- proxy1->Start(&callback_);
- OnStart();
-
- // Open, but do not start the second proxy.
- AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_.get());
- EXPECT_TRUE(proxy2->Open());
-
- // Open, start and then stop the third proxy.
- AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_.get());
- EXPECT_TRUE(proxy3->Open());
- proxy3->Start(&callback_);
- OnStart();
- proxy3->Stop();
-
- // Wait for stream to timeout and shutdown.
- WaitForCloseTimer(&stream2);
-
- EXPECT_CALL(stream1, Close());
- resampler_->CloseStreamsForWedgeFix();
-
- // Don't pump the MessageLoop between CloseStreamsForWedgeFix() and
- // RestartStreamsForWedgeFix() to simulate intended usage. The OnStart() call
- // will take care of necessary work.
-
- // Stream3 should take Stream1's place after RestartStreamsForWedgeFix(). No
- // additional streams should be opened for proxy2 and proxy3.
- EXPECT_CALL(stream3, Open())
- .WillOnce(Return(true));
- EXPECT_CALL(stream3, SetVolume(_));
-
- resampler_->RestartStreamsForWedgeFix();
- OnStart();
-
- // Perform the required Stop()/Close() shutdown dance for each proxy.
- proxy3->Close();
- proxy2->Close();
- proxy1->Stop();
- CloseAndWaitForCloseTimer(proxy1, &stream3);
-
- // Wait for all of the messages to fly and then verify stream behavior.
- EXPECT_TRUE(stream1.stop_called());
- EXPECT_TRUE(stream1.start_called());
- EXPECT_TRUE(stream2.stop_called());
- EXPECT_TRUE(stream2.start_called());
- EXPECT_TRUE(stream3.stop_called());
- EXPECT_TRUE(stream3.start_called());
-}
-