Commit 7ef2b182 authored by Xinghui Lu's avatar Xinghui Lu Committed by Commit Bot

Add unit tests for safe_browsing_url_checker_impl.

This is the first setup of safe_browsing_url_checker_impl unit tests.
Use MockSafeBrowsingDatabaseManager, MockUrlCheckerDelegate and
MockRealTimeUrlLookupService as helper classes for the tests.

The current tests are mostly for verifying the overall workflows.
They don't check every parameters in details. More value checks
will be added in followup CLs.

Bug: 1054660
Change-Id: I7a91bef4e9f307992080351a3a463d367669655d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128937
Commit-Queue: Xinghui Lu <xinghuilu@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756128}
parent d77e8264
......@@ -5034,6 +5034,7 @@ test("unit_tests") {
"//components/safe_browsing/content/renderer:websocket_sb_handshake_throttle_unittest",
"//components/safe_browsing/content/triggers:ad_redirect_trigger",
"//components/safe_browsing/core:ping_manager_unittest",
"//components/safe_browsing/core/browser:safe_browsing_url_checker_unittest",
"//components/safe_browsing/core/browser:token_fetcher_unittest",
"//components/safe_browsing/core/db:v4_test_util",
]
......
......@@ -50,6 +50,22 @@ if (!is_ios) {
"//net:extras",
]
}
source_set("safe_browsing_url_checker_unittest") {
testonly = true
sources = [ "safe_browsing_url_checker_impl_unittest.cc" ]
deps = [
":browser",
"//base/test:test_support",
"//components/safe_browsing/core/common:test_support",
"//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:test_database_manager",
"//components/safe_browsing/core/db:util",
"//components/safe_browsing/core/realtime:url_lookup_service",
"//content/public/browser:browser",
"//testing/gtest",
]
}
}
source_set("referrer_chain_provider") {
......
......@@ -71,9 +71,6 @@ RealTimeUrlLookupService::RealTimeUrlLookupService(
sync_service_(sync_service),
pref_service_(pref_service),
is_off_the_record_(is_off_the_record) {
DCHECK(cache_manager_);
DCHECK(identity_manager_);
DCHECK(pref_service_);
token_fetcher_ =
std::make_unique<SafeBrowsingTokenFetcher>(identity_manager_);
}
......
......@@ -52,6 +52,8 @@ class SafeBrowsingTokenFetcher;
// TODO(crbug.com/1050859): Add RTLookupService check flow.
class RealTimeUrlLookupService : public KeyedService {
public:
// |cache_manager|, |identity_manager|, |sync_service| and |pref_service| may
// be null in tests.
RealTimeUrlLookupService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
VerdictCacheManager* cache_manager,
......@@ -85,9 +87,10 @@ class RealTimeUrlLookupService : public KeyedService {
// when response is received.
// Note that |request_callback| is not called if there's a valid entry in the
// cache for |url|.
void StartLookup(const GURL& url,
RTLookupRequestCallback request_callback,
RTLookupResponseCallback response_callback);
// This function is overridden in unit tests.
virtual void StartLookup(const GURL& url,
RTLookupRequestCallback request_callback,
RTLookupResponseCallback response_callback);
// KeyedService:
// Called before the actual deletion of the object.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment