Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: content/browser/media/webrtc_aecdump_browsertest.cc

Issue 1272223003: Implement writing mic audio input data to file for debugging purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/media/webrtc_audio_debug_recordings_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/process/process_handle.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/stringprintf.h"
8 #include "content/browser/media/webrtc_internals.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "content/test/webrtc_content_browsertest_base.h"
14 #include "media/audio/audio_manager.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16
17 namespace {
18
19 const int kExpectedConsumerId = 0;
20
21 // Get the ID for the render process host when there should only be one.
22 bool GetRenderProcessHostId(base::ProcessId* id) {
23 content::RenderProcessHost::iterator it(
24 content::RenderProcessHost::AllHostsIterator());
25 *id = base::GetProcId(it.GetCurrentValue()->GetHandle());
26 EXPECT_NE(base::kNullProcessId, *id);
27 if (*id == base::kNullProcessId)
28 return false;
29 it.Advance();
30 EXPECT_TRUE(it.IsAtEnd());
31 return it.IsAtEnd();
32 }
33
34 } // namespace
35
36 namespace content {
37
38 class WebRtcAecDumpBrowserTest : public WebRtcContentBrowserTest {
39 public:
40 WebRtcAecDumpBrowserTest() {}
41 ~WebRtcAecDumpBrowserTest() override {}
42 };
43
44 #if defined(OS_WIN)
45 #define IntToStringType base::IntToString16
46 #else
47 #define IntToStringType base::IntToString
48 #endif
49
50 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
51 // Timing out on ARM linux bot: http://crbug.com/238490
52 #define MAYBE_CallWithAecDump DISABLED_CallWithAecDump
53 #elif defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
54 // Renderer crashes under Android ASAN: https://crbug.com/408496.
55 #define MAYBE_CallWithAecDump DISABLED_CallWithAecDump
56 #else
57 #define MAYBE_CallWithAecDump CallWithAecDump
58 #endif
59
60 // This tests will make a complete PeerConnection-based call, verify that
61 // video is playing for the call, and verify that a non-empty AEC dump file
62 // exists. The AEC dump is enabled through webrtc-internals. The HTML and
63 // Javascript is bypassed since it would trigger a file picker dialog. Instead,
64 // the dialog callback FileSelected() is invoked directly. In fact, there's
65 // never a webrtc-internals page opened at all since that's not needed.
66 IN_PROC_BROWSER_TEST_F(WebRtcAecDumpBrowserTest, MAYBE_CallWithAecDump) {
67 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
68 LOG(INFO) << "Missing output devices: skipping test...";
69 return;
70 }
71
72 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
73
74 // We must navigate somewhere first so that the render process is created.
75 NavigateToURL(shell(), GURL(""));
76
77 base::FilePath dump_file;
78 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
79 base::DeleteFile(dump_file, false);
80
81 // This fakes the behavior of another open tab with webrtc-internals, and
82 // enabling AEC dump in that tab.
83 WebRTCInternals::GetInstance()->FileSelected(dump_file, -1, NULL);
84
85 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
86 NavigateToURL(shell(), url);
87 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
88
89 EXPECT_FALSE(base::PathExists(dump_file));
90
91 // Add file extensions that we expect to be added. The dump name will be
92 // <temporary path>.<render process id>.<consumer id>, for example
93 // "/tmp/.com.google.Chrome.Z6UC3P.12345.0".
94 base::ProcessId render_process_id = base::kNullProcessId;
95 EXPECT_TRUE(GetRenderProcessHostId(&render_process_id));
96 dump_file = dump_file.AddExtension(IntToStringType(render_process_id))
97 .AddExtension(IntToStringType(kExpectedConsumerId));
98
99 EXPECT_TRUE(base::PathExists(dump_file));
100 int64 file_size = 0;
101 EXPECT_TRUE(base::GetFileSize(dump_file, &file_size));
102 EXPECT_GT(file_size, 0);
103
104 base::DeleteFile(dump_file, false);
105 }
106
107 // TODO(grunell): Add test for multiple dumps when re-use of
108 // MediaStreamAudioProcessor in AudioCapturer has been removed.
109
110 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
111 // Timing out on ARM linux bot: http://crbug.com/238490
112 #define MAYBE_CallWithAecDumpEnabledThenDisabled DISABLED_CallWithAecDumpEnabled ThenDisabled
113 #elif defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
114 // Renderer crashes under Android ASAN: https://crbug.com/408496.
115 #define MAYBE_CallWithAecDumpEnabledThenDisabled DISABLED_CallWithAecDumpEnabled ThenDisabled
116 #else
117 #define MAYBE_CallWithAecDumpEnabledThenDisabled CallWithAecDumpEnabledThenDisab led
118 #endif
119
120 // As above, but enable and disable dump before starting a call. The file should
121 // be created, but should be empty.
122 IN_PROC_BROWSER_TEST_F(WebRtcAecDumpBrowserTest,
123 MAYBE_CallWithAecDumpEnabledThenDisabled) {
124 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
125 LOG(INFO) << "Missing output devices: skipping test...";
126 return;
127 }
128
129 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
130
131 // We must navigate somewhere first so that the render process is created.
132 NavigateToURL(shell(), GURL(""));
133
134 base::FilePath dump_file;
135 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
136 base::DeleteFile(dump_file, false);
137
138 // This fakes the behavior of another open tab with webrtc-internals, and
139 // enabling AEC dump in that tab, then disabling it.
140 WebRTCInternals::GetInstance()->FileSelected(dump_file, -1, NULL);
141 WebRTCInternals::GetInstance()->DisableAecDump();
142
143 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
144 NavigateToURL(shell(), url);
145 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
146
147 // Add file extensions that we expect to be added.
148 base::ProcessId render_process_id = base::kNullProcessId;
149 EXPECT_TRUE(GetRenderProcessHostId(&render_process_id));
150 dump_file = dump_file.AddExtension(IntToStringType(render_process_id))
151 .AddExtension(IntToStringType(kExpectedConsumerId));
152
153 EXPECT_FALSE(base::PathExists(dump_file));
154
155 base::DeleteFile(dump_file, false);
156 }
157
158 // Timing out on ARM linux bot: http://crbug.com/238490
159 // Renderer crashes under Android ASAN: https://crbug.com/408496.
160 // Flaky on XP and Mac: http://crbug.com/425034.
161 IN_PROC_BROWSER_TEST_F(WebRtcAecDumpBrowserTest, DISABLED_TwoCallsWithAecDump) {
162 if (OnWinXp()) {
163 LOG(INFO) << "Disabled on Win XP: skipping test...";
164 return;
165 }
166 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
167 LOG(INFO) << "Missing output devices: skipping test...";
168 return;
169 }
170
171 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
172
173 // We must navigate somewhere first so that the render process is created.
174 NavigateToURL(shell(), GURL(""));
175
176 // Create a second window.
177 Shell* shell2 = CreateBrowser();
178 NavigateToURL(shell2, GURL(""));
179
180 base::FilePath dump_file;
181 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
182 base::DeleteFile(dump_file, false);
183
184 // This fakes the behavior of another open tab with webrtc-internals, and
185 // enabling AEC dump in that tab.
186 WebRTCInternals::GetInstance()->FileSelected(dump_file, -1, NULL);
187
188 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
189
190 NavigateToURL(shell(), url);
191 NavigateToURL(shell2, url);
192 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
193 std::string result;
194 EXPECT_TRUE(ExecuteScriptAndExtractString(
195 shell2->web_contents(),
196 "call({video: true, audio: true});",
197 &result));
198 ASSERT_STREQ("OK", result.c_str());
199
200 EXPECT_FALSE(base::PathExists(dump_file));
201
202 RenderProcessHost::iterator it =
203 content::RenderProcessHost::AllHostsIterator();
204 for (; !it.IsAtEnd(); it.Advance()) {
205 base::ProcessId render_process_id =
206 base::GetProcId(it.GetCurrentValue()->GetHandle());
207 EXPECT_NE(base::kNullProcessId, render_process_id);
208
209 // Add file extensions that we expect to be added.
210 base::FilePath unique_dump_file =
211 dump_file.AddExtension(IntToStringType(render_process_id))
212 .AddExtension(IntToStringType(kExpectedConsumerId));
213
214 EXPECT_TRUE(base::PathExists(unique_dump_file));
215 int64 file_size = 0;
216 EXPECT_TRUE(base::GetFileSize(unique_dump_file, &file_size));
217 EXPECT_GT(file_size, 0);
218
219 base::DeleteFile(unique_dump_file, false);
220 }
221 }
222
223 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/webrtc_audio_debug_recordings_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698