chromium/components/safe_browsing/content/browser/password_protection/password_protection_service_unittest.cc

// Copyright 2017 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/safe_browsing/content/browser/password_protection/password_protection_service.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/null_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_reuse_detector.h"
#include "components/safe_browsing/content/browser/client_side_detection_feature_cache.h"
#include "components/safe_browsing/content/browser/password_protection/mock_password_protection_service.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_commit_deferring_condition.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_request_content.h"
#include "components/safe_browsing/content/common/safe_browsing.mojom-forward.h"
#include "components/safe_browsing/content/common/safe_browsing.mojom.h"
#include "components/safe_browsing/core/browser/db/test_database_manager.h"
#include "components/safe_browsing/core/browser/password_protection/metrics_util.h"
#include "components/safe_browsing/core/browser/password_protection/password_protection_request.h"
#include "components/safe_browsing/core/browser/verdict_cache_manager.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/safe_browsing/core/common/safebrowsing_constants.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "mojo/public/cpp/base/proto_wrapper.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"

ASCIIToUTF16;
_;
AnyNumber;
ElementsAre;
IsEmpty;
Mock;
NiceMock;
Return;
StrictMock;

namespace safe_browsing {

namespace {

const char kFormActionUrl[] =;
const char kPasswordFrameUrl[] =;
const char kSavedDomain[] =;
const char kSavedDomain2[] =;
const char kTargetUrl[] =;
const char kUserName[] =;

PasswordReuseEvent;

class MockSafeBrowsingTokenFetcher : public SafeBrowsingTokenFetcher {};

class MockSafeBrowsingDatabaseManager : public TestSafeBrowsingDatabaseManager {};

class TestPhishingDetector : public mojom::PhishingDetector {};

class TestPasswordProtectionService : public MockPasswordProtectionService {};

}  // namespace

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

TEST_F(PasswordProtectionServiceTest,
       VerifyCommitDeferringConditionNotRemovedWhenCanceledOnTimeout) {}

TEST_F(PasswordProtectionServiceTest,
       VerifyCommitDeferringConditionRemovedWhenCanceledNotOnTimeout) {}

TEST_F(PasswordProtectionServiceTest, NoSendPingPrivateIpHostname) {}

class PasswordProtectionServiceBaseTest
    : public ::testing::TestWithParam<bool> {};

TEST_P(PasswordProtectionServiceBaseTest, TestCachePasswordReuseVerdicts) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestCachePasswordReuseVerdictsIncognito) {}

TEST_P(PasswordProtectionServiceBaseTest, TestCacheUnfamiliarLoginVerdicts) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestCacheUnfamiliarLoginVerdictsIncognito) {}

TEST_P(PasswordProtectionServiceBaseTest, TestGetCachedVerdicts) {}

TEST_P(PasswordProtectionServiceBaseTest, TestDoesNotCacheAboutBlank) {}

TEST_P(PasswordProtectionServiceBaseTest, VerifyCanGetReputationOfURL) {}

TEST_P(PasswordProtectionServiceBaseTest, TestNoRequestSentForAllowlistedURL) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestNoRequestSentIfVerdictAlreadyCached) {}

TEST_P(PasswordProtectionServiceBaseTest, TestResponseFetchFailed) {}

TEST_P(PasswordProtectionServiceBaseTest, TestMalformedResponse) {}

TEST_P(PasswordProtectionServiceBaseTest, TestRequestTimedout) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestPasswordOnFocusRequestAndResponseSuccessfull) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestPasswordOnFocusRequestEnhancedProtectionShouldHaveToken) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestPasswordOnFocusRequestNoEnhancedProtectionShouldNotHaveToken) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestProtectedPasswordEntryRequestAndResponseSuccessfull) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestSyncPasswordEntryRequestAndResponseSuccessfull) {}

TEST_P(PasswordProtectionServiceBaseTest, TestTearDownWithPendingRequests) {}

TEST_P(PasswordProtectionServiceBaseTest, VerifyPasswordOnFocusRequestProto) {}

TEST_P(PasswordProtectionServiceBaseTest,
       VerifyPasswordOnFocusRequestProtoForAllowlistMatch) {}

TEST_P(PasswordProtectionServiceBaseTest,
       VerifySyncPasswordProtectionRequestProto) {}

TEST_P(PasswordProtectionServiceBaseTest,
       VerifySavePasswordProtectionRequestProto) {}

TEST_P(PasswordProtectionServiceBaseTest, VerifyShouldShowModalWarning) {}

TEST_P(PasswordProtectionServiceBaseTest, VerifyContentTypeIsPopulated) {}

TEST_P(PasswordProtectionServiceBaseTest,
       VerifyIsSupportedPasswordTypeForPinging) {}

TEST_P(PasswordProtectionServiceBaseTest, TestPingsForAboutBlank) {}

// DOM features and visual features are not supported on Android.
#if !BUILDFLAG(IS_ANDROID)
TEST_P(PasswordProtectionServiceBaseTest,
       TestVisualFeaturesPopulatedInOnFocusPing) {}

TEST_P(PasswordProtectionServiceBaseTest, TestDomFeaturesPopulated) {}

TEST_P(PasswordProtectionServiceBaseTest, TestDomFeaturesTimeout) {}
#endif

TEST_P(PasswordProtectionServiceBaseTest, TestWebContentsDestroyed) {}

// TODO(crbug.com/40918301): [Also TODO(thefrog)] Remove test case once
// kHashPrefixRealTimeLookups is launched.
TEST_P(PasswordProtectionServiceBaseTest,
       TestHashPrefixRealTimeLookupsFeatureEnabled) {}

// TODO(crbug.com/40918301): [Also TODO(thefrog)] Remove test case once
// kHashPrefixRealTimeLookups is launched.
TEST_P(PasswordProtectionServiceBaseTest,
       TestHashPrefixRealTimeLookupsFeatureControl) {}

// TODO(crbug.com/40918301): [Also TODO(thefrog)] Remove test case once
// kHashPrefixRealTimeLookups is launched.
TEST_P(PasswordProtectionServiceBaseTest,
       TestHashPrefixRealTimeLookupsFeatureDefault) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestAsyncRealTimeCheckFeatureEnabled) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestAsyncRealTimeCheckFeatureEnabled_Incognito) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestAsyncRealTimeCheckFeatureControl) {}

TEST_P(PasswordProtectionServiceBaseTest,
       TestAsyncRealTimeCheckFeatureDefault) {}

// TODO(crbug.com/40918301): [Also TODO(thefrog)] Remove test case once
// kHashPrefixRealTimeLookups is launched.
TEST_P(PasswordProtectionServiceBaseTest,
       TestAsyncRealTimeCheckAndHashPrefixRealTimeLookupsFeaturesEnabled) {}

TEST_P(PasswordProtectionServiceBaseTest, TestCSDVerdictInCache) {}

TEST_P(PasswordProtectionServiceBaseTest, TestCSDDebuggingMetadataInCache) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
}  // namespace safe_browsing