| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "media/audio/audio_debug_recording_manager.h" | 5 #include "media/audio/audio_debug_recording_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 // Mock class to verify enable and disable calls. | 55 // Mock class to verify enable and disable calls. |
| 56 class MockAudioDebugRecordingHelper : public AudioDebugRecordingHelper { | 56 class MockAudioDebugRecordingHelper : public AudioDebugRecordingHelper { |
| 57 public: | 57 public: |
| 58 MockAudioDebugRecordingHelper( | 58 MockAudioDebugRecordingHelper( |
| 59 const AudioParameters& params, | 59 const AudioParameters& params, |
| 60 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 60 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 61 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | |
| 62 base::OnceClosure on_destruction_closure) | 61 base::OnceClosure on_destruction_closure) |
| 63 : AudioDebugRecordingHelper(params, | 62 : AudioDebugRecordingHelper(params, |
| 64 std::move(task_runner), | 63 std::move(task_runner), |
| 65 std::move(file_task_runner), | |
| 66 base::OnceClosure()), | 64 base::OnceClosure()), |
| 67 on_destruction_closure_in_mock_(std::move(on_destruction_closure)) { | 65 on_destruction_closure_in_mock_(std::move(on_destruction_closure)) { |
| 68 if (g_expect_enable_after_create_helper) | 66 if (g_expect_enable_after_create_helper) |
| 69 EXPECT_CALL(*this, EnableDebugRecording(_)); | 67 EXPECT_CALL(*this, EnableDebugRecording(_)); |
| 70 } | 68 } |
| 71 | 69 |
| 72 ~MockAudioDebugRecordingHelper() override { | 70 ~MockAudioDebugRecordingHelper() override { |
| 73 if (on_destruction_closure_in_mock_) | 71 if (on_destruction_closure_in_mock_) |
| 74 std::move(on_destruction_closure_in_mock_).Run(); | 72 std::move(on_destruction_closure_in_mock_).Run(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 MOCK_METHOD1(EnableDebugRecording, void(const base::FilePath&)); | 75 MOCK_METHOD1(EnableDebugRecording, void(const base::FilePath&)); |
| 78 MOCK_METHOD0(DisableDebugRecording, void()); | 76 MOCK_METHOD0(DisableDebugRecording, void()); |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 // We let the mock run the destruction closure to not rely on the real | 79 // We let the mock run the destruction closure to not rely on the real |
| 82 // implementation. | 80 // implementation. |
| 83 base::OnceClosure on_destruction_closure_in_mock_; | 81 base::OnceClosure on_destruction_closure_in_mock_; |
| 84 | 82 |
| 85 DISALLOW_COPY_AND_ASSIGN(MockAudioDebugRecordingHelper); | 83 DISALLOW_COPY_AND_ASSIGN(MockAudioDebugRecordingHelper); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 // Sub-class of the manager that overrides the CreateAudioDebugRecordingHelper | 86 // Sub-class of the manager that overrides the CreateAudioDebugRecordingHelper |
| 89 // function to create the above mock instead. | 87 // function to create the above mock instead. |
| 90 class AudioDebugRecordingManagerUnderTest : public AudioDebugRecordingManager { | 88 class AudioDebugRecordingManagerUnderTest : public AudioDebugRecordingManager { |
| 91 public: | 89 public: |
| 92 AudioDebugRecordingManagerUnderTest( | 90 AudioDebugRecordingManagerUnderTest( |
| 93 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 91 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 94 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) | 92 : AudioDebugRecordingManager(std::move(task_runner)) {} |
| 95 : AudioDebugRecordingManager(std::move(task_runner), | |
| 96 std::move(file_task_runner)) {} | |
| 97 ~AudioDebugRecordingManagerUnderTest() override {} | 93 ~AudioDebugRecordingManagerUnderTest() override {} |
| 98 | 94 |
| 99 private: | 95 private: |
| 100 std::unique_ptr<AudioDebugRecordingHelper> CreateAudioDebugRecordingHelper( | 96 std::unique_ptr<AudioDebugRecordingHelper> CreateAudioDebugRecordingHelper( |
| 101 const AudioParameters& params, | 97 const AudioParameters& params, |
| 102 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 98 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 103 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | |
| 104 base::OnceClosure on_destruction_closure) override { | 99 base::OnceClosure on_destruction_closure) override { |
| 105 return base::MakeUnique<MockAudioDebugRecordingHelper>( | 100 return base::MakeUnique<MockAudioDebugRecordingHelper>( |
| 106 params, std::move(task_runner), std::move(file_task_runner), | 101 params, std::move(task_runner), std::move(on_destruction_closure)); |
| 107 std::move(on_destruction_closure)); | |
| 108 } | 102 } |
| 109 | 103 |
| 110 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManagerUnderTest); | 104 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingManagerUnderTest); |
| 111 }; | 105 }; |
| 112 | 106 |
| 113 // The test fixture. | 107 // The test fixture. |
| 114 class AudioDebugRecordingManagerTest : public ::testing::Test { | 108 class AudioDebugRecordingManagerTest : public ::testing::Test { |
| 115 public: | 109 public: |
| 116 AudioDebugRecordingManagerTest() | 110 AudioDebugRecordingManagerTest() |
| 117 : manager_(message_loop_.task_runner(), message_loop_.task_runner()), | 111 : manager_(message_loop_.task_runner()), |
| 118 base_file_path_(base::FilePath::FromUTF8Unsafe("base_path")) {} | 112 base_file_path_(base::FilePath::FromUTF8Unsafe("base_path")) {} |
| 119 | 113 |
| 120 ~AudioDebugRecordingManagerTest() override {} | 114 ~AudioDebugRecordingManagerTest() override {} |
| 121 | 115 |
| 122 // Registers a source and increases counter for the expected next source id. | 116 // Registers a source and increases counter for the expected next source id. |
| 123 std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource( | 117 std::unique_ptr<AudioDebugRecorder> RegisterDebugRecordingSource( |
| 124 const AudioParameters& params) { | 118 const AudioParameters& params) { |
| 125 ++expected_next_source_id_; | 119 ++expected_next_source_id_; |
| 126 return manager_.RegisterDebugRecordingSource(kFileNameExtension, params); | 120 return manager_.RegisterDebugRecordingSource(kFileNameExtension, params); |
| 127 } | 121 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 for (const auto& recorder : recorders) { | 214 for (const auto& recorder : recorders) { |
| 221 MockAudioDebugRecordingHelper* mock_recording_helper = | 215 MockAudioDebugRecordingHelper* mock_recording_helper = |
| 222 static_cast<MockAudioDebugRecordingHelper*>(recorder.get()); | 216 static_cast<MockAudioDebugRecordingHelper*>(recorder.get()); |
| 223 EXPECT_CALL(*mock_recording_helper, DisableDebugRecording()); | 217 EXPECT_CALL(*mock_recording_helper, DisableDebugRecording()); |
| 224 } | 218 } |
| 225 | 219 |
| 226 manager_.DisableDebugRecording(); | 220 manager_.DisableDebugRecording(); |
| 227 } | 221 } |
| 228 | 222 |
| 229 } // namespace media | 223 } // namespace media |
| OLD | NEW |