#include "components/blocked_content/safe_browsing_triggered_popup_blocker.h"
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/path_service.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_database_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/back_forward_cache/back_forward_cache_disable.h"
#include "components/blocked_content/popup_blocker_tab_helper.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/browser/db/safebrowsing.pb.h"
#include "components/safe_browsing/core/browser/db/v4_embedded_test_server_util.h"
#include "components/safe_browsing/core/browser/db/v4_test_util.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
PageSpecificContentSettings;
SubresourceFilterLevel;
SubresourceFilterType;
namespace {
void RoundTripAndVerifyLogMessages(
const content::WebContentsConsoleObserver& observer,
content::WebContents* web_contents,
std::set<std::string> messages_expected,
std::set<std::string> messages_not_expected) { … }
}
class SafeBrowsingTriggeredPopupBlockerBrowserTest
: public InProcessBrowserTest { … };
class SafeBrowsingTriggeredPopupBlockerDisabledTest
: public SafeBrowsingTriggeredPopupBlockerBrowserTest { … };
class SafeBrowsingTriggeredInterceptingBrowserTest
: public SafeBrowsingTriggeredPopupBlockerBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerDisabledTest,
NoFeature_AllowCreatingNewWindows) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerDisabledTest,
NoFeature_NoMessages) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
DrivenByEnterprisePolicy) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
NoList_AllowCreatingNewWindows) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
NoAbusive_AllowCreatingNewWindows) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
BlockCreatingNewWindows) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
ShowBlockedPopup) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
BlockCreatingNewWindows_LogsToConsole) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
AllowCreatingNewWindows_NoLogToConsole) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
BlockOpenURLFromTab) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
BlockOpenURLFromTabInIframe) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
MultipleNavigations) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
WarningDoNotBlockCreatingNewWindows_LogsToConsole) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
WarningAllowCreatingNewWindows_LogsToConsole) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredInterceptingBrowserTest,
AbusiveMetadata) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
AbusivePagesAreNotPutIntoBackForwardCache) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerBrowserTest,
OpenNewWindowInSubFrame) { … }
class SafeBrowsingTriggeredPopupBlockerPrerenderingBrowserTest
: public SafeBrowsingTriggeredPopupBlockerBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerPrerenderingBrowserTest,
DISABLED_ConsoleLogWithSourceFrame) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerPrerenderingBrowserTest,
PopupBlockedAfterActivation) { … }
class SafeBrowsingTriggeredPopupBlockerFencedFrameBrowserTest
: public SafeBrowsingTriggeredPopupBlockerBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerFencedFrameBrowserTest,
ShouldNotTriggerPopupBlocker) { … }
IN_PROC_BROWSER_TEST_F(SafeBrowsingTriggeredPopupBlockerFencedFrameBrowserTest,
ShouldTriggerPopupBlocker) { … }