Commit 3c4c7fde authored by Elad Alon's avatar Elad Alon Committed by Commit Bot

Initialize WebRtcEventLogManager before WebRTCInternals

Bug: 775415
Change-Id: I334dda306d5844784fd13f9e046cbe7b6722e92b
Reviewed-on: https://chromium-review.googlesource.com/973166Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Elad Alon <eladalon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545763}
parent dc850d8f
......@@ -309,6 +309,11 @@ void BrowserProcessImpl::Init() {
std::max(std::min(max_per_proxy, 99),
net::ClientSocketPoolManager::max_sockets_per_group(
net::HttpNetworkSession::NORMAL_SOCKET_POOL)));
#if BUILDFLAG(ENABLE_WEBRTC)
DCHECK(!webrtc_event_log_manager_);
webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
#endif
}
BrowserProcessImpl::~BrowserProcessImpl() {
......@@ -1165,11 +1170,6 @@ void BrowserProcessImpl::PreMainMessageLoopRun() {
base::WrapUnique(new base::DefaultTickClock()), local_state(),
system_request_context());
}
#if BUILDFLAG(ENABLE_WEBRTC)
DCHECK(!webrtc_event_log_manager_);
webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
#endif
}
void BrowserProcessImpl::CreateIconManager() {
......
......@@ -711,3 +711,7 @@ WebRtcEventLogManager::GetTaskRunnerForTesting() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return task_runner_;
}
void WebRtcEventLogManager::PostNullTaskForTesting(base::OnceClosure reply) {
task_runner_->PostTask(FROM_HERE, std::move(reply));
}
......@@ -271,8 +271,11 @@ class WebRtcEventLogManager final : public content::RenderProcessHostObserver,
// This allows unit tests that do not wish to change the task runner to still
// check when certain operations are finished.
// TODO(crbug.com/775415): Remove this and use PostNullTaskForTesting instead.
scoped_refptr<base::SequencedTaskRunner>& GetTaskRunnerForTesting();
void PostNullTaskForTesting(base::OnceClosure reply) override;
static WebRtcEventLogManager* g_webrtc_event_log_manager;
// Observer which will be informed whenever a local log file is started or
......
// Copyright (c) 2018 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/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/webrtc_event_logger.h"
#include "content/public/common/content_switches.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
}
class WebRTCInternalsIntegrationBrowserTest : public WebRtcTestBase {
public:
~WebRTCInternalsIntegrationBrowserTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
InProcessBrowserTest::SetUpDefaultCommandLine(command_line);
command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(local_logs_dir_.CreateUniqueTempDir());
}
command_line->AppendSwitchASCII(switches::kWebRtcLocalEventLogging,
local_logs_dir_.GetPath().MaybeAsASCII());
}
// To avoid flaky tests, we need to synchronize with WebRtcEventLogger's
// internal task runners (if any exist) before we examine anything we
// expect to be produced by WebRtcEventLogger (files, etc.).
void WaitForEventLogProcessing() {
auto* webrtc_event_logger = content::WebRtcEventLogger::Get();
ASSERT_TRUE(webrtc_event_logger);
base::RunLoop run_loop;
webrtc_event_logger->PostNullTaskForTesting(run_loop.QuitWhenIdleClosure());
run_loop.Run();
}
bool IsDirectoryEmpty(const base::FilePath& path) {
base::ScopedAllowBlockingForTesting allow_blocking;
return base::IsDirectoryEmpty(path);
}
base::ScopedTempDir local_logs_dir_;
};
IN_PROC_BROWSER_TEST_F(WebRTCInternalsIntegrationBrowserTest,
IntegrationWithWebRtcEventLogger) {
ASSERT_TRUE(embedded_test_server()->Start());
content::WebContents* tab =
OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
ASSERT_TRUE(IsDirectoryEmpty(local_logs_dir_.GetPath())); // Sanity on test.
// Local WebRTC event logging turned on from command line using the
// kWebRtcLocalEventLogging flag. When we set up a peer connection, it
// will be logged to a file under |local_logs_dir_|.
SetupPeerconnectionWithLocalStream(tab);
WaitForEventLogProcessing();
EXPECT_FALSE(IsDirectoryEmpty(local_logs_dir_.GetPath()));
}
......@@ -582,6 +582,7 @@ test("browser_tests") {
"../browser/media/webrtc/webrtc_desktop_capture_browsertest.cc",
"../browser/media/webrtc/webrtc_disable_encryption_flag_browsertest.cc",
"../browser/media/webrtc/webrtc_getmediadevices_browsertest.cc",
"../browser/media/webrtc/webrtc_internals_integration_browsertest.cc",
"../browser/media/webrtc/webrtc_internals_perf_browsertest.cc",
"../browser/media/webrtc/webrtc_rtp_browsertest.cc",
"../browser/media/webrtc/webrtc_simulcast_browsertest.cc",
......@@ -1783,6 +1784,7 @@ test("browser_tests") {
"../browser/media/webrtc/webrtc_browsertest.cc",
"../browser/media/webrtc/webrtc_disable_encryption_flag_browsertest.cc",
"../browser/media/webrtc/webrtc_getmediadevices_browsertest.cc",
"../browser/media/webrtc/webrtc_internals_integration_browsertest.cc",
"../browser/media/webrtc/webrtc_internals_perf_browsertest.cc",
"../browser/media/webrtc/webrtc_rtp_browsertest.cc",
"../browser/media/webrtc/webrtc_simulcast_browsertest.cc",
......
......@@ -11,6 +11,8 @@
#include "base/files/file_path.h"
#include "content/common/content_export.h"
class WebRTCInternalsIntegrationBrowserTest;
namespace content {
class BrowserContext;
......@@ -133,7 +135,15 @@ class CONTENT_EXPORT WebRtcEventLogger {
base::OnceCallback<void(std::pair<bool, bool>)>()) = 0;
protected:
friend WebRTCInternalsIntegrationBrowserTest; // (PostNullTaskForTesting)
WebRtcEventLogger();
// Allows tests to synchronize with internal task queues (if such exist in
// the subclass). This allows tests to only examine products (such as log
// files) at a time when, if the program is behaving as expected, they would
// be guaranteed to be ready.
virtual void PostNullTaskForTesting(base::OnceClosure reply) = 0;
};
} // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment