#include "chrome/browser/extensions/service_worker_apitest.h"
#include <stdint.h>
#include <optional>
#include <utility>
#include "base/auto_reset.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.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/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/permissions/permissions_api.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/error_console/error_console_test_observer.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/notification_permission_context.h"
#include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
#include "chrome/browser/push_messaging/push_messaging_features.h"
#include "chrome/browser/push_messaging/push_messaging_service_factory.h"
#include "chrome/browser/push_messaging/push_messaging_service_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/web_navigation.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/gcm_driver/fake_gcm_profile_service.h"
#include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
#include "components/version_info/channel.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/console_message.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/service_worker_context_observer.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/page_type.h"
#include "content/public/common/result_codes.h"
#include "content/public/test/background_sync_test_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/service_worker_test_helpers.h"
#include "extensions/browser/browsertest_util.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_histogram_value.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/service_worker/service_worker_task_queue.h"
#include "extensions/browser/service_worker/service_worker_test_utils.h"
#include "extensions/common/api/test.h"
#include "extensions/common/extensions_client.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/verifier_formats.h"
#include "extensions/test/extension_background_page_waiter.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "ui/message_center/public/cpp/notification.h"
#include "url/url_constants.h"
namespace extensions {
TestServiceWorkerTaskQueueObserver;
namespace {
HasSubstr;
class WebContentsLoadStopObserver : content::WebContentsObserver { … };
constexpr char kTestExtensionId[] = …;
}
void ServiceWorkerTest::SetUpOnMainThread() { … }
const Extension* ServiceWorkerTest::StartTestFromBackgroundPage(
const char* script_name) { … }
content::WebContents* ServiceWorkerTest::Navigate(const GURL& url) { … }
content::PageType ServiceWorkerTest::NavigateAndGetPageType(const GURL& url) { … }
std::string ServiceWorkerTest::ExtractInnerText(
content::WebContents* contents) { … }
std::string ServiceWorkerTest::NavigateAndExtractInnerText(const GURL& url) { … }
size_t ServiceWorkerTest::GetWorkerRefCount(const blink::StorageKey& key) { … }
void ServiceWorkerBasedBackgroundTest::SetUpOnMainThread() { … }
std::optional<WorkerId>
ServiceWorkerBasedBackgroundTest::GetUniqueRunningWorkerId(
const ExtensionId& extension_id) { … }
bool ServiceWorkerBasedBackgroundTest::ExtensionHasRenderProcessHost(
const ExtensionId& extension_id) { … }
class ServiceWorkerBasedBackgroundTestWithNotification
: public ServiceWorkerBasedBackgroundTest { … };
enum class ManifestVersion { … };
class ServiceWorkerWithManifestVersionTest
: public ServiceWorkerBasedBackgroundTest,
public testing::WithParamInterface<ManifestVersion> { … };
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, PRE_Basic) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, Basic) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, NonRootDirectory) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ModuleServiceWorkerWithStaticImport) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ModuleServiceWorkerWithDynamicImport) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ServiceWorkerWithRegistrationFailure) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, SyntaxError) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, UndefinedVariable) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, ConsoleError) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_FetchFileSchemeURLWithFileAccess …
#else
#define MAYBE_FetchFileSchemeURLWithFileAccess …
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
MAYBE_FetchFileSchemeURLWithFileAccess) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
FetchFileSchemeURLWithNoFileAccess) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, OnInstalledEvent) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, RuntimeMisc) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, ChromeAppUndefined) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, StorageSetAndGet) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, StorageNoPermissions) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsBasic) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsEvents) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsExecuteScript) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WindowsBasic) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WebRequest) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, DISABLED_WebRequest2) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WebRequestBlocking) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, FilteredEvents) { … }
template <const char message[]>
class ServiceWorkerWithEarlyMessageListenerTest
: public ServiceWorkerBasedBackgroundTest { … };
constexpr char kMsgOnStartup[] = …;
ServiceWorkerOnStartupEventTest;
IN_PROC_BROWSER_TEST_F(ServiceWorkerOnStartupEventTest, PRE_Event) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerOnStartupEventTest, Event) { … }
constexpr char kMsgWorkerRunning[] = …;
class ServiceWorkerRegistrationAtStartupTest
: public ServiceWorkerWithEarlyMessageListenerTest<kMsgWorkerRunning> { … };
#if BUILDFLAG(IS_WIN)
#define MAYBE_PRE_ExtensionActivationDoesNotReregister …
#define MAYBE_ExtensionActivationDoesNotReregister …
#else
#define MAYBE_PRE_ExtensionActivationDoesNotReregister …
#define MAYBE_ExtensionActivationDoesNotReregister …
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerRegistrationAtStartupTest,
MAYBE_PRE_ExtensionActivationDoesNotReregister) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerRegistrationAtStartupTest,
MAYBE_ExtensionActivationDoesNotReregister) { … }
class EarlyWorkerMessageSender : public EventRouter::Observer { … };
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, EarlyEventDispatch) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
EarlyFilteredEventDispatch) { … }
class ServiceWorkerBackgroundSyncTest : public ServiceWorkerTest { … };
class ServiceWorkerPushMessagingTest : public ServiceWorkerTest { … };
class ServiceWorkerLazyBackgroundTest : public ServiceWorkerTest { … };
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterSucceeds) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateRefreshesServiceWorker) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateWithoutSkipWaiting) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateToMV3RefreshesServiceWorker) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, FetchArbitraryPaths) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
FetchExtensionResourceFromServiceWorker) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, OnBeforeRequest) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, SWServedBackgroundPageReceivesEvent) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, SWServedBackgroundPage) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
ServiceWorkerPostsMessageToBackgroundClient) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
BackgroundPagePostsMessageToServiceWorker) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
ServiceWorkerSuspensionOnExtensionUnload) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
UpdatePackedExtension) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
UpdateUnpackedExtension) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, VerifyNoApiBindings) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest,
FetchFromContentScriptShouldNotGoToServiceWorkerOfPage) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerPushMessagingTest, OnPush) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MimeHandlerView) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
EventsToStoppedWorker) { … }
namespace {
constexpr char kIncognitoManifest[] = …;
constexpr char kQueryWorkerScript[] = …;
constexpr char kTabsOnUpdatedSplitScript[] = …;
constexpr char kTabsOnUpdatedSpanningScript[] = …;
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsQuerySplit) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
AlreadyLoadedSplitExtensionActivationInIncognito) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsQuerySpanning) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsOnUpdatedSplit) { … }
#if defined(ADDRESS_SANITIZER)
#define MAYBE_DisallowIncognitoWithOnInstalledListener …
#else
#define MAYBE_DisallowIncognitoWithOnInstalledListener …
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
MAYBE_DisallowIncognitoWithOnInstalledListener) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
TabsOnUpdatedSpanning) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ServiceWorkerScriptRootScope) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
WorkerStartFailureClearsPendingTasks) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ProcessManagerRegistrationOnShutdown) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ProcessManagerRegistrationOnTerminate) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
PRE_EventsAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, EventsAfterRestart) { … }
constexpr char kListenerAdded[] = …;
ServiceWorkerWebRequestEarlyListenerTest;
IN_PROC_BROWSER_TEST_F(ServiceWorkerWebRequestEarlyListenerTest,
PRE_WebRequestAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerWebRequestEarlyListenerTest,
WebRequestAfterRestart) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_PRE_FilteredEventsAfterRestart …
#define MAYBE_FilteredEventsAfterRestart …
#else
#define MAYBE_PRE_FilteredEventsAfterRestart …
#define MAYBE_FilteredEventsAfterRestart …
#endif
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
MAYBE_PRE_FilteredEventsAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
MAYBE_FilteredEventsAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
BrowserActionUserGesture) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTestWithNotification,
ServiceWorkerNotificationClick) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, PermissionsAPI) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, Component) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest,
ObserveServiceWorkerContext) { … }
constexpr char kReady[] = …;
class ServiceWorkerTestWithEarlyReadyMesssage
: public ServiceWorkerWithEarlyMessageListenerTest<kReady> { … };
IN_PROC_BROWSER_TEST_F(ServiceWorkerTestWithEarlyReadyMesssage,
PRE_MissingRegistrationMitigated) { … }
IN_PROC_BROWSER_TEST_F(ServiceWorkerTestWithEarlyReadyMesssage,
MissingRegistrationMitigated) { … }
IN_PROC_BROWSER_TEST_P(ServiceWorkerWithManifestVersionTest,
ExtensionCSPModification) { … }
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_F(ServiceWorkerLazyBackgroundTest, ConsoleLogging) { … }
class ServiceWorkerCheckBindingsTest
: public ServiceWorkerTest,
public testing::WithParamInterface<version_info::Channel> { … };
IN_PROC_BROWSER_TEST_P(ServiceWorkerCheckBindingsTest, BindingsAvailability) { … }
INSTANTIATE_TEST_SUITE_P(…);
}