From 14654707e68e1c32e94686e679667559c906d5cd Mon Sep 17 00:00:00 2001 From: Dorel Luca Date: Wed, 10 Oct 2018 18:31:01 +0300 Subject: [PATCH] Backed out changeset 2c01f22661fa (bug 1263734) for wpt failures in fetch/api/request/destination/fetch-destination-no-load-event.https.html. CLOSED TREE --- dom/base/nsDocument.cpp | 10 - dom/clients/manager/ClientSource.cpp | 124 ++++++++++- dom/serviceworkers/ServiceWorkerContainer.cpp | 202 ----------------- dom/serviceworkers/ServiceWorkerContainer.h | 50 +---- dom/webidl/ServiceWorkerContainer.webidl | 4 +- .../serviceworker-intercepted.https.html | 12 +- .../fetch-destination-worker-no-load-event.js | 2 +- .../postmessage-to-client.https.html | 204 ------------------ .../about-blank-replacement-ping-frame.py | 1 - .../enable-client-message-queue.html | 39 ---- .../resources/message-vs-microtask.html | 18 -- .../resources/nested-iframe-parent.html | 5 - .../resources/stalling-service-worker.js | 54 ----- 13 files changed, 122 insertions(+), 603 deletions(-) delete mode 100644 testing/web-platform/tests/service-workers/service-worker/resources/enable-client-message-queue.html delete mode 100644 testing/web-platform/tests/service-workers/service-worker/resources/message-vs-microtask.html delete mode 100644 testing/web-platform/tests/service-workers/service-worker/resources/nested-iframe-parent.html delete mode 100644 testing/web-platform/tests/service-workers/service-worker/resources/stalling-service-worker.js diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 054b294b53de..73eee6587a97 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -67,8 +67,6 @@ #include "mozilla/dom/FeaturePolicy.h" #include "mozilla/dom/FramingChecker.h" #include "mozilla/dom/HTMLSharedElement.h" -#include "mozilla/dom/Navigator.h" -#include "mozilla/dom/ServiceWorkerContainer.h" #include "mozilla/dom/SVGUseElement.h" #include "nsGenericHTMLElement.h" #include "mozilla/dom/CDATASection.h" @@ -5197,14 +5195,6 @@ nsIDocument::DispatchContentLoadedEvents() NS_LITERAL_STRING("DOMContentLoaded"), CanBubble::eYes, Cancelable::eNo); - if (auto* const window = GetInnerWindow()) { - const RefPtr serviceWorker = window->Navigator()->ServiceWorker(); - - // This could cause queued messages from a service worker to get - // dispatched on serviceWorker. - serviceWorker->StartMessages(); - } - if (MayStartLayout()) { MaybeResolveReadyForIdle(); } diff --git a/dom/clients/manager/ClientSource.cpp b/dom/clients/manager/ClientSource.cpp index 9f431ddf1521..5bb18b7719bf 100644 --- a/dom/clients/manager/ClientSource.cpp +++ b/dom/clients/manager/ClientSource.cpp @@ -605,17 +605,125 @@ RefPtr ClientSource::PostMessage(const ClientPostMessageArgs& aArgs) { NS_ASSERT_OWNINGTHREAD(ClientSource); + RefPtr ref; - // TODO: Currently this function only supports clients whose global - // object is a Window; it should also support those whose global - // object is a WorkerGlobalScope. - if (nsPIDOMWindowInner* const window = GetInnerWindow()) { - const RefPtr container = window->Navigator()->ServiceWorker(); - container->ReceiveMessage(aArgs); - return ClientOpPromise::CreateAndResolve(NS_OK, __func__).forget(); + ServiceWorkerDescriptor source(aArgs.serviceWorker()); + const PrincipalInfo& principalInfo = source.PrincipalInfo(); + + StructuredCloneData clonedData; + clonedData.BorrowFromClonedMessageDataForBackgroundChild(aArgs.clonedData()); + + // Currently we only support firing these messages on window Clients. + // Once we expose ServiceWorkerContainer and the ServiceWorker on Worker + // threads then this will need to change. See bug 1113522. + if (mClientInfo.Type() != ClientType::Window) { + ref = ClientOpPromise::CreateAndReject(NS_ERROR_NOT_IMPLEMENTED, __func__); + return ref.forget(); } - return ClientOpPromise::CreateAndReject(NS_ERROR_NOT_IMPLEMENTED, __func__).forget(); + MOZ_ASSERT(NS_IsMainThread()); + + RefPtr target; + nsCOMPtr globalObject; + + // We don't need to force the creation of the about:blank document + // here because there is no postMessage listener. If a listener + // was registered then the document will already be created. + nsPIDOMWindowInner* window = GetInnerWindow(); + if (window) { + globalObject = do_QueryInterface(window); + target = window->Navigator()->ServiceWorker(); + } + + if (NS_WARN_IF(!target)) { + ref = ClientOpPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR, + __func__); + return ref.forget(); + } + + // If AutoJSAPI::Init() fails then either global is nullptr or not + // in a usable state. + AutoJSAPI jsapi; + if (!jsapi.Init(globalObject)) { + ref = ClientOpPromise::CreateAndResolve(NS_OK, __func__); + return ref.forget(); + } + + JSContext* cx = jsapi.cx(); + + ErrorResult result; + JS::Rooted messageData(cx); + clonedData.Read(cx, &messageData, result); + if (result.MaybeSetPendingException(cx)) { + // We reported the error in the current window context. Resolve + // promise instead of rejecting. + ref = ClientOpPromise::CreateAndResolve(NS_OK, __func__); + return ref.forget(); + } + + RootedDictionary init(cx); + + init.mData = messageData; + if (!clonedData.TakeTransferredPortsAsSequence(init.mPorts)) { + // Report the error in the current window context and resolve the + // promise instead of rejecting. + xpc::Throw(cx, NS_ERROR_OUT_OF_MEMORY); + ref = ClientOpPromise::CreateAndResolve(NS_OK, __func__); + return ref.forget(); + } + + nsresult rv = NS_OK; + nsCOMPtr principal = + PrincipalInfoToPrincipal(principalInfo, &rv); + if (NS_FAILED(rv) || !principal) { + ref = ClientOpPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); + return ref.forget(); + } + + nsAutoCString origin; + rv = principal->GetOriginNoSuffix(origin); + if (NS_SUCCEEDED(rv)) { + CopyUTF8toUTF16(origin, init.mOrigin); + } + + RefPtr instance; + + if (ServiceWorkerParentInterceptEnabled()) { + instance = globalObject->GetOrCreateServiceWorker(source); + } else { + // If we are in legacy child-side intercept mode then we need to verify + // this registration exists in the current process. + RefPtr swm = ServiceWorkerManager::GetInstance(); + if (!swm) { + // Shutting down. Just don't deliver this message. + ref = ClientOpPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); + return ref.forget(); + } + + RefPtr reg = + swm->GetRegistration(principal, source.Scope()); + if (reg) { + instance = globalObject->GetOrCreateServiceWorker(source); + } + } + + if (instance) { + init.mSource.SetValue().SetAsServiceWorker() = instance; + } + + RefPtr event = + MessageEvent::Constructor(target, NS_LITERAL_STRING("message"), init); + event->SetTrusted(true); + + target->DispatchEvent(*event, result); + if (result.Failed()) { + result.SuppressException(); + ref = ClientOpPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); + return ref.forget(); + } + + ref = ClientOpPromise::CreateAndResolve(NS_OK, __func__); + return ref.forget(); } RefPtr diff --git a/dom/serviceworkers/ServiceWorkerContainer.cpp b/dom/serviceworkers/ServiceWorkerContainer.cpp index 913f194f7488..142f29643526 100644 --- a/dom/serviceworkers/ServiceWorkerContainer.cpp +++ b/dom/serviceworkers/ServiceWorkerContainer.cpp @@ -12,7 +12,6 @@ #include "nsIDocument.h" #include "nsIServiceWorkerManager.h" #include "nsIScriptError.h" -#include "nsThreadUtils.h" #include "nsIURL.h" #include "nsNetUtil.h" #include "nsPIDOMWindow.h" @@ -23,16 +22,11 @@ #include "nsServiceManagerUtils.h" #include "mozilla/LoadInfo.h" -#include "mozilla/dom/ClientIPCTypes.h" #include "mozilla/dom/DOMMozPromiseRequestHolder.h" -#include "mozilla/dom/MessageEvent.h" -#include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/Navigator.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ServiceWorker.h" #include "mozilla/dom/ServiceWorkerContainerBinding.h" -#include "mozilla/dom/ServiceWorkerManager.h" -#include "mozilla/dom/ipc/StructuredCloneData.h" #include "RemoteServiceWorkerContainerImpl.h" #include "ServiceWorker.h" @@ -40,11 +34,6 @@ #include "ServiceWorkerRegistration.h" #include "ServiceWorkerUtils.h" -// This is defined to something else on Windows -#ifdef DispatchMessage - #undef DispatchMessage -#endif - namespace mozilla { namespace dom { @@ -163,39 +152,6 @@ ServiceWorkerContainer::ControllerChanged(ErrorResult& aRv) aRv = DispatchTrustedEvent(NS_LITERAL_STRING("controllerchange")); } -using mozilla::dom::ipc::StructuredCloneData; - -// A ReceivedMessage represents a message sent via -// Client.postMessage(). It is used as used both for queuing of -// incoming messages and as an interface to DispatchMessage(). -struct MOZ_HEAP_CLASS ServiceWorkerContainer::ReceivedMessage -{ - explicit ReceivedMessage(const ClientPostMessageArgs& aArgs) - : mServiceWorker(aArgs.serviceWorker()) - { - mClonedData.CopyFromClonedMessageDataForBackgroundChild(aArgs.clonedData()); - } - - ServiceWorkerDescriptor mServiceWorker; - StructuredCloneData mClonedData; - - NS_INLINE_DECL_REFCOUNTING(ReceivedMessage) - -private: - ~ReceivedMessage() = default; -}; - -void -ServiceWorkerContainer::ReceiveMessage(const ClientPostMessageArgs& aArgs) -{ - RefPtr message = new ReceivedMessage(aArgs); - if (mMessagesStarted) { - EnqueueReceivedMessageDispatch(message.forget()); - } else { - mPendingMessages.AppendElement(message.forget()); - } -} - JSObject* ServiceWorkerContainer::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { @@ -470,16 +426,6 @@ ServiceWorkerContainer::GetRegistrations(ErrorResult& aRv) return outer.forget(); } -void -ServiceWorkerContainer::StartMessages() -{ - while (!mPendingMessages.IsEmpty()) { - EnqueueReceivedMessageDispatch(mPendingMessages.ElementAt(0)); - mPendingMessages.RemoveElementAt(0); - } - mMessagesStarted = true; -} - already_AddRefed ServiceWorkerContainer::GetRegistration(const nsAString& aURL, ErrorResult& aRv) @@ -672,153 +618,5 @@ ServiceWorkerContainer::GetGlobalIfValid(ErrorResult& aRv, return window->AsGlobal(); } -void -ServiceWorkerContainer::EnqueueReceivedMessageDispatch(RefPtr aMessage) { - if (nsPIDOMWindowInner* const window = GetOwner()) { - if (auto* const target = window->EventTargetFor(TaskCategory::Other)) { - target->Dispatch( - NewRunnableMethod>( - "ServiceWorkerContainer::DispatchMessage", - this, - &ServiceWorkerContainer::DispatchMessage, - std::move(aMessage) - ) - ); - } - } -} - -template -void -ServiceWorkerContainer::RunWithJSContext(F&& aCallable) -{ - nsCOMPtr globalObject; - if (nsPIDOMWindowInner* const window = GetOwner()) { - globalObject = do_QueryInterface(window); - } - - // If AutoJSAPI::Init() fails then either global is nullptr or not - // in a usable state. - AutoJSAPI jsapi; - if (!jsapi.Init(globalObject)) { - return; - } - - aCallable(jsapi.cx(), globalObject); -} - -void -ServiceWorkerContainer::DispatchMessage(RefPtr aMessage) -{ - MOZ_ASSERT(NS_IsMainThread()); - - // When dispatching a message, either DOMContentLoaded has already - // been fired, or someone called startMessages() or set onmessage. - // Either way, a global object is supposed to be present. If it's - // not, we'd fail to initialize the JS API and exit. - RunWithJSContext([this, message = std::move(aMessage)](JSContext* const aCx, - nsIGlobalObject* const aGlobal) { - RootedDictionary init(aCx); - if (!FillInMessageEventInit(aCx, aGlobal, *message, init)) { - // TODO: The spec requires us to fire a messageerror event here. - return; - } - - RefPtr event = - MessageEvent::Constructor(this, NS_LITERAL_STRING("message"), init); - event->SetTrusted(true); - - ErrorResult result; - DispatchEvent(*event, result); - if (result.Failed()) { - result.SuppressException(); - } - }); -} - -namespace { - -nsresult -FillInOriginNoSuffix(const ServiceWorkerDescriptor& aServiceWorker, nsString& aOrigin) -{ - using mozilla::ipc::PrincipalInfoToPrincipal; - - nsresult rv; - - nsCOMPtr principal = PrincipalInfoToPrincipal(aServiceWorker.PrincipalInfo(), &rv); - if (NS_FAILED(rv) || !principal) { - return rv; - } - - nsAutoCString originUTF8; - rv = principal->GetOriginNoSuffix(originUTF8); - if (NS_FAILED(rv)) { - return rv; - } - - CopyUTF8toUTF16(originUTF8, aOrigin); - return NS_OK; -} - -already_AddRefed -GetOrCreateServiceWorkerWithoutWarnings(nsIGlobalObject* const aGlobal, - const ServiceWorkerDescriptor& aDescriptor) -{ - // In child-intercept mode we have to verify that the registration - // exists in the current process. This exact check is also performed - // (indirectly) in nsIGlobalObject::GetOrCreateServiceWorker, but it - // also emits a warning when the registration is not present. To - // to avoid having too many warnings, we do a precheck here. - if (!ServiceWorkerParentInterceptEnabled()) { - const RefPtr serviceWorkerManager = ServiceWorkerManager::GetInstance(); - if (!serviceWorkerManager) { - return nullptr; - } - - const RefPtr registration = - serviceWorkerManager->GetRegistration(aDescriptor.PrincipalInfo(), aDescriptor.Scope()); - if (!registration) { - return nullptr; - } - } - - return aGlobal->GetOrCreateServiceWorker(aDescriptor).forget(); -} - -} - -bool -ServiceWorkerContainer::FillInMessageEventInit(JSContext* const aCx, - nsIGlobalObject* const aGlobal, - ReceivedMessage& aMessage, - MessageEventInit& aInit) -{ - ErrorResult result; - JS::Rooted messageData(aCx); - aMessage.mClonedData.Read(aCx, &messageData, result); - if (result.Failed()) { - return false; - } - - aInit.mData = messageData; - - if (!aMessage.mClonedData.TakeTransferredPortsAsSequence(aInit.mPorts)) { - return false; - } - - const nsresult rv = FillInOriginNoSuffix(aMessage.mServiceWorker, aInit.mOrigin); - if (NS_FAILED(rv)) { - return false; - } - - const RefPtr serviceWorkerInstance = - GetOrCreateServiceWorkerWithoutWarnings(aGlobal, aMessage.mServiceWorker); - if (serviceWorkerInstance) { - aInit.mSource.SetValue().SetAsServiceWorker() = serviceWorkerInstance; - } - - return true; -} - } // namespace dom } // namespace mozilla diff --git a/dom/serviceworkers/ServiceWorkerContainer.h b/dom/serviceworkers/ServiceWorkerContainer.h index 93dfa0d00399..b0e5f571b371 100644 --- a/dom/serviceworkers/ServiceWorkerContainer.h +++ b/dom/serviceworkers/ServiceWorkerContainer.h @@ -15,8 +15,6 @@ class nsIGlobalWindow; namespace mozilla { namespace dom { -class ClientPostMessageArgs; -struct MessageEventInit; class Promise; struct RegistrationOptions; class ServiceWorker; @@ -66,19 +64,7 @@ public: IMPL_EVENT_HANDLER(controllerchange) IMPL_EVENT_HANDLER(error) - - // Almost a manual expansion of IMPL_EVENT_HANDLER(message), but - // with the additional StartMessages() when setting the handler, as - // required by the spec. - inline mozilla::dom::EventHandlerNonNull* GetOnmessage() - { - return GetEventHandler(nsGkAtoms::onmessage); - } - inline void SetOnmessage(mozilla::dom::EventHandlerNonNull* aCallback) - { - SetEventHandler(nsGkAtoms::onmessage, aCallback); - StartMessages(); - } + IMPL_EVENT_HANDLER(message) static bool IsEnabled(JSContext* aCx, JSObject* aGlobal); @@ -103,9 +89,6 @@ public: already_AddRefed GetRegistrations(ErrorResult& aRv); - void - StartMessages(); - Promise* GetReady(ErrorResult& aRv); @@ -121,9 +104,6 @@ public: void ControllerChanged(ErrorResult& aRv); - void - ReceiveMessage(const ClientPostMessageArgs& aArgs); - private: ServiceWorkerContainer(nsIGlobalObject* aGlobal, already_AddRefed aInner); @@ -141,27 +121,6 @@ private: GetGlobalIfValid(ErrorResult& aRv, const std::function&& aStorageFailureCB = nullptr) const; - struct ReceivedMessage; - - // Dispatch a Runnable that dispatches the given message on this - // object. When the owner of this object is a Window, the Runnable - // is dispatched on the corresponding TabGroup. - void - EnqueueReceivedMessageDispatch(RefPtr aMessage); - - template - void - RunWithJSContext(F&& aCallable); - - void - DispatchMessage(RefPtr aMessage); - - static bool - FillInMessageEventInit(JSContext* aCx, - nsIGlobalObject* aGlobal, - ReceivedMessage& aMessage, - MessageEventInit& aInit); - RefPtr mInner; // This only changes when a worker hijacks everything in its scope by calling @@ -170,13 +129,6 @@ private: RefPtr mReadyPromise; MozPromiseRequestHolder mReadyPromiseHolder; - - // Set after StartMessages() has been called. - bool mMessagesStarted = false; - - // Queue holding messages posted from service worker as long as - // StartMessages() hasn't been called. - nsTArray> mPendingMessages; }; } // namespace dom diff --git a/dom/webidl/ServiceWorkerContainer.webidl b/dom/webidl/ServiceWorkerContainer.webidl index b714f56b71d8..3d0bc34f2616 100644 --- a/dom/webidl/ServiceWorkerContainer.webidl +++ b/dom/webidl/ServiceWorkerContainer.webidl @@ -4,7 +4,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * https://w3c.github.io/ServiceWorker/#serviceworkercontainer + * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html * */ @@ -29,8 +29,6 @@ interface ServiceWorkerContainer : EventTarget { [NewObject] Promise> getRegistrations(); - void startMessages(); - attribute EventHandler oncontrollerchange; attribute EventHandler onerror; attribute EventHandler onmessage; diff --git a/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html b/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html index a88aa896c90b..623036d46639 100644 --- a/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html +++ b/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html @@ -21,8 +21,7 @@ } promise_test(async t => { - const suffix = "?q=aborted-not-intercepted"; - const scope = SCOPE + suffix; + const scope = SCOPE + "?q=aborted-not-intercepted"; await setupRegistration(t, scope); const iframe = await with_iframe(scope); add_completion_callback(_ => iframe.remove()); @@ -34,13 +33,8 @@ const nextData = new Promise(resolve => { w.navigator.serviceWorker.addEventListener('message', function once(event) { - // The message triggered by the iframe's document's fetch - // request cannot get dispatched by the time we add the event - // listener, so we have to guard against it. - if (!event.data.endsWith(suffix)) { - w.navigator.serviceWorker.removeEventListener('message', once); - resolve(event.data); - } + w.navigator.serviceWorker.removeEventListener('message', once); + resolve(event.data); }) }); diff --git a/testing/web-platform/tests/fetch/api/request/destination/resources/fetch-destination-worker-no-load-event.js b/testing/web-platform/tests/fetch/api/request/destination/resources/fetch-destination-worker-no-load-event.js index 4a45c69582f9..5a3c679cc03e 100644 --- a/testing/web-platform/tests/fetch/api/request/destination/resources/fetch-destination-worker-no-load-event.js +++ b/testing/web-platform/tests/fetch/api/request/destination/resources/fetch-destination-worker-no-load-event.js @@ -1,5 +1,5 @@ self.addEventListener('fetch', function(event) { - if (event.request.url.includes('dummy.html?')) { + if (event.request.url.includes('dummy')) { event.waitUntil(async function() { let destination = new URL(event.request.url).searchParams.get("dest"); var result = "FAIL"; diff --git a/testing/web-platform/tests/service-workers/service-worker/postmessage-to-client.https.html b/testing/web-platform/tests/service-workers/service-worker/postmessage-to-client.https.html index b1dc41a018f2..15d2e8893370 100644 --- a/testing/web-platform/tests/service-workers/service-worker/postmessage-to-client.https.html +++ b/testing/web-platform/tests/service-workers/service-worker/postmessage-to-client.https.html @@ -51,208 +51,4 @@ promise_test(t => { }) .then(e => { assert_equals(e.data, 'quit'); }); }, 'postMessage from ServiceWorker to Client.'); - -// This function creates a message listener that captures all messages -// sent to this window and matches them with corresponding requests. -// This frees test code from having to use clunky constructs just to -// avoid race conditions, since the relative order of message and -// request arrival doesn't matter. -function create_message_listener(t) { - const listener = { - messages: new Set(), - requests: new Set(), - waitFor: function(predicate) { - for (const event of this.messages) { - // If a message satisfying the predicate has already - // arrived, it gets matched to this request. - if (predicate(event)) { - this.messages.delete(event); - return Promise.resolve(event); - } - } - - // If no match was found, the request is stored and a - // promise is returned. - const request = { predicate }; - const promise = new Promise(resolve => request.resolve = resolve); - this.requests.add(request); - return promise; - } - }; - window.onmessage = t.step_func(event => { - for (const request of listener.requests) { - // If the new message matches a stored request's - // predicate, the request's promise is resolved with this - // message. - if (request.predicate(event)) { - listener.requests.delete(request); - request.resolve(event); - return; - } - }; - - // No outstanding request for this message, store it in case - // it's requested later. - listener.messages.add(event); - }); - return listener; -} - -async function service_worker_register_and_activate(t, script, scope) { - const registration = await service_worker_unregister_and_register(t, script, scope); - t.add_cleanup(() => registration.unregister()); - const worker = registration.installing; - await wait_for_state(t, worker, 'activated'); - return worker; -} - -// Add an iframe (parent) whose document contains a nested iframe -// (child), then set the child's src attribute to child_url and return -// its Window (without waiting for it to finish loading). -async function with_nested_iframes(t, child_url) { - const parent = await with_iframe('resources/nested-iframe-parent.html?role=parent'); - t.add_cleanup(() => parent.remove()); - const child = parent.contentWindow.document.getElementById('child'); - child.setAttribute('src', child_url); - return child.contentWindow; -} - -// Returns a predicate matching a fetch message with the specified -// key. -function fetch_message(key) { - return event => event.data.type === 'fetch' && event.data.key === key; -} - -// Returns a predicate matching a ping message with the specified -// payload. -function ping_message(data) { - return event => event.data.type === 'ping' && event.data.data === data; -} - -// A client message queue test is a testharness.js test with some -// additional setup: -// 1. A listener (see create_message_listener) -// 2. An active service worker -// 3. Two nested iframes -// 4. A state transition function that controls the order of events -// during the test -function client_message_queue_test(url, test_function, description) { - promise_test(async t => { - t.listener = create_message_listener(t); - - const script = 'resources/stalling-service-worker.js'; - const scope = 'resources/'; - t.service_worker = await service_worker_register_and_activate(t, script, scope); - - // We create two nested iframes such that both are controlled by - // the newly installed service worker. - const child_url = url + '?role=child'; - t.frame = await with_nested_iframes(t, child_url); - - t.state_transition = async function(from, to, scripts) { - // A state transition begins with the child's parser - // fetching a script due to a diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/about-blank-replacement-ping-frame.py b/testing/web-platform/tests/service-workers/service-worker/resources/about-blank-replacement-ping-frame.py index bb07c241ad49..58fb4403f9c6 100644 --- a/testing/web-platform/tests/service-workers/service-worker/resources/about-blank-replacement-ping-frame.py +++ b/testing/web-platform/tests/service-workers/service-worker/resources/about-blank-replacement-ping-frame.py @@ -41,7 +41,6 @@ if (win.location.href !== 'about:blank') { }); } }); - win.navigator.serviceWorker.startMessages(); } diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/enable-client-message-queue.html b/testing/web-platform/tests/service-workers/service-worker/resources/enable-client-message-queue.html deleted file mode 100644 index 512bd14bc67d..000000000000 --- a/testing/web-platform/tests/service-workers/service-worker/resources/enable-client-message-queue.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/message-vs-microtask.html b/testing/web-platform/tests/service-workers/service-worker/resources/message-vs-microtask.html deleted file mode 100644 index 2c45c59a475a..000000000000 --- a/testing/web-platform/tests/service-workers/service-worker/resources/message-vs-microtask.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/nested-iframe-parent.html b/testing/web-platform/tests/service-workers/service-worker/resources/nested-iframe-parent.html deleted file mode 100644 index 115ab26e1221..000000000000 --- a/testing/web-platform/tests/service-workers/service-worker/resources/nested-iframe-parent.html +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/stalling-service-worker.js b/testing/web-platform/tests/service-workers/service-worker/resources/stalling-service-worker.js deleted file mode 100644 index fdf1e6cac04e..000000000000 --- a/testing/web-platform/tests/service-workers/service-worker/resources/stalling-service-worker.js +++ /dev/null @@ -1,54 +0,0 @@ -async function post_message_to_client(role, message, ports) { - (await clients.matchAll()).forEach(client => { - if (new URL(client.url).searchParams.get('role') === role) { - client.postMessage(message, ports); - } - }); -} - -async function post_message_to_child(message, ports) { - await post_message_to_client('child', message, ports); -} - -function ping_message(data) { - return { type: 'ping', data }; -} - -self.onmessage = event => { - const message = ping_message(event.data); - post_message_to_child(message); - post_message_to_parent(message); -} - -async function post_message_to_parent(message, ports) { - await post_message_to_client('parent', message, ports); -} - -function fetch_message(key) { - return { type: 'fetch', key }; -} - -// Send a message to the parent along with a MessagePort to respond -// with. -function report_fetch_request(key) { - const channel = new MessageChannel(); - const reply = new Promise(resolve => { - channel.port1.onmessage = resolve; - }).then(event => event.data); - return post_message_to_parent(fetch_message(key), [channel.port2]).then(() => reply); -} - -function respond_with_script(script) { - return new Response(new Blob(script, { type: 'text/javascript' })); -} - -// Whenever a controlled document requests a URL with a 'key' search -// parameter we report the request to the parent frame and wait for -// a response. The content of the response is then used to respond to -// the fetch request. -addEventListener('fetch', event => { - let key = new URL(event.request.url).searchParams.get('key'); - if (key) { - event.respondWith(report_fetch_request(key).then(respond_with_script)); - } -});