Bug 1497782 [wpt PR 13448] - [ServiceWorker] Add WPT tests to check request header for update, a=testonly
☠☠ backed out by 09dd66ffc95a ☠ ☠
authormomohatt <momohatt10@gmail.com>
Mon, 15 Oct 2018 18:19:37 +0000
changeset 500068 49fcbe25c596eac667929a2b9537e8213fe07b79
parent 500067 4cde50991a6b460c8631a4f3647e481558f81653
child 500069 b4a3f1a30972168886183642c3dc795c7a9246bb
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1497782, 13448, 1267297, 599126
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497782 [wpt PR 13448] - [ServiceWorker] Add WPT tests to check request header for update, a=testonly Automatic update from web-platform-tests[ServiceWorker] Add WPT tests to check request header for update Spec requires that during the update of service workers, request headers for fetching main scripts should include "Service-Worker" field, while that for fetching importScripts() resources should not. This patch adds WPT tests to validate this behavior. Change-Id: I24949fd0b375f6b811a73ce24aae87a4ea7c234f Reviewed-on: https://chromium-review.googlesource.com/c/1267297 Commit-Queue: Makoto Shimazu <shimazu@chromium.org> Reviewed-by: Makoto Shimazu <shimazu@chromium.org> Cr-Commit-Position: refs/heads/master@{#599126} -- wpt-commits: 2cb31fe81723d02ae720d3c508d6bc8d80b70bf3 wpt-pr: 13448
testing/web-platform/tests/service-workers/service-worker/resources/service-worker-header.py
testing/web-platform/tests/service-workers/service-worker/service-worker-header.https.html
--- a/testing/web-platform/tests/service-workers/service-worker/resources/service-worker-header.py
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/service-worker-header.py
@@ -1,7 +1,20 @@
 def main(request, response):
   service_worker_header = request.headers.get('service-worker')
-  if service_worker_header == 'script':
-    body = '// Request has `Service-Worker: script` header'
-    return 200, [('Content-Type', 'application/javascript')], body
-  else:
+
+  if 'header' in request.GET and service_worker_header != 'script':
+    return 400, [('Content-Type', 'text/plain')], 'Bad Request'
+
+  if 'no-header' in request.GET and service_worker_header == 'script':
     return 400, [('Content-Type', 'text/plain')], 'Bad Request'
+
+  # no-cache itself to ensure the user agent finds a new version for each
+  # update.
+  headers = [('Cache-Control', 'no-cache, must-revalidate'),
+             ('Pragma', 'no-cache'),
+             ('Content-Type', 'application/javascript')]
+  body = '/* This is a service worker script */\n'
+
+  if 'import' in request.GET:
+    body += "importScripts('%s');" % request.GET['import']
+
+  return 200, headers, body
--- a/testing/web-platform/tests/service-workers/service-worker/service-worker-header.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/service-worker-header.https.html
@@ -1,18 +1,23 @@
 <!DOCTYPE html>
 <title>Service Worker: Service-Worker header</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 
-promise_test(t => {
-  const script = 'resources/service-worker-header.py';
+promise_test(async t => {
+  const script = 'resources/service-worker-header.py'
+    + '?header&import=service-worker-header.py?no-header';
   const scope = 'resources/service-worker-header';
-  return service_worker_unregister_and_register(t, script, scope)
-    .then(registration => {
-      assert_true(registration instanceof ServiceWorkerRegistration);
-      return registration.unregister();
-    });
-}, 'A request to fetch service worker script should have Service-Worker header');
+  const expected_url = normalizeURL(script);
+  const registration =
+    await service_worker_unregister_and_register(t, script, scope);
+  t.add_cleanup(() => registration.unregister());
+  assert_true(registration instanceof ServiceWorkerRegistration);
+
+  await wait_for_state(t, registration.installing, 'activated');
+  await registration.update();
+}, 'A request to fetch service worker main script should have Service-Worker '
+  + 'header and imported scripts should not have one');
 
 </script>