Commit ba690ff4 authored by Xinghui Lu's avatar Xinghui Lu Committed by Commit Bot

Add browser tests for real time URL check.

Bug: 1144940
Change-Id: Icbc8084ca209b121388f5910a52b0735681ad1ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515207Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Xinghui Lu <xinghuilu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823429}
parent 2b3bf325
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/browser/safe_browsing/test_safe_browsing_service.h" #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
#include "chrome/browser/safe_browsing/ui_manager.h" #include "chrome/browser/safe_browsing/ui_manager.h"
#include "chrome/browser/safe_browsing/user_interaction_observer.h" #include "chrome/browser/safe_browsing/user_interaction_observer.h"
#include "chrome/browser/safe_browsing/verdict_cache_manager_factory.h"
#include "chrome/browser/ssl/cert_verifier_browser_test.h" #include "chrome/browser/ssl/cert_verifier_browser_test.h"
#include "chrome/browser/ssl/security_state_tab_helper.h" #include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -63,6 +64,7 @@ ...@@ -63,6 +64,7 @@
#include "components/safe_browsing/core/db/util.h" #include "components/safe_browsing/core/db/util.h"
#include "components/safe_browsing/core/db/v4_protocol_manager_util.h" #include "components/safe_browsing/core/db/v4_protocol_manager_util.h"
#include "components/safe_browsing/core/features.h" #include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/verdict_cache_manager.h"
#include "components/safe_browsing/core/web_ui/constants.h" #include "components/safe_browsing/core/web_ui/constants.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h" #include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h" #include "components/security_interstitials/content/security_interstitial_tab_helper.h"
...@@ -74,6 +76,7 @@ ...@@ -74,6 +76,7 @@
#include "components/security_interstitials/core/urls.h" #include "components/security_interstitials/core/urls.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/unified_consent/pref_names.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
...@@ -2835,4 +2838,95 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageEnhancedProtectionMessageTest, ...@@ -2835,4 +2838,95 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageEnhancedProtectionMessageTest,
browser(), "enhanced-protection-message")); browser(), "enhanced-protection-message"));
} }
// Tests for real time URL check. To test it without making network requests to
// Safe Browsing servers, store an unsafe verdict in cache for the URL.
class SafeBrowsingBlockingPageRealTimeUrlCheckTest
: public InProcessBrowserTest {
public:
SafeBrowsingBlockingPageRealTimeUrlCheckTest() = default;
void SetUp() override {
scoped_feature_list_.InitWithFeatures(
/*enabled_features=*/{},
/*disabled_features=*/{kDelayedWarnings});
InProcessBrowserTest::SetUp();
}
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
content::SetupCrossSiteRedirector(embedded_test_server());
ASSERT_TRUE(embedded_test_server()->Start());
}
void CreatedBrowserMainParts(
content::BrowserMainParts* browser_main_parts) override {
// Test UI manager and test database manager should be set before
// the browser is started but after threads are created.
factory_.SetTestUIManager(new FakeSafeBrowsingUIManager());
factory_.SetTestDatabaseManager(new FakeSafeBrowsingDatabaseManager());
SafeBrowsingService::RegisterFactory(&factory_);
SafeBrowsingBlockingPage::RegisterFactory(&blocking_page_factory_);
}
protected:
void SetupUnsafeVerdict(GURL url, Profile* profile) {
auto* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(
"mark_as_real_time_phishing",
embedded_test_server()->GetURL("/empty.html").spec());
safe_browsing::VerdictCacheManagerFactory::GetForProfile(profile)
->CacheArtificialVerdict();
}
private:
TestSafeBrowsingServiceFactory factory_;
TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageRealTimeUrlCheckTest);
};
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageRealTimeUrlCheckTest,
WarningShown_EnhancedProtectionEnabled) {
safe_browsing::SetSafeBrowsingState(
browser()->profile()->GetPrefs(),
safe_browsing::SafeBrowsingState::ENHANCED_PROTECTION);
GURL url = embedded_test_server()->GetURL("/empty.html");
SetupUnsafeVerdict(url, browser()->profile());
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(IsShowingInterstitial(
browser()->tab_strip_model()->GetActiveWebContents()));
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageRealTimeUrlCheckTest,
WarningShown_MbbEnabled) {
safe_browsing::SetSafeBrowsingState(
browser()->profile()->GetPrefs(),
safe_browsing::SafeBrowsingState::STANDARD_PROTECTION);
browser()->profile()->GetPrefs()->SetBoolean(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled, true);
GURL url = embedded_test_server()->GetURL("/empty.html");
SetupUnsafeVerdict(url, browser()->profile());
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(IsShowingInterstitial(
browser()->tab_strip_model()->GetActiveWebContents()));
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageRealTimeUrlCheckTest,
WarningNotShown_MbbDisabled) {
safe_browsing::SetSafeBrowsingState(
browser()->profile()->GetPrefs(),
safe_browsing::SafeBrowsingState::STANDARD_PROTECTION);
browser()->profile()->GetPrefs()->SetBoolean(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled, false);
GURL url = embedded_test_server()->GetURL("/empty.html");
SetupUnsafeVerdict(url, browser()->profile());
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_FALSE(IsShowingInterstitial(
browser()->tab_strip_model()->GetActiveWebContents()));
}
} // namespace safe_browsing } // namespace safe_browsing
...@@ -104,6 +104,7 @@ class VerdictCacheManager : public history::HistoryServiceObserver, ...@@ -104,6 +104,7 @@ class VerdictCacheManager : public history::HistoryServiceObserver,
void StopCleanUpTimerForTesting(); void StopCleanUpTimerForTesting();
private: private:
friend class SafeBrowsingBlockingPageRealTimeUrlCheckTest;
FRIEND_TEST_ALL_PREFIXES(VerdictCacheManagerTest, TestCleanUpExpiredVerdict); FRIEND_TEST_ALL_PREFIXES(VerdictCacheManagerTest, TestCleanUpExpiredVerdict);
FRIEND_TEST_ALL_PREFIXES(VerdictCacheManagerTest, FRIEND_TEST_ALL_PREFIXES(VerdictCacheManagerTest,
TestCleanUpExpiredVerdictWithInvalidEntry); TestCleanUpExpiredVerdictWithInvalidEntry);
......
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