forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_recording_unittest.cc
204 lines (164 loc) · 6.61 KB
/
debug_recording_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/audio/debug_recording.h"
#include <memory>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/test/task_environment.h"
#include "media/audio/aecdump_recording_manager.h"
#include "media/audio/audio_debug_recording_test.h"
#include "media/audio/mock_audio_debug_recording_manager.h"
#include "media/audio/mock_audio_manager.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/audio/public/cpp/debug_recording_session.h"
#include "services/audio/public/mojom/debug_recording.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
using testing::_;
using testing::Exactly;
using testing::Sequence;
namespace audio {
namespace {
const base::FilePath::CharType kBaseFileName[] =
FILE_PATH_LITERAL("base_file_name");
// Empty function bound and passed to DebugRecording::CreateWavFile and
// DebugRecording::CreateAecdumpFile.
void FileCreated(base::File file) {}
} // namespace
class MockFileProvider : public mojom::DebugRecordingFileProvider {
public:
MockFileProvider(
mojo::PendingReceiver<mojom::DebugRecordingFileProvider> receiver,
const base::FilePath& file_name_base)
: receiver_(this, std::move(receiver)) {}
MockFileProvider(const MockFileProvider&) = delete;
MockFileProvider& operator=(const MockFileProvider&) = delete;
MOCK_METHOD2(DoCreateWavFile,
void(media::AudioDebugRecordingStreamType stream_type,
uint32_t id));
MOCK_METHOD1(DoCreateAecdumpFile, void(uint32_t id));
void CreateWavFile(media::AudioDebugRecordingStreamType stream_type,
uint32_t id,
CreateWavFileCallback reply_callback) override {
DoCreateWavFile(stream_type, id);
std::move(reply_callback).Run(base::File());
}
void CreateAecdumpFile(uint32_t id,
CreateAecdumpFileCallback reply_callback) override {
DoCreateAecdumpFile(id);
std::move(reply_callback).Run(base::File());
}
private:
mojo::Receiver<mojom::DebugRecordingFileProvider> receiver_;
};
class MockAecdumpRecordingManager : public media::AecdumpRecordingManager {
public:
explicit MockAecdumpRecordingManager(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: AecdumpRecordingManager(task_runner) {}
MOCK_METHOD1(EnableDebugRecording, void(CreateFileCallback));
MOCK_METHOD0(DisableDebugRecording, void());
};
class DebugRecordingTest : public media::AudioDebugRecordingTest {
public:
DebugRecordingTest() = default;
DebugRecordingTest(const DebugRecordingTest&) = delete;
DebugRecordingTest& operator=(const DebugRecordingTest&) = delete;
~DebugRecordingTest() override = default;
void SetUp() override {
CreateAudioManager();
InitializeAudioDebugRecordingManager();
mock_aecdump_recording_manager_ =
std::make_unique<MockAecdumpRecordingManager>(
mock_audio_manager_->GetTaskRunner());
}
void TearDown() override { ShutdownAudioManager(); }
protected:
void CreateDebugRecording() {
if (remote_debug_recording_)
remote_debug_recording_.reset();
debug_recording_ = std::make_unique<DebugRecording>(
remote_debug_recording_.BindNewPipeAndPassReceiver(),
static_cast<media::AudioManager*>(mock_audio_manager_.get()),
mock_aecdump_recording_manager_.get());
}
void EnableDebugRecording() {
mojo::PendingRemote<mojom::DebugRecordingFileProvider> remote_file_provider;
DebugRecordingSession::DebugRecordingFileProvider file_provider(
remote_file_provider.InitWithNewPipeAndPassReceiver(),
base::FilePath(kBaseFileName));
remote_debug_recording_->Enable(std::move(remote_file_provider));
}
void DestroyDebugRecording() {
remote_debug_recording_.reset();
task_environment_.RunUntilIdle();
}
std::unique_ptr<MockAecdumpRecordingManager> mock_aecdump_recording_manager_;
std::unique_ptr<DebugRecording> debug_recording_;
mojo::Remote<mojom::DebugRecording> remote_debug_recording_;
};
TEST_F(DebugRecordingTest, EnableResetEnablesDisablesDebugRecording) {
Sequence s1;
EXPECT_CALL(*mock_debug_recording_manager_, EnableDebugRecording(_))
.InSequence(s1);
EXPECT_CALL(*mock_debug_recording_manager_, DisableDebugRecording())
.InSequence(s1);
Sequence s2;
EXPECT_CALL(*mock_aecdump_recording_manager_, EnableDebugRecording(_))
.InSequence(s2);
EXPECT_CALL(*mock_aecdump_recording_manager_, DisableDebugRecording())
.InSequence(s2);
CreateDebugRecording();
EnableDebugRecording();
DestroyDebugRecording();
}
TEST_F(DebugRecordingTest, ResetWithoutEnableDoesNotDisableDebugRecording) {
EXPECT_CALL(*mock_debug_recording_manager_, DisableDebugRecording()).Times(0);
EXPECT_CALL(*mock_aecdump_recording_manager_, DisableDebugRecording())
.Times(0);
CreateDebugRecording();
DestroyDebugRecording();
}
TEST_F(DebugRecordingTest, CreateFileCallsFileProviderCreateFile) {
Sequence s1;
EXPECT_CALL(*mock_debug_recording_manager_, EnableDebugRecording(_))
.InSequence(s1);
EXPECT_CALL(*mock_debug_recording_manager_, DisableDebugRecording())
.InSequence(s1);
Sequence s2;
EXPECT_CALL(*mock_aecdump_recording_manager_, EnableDebugRecording(_))
.InSequence(s2);
EXPECT_CALL(*mock_aecdump_recording_manager_, DisableDebugRecording())
.InSequence(s2);
CreateDebugRecording();
mojo::PendingRemote<mojom::DebugRecordingFileProvider> remote_file_provider;
MockFileProvider mock_file_provider(
remote_file_provider.InitWithNewPipeAndPassReceiver(),
base::FilePath(kBaseFileName));
remote_debug_recording_->Enable(std::move(remote_file_provider));
task_environment_.RunUntilIdle();
const int id = 1;
EXPECT_CALL(
mock_file_provider,
DoCreateWavFile(media::AudioDebugRecordingStreamType::kInput, id));
EXPECT_CALL(mock_file_provider, DoCreateAecdumpFile(id));
debug_recording_->CreateWavFile(media::AudioDebugRecordingStreamType::kInput,
id, base::BindOnce(&FileCreated));
debug_recording_->CreateAecdumpFile(id, base::BindOnce(&FileCreated));
task_environment_.RunUntilIdle();
DestroyDebugRecording();
}
TEST_F(DebugRecordingTest, SequencialCreate) {
CreateDebugRecording();
DestroyDebugRecording();
CreateDebugRecording();
DestroyDebugRecording();
}
TEST_F(DebugRecordingTest, ConcurrentCreate) {
CreateDebugRecording();
CreateDebugRecording();
DestroyDebugRecording();
}
} // namespace audio