Add ICU message format support
[chromium-blink-merge.git] / content / browser / media / webrtc_aecdump_browsertest.cc
blob212cc880b9bcfff4b43d6d65e93714afd4d7be45
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.
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"
17 namespace {
19 const int kExpectedConsumerId = 0;
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();
34 } // namespace
36 namespace content {
38 class WebRtcAecDumpBrowserTest : public WebRtcContentBrowserTest {
39 public:
40 WebRtcAecDumpBrowserTest() {}
41 ~WebRtcAecDumpBrowserTest() override {}
44 #if defined(OS_WIN)
45 #define IntToStringType base::IntToString16
46 #else
47 #define IntToStringType base::IntToString
48 #endif
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
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;
72 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
74 // We must navigate somewhere first so that the render process is created.
75 NavigateToURL(shell(), GURL(""));
77 base::FilePath dump_file;
78 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
79 base::DeleteFile(dump_file, false);
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);
85 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
86 NavigateToURL(shell(), url);
87 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
89 EXPECT_FALSE(base::PathExists(dump_file));
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));
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);
104 base::DeleteFile(dump_file, false);
107 // TODO(grunell): Add test for multiple dumps when re-use of
108 // MediaStreamAudioProcessor in AudioCapturer has been removed.
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_CallWithAecDumpEnabledThenDisabled
113 #elif defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
114 // Renderer crashes under Android ASAN: https://crbug.com/408496.
115 #define MAYBE_CallWithAecDumpEnabledThenDisabled DISABLED_CallWithAecDumpEnabledThenDisabled
116 #else
117 #define MAYBE_CallWithAecDumpEnabledThenDisabled CallWithAecDumpEnabledThenDisabled
118 #endif
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;
129 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
131 // We must navigate somewhere first so that the render process is created.
132 NavigateToURL(shell(), GURL(""));
134 base::FilePath dump_file;
135 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
136 base::DeleteFile(dump_file, false);
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();
143 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
144 NavigateToURL(shell(), url);
145 ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
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));
153 EXPECT_FALSE(base::PathExists(dump_file));
155 base::DeleteFile(dump_file, false);
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;
166 if (!media::AudioManager::Get()->HasAudioOutputDevices()) {
167 LOG(INFO) << "Missing output devices: skipping test...";
168 return;
171 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
173 // We must navigate somewhere first so that the render process is created.
174 NavigateToURL(shell(), GURL(""));
176 // Create a second window.
177 Shell* shell2 = CreateBrowser();
178 NavigateToURL(shell2, GURL(""));
180 base::FilePath dump_file;
181 ASSERT_TRUE(CreateTemporaryFile(&dump_file));
182 base::DeleteFile(dump_file, false);
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);
188 GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
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());
200 EXPECT_FALSE(base::PathExists(dump_file));
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);
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));
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);
219 base::DeleteFile(unique_dump_file, false);
223 } // namespace content