#include <string>
#include <string_view>
#include <vector>
#include "base/containers/to_vector.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/extensions/api/permissions/permissions_api.h"
#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/embedder_support/switches.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/console_message.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/service_worker_context_observer.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/resource_load_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/browsertest_util.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/service_worker/service_worker_test_utils.h"
#include "extensions/browser/url_loader_factory_manager.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/permissions_manager_waiter.h"
#include "extensions/test/test_extension_dir.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 "net/test/embedded_test_server/http_request.h"
#include "services/network/public/cpp/cors/origin_access_list.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_context.mojom-shared.h"
#include "services/network/public/mojom/trust_tokens.mojom-shared.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace extensions {
namespace {
const char kCorsErrorWhenFetching[] = …;
constexpr char kOriginTrialPublicKeyForTesting[] = …;
std::string CreateFetchScript(
const GURL& resource,
std::optional<base::Value::Dict> request_init = std::nullopt) { … }
std::string PopString(content::DOMMessageQueue* message_queue) { … }
}
HasSubstr;
class OrbAndCorsExtensionTestBase : public ExtensionBrowserTest { … };
class ServiceWorkerConsoleObserver
: public content::ServiceWorkerContextObserver { … };
class OrbAndCorsExtensionBrowserTest : public OrbAndCorsExtensionTestBase { … };
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromDeclarativeContentScript_NoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_NoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_UnloadedExtension) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ContentScriptVsHostBlockedByPolicy_NoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ContentScriptVsHostBlockedByPolicy_AllowedTextResource) { … }
class OrbAndCorsUserHostRestrictionsBrowserTest
: public OrbAndCorsExtensionBrowserTest { … };
IN_PROC_BROWSER_TEST_F(OrbAndCorsUserHostRestrictionsBrowserTest,
PolicyVsUserHostRestrictions) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_PermissionToAllUrls) { … }
IN_PROC_BROWSER_TEST_F(
OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_PermissionToAllUrls_FileUrls) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_SubdomainPermissions) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_RedirectToNoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ContentScript_CorsAllowedByServer_NoPermissionToTarget) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ContentScript_CorsIgnoredByServer_NoPermissionToTarget) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_SameOrigin) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_AllowedTextResource) { … }
class TrustTokenExtensionBrowserTest : public OrbAndCorsExtensionBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
TrustTokenExtensionBrowserTest,
DISABLED_FromProgrammaticContentScript_TrustTokenRedemptionAllowed) { … }
IN_PROC_BROWSER_TEST_F(
OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_AllowedTextResource_SubdomainPermissions) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_AllowedAfterSniffing) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromProgrammaticContentScript_EmptyAndBlocked) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_NoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_NoSniffXml_OriginAccessList) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_NoSniffXml_NoCors) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_IncognitoSplitMode) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ExtensionWithNoHttpPermissions) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ExtensionWithOptionalHttpPermissions) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromForegroundPage_NoSniffXml) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromForegroundPage_IncognitoSplitMode) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromRegisteredServiceWorker_NoSniffXml) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || \
BUILDFLAG(IS_MAC)
#define MAYBE_FromBackgroundServiceWorker_NoSniffXml …
#else
#define MAYBE_FromBackgroundServiceWorker_NoSniffXml …
#endif
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
MAYBE_FromBackgroundServiceWorker_NoSniffXml) { … }
class ReadyToCommitWaiter : public content::WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
ProgrammaticContentScriptVsWebUI) { … }
class OrbAndCorsAppBrowserTest : public PlatformAppBrowserTest { … };
IN_PROC_BROWSER_TEST_F(OrbAndCorsAppBrowserTest, WebViewContentScript) { … }
OriginHeaderExtensionBrowserTest;
IN_PROC_BROWSER_TEST_F(OriginHeaderExtensionBrowserTest,
OriginHeaderInCrossOriginGetRequest) { … }
IN_PROC_BROWSER_TEST_F(OriginHeaderExtensionBrowserTest,
OriginHeaderInCrossOriginPostRequest) { … }
IN_PROC_BROWSER_TEST_F(OriginHeaderExtensionBrowserTest,
OriginHeaderInSameOriginPostRequest) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
RequestHeaders_InSameOriginFetch_FromContentScript) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
RequestHeaders_InSameOriginXhr_FromContentScript) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest, CorsFromContentScript) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_ActiveTabPermission) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_ActiveTabPermission_SplitMode) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_ActiveTabPermission_SplitMode2) { … }
IN_PROC_BROWSER_TEST_F(OrbAndCorsExtensionBrowserTest,
FromBackgroundPage_ActiveTabPermission_SpanningMode) { … }
}