#include <optional>
#include <string_view>
#include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/statistics_recorder.h"
#include "base/no_destructor.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.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/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/embedder_support/switches.h"
#include "components/language/core/browser/language_prefs.h"
#include "components/language/core/browser/pref_names.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/origin_trials_controller_delegate.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/origin.h"
namespace {
URLLoaderInterceptor;
EmbeddedTestServer;
enum class FeatureEnableType { … };
struct ReduceAcceptLanguageTestOptions { … };
struct ServerPortAndValidOriginToken { … };
const char kLargeLanguages[] = …;
static constexpr const char kFirstPartyOriginUrl[] = …;
static constexpr char kThirdPartyOriginUrl[] = …;
static constexpr const char kValidFirstPartyToken[] = …;
static constexpr const char kValidThirdPartyToken[] = …;
static constexpr const char kValidMySiteFirstPartyToken[] = …;
static constexpr const char kInvalidOriginToken[] = …;
static constexpr const char kDeprecationTrialName[] = …;
}
class ReduceAcceptLanguageBrowserTest : public InProcessBrowserTest { … };
class DisableFeatureReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(DisableFeatureReduceAcceptLanguageBrowserTest,
NoAcceptLanguageHeader) { … }
IN_PROC_BROWSER_TEST_F(DisableFeatureReduceAcceptLanguageBrowserTest,
IframeNoAcceptLanguageHeader) { … }
class SameOriginReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
LargeLanguageListAndScriptDisable) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
EmptyUserAcceptLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
NoAvailLanguageHeader) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
NoContentLanguageHeader) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
EmptyAvailLanguageAcceptLanguages) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
AvailLanguageAcceptLanguagesWhiteSpace) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
SiteLanguageMatchNonPrimaryLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
ServiceWorkerNavigationPreload) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
SiteLanguageMatchPrimaryLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
SubresourceRequestNoRestart) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
SiteLanguageMatchMultipleLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
SiteLanguageDontMatchAnyPreferredLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
PersistedAcceptLanguageNotAvailable) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
IframeReduceAcceptLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
ImgSubresourceReduceAcceptLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
IframeNoContentLanguageInChild) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
IframeNoAvailLanguageAcceptLanguageInChild) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
IframeSameContentLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageBrowserTest,
IframeDifferentContentLanguage) { … }
class ThirdPartyReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ThirdPartyReduceAcceptLanguageBrowserTest,
IframeDifferentContentLanguage) { … }
IN_PROC_BROWSER_TEST_F(ThirdPartyReduceAcceptLanguageBrowserTest,
ThirdPartyIframeWithSubresourceRequests) { … }
IN_PROC_BROWSER_TEST_F(ThirdPartyReduceAcceptLanguageBrowserTest,
ThirdPartyIframeWithSubresourceRedirectRequests) { … }
class FencedFrameReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(FencedFrameReduceAcceptLanguageBrowserTest,
CrossOriginFencedFrame) { … }
IN_PROC_BROWSER_TEST_F(FencedFrameReduceAcceptLanguageBrowserTest,
SameOriginFencedFrame) { … }
class SameOriginRedirectReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SameOriginRedirectReduceAcceptLanguageBrowserTest,
MatchFirstLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginRedirectReduceAcceptLanguageBrowserTest,
MatchSecondaryLanguage) { … }
class CrossOriginRedirectReduceAcceptLanguageBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageBrowserTest,
RestartOnA) { … }
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageBrowserTest,
RestartOnB) { … }
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageBrowserTest,
RestartBothAB) { … }
class SameOriginRedirectReduceAcceptLanguageOTBrowserTest
: public SameOriginRedirectReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SameOriginRedirectReduceAcceptLanguageOTBrowserTest,
MatchFirstLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginRedirectReduceAcceptLanguageOTBrowserTest,
MatchNonPrimaryLanguage) { … }
class CrossOriginRedirectReduceAcceptLanguageOTBrowserTest
: public CrossOriginRedirectReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageOTBrowserTest,
RestartOnA) { … }
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageOTBrowserTest,
RestartOnB) { … }
IN_PROC_BROWSER_TEST_F(CrossOriginRedirectReduceAcceptLanguageOTBrowserTest,
RestartOnAB) { … }
class SameOriginReduceAcceptLanguageDeprecationOTBrowserTest
: public ReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
FirstRequestMatchPrimaryLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
FirstRequestMatchNonPrimaryLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
FirstRequestMatchNonPrimaryLanguageWithCriticalTrial) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
FirstRequestNoMatchLanguage) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
IframeRequestRestart) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
IframeRequestRestartWithCriticalTrial) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
IframeRequestNoRestart) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
IframeRequestNoRestartWithCriticalTrial) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
ImgSubresourceRestart) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
ImgSubresourceRestartWithCriticalTrial) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
ImgSubresourceNoRestart) { … }
IN_PROC_BROWSER_TEST_F(SameOriginReduceAcceptLanguageDeprecationOTBrowserTest,
ImgSubresourceNoRestartWithCriticalTrial) { … }
class ThirdPartyReduceAcceptLanguageDeprecationOTBrowserTest
: public ThirdPartyReduceAcceptLanguageBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ThirdPartyReduceAcceptLanguageDeprecationOTBrowserTest,
IframeRequests) { … }
IN_PROC_BROWSER_TEST_F(ThirdPartyReduceAcceptLanguageDeprecationOTBrowserTest,
JavaScriptRequest) { … }