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

Side by Side Diff: chrome/browser/extensions/api/webrtc_logging_private/webrtc_event_log_apitest.cc

Issue 1650133002: Start and stop RTC event logs from private extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug in current time-limited audio debug recordings. Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2016 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/command_line.h"
6 #include "base/json/json_writer.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/threading/platform_thread.h"
9 #include "base/time/time.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h"
12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/media/webrtc_browsertest_base.h"
15 #include "chrome/browser/media/webrtc_browsertest_common.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "extensions/browser/api_test_utils.h"
20 #include "extensions/common/test_util.h"
21 #include "media/base/media_switches.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
23
24 #if defined(OS_WIN)
25 #define IntToStringType base::IntToString16
26 #else
27 #define IntToStringType base::IntToString
28 #endif
29
30 using extensions::WebrtcLoggingPrivateStartWebRtcEventLoggingFunction;
31 using extensions::WebrtcLoggingPrivateStopWebRtcEventLoggingFunction;
32
33 namespace utils = extension_function_test_utils;
34
35 namespace {
36
37 // Get the expected EventLog file name. The name will be
38 // <temporary path>.<render process id>.event_log.<consumer id>, for example
39 // "/tmp/.com.google.Chrome.Z6UC3P.12345.event_log.1".
40 base::FilePath GetExpectedEventLogFileName(const base::FilePath& base_file,
41 int render_process_id) {
42 const int kExpectedConsumerId = 1;
tommi (sloooow) - chröme 2016/04/07 12:44:29 nit: static const int kExpectedConsumerId = 1; (kF
terelius-chromium 2016/04/13 08:52:04 Done.
43 return base_file.AddExtension(IntToStringType(render_process_id))
44 .AddExtension(FILE_PATH_LITERAL("event_log"))
45 .AddExtension(IntToStringType(kExpectedConsumerId));
46 }
47
48 static const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
49
50 std::string ParamsToString(const base::ListValue& parameters) {
51 std::string parameter_string;
52 EXPECT_TRUE(base::JSONWriter::Write(parameters, &parameter_string));
53 return parameter_string;
54 }
55
56 class WebrtcEventLogApiTest : public WebRtcTestBase {
57 protected:
58 void SetUp() override {
59 WebRtcTestBase::SetUp();
60 extension_ = extensions::test_util::CreateEmptyExtension();
61 }
62
63 void SetUpInProcessBrowserTestFixture() override {
64 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
65 }
66
67 void SetUpCommandLine(base::CommandLine* command_line) override {
68 // Ensure the infobar is enabled, since we expect that in this test.
69 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
70
71 // Always use fake devices.
72 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
73
74 // Flag used by TestWebAudioMediaStream to force garbage collection.
75 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
76
77 // Enable the the event log in the extension API.
78 command_line->AppendSwitch(
79 switches::kEnableWebRtcEventLoggingFromExtension);
80 }
81
82 template <typename T>
83 scoped_refptr<T> CreateFunction() {
tommi (sloooow) - chröme 2016/04/07 12:44:29 nit: CreateExtensionFunction
terelius-chromium 2016/04/13 08:52:05 Done.
84 scoped_refptr<T> function(new T());
85 function->set_extension(extension_.get());
86 function->set_has_callback(true);
87 return function;
88 }
89
90 void AppendTabIdAndUrl(base::ListValue* parameters,
91 content::WebContents* tab) {
92 base::DictionaryValue* request_info = new base::DictionaryValue();
93 request_info->SetInteger("tabId",
94 extensions::ExtensionTabUtil::GetTabId(tab));
95 parameters->Append(request_info);
96 parameters->AppendString(tab->GetURL().GetOrigin().spec());
97 }
98
99 private:
100 scoped_refptr<extensions::Extension> extension_;
101 };
102
103 } // namespace
104
105 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, TestStartStopWebRtcEventLogging) {
106 if (OnWinXp())
tommi (sloooow) - chröme 2016/04/07 12:44:29 I don't think XP is supported any longer, so this
terelius-chromium 2016/04/13 08:52:04 Done.
107 return;
108
109 ASSERT_TRUE(embedded_test_server()->Start());
110
111 content::WebContents* left_tab =
112 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
113 content::WebContents* right_tab =
114 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
115
116 SetupPeerconnectionWithLocalStream(left_tab);
117 SetupPeerconnectionWithLocalStream(right_tab);
118
119 NegotiateCall(left_tab, right_tab, "VP8");
120
121 StartDetectingVideo(left_tab, "remote-view");
122 StartDetectingVideo(right_tab, "remote-view");
123
124 // Start the event log.
125 const int seconds = 0;
126 base::ListValue start_params;
127 AppendTabIdAndUrl(&start_params, left_tab);
128 start_params.AppendInteger(seconds);
129 scoped_refptr<WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>
130 start_function(CreateFunction<
131 WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>());
132 scoped_ptr<base::Value> start_result(utils::RunFunctionAndReturnSingleResult(
133 start_function.get(), ParamsToString(start_params), browser()));
134 ASSERT_TRUE(start_result.get());
135
136 // Get the file name.
137 scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
138 recordings_info_start(
139 extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
140 *start_result.get()));
141 ASSERT_TRUE(recordings_info_start.get());
142 base::FilePath file_name_start(
143 base::FilePath::FromUTF8Unsafe(recordings_info_start->prefix_path));
144
145 #if !defined(OS_MACOSX)
146 // Video is choppy on Mac OS X. http://crbug.com/443542.
147 WaitForVideoToPlay(left_tab);
148 WaitForVideoToPlay(right_tab);
149 #endif
150
151 // Stop the event log.
152 base::ListValue stop_params;
153 AppendTabIdAndUrl(&stop_params, left_tab);
154 scoped_refptr<WebrtcLoggingPrivateStopWebRtcEventLoggingFunction>
155 stop_function(
156 CreateFunction<WebrtcLoggingPrivateStopWebRtcEventLoggingFunction>());
157 scoped_ptr<base::Value> stop_result(utils::RunFunctionAndReturnSingleResult(
158 stop_function.get(), ParamsToString(stop_params), browser()));
159
160 // Get the file name.
161 scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
162 recordings_info_stop(
163 extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
164 *stop_result.get()));
165 ASSERT_TRUE(recordings_info_stop.get());
166 base::FilePath file_name_stop(
167 base::FilePath::FromUTF8Unsafe(recordings_info_stop->prefix_path));
168
169 HangUp(left_tab);
170 HangUp(right_tab);
171
172 EXPECT_EQ(file_name_start, file_name_stop);
173
174 // Check that the file exists and is non-empty.
175 base::ProcessId render_process_id =
176 base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle());
177 EXPECT_NE(render_process_id, base::kNullProcessId);
178 base::FilePath full_file_name =
179 GetExpectedEventLogFileName(file_name_stop, render_process_id);
tommi (sloooow) - chröme 2016/04/07 12:44:29 what if there were two tests running at the same t
terelius-chromium 2016/04/13 08:52:05 The path is based on Profile::GetPath(). This path
180 while (!base::PathExists(full_file_name)) {
181 LOG(INFO) << "Waiting for logfile to become available...";
tommi (sloooow) - chröme 2016/04/07 12:44:29 I think 'INFO' is discouraged. Instead use VLOG(1
terelius-chromium 2016/04/13 08:52:04 Done.
182 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
tommi (sloooow) - chröme 2016/04/07 12:44:29 ehm... ok, I see now what this loop is about. Sle
terelius-chromium 2016/04/13 08:52:05 I've updated the loop based on our offline discuss
183 }
184 EXPECT_TRUE(base::PathExists(full_file_name));
tommi (sloooow) - chröme 2016/04/07 12:44:29 should this be ASSERT_TRUE()? As is, you'll conti
terelius-chromium 2016/04/13 08:52:04 Done. However, the loop above will not exit until
185 int64_t file_size = 0;
186 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size));
187 EXPECT_GT(file_size, 0);
188
189 // Clean up.
190 base::DeleteFile(full_file_name, false);
tommi (sloooow) - chröme 2016/04/07 12:44:29 If you use some of the temporary file utilities in
terelius-chromium 2016/04/13 08:52:05 Acknowledged. The idea was to exercise the same co
191 }
192
193 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest,
194 TestStartTimedWebRtcEventLogging) {
195 if (OnWinXp())
196 return;
197
198 ASSERT_TRUE(embedded_test_server()->Start());
199
200 content::WebContents* left_tab =
201 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
202 content::WebContents* right_tab =
203 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
204
205 SetupPeerconnectionWithLocalStream(left_tab);
206 SetupPeerconnectionWithLocalStream(right_tab);
207
208 NegotiateCall(left_tab, right_tab, "VP8");
209
210 StartDetectingVideo(left_tab, "remote-view");
211 StartDetectingVideo(right_tab, "remote-view");
212
213 // Start the event log. RunFunctionAndReturnSingleResult will block until a
214 // result is available, which happens when the logging stops after 1 second.
215 const int seconds = 1;
216 base::ListValue start_params;
217 AppendTabIdAndUrl(&start_params, left_tab);
218 start_params.AppendInteger(seconds);
219 scoped_refptr<WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>
220 start_function(CreateFunction<
221 WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>());
222 scoped_ptr<base::Value> start_result(utils::RunFunctionAndReturnSingleResult(
223 start_function.get(), ParamsToString(start_params), browser()));
224 ASSERT_TRUE(start_result.get());
225
226 // Get the file name.
227 scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
228 recordings_info_start(
229 extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
230 *start_result.get()));
231 ASSERT_TRUE(recordings_info_start.get());
232 base::FilePath file_name_start(
233 base::FilePath::FromUTF8Unsafe(recordings_info_start->prefix_path));
234
235 #if !defined(OS_MACOSX)
236 // Video is choppy on Mac OS X. http://crbug.com/443542.
237 WaitForVideoToPlay(left_tab);
238 WaitForVideoToPlay(right_tab);
239 #endif
240
241 HangUp(left_tab);
242 HangUp(right_tab);
243
244 // The log has stopped automatically. Check that the file exists and is
245 // non-empty.
246 base::ProcessId render_process_id =
247 base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle());
248 EXPECT_NE(render_process_id, base::kNullProcessId);
249 base::FilePath full_file_name =
250 GetExpectedEventLogFileName(file_name_start, render_process_id);
251 while (!base::PathExists(full_file_name)) {
252 LOG(INFO) << "Waiting for logfile to become available...";
253 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
tommi (sloooow) - chröme 2016/04/07 12:44:29 Use RunLoop instead
terelius-chromium 2016/04/13 08:52:04 There is currently no easy way to get a callback f
254 }
255 int64_t file_size = 0;
256 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size));
257 EXPECT_GT(file_size, 0);
258
259 // Clean up.
260 base::DeleteFile(full_file_name, false);
261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698