#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/subresource_filter/subresource_filter_browser_test_harness.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/page_load_metrics/browser/observers/use_counter_page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/page_load_metrics_test_waiter.h"
#include "components/subresource_filter/content/shared/browser/ruleset_service.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/common/activation_scope.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/test_ruleset_utils.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "media/base/media_switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace {
enum class OtherFrameNavigationType { … };
std::ostream& operator<<(std::ostream& os, OtherFrameNavigationType type) { … }
enum class DownloadSource { … };
std::ostream& operator<<(std::ostream& os, DownloadSource source) { … }
enum class SandboxOption { … };
std::ostream& operator<<(std::ostream& os, SandboxOption sandbox_option) { … }
const char kSandboxTokensDisallowDownloads[] = …;
const char kSandboxTokensAllowDownloads[] = …;
class PopupPageLoadMetricsWaiterInitializer : public TabStripModelObserver { … };
}
class DownloadFramePolicyBrowserTest
: public subresource_filter::SubresourceFilterBrowserTest { … };
class SubframeSameFrameDownloadBrowserTest_Sandbox
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<
std::tuple<DownloadSource,
SandboxOption,
bool >> { … };
IN_PROC_BROWSER_TEST_P(SubframeSameFrameDownloadBrowserTest_Sandbox, Download) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SubframeSameFrameDownloadBrowserTest_AdFrame
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<std::tuple<
DownloadSource,
bool ,
bool ,
bool >> { … };
IN_PROC_BROWSER_TEST_P(SubframeSameFrameDownloadBrowserTest_AdFrame, Download) { … }
INSTANTIATE_TEST_SUITE_P(…);
class OtherFrameNavigationDownloadBrowserTest_Sandbox
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<
std::tuple<bool , OtherFrameNavigationType>> { … };
IN_PROC_BROWSER_TEST_P(OtherFrameNavigationDownloadBrowserTest_Sandbox,
Download) { … }
INSTANTIATE_TEST_SUITE_P(…);
class OtherFrameNavigationDownloadBrowserTest_AdFrame
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<std::tuple<
bool ,
bool ,
OtherFrameNavigationType>> { … };
IN_PROC_BROWSER_TEST_P(OtherFrameNavigationDownloadBrowserTest_AdFrame,
Download) { … }
INSTANTIATE_TEST_SUITE_P(…);
class TopFrameSameFrameDownloadBrowserTest
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<
std::tuple<DownloadSource, SandboxOption>> { … };
IN_PROC_BROWSER_TEST_P(TopFrameSameFrameDownloadBrowserTest, Download) { … }
INSTANTIATE_TEST_SUITE_P(…);
class DownloadFramePolicyBrowserTest_UpdateIframeSandboxFlags
: public DownloadFramePolicyBrowserTest,
public ::testing::WithParamInterface<
std::tuple<bool ,
bool >> { … };
IN_PROC_BROWSER_TEST_P(
DownloadFramePolicyBrowserTest_UpdateIframeSandboxFlags,
PendingSandboxPolicyUsedForNavigationInstantiatingFrame) { … }
IN_PROC_BROWSER_TEST_P(DownloadFramePolicyBrowserTest_UpdateIframeSandboxFlags,
EffectiveSandboxPolicyUsedForNavigationInitiatorFrame) { … }
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_F(DownloadFramePolicyBrowserTest,
SubframeNavigationDownloadBlockedByLoadPolicy) { … }