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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webrtc_logging_private/webrtc_event_log_apitest.cc
diff --git a/chrome/browser/extensions/api/webrtc_logging_private/webrtc_event_log_apitest.cc b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_event_log_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..967c2d72901c983e463edfde34d0c5abed705443
--- /dev/null
+++ b/chrome/browser/extensions/api/webrtc_logging_private/webrtc_event_log_apitest.cc
@@ -0,0 +1,261 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/json/json_writer.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/threading/platform_thread.h"
+#include "base/time/time.h"
+#include "build/build_config.h"
+#include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.h"
+#include "chrome/browser/extensions/extension_function_test_utils.h"
+#include "chrome/browser/extensions/extension_tab_util.h"
+#include "chrome/browser/media/webrtc_browsertest_base.h"
+#include "chrome/browser/media/webrtc_browsertest_common.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
+#include "extensions/browser/api_test_utils.h"
+#include "extensions/common/test_util.h"
+#include "media/base/media_switches.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+
+#if defined(OS_WIN)
+#define IntToStringType base::IntToString16
+#else
+#define IntToStringType base::IntToString
+#endif
+
+using extensions::WebrtcLoggingPrivateStartWebRtcEventLoggingFunction;
+using extensions::WebrtcLoggingPrivateStopWebRtcEventLoggingFunction;
+
+namespace utils = extension_function_test_utils;
+
+namespace {
+
+// Get the expected EventLog file name. The name will be
+// <temporary path>.<render process id>.event_log.<consumer id>, for example
+// "/tmp/.com.google.Chrome.Z6UC3P.12345.event_log.1".
+base::FilePath GetExpectedEventLogFileName(const base::FilePath& base_file,
+ int render_process_id) {
+ 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.
+ return base_file.AddExtension(IntToStringType(render_process_id))
+ .AddExtension(FILE_PATH_LITERAL("event_log"))
+ .AddExtension(IntToStringType(kExpectedConsumerId));
+}
+
+static const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
+
+std::string ParamsToString(const base::ListValue& parameters) {
+ std::string parameter_string;
+ EXPECT_TRUE(base::JSONWriter::Write(parameters, &parameter_string));
+ return parameter_string;
+}
+
+class WebrtcEventLogApiTest : public WebRtcTestBase {
+ protected:
+ void SetUp() override {
+ WebRtcTestBase::SetUp();
+ extension_ = extensions::test_util::CreateEmptyExtension();
+ }
+
+ void SetUpInProcessBrowserTestFixture() override {
+ DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
+ }
+
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ // Ensure the infobar is enabled, since we expect that in this test.
+ EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
+
+ // Always use fake devices.
+ command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
+
+ // Flag used by TestWebAudioMediaStream to force garbage collection.
+ command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
+
+ // Enable the the event log in the extension API.
+ command_line->AppendSwitch(
+ switches::kEnableWebRtcEventLoggingFromExtension);
+ }
+
+ template <typename T>
+ 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.
+ scoped_refptr<T> function(new T());
+ function->set_extension(extension_.get());
+ function->set_has_callback(true);
+ return function;
+ }
+
+ void AppendTabIdAndUrl(base::ListValue* parameters,
+ content::WebContents* tab) {
+ base::DictionaryValue* request_info = new base::DictionaryValue();
+ request_info->SetInteger("tabId",
+ extensions::ExtensionTabUtil::GetTabId(tab));
+ parameters->Append(request_info);
+ parameters->AppendString(tab->GetURL().GetOrigin().spec());
+ }
+
+ private:
+ scoped_refptr<extensions::Extension> extension_;
+};
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, TestStartStopWebRtcEventLogging) {
+ 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.
+ return;
+
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ content::WebContents* left_tab =
+ OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
+ content::WebContents* right_tab =
+ OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
+
+ SetupPeerconnectionWithLocalStream(left_tab);
+ SetupPeerconnectionWithLocalStream(right_tab);
+
+ NegotiateCall(left_tab, right_tab, "VP8");
+
+ StartDetectingVideo(left_tab, "remote-view");
+ StartDetectingVideo(right_tab, "remote-view");
+
+ // Start the event log.
+ const int seconds = 0;
+ base::ListValue start_params;
+ AppendTabIdAndUrl(&start_params, left_tab);
+ start_params.AppendInteger(seconds);
+ scoped_refptr<WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>
+ start_function(CreateFunction<
+ WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>());
+ scoped_ptr<base::Value> start_result(utils::RunFunctionAndReturnSingleResult(
+ start_function.get(), ParamsToString(start_params), browser()));
+ ASSERT_TRUE(start_result.get());
+
+ // Get the file name.
+ scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
+ recordings_info_start(
+ extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
+ *start_result.get()));
+ ASSERT_TRUE(recordings_info_start.get());
+ base::FilePath file_name_start(
+ base::FilePath::FromUTF8Unsafe(recordings_info_start->prefix_path));
+
+#if !defined(OS_MACOSX)
+ // Video is choppy on Mac OS X. http://crbug.com/443542.
+ WaitForVideoToPlay(left_tab);
+ WaitForVideoToPlay(right_tab);
+#endif
+
+ // Stop the event log.
+ base::ListValue stop_params;
+ AppendTabIdAndUrl(&stop_params, left_tab);
+ scoped_refptr<WebrtcLoggingPrivateStopWebRtcEventLoggingFunction>
+ stop_function(
+ CreateFunction<WebrtcLoggingPrivateStopWebRtcEventLoggingFunction>());
+ scoped_ptr<base::Value> stop_result(utils::RunFunctionAndReturnSingleResult(
+ stop_function.get(), ParamsToString(stop_params), browser()));
+
+ // Get the file name.
+ scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
+ recordings_info_stop(
+ extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
+ *stop_result.get()));
+ ASSERT_TRUE(recordings_info_stop.get());
+ base::FilePath file_name_stop(
+ base::FilePath::FromUTF8Unsafe(recordings_info_stop->prefix_path));
+
+ HangUp(left_tab);
+ HangUp(right_tab);
+
+ EXPECT_EQ(file_name_start, file_name_stop);
+
+ // Check that the file exists and is non-empty.
+ base::ProcessId render_process_id =
+ base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle());
+ EXPECT_NE(render_process_id, base::kNullProcessId);
+ base::FilePath full_file_name =
+ 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
+ while (!base::PathExists(full_file_name)) {
+ 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.
+ 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
+ }
+ 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
+ int64_t file_size = 0;
+ EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size));
+ EXPECT_GT(file_size, 0);
+
+ // Clean up.
+ 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
+}
+
+IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest,
+ TestStartTimedWebRtcEventLogging) {
+ if (OnWinXp())
+ return;
+
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ content::WebContents* left_tab =
+ OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
+ content::WebContents* right_tab =
+ OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
+
+ SetupPeerconnectionWithLocalStream(left_tab);
+ SetupPeerconnectionWithLocalStream(right_tab);
+
+ NegotiateCall(left_tab, right_tab, "VP8");
+
+ StartDetectingVideo(left_tab, "remote-view");
+ StartDetectingVideo(right_tab, "remote-view");
+
+ // Start the event log. RunFunctionAndReturnSingleResult will block until a
+ // result is available, which happens when the logging stops after 1 second.
+ const int seconds = 1;
+ base::ListValue start_params;
+ AppendTabIdAndUrl(&start_params, left_tab);
+ start_params.AppendInteger(seconds);
+ scoped_refptr<WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>
+ start_function(CreateFunction<
+ WebrtcLoggingPrivateStartWebRtcEventLoggingFunction>());
+ scoped_ptr<base::Value> start_result(utils::RunFunctionAndReturnSingleResult(
+ start_function.get(), ParamsToString(start_params), browser()));
+ ASSERT_TRUE(start_result.get());
+
+ // Get the file name.
+ scoped_ptr<extensions::api::webrtc_logging_private::RecordingInfo>
+ recordings_info_start(
+ extensions::api::webrtc_logging_private::RecordingInfo::FromValue(
+ *start_result.get()));
+ ASSERT_TRUE(recordings_info_start.get());
+ base::FilePath file_name_start(
+ base::FilePath::FromUTF8Unsafe(recordings_info_start->prefix_path));
+
+#if !defined(OS_MACOSX)
+ // Video is choppy on Mac OS X. http://crbug.com/443542.
+ WaitForVideoToPlay(left_tab);
+ WaitForVideoToPlay(right_tab);
+#endif
+
+ HangUp(left_tab);
+ HangUp(right_tab);
+
+ // The log has stopped automatically. Check that the file exists and is
+ // non-empty.
+ base::ProcessId render_process_id =
+ base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle());
+ EXPECT_NE(render_process_id, base::kNullProcessId);
+ base::FilePath full_file_name =
+ GetExpectedEventLogFileName(file_name_start, render_process_id);
+ while (!base::PathExists(full_file_name)) {
+ LOG(INFO) << "Waiting for logfile to become available...";
+ 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
+ }
+ int64_t file_size = 0;
+ EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size));
+ EXPECT_GT(file_size, 0);
+
+ // Clean up.
+ base::DeleteFile(full_file_name, false);
+}

Powered by Google App Engine
This is Rietveld 408576698