chromium/chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include <memory>
#include <utility>

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_writer.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager.h"
#include "chrome/browser/media/webrtc/webrtc_event_log_manager_common.h"
#include "chrome/browser/media/webrtc/webrtc_log_uploader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/policy_constants.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/common/extension_builder.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "third_party/zlib/google/compression_utils.h"

GzipUncompress;
Extension;
WebrtcLoggingPrivateDiscardFunction;
WebrtcLoggingPrivateSetMetaDataFunction;
WebrtcLoggingPrivateStartAudioDebugRecordingsFunction;
WebrtcLoggingPrivateStartEventLoggingFunction;
WebrtcLoggingPrivateStartFunction;
WebrtcLoggingPrivateStartRtpDumpFunction;
WebrtcLoggingPrivateStopAudioDebugRecordingsFunction;
WebrtcLoggingPrivateStopFunction;
WebrtcLoggingPrivateStopRtpDumpFunction;
WebrtcLoggingPrivateStoreFunction;
WebrtcLoggingPrivateUploadFunction;
WebrtcLoggingPrivateUploadStoredFunction;
kMaxOutputPeriodMs;
kMaxRemoteLogFileSizeBytes;
kStartRemoteLoggingFailureAlreadyLogging;
kStartRemoteLoggingFailureFeatureDisabled;
kStartRemoteLoggingFailureMaxSizeTooLarge;
kStartRemoteLoggingFailureMaxSizeTooSmall;
kStartRemoteLoggingFailureOutputPeriodMsTooLarge;
kStartRemoteLoggingFailureUnknownOrInactivePeerConnection;
kStartRemoteLoggingFailureUnlimitedSizeDisallowed;
kWebRtcEventLogManagerUnlimitedFileSize;
WebRtcEventLogManager;

utils;

namespace {

static const char kTestLoggingSessionIdKey[] =;
static const char kTestLoggingSessionIdValue[] =;
static const char kTestLoggingUrl[] =;

constexpr int kWebAppId =;  // Arbitrary.

constexpr char kTestUploadUrlPath[] =;
constexpr char kTestReportId[] =;

std::string ParamsToString(const base::Value::List& parameters) {}

void InitializeTestMetaData(base::Value::List& parameters) {}

class WebrtcLoggingPrivateApiTest : public extensions::ExtensionApiTest {};

}  // namespace

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopDiscard) {}

// Tests WebRTC diagnostic logging. Sets up the browser to save the multipart
// contents to a buffer instead of uploading it, then verifies it after a calls.
// Example of multipart contents:
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="prod"
//
// Chrome_Linux
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="ver"
//
// 30.0.1554.0
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="guid"
//
// 0
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="type"
//
// webrtc_log
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="app_session_id"
//
// 0123456789abcdef
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="url"
//
// http://127.0.0.1:43213/webrtc/webrtc_jsep01_test.html
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**----
// Content-Disposition: form-data; name="webrtc_log"; filename="webrtc_log.gz"
// Content-Type: application/gzip
//
// <compressed data (zip)>
// ------**--yradnuoBgoLtrapitluMklaTelgooG--**------
//
IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopUpload) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopRtpDump) {}

// Tests trying to store a log when a log is not being captured.
// We should get a failure callback in this case.
IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStoreWithoutLog) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, TestStartStopStore) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
                       TestStartStopStoreAndUpload) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
                       TestStartStopStoreAndUploadWithRtp) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
                       TestStartStopStoreAndUploadWithMetaData) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
                       TestStartStopAudioDebugRecordings) {}

IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
                       TestStartTimedAudioDebugRecordings) {}

#if !BUILDFLAG(IS_ANDROID)

// Fixture for various tests over StartEventLogging. Intended to be sub-classed
// to test different scenarios.
class WebrtcLoggingPrivateApiStartEventLoggingTestBase
    : public WebrtcLoggingPrivateApiTest {};

// Test StartEventLogging's behavior when the feature is active (kill-switch
// from Finch *not* engaged, working in a profile where the policy is
// configured).
class WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled
    : public WebrtcLoggingPrivateApiStartEventLoggingTestBase,
      public testing::WithParamInterface<bool> {};

// Also covers StartEventLoggingForLegalWebAppIdSucceeds scenario.
IN_PROC_BROWSER_TEST_P(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForKnownPeerConnectionSucceeds) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingWithUnlimitedSizeFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingWithTooSmallMaxSize) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingWithExcessiveMaxSizeFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingWithTooLargeOutputPeriodMsFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForNeverAddedPeerConnectionFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForWrongSessionIdFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingIfSessionIdNeverSetFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingIfSessionIdNeverSetFailsForEmptySessionId) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLogginWithEmptySessionIdFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForAlreadyLoggedPeerConnectionFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForTooLowWebAppIdFails) {}

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureAndPolicyEnabled,
    StartEventLoggingForTooHighWebAppIdFails) {}

INSTANTIATE_TEST_SUITE_P();

// Testing with either the feature or the policy disabled (not both).
class WebrtcLoggingPrivateApiStartEventLoggingTestFeatureOrPolicyDisabled
    : public WebrtcLoggingPrivateApiStartEventLoggingTestBase,
      public ::testing::WithParamInterface<bool> {};

IN_PROC_BROWSER_TEST_P(
    WebrtcLoggingPrivateApiStartEventLoggingTestFeatureOrPolicyDisabled,
    StartEventLoggingFails) {}

INSTANTIATE_TEST_SUITE_P();

// Make sure that, even if both the feature and the policy enable remote-bound
// event logging, it will be blocked for incognito sessions.
class WebrtcLoggingPrivateApiStartEventLoggingTestInIncognitoMode
    : public WebrtcLoggingPrivateApiStartEventLoggingTestBase {};

IN_PROC_BROWSER_TEST_F(
    WebrtcLoggingPrivateApiStartEventLoggingTestInIncognitoMode,
    StartEventLoggingFails) {}

#endif  // !BUILDFLAG(IS_ANDROID)