#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/enterprise/connectors/reporting/extension_telemetry_event_router_factory.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client_factory.h"
#include "chrome/browser/enterprise/connectors/test/deep_scanning_test_utils.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/safe_browsing/extension_telemetry/cookies_get_signal.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_uploader.h"
#include "chrome/browser/safe_browsing/extension_telemetry/tabs_execute_script_signal.h"
#include "chrome/browser/safe_browsing/test_extension_event_observer.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/crx_file/id_util.h"
#include "components/enterprise/connectors/core/reporting_service_settings.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/management/scoped_management_service_override_for_testing.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/browser_context.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/switches.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
Extension;
ExtensionBuilder;
ExtensionId;
ManifestLocation;
ExtensionInfo;
TelemetryReport;
ExtensionTelemetryReportResponse;
OffstoreExtensionVerdict;
ExtensionService;
namespace safe_browsing {
namespace {
constexpr auto kExtensionId = …;
constexpr auto kExtensionName = …;
constexpr const char kExtensionVersion[] = …;
constexpr const char kTestUpdateUrl[] = …;
constexpr const char kInstallationMode[] = …;
constexpr const char kUpdateUrl[] = …;
constexpr const char kScriptCode[] = …;
constexpr const char kCookieName[] = …;
constexpr const char kCookieStoreId[] = …;
constexpr const char kCookieURL[] = …;
constexpr char kFileDataProcessTimestampPref[] = …;
constexpr char kFileDataDictPref[] = …;
constexpr char kManifestFile[] = …;
constexpr char kJavaScriptFile[] = …;
}
class ExtensionTelemetryServiceTest : public ::testing::Test { … };
ExtensionTelemetryServiceTest::ExtensionTelemetryServiceTest()
: … { … }
base::FilePath ExtensionTelemetryServiceTest::CreateExtensionForCommandLineLoad(
const std::string& extension_name) { … }
void ExtensionTelemetryServiceTest::RegisterExtensionWithExtensionService(
const ExtensionId& extension_id,
const std::string& extension_name,
const ManifestLocation& location,
int flags) { … }
void ExtensionTelemetryServiceTest::UnregisterExtensionWithExtensionService(
const ExtensionId& extension_id) { … }
void ExtensionTelemetryServiceTest::PrimeTelemetryServiceWithSignal() { … }
TEST_F(ExtensionTelemetryServiceTest, CheckEnableConditionsForESB) { … }
TEST_F(ExtensionTelemetryServiceTest, CheckEnableConditionsForEnterprise) { … }
TEST_F(ExtensionTelemetryServiceTest, ProcessesSignal) { … }
TEST_F(ExtensionTelemetryServiceTest, ProcessesSignalForEnterprise) { … }
TEST_F(ExtensionTelemetryServiceTest, DiscardsInvalidSignal) { … }
TEST_F(ExtensionTelemetryServiceTest, GeneratesReportAtProperIntervals) { … }
TEST_F(ExtensionTelemetryServiceTest, DoesNotGenerateEmptyTelemetryReport) { … }
TEST_F(ExtensionTelemetryServiceTest,
DoesNotGenerateEmptyTelemetryReportForEnterprise) { … }
TEST_F(ExtensionTelemetryServiceTest, GeneratesTelemetryReportWithNoSignals) { … }
TEST_F(ExtensionTelemetryServiceTest,
GeneratesTelemetryReportWithSignalForESBOnly) { … }
TEST_F(ExtensionTelemetryServiceTest,
GeneratesTelemetryReportWithSignalForEnterpriseOnly) { … }
TEST_F(ExtensionTelemetryServiceTest,
GeneratesTelemetryReportWithSignalForESBAndEnterprise) { … }
TEST_F(ExtensionTelemetryServiceTest,
GeneratesTelemetryReportWithDeveloperMode) { … }
TEST_F(ExtensionTelemetryServiceTest,
GeneratesTelemetryReportWithManagementAuthorityTrustworthiness) { … }
TEST_F(ExtensionTelemetryServiceTest, TestExtensionInfoProtoConstruction) { … }
TEST_F(ExtensionTelemetryServiceTest,
PersistsReportsOnShutdownWithSignalDataPresent) { … }
TEST_F(ExtensionTelemetryServiceTest,
DoesNotPersistsReportsOnShutdownWithNoSignalDataPresent) { … }
TEST_F(ExtensionTelemetryServiceTest, PersistsReportOnFailedUpload) { … }
TEST_F(ExtensionTelemetryServiceTest, NoReportPersistedIfUploadSucceeds) { … }
TEST_F(ExtensionTelemetryServiceTest, PersistsReportsOnInterval) { … }
TEST_F(ExtensionTelemetryServiceTest, MalformedPersistedFile) { … }
TEST_F(ExtensionTelemetryServiceTest, StartupUploadCheck) { … }
TEST_F(ExtensionTelemetryServiceTest, PersisterThreadSafetyCheck) { … }
TEST_F(ExtensionTelemetryServiceTest, FileData_ProcessesOffstoreExtensions) { … }
TEST_F(ExtensionTelemetryServiceTest, FileData_IgnoresNonOffstoreExtensions) { … }
TEST_F(ExtensionTelemetryServiceTest, FileData_RemovesStaleExtensionFromPref) { … }
TEST_F(ExtensionTelemetryServiceTest,
FileData_ProcessesEachExtensionOncePerDay) { … }
TEST_F(ExtensionTelemetryServiceTest, FileData_HandlesEmptyTimestampsInPrefs) { … }
TEST_F(ExtensionTelemetryServiceTest,
FileData_AttachesOffstoreFileDataToReport) { … }
TEST_F(ExtensionTelemetryServiceTest,
FileData_IncludesCommandlineExtensionsFileDataInReport) { … }
TEST_F(ExtensionTelemetryServiceTest,
FileData_DoesNotAttachFileDataForNonOffstoreExtensions) { … }
TEST_F(ExtensionTelemetryServiceTest, FileData_HandlesEmptyFileDataInPrefs) { … }
TEST_F(ExtensionTelemetryServiceTest,
FileData_EnforcesCollectionDurationLimit) { … }
TEST_F(ExtensionTelemetryServiceTest, DisableOffstoreExtensions) { … }
TEST_F(ExtensionTelemetryServiceTest,
DisableOffstoreExtensions_IgnoresNonOffstoreExtensions) { … }
TEST_F(ExtensionTelemetryServiceTest, DisableOffstoreExtensions_Reenable) { … }
}