chromium/chrome/browser/ui/safety_hub/password_status_check_service_unittest.cc

// Copyright 2023 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/ui/safety_hub/password_status_check_service.h"

#include <string>
#include <string_view>

#include "base/json/values_util.h"
#include "base/location.h"
#include "base/test/bind.h"
#include "base/time/time.h"
#include "chrome/browser/password_manager/password_manager_test_util.h"
#include "chrome/browser/ui/safety_hub/password_status_check_result.h"
#include "chrome/browser/ui/safety_hub/safety_hub_constants.h"
#include "chrome/browser/ui/safety_hub/safety_hub_prefs.h"
#include "chrome/browser/ui/safety_hub/safety_hub_test_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "components/password_manager/core/browser/leak_detection/bulk_leak_check_service.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_delegate_interface.h"
#include "components/password_manager/core/browser/password_store/test_password_store.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/test/browser_task_environment.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

constexpr char kTestEmail[] =;
constexpr char kOrigin1[] =;
constexpr char kOrigin2[] =;
constexpr char16_t kUsername1[] =;
constexpr char16_t kUsername2[] =;
constexpr char16_t kUsername3[] =;
constexpr char16_t kUsername4[] =;
constexpr char16_t kPassword[] =;
constexpr char16_t kPassword2[] =;
constexpr char16_t kWeakPassword[] =;

BulkLeakCheckDelegateInterface;
BulkLeakCheckService;
BulkLeakCheckServiceInterface;
InsecureType;
IsLeaked;
LeakCheckCredential;
PasswordForm;
TestPasswordStore;
SafetyHubCardState;
MakeForm;

// Mock observer for BulkLeakCheckService for EXPECT_CALL.
class MockObserver : public BulkLeakCheckService::Observer {};

PasswordForm WeakForm() {}

PasswordForm LeakedForm() {}

PasswordForm ReusedForm1() {}

PasswordForm ReusedForm2() {}

}  // namespace

class PasswordStatusCheckServiceBaseTest : public testing::Test {};

class PasswordStatusCheckServiceParameterizedIssueTest
    : public PasswordStatusCheckServiceBaseTest,
      public testing::WithParamInterface<
          testing::tuple</*include_weak*/ bool,
                         /*include_compromised*/ bool,
                         /*include_reused*/ bool>> {};

class PasswordStatusCheckServiceParameterizedStoreTest
    : public PasswordStatusCheckServiceBaseTest,
      public testing::WithParamInterface</*use_profile_store*/ bool> {};

class PasswordStatusCheckServiceParameterizedCardTest
    : public PasswordStatusCheckServiceBaseTest,
      public testing::WithParamInterface<
          testing::tuple</*include_compromised*/ bool,
                         /*include_weak*/ bool,
                         /*include_reused*/ bool,
                         /*check_ran_previously*/ bool,
                         /*signed_in*/ bool,
                         /*include_safe_password*/ bool,
                         /*password_saving_allowed*/ bool>> {};

class PasswordStatusCheckServiceParameterizedSchedulingTest
    : public PasswordStatusCheckServiceBaseTest,
      public testing::WithParamInterface<int> {};

TEST_F(PasswordStatusCheckServiceBaseTest, NoIssuesInitially) {}

TEST_P(PasswordStatusCheckServiceParameterizedIssueTest,
       DetectIssuesDuringConstruction) {}

TEST_P(PasswordStatusCheckServiceParameterizedIssueTest,
       DetectIssuesWhileActive) {}

TEST_P(PasswordStatusCheckServiceParameterizedIssueTest,
       DetectAddedAndRemovedIssuesAutomatically) {}

TEST_P(PasswordStatusCheckServiceParameterizedStoreTest,
       DetectChangingWeakPassword) {}

TEST_P(PasswordStatusCheckServiceParameterizedStoreTest,
       DetectChangingLeakedPassword) {}

TEST_P(PasswordStatusCheckServiceParameterizedStoreTest,
       DetectChangingReusedPassword) {}

TEST_F(PasswordStatusCheckServiceBaseTest, RepeatedlyUpdatingDoesNotCrash) {}

TEST_F(PasswordStatusCheckServiceBaseTest, PasswordCheckNoPasswords) {}

// TODO: [email protected] - Investigate why this test fails.
TEST_F(PasswordStatusCheckServiceBaseTest,
       DISABLED_PasswordCheckSignedOutWithPasswords) {}

TEST_F(PasswordStatusCheckServiceBaseTest,
       DISABLED_PasswordCheck_FindCompromised) {}

TEST_F(PasswordStatusCheckServiceBaseTest, DISABLED_PasswordCheck_Error) {}

TEST_F(PasswordStatusCheckServiceBaseTest, PrefInitialized) {}

// If interval changes, the scheduled time at which the password check runs
// should be recomputed when `StartRepeatedUpdates` runs.
TEST_F(PasswordStatusCheckServiceBaseTest, CheckTimeUpdatedOnIntervalChange) {}

TEST_F(PasswordStatusCheckServiceBaseTest,
       CheckTimeUpdatedAfterRunScheduledInTheFuture) {}

TEST_F(PasswordStatusCheckServiceBaseTest,
       CheckTimeUpdatedAfterRunScheduledInThePast) {}

TEST_F(PasswordStatusCheckServiceBaseTest,
       CheckTimeUpdatedAfterRunScheduledLongTimeInThePast) {}

TEST_F(PasswordStatusCheckServiceBaseTest, ScheduledCheckRunsRepeatedly) {}

TEST_F(PasswordStatusCheckServiceBaseTest, WeakAndReusesCheckRunningDaily) {}

TEST_F(PasswordStatusCheckServiceBaseTest, IgnoredCompromisedPasswords) {}

TEST_F(PasswordStatusCheckServiceBaseTest, IgnoredSavedPasswords) {}

TEST_P(PasswordStatusCheckServiceParameterizedCardTest, PasswordCardState) {}

TEST_F(PasswordStatusCheckServiceBaseTest, PasswordCardCheckTime) {}

TEST_P(PasswordStatusCheckServiceParameterizedStoreTest,
       ResultWhenChangingLeakedPassword) {}

TEST_P(PasswordStatusCheckServiceParameterizedSchedulingTest,
       CheckWeightedRandomScheduling) {}

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

// A range from 0 (inclusive) to 7 (exclusive) to test randomization for each
// day of week.
INSTANTIATE_TEST_SUITE_P();