chromium/chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service_unittest.cc

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

#include "chrome/browser/safe_browsing/tailored_security/chrome_tailored_security_service.h"

#include "base/files/scoped_temp_dir.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/chrome_signin_client_test_util.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/prefs/testing_pref_store.h"
#include "components/safe_browsing/core/browser/tailored_security_service/tailored_security_notification_result.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/sync/test/test_sync_service.h"
#include "components/sync_preferences/pref_model_associator_client.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

class Profile;

namespace safe_browsing {

// Names for Tailored Security status to make the test cases clearer.
const bool kTailoredSecurityEnabled =;
const bool kTailoredSecurityDisabled =;

namespace {
// Test implementation of ChromeTailoredSecurityService.
class TestChromeTailoredSecurityService : public ChromeTailoredSecurityService {};
}  // namespace

// TODO(crbug.com/40927036): Move tests related to base class behavior of
// MaybeNotifySyncUser to the test suite for TailoredSecurityService.
class ChromeTailoredSecurityServiceTest : public testing::Test {};

class ChromeTailoredSecurityServiceRetryForSyncUsersDisabledTest
    : public ChromeTailoredSecurityServiceTest {};

// Some of the test names are shorted using "Ts" for Tailored Security, "Ep"
// for Enhanced Protection and "Sb" for Safe Browsing.

TEST_F(ChromeTailoredSecurityServiceTest,
       TailoredSecurityEnabledShowsEnableDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       TailoredSecurityEnabledButHistorySyncDisabledDoesNotShowEnableDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       TailoredSecurityEnabledButHistorySyncDisabledLogsHistoryNotSynced) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       TailoredSecurityEnabledButHistorySyncEnabledDoesNotLogHistoryNotSynced) {}

TEST_F(ChromeTailoredSecurityServiceTest, TsEnabledEnablesEp) {}

TEST_F(ChromeTailoredSecurityServiceTest, EpAlreadyEnabledDoesNotShowDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest, EpAlreadyEnabledLeavesEpEnabled) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       EpWasEnabledByTsAndTsNowDisabledShowsDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       EpEnabledByTsAndTsNowDisabledDisablesEp) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       SpEnabledAndTsNowDisabledDoesNotShowDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       SpEnabledAndTsNowDisabledDoesNotChangeSb) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       EpEnabledByUserTsDisabledDoesNotShowDialog) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       EpEnabledByUserTsDisabledDoesNotChangeSb) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryEnabledOnSuccessStoresNoRetryNeeded) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryEnabledButHistorySyncDisabledSetsNoRetryNeeded) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryEnabledAndSbControlledByPolicySetsNoRetryNeeded) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryEnabledAndEpAlreadyEnabledSetsNoRetryNeeded) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       HistorySyncAndSbNotControlledByPolicyRunsRetryLogicAfterStartupDelay) {}

TEST_F(ChromeTailoredSecurityServiceTest, HistorySyncNotSetDoesNotRetry) {}

TEST_F(ChromeTailoredSecurityServiceTest, SbControlledByPolicyDoesNotRetry) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       TailoredSecurityUpdateTimeNotSetDoesNotRetry) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryNeededButNotEnoughTimeHasPassedDoesNotRetry) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryNeededAndEnoughTimeHasPassedRetries) {}

TEST_F(
    ChromeTailoredSecurityServiceTest,
    WhenRetryNeededAndEnoughTimeHasPassedUpdatesNextSyncFlowTimestampByNextAttemptDelay) {}

TEST_F(
    ChromeTailoredSecurityServiceTest,
    WhenRetryNotSetAndEnhancedProtectionEnabledViaTailoredSecurityDoesNotSetNextSyncFlowTimestamp) {}

TEST_F(
    ChromeTailoredSecurityServiceTest,
    WhenRetryNotSetAndNextSyncFlowNotSetSetsNextSyncFlowToWaitingIntervalFromNow) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryNotSetAndNextSyncFlowHasPassedRunsRetry) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryNotSetAndNextSyncFlowHasPassedSetsNextSyncFlowToTomorrow) {}

TEST_F(ChromeTailoredSecurityServiceTest,
       WhenRetryNotSetAndNextSyncFlowHasNotPassedDoesNotRunRetryLogic) {}

TEST_F(ChromeTailoredSecurityServiceTest, WhenNoRetryNeededDoesNotRetry) {}

TEST_F(ChromeTailoredSecurityServiceRetryForSyncUsersDisabledTest,
       OnSuccessDoesNotUpdateRetryStatePref) {}

TEST_F(ChromeTailoredSecurityServiceRetryForSyncUsersDisabledTest,
       WhenRetryForSyncUsersIsDisabledDoesNotRunRetryLogicAfterStartupDelay) {}

}  // namespace safe_browsing