Bug 1179397 - Disallow FetchEvent.respondWith() when the dispatch flag is unset; r=jdm a=lizzard
☠☠ backed out by a168d4128c4d ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 07 Oct 2015 17:01:28 -0400
changeset 296403 ca97cca1a50ceaaebcf0773b5a1cdc1236125296
parent 296402 369aac182bf6dc4a14d0921890e916f8fddee2a6
child 296404 28ddc15188e4dfddc9876f0a15c3328c6265c8a7
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, lizzard
bugs1179397
milestone43.0a2
Bug 1179397 - Disallow FetchEvent.respondWith() when the dispatch flag is unset; r=jdm a=lizzard
dom/workers/ServiceWorkerEvents.cpp
testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-event-async-respond-with.https.html
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -398,17 +398,17 @@ RespondWithHandler::CancelRequest(nsresu
   NS_DispatchToMainThread(runnable);
 }
 
 } // namespace
 
 void
 FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv)
 {
-  if (mWaitToRespond) {
+  if (EventPhase() == nsIDOMEvent::NONE || mWaitToRespond) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   nsRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
   StopImmediatePropagation();
   mWaitToRespond = true;
   nsRefPtr<RespondWithHandler> handler =
deleted file mode 100644
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[fetch-event-async-respond-with.https.html]
-  type: testharness
-  [Calling respondWith asynchronously throws an exception]
-    expected: FAIL
-
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-event-async-respond-with.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-event-async-respond-with.https.html
@@ -17,18 +17,18 @@ promise_test(function(t) {
         })
       .then(function(frame) {
           var channel = new MessageChannel();
           var saw_message = new Promise(function(resolve) {
               channel.port1.onmessage = function(e) { resolve(e.data); }
             });
           var worker = frame.contentWindow.navigator.serviceWorker.controller;
 
+          worker.postMessage({port: channel.port2}, [channel.port2]);
           frame.remove();
-          worker.postMessage({port: channel.port2}, [channel.port2]);
           return saw_message;
         })
       .then(function(message) {
           assert_equals(message, 'PASS');
           return service_worker_unregister_and_done(t, scope);
         })
   }, 'Calling respondWith asynchronously throws an exception');
 </script>