Service Worker: Fetch event added asynchronously doesn't throw.

Based on the spec (https://github.com/whatwg/dom/pull/653),
addEventListener after the first evaluation of the Service
worker script should not throw.

Change-Id: I46af276a67e021cf277a98195bf5c04583ad0b0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1838376
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Commit-Queue: Daniel Soromou <fosoromo@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#702753}
diff --git a/service-workers/service-worker/fetch-event-add-async.https.html b/service-workers/service-worker/fetch-event-add-async.https.html
new file mode 100644
index 0000000..ac13e4f
--- /dev/null
+++ b/service-workers/service-worker/fetch-event-add-async.https.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<title>Service Worker: Fetch event added asynchronously doesn't throw</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+'use strict';
+
+service_worker_test(
+  'resources/fetch-event-add-async-worker.js');
+</script>
diff --git a/service-workers/service-worker/resources/fetch-event-add-async-worker.js b/service-workers/service-worker/resources/fetch-event-add-async-worker.js
new file mode 100644
index 0000000..a5a44a5
--- /dev/null
+++ b/service-workers/service-worker/resources/fetch-event-add-async-worker.js
@@ -0,0 +1,6 @@
+importScripts('/resources/testharness.js');
+
+promise_test(async () => {
+  await new Promise(handler => { step_timeout(handler, 0); });
+  self.addEventListener('fetch', () => {});
+}, 'fetch event added asynchronously does not throw');