chromium/chrome/browser/enterprise/reporting/report_scheduler_unittest.cc

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

#include "components/enterprise/browser/reporting/report_scheduler.h"

#include <utility>

#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/strcat.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/reporting/prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/upgrade_detector/build_state.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/enterprise/browser/controller/fake_browser_dm_token_storage.h"
#include "components/enterprise/browser/reporting/chrome_profile_request_generator.h"
#include "components/enterprise/browser/reporting/common_pref_names.h"
#include "components/enterprise/browser/reporting/report_generator.h"
#include "components/enterprise/browser/reporting/report_request.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/reporting/client/report_queue_provider.h"
#include "components/reporting/proto/synced/record_constants.pb.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/version_info/version_info.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/enterprise/reporting/report_scheduler_android.h"
#include "chrome/browser/enterprise/reporting/reporting_delegate_factory_android.h"
#else
#include "chrome/browser/enterprise/reporting/report_scheduler_desktop.h"
#include "chrome/browser/enterprise/reporting/reporting_delegate_factory_desktop.h"
#endif  // BUILDFLAG(IS_ANDROID)

RunOnceCallback;
_;
ByMove;
DoAll;
Invoke;
InvokeWithoutArgs;
Return;
WithArgs;

em;
namespace enterprise_reporting {

namespace {

constexpr char kDMToken[] =;
constexpr char kClientId[] =;
constexpr base::TimeDelta kUploadFrequency =;
constexpr base::TimeDelta kNewUploadFrequency =;

constexpr char kUploadTriggerMetricName[] =;

}  // namespace

ACTION_P(ScheduleGeneratorCallback, request_number) {}

ACTION(ScheduleProfileRequestGeneratorCallback) {}

class MockReportGenerator : public ReportGenerator {};

class MockReportUploader : public ReportUploader {};

class MockChromeProfileRequestGenerator : public ChromeProfileRequestGenerator {};

class ReportSchedulerTest : public ::testing::Test {};

TEST_F(ReportSchedulerTest, NoReportWithoutPolicy) {}

// Chrome OS needn't set dm token and client id in the report scheduler.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ReportSchedulerTest, NoReportWithoutDMToken) {}

TEST_F(ReportSchedulerTest, NoReportWithoutClientId) {}
#endif

TEST_F(ReportSchedulerTest, UploadReportSucceeded) {}

// Profile reporting does not support ash.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ReportSchedulerTest, UploadReportSucceededForProfileReporting) {}
#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(ReportSchedulerTest, UploadReportTransientError) {}

TEST_F(ReportSchedulerTest, UploadReportPersistentError) {}

TEST_F(ReportSchedulerTest, NoReportGenerate) {}

TEST_F(ReportSchedulerTest, TimerDelayWithLastUploadTimestamp) {}

TEST_F(ReportSchedulerTest, TimerDelayWithoutLastUploadTimestamp) {}

TEST_F(ReportSchedulerTest, TimerDelayUpdate) {}

TEST_F(ReportSchedulerTest, IgnoreFrequencyWithoutReportEnabled) {}

TEST_F(ReportSchedulerTest,
       ReportingIsDisabledWhileNewReportIsScheduledButNotPosted) {}

TEST_F(ReportSchedulerTest, ReportingIsDisabledWhileNewReportIsPosted) {}

TEST_F(ReportSchedulerTest, ManualReport) {}

TEST_F(ReportSchedulerTest, ScheduledReportAfterManualReport) {}

TEST_F(ReportSchedulerTest, ManualReportWithRegularOneOngoing) {}

// Android does not support version updates
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)

// Tests that a basic report is generated and uploaded when a browser update is
// detected.
TEST_F(ReportSchedulerTest, OnUpdate) {}

TEST_F(ReportSchedulerTest, OnUpdateAndPersistentError) {}

// Tests that a full report is generated and uploaded following a basic report
// if the timer fires while the basic report is being uploaded.
TEST_F(ReportSchedulerTest, DeferredTimer) {}

// Tests that a basic report is generated and uploaded during startup when a
// new version is being run and the last periodic upload was less than a day
// ago.
TEST_F(ReportSchedulerTest, OnNewVersion) {}

// Tests that a full report is generated and uploaded during startup when a
// new version is being run and the last periodic upload was more than a day
// ago.
TEST_F(ReportSchedulerTest, OnNewVersionRegularReport) {}

#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace enterprise_reporting