// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/audio/audio_debug_recording_manager.h" #include <memory> #include <vector> #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/test/task_environment.h" #include "media/audio/audio_debug_recording_helper.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" _; namespace media { namespace { // The stream type expected to be added to file name. const AudioDebugRecordingStreamType kStreamType( AudioDebugRecordingStreamType::kOutput); // Used to be able to set call expectations in the MockAudioDebugRecordingHelper // ctor. See also comment on the test EnableRegisterDisable. bool g_expect_enable_after_create_helper = …; // A helper struct to be able to set and unset // |g_expect_enable_after_create_helper| scoped. struct ScopedExpectEnableAfterCreateHelper { … }; // Function bound and passed to AudioDebugRecordingManager::EnableDebugRecording // as AudioDebugRecordingManager::CreateWavFileCallback. void CreateWavFile(AudioDebugRecordingStreamType stream_type, uint32_t id, base::OnceCallback<void(base::File)>) { … } } // namespace // Mock class to verify enable and disable calls. class MockAudioDebugRecordingHelper : public AudioDebugRecordingHelper { … }; // Sub-class of the manager that overrides the CreateAudioDebugRecordingHelper // function to create the above mock instead. class AudioDebugRecordingManagerUnderTest : public AudioDebugRecordingManager { … }; // The test fixture. class AudioDebugRecordingManagerTest : public ::testing::Test { … }; uint32_t AudioDebugRecordingManagerTest::expected_next_source_id_ = …; // Shouldn't do anything but store the CreateWavFileCallback, i.e. no calls to // recorders. TEST_F(AudioDebugRecordingManagerTest, EnableDisable) { … } // Tests registration and automatic unregistration on destruction of a recorder. // The unregistration relies on that the MockAudioDebugRecordingHelper runs the // |on_destruction_closure| given to it. TEST_F(AudioDebugRecordingManagerTest, RegisterAutomaticUnregisterAtDelete) { … } TEST_F(AudioDebugRecordingManagerTest, RegisterEnableDisable) { … } // Test enabling first, then registering. This should call enable on the // recoders, but we can't set expectation for that since the mock object is // created and called enable upon in RegisterDebugRecordingSource(), then // returned. Instead expectation is set in the ctor of the mock by setting // |g_expect_enable_after_create_helper| to true here (by using the scoped // variable). TEST_F(AudioDebugRecordingManagerTest, EnableRegisterDisable) { … } } // namespace media