Changeset 246363 in webkit


Ignore:
Timestamp:
Jun 12, 2019 10:47:27 AM (5 years ago)
Author:
youenn@apple.com
Message:

Update WPT service workers test up to 0df7c68
https://bugs.webkit.org/show_bug.cgi?id=198720

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

  • web-platform-tests/service-workers: Resynced.

LayoutTests:

Location:
trunk/LayoutTests
Files:
129 added
98 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246362 r246363  
     12019-06-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Update WPT service workers test up to 0df7c68
     4        https://bugs.webkit.org/show_bug.cgi?id=198720
     5
     6        Reviewed by Eric Carlson.
     7
     8        * TestExpectations:
     9        * tests-options.json:
     10
    1112019-06-12  Truitt Savell  <tsavell@apple.com>
    212
  • trunk/LayoutTests/TestExpectations

    r246330 r246363  
    24532453
    24542454webkit.org/b/182311 imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html [ Skip ]
     2455imported/w3c/web-platform-tests/service-workers/service-worker/svg-target-reftest.https.html [ ImageOnlyFailure ]
    24552456
    24562457webkit.org/b/90980 fast/forms/textarea/textarea-state-restore.html [ Pass Timeout ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r246339 r246363  
     12019-06-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Update WPT service workers test up to 0df7c68
     4        https://bugs.webkit.org/show_bug.cgi?id=198720
     5
     6        Reviewed by Eric Carlson.
     7
     8        * web-platform-tests/service-workers: Resynced.
     9
    1102019-06-11  Devin Rousso  <drousso@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/script-tests/cache-match.js

    r238592 r246363  
    144144        });
    145145  }, 'Cache.match supports ignoreVary');
     146
     147cache_test(function(cache) {
     148    let has_cache_name = false;
     149    const opts = {
     150      get cacheName() {
     151        has_cache_name = true;
     152        return undefined;
     153      }
     154    };
     155    return self.caches.open('foo')
     156      .then(function() {
     157          return cache.match('bar', opts);
     158        })
     159      .then(function() {
     160          assert_false(has_cache_name,
     161                       'Cache.match does not support cacheName option ' +
     162                       'which was removed in CacheQueryOptions.');
     163        });
     164  }, 'Cache.match does not support cacheName option');
    146165
    147166prepopulated_cache_test(simple_entries, function(cache, entries) {
     
    338357  }, 'cors-exposed header should be stored correctly.');
    339358
     359cache_test(async (cache) => {
     360    // A URL that should load a resource with a known mime type.
     361    const url = '/service-workers/cache-storage/resources/blank.html';
     362    const expected_mime_type = 'text/html';
     363
     364    // Verify we get the expected mime type from the network.  Note,
     365    // we cannot use an exact match here since some browsers append
     366    // character encoding information to the blob.type value.
     367    const net_response = await fetch(url);
     368    const net_mime_type = (await net_response.blob()).type;
     369    assert_true(net_mime_type.includes(expected_mime_type),
     370                'network response should include the expected mime type');
     371
     372    // Verify we get the exact same mime type when reading the same
     373    // URL resource back out of the cache.
     374    await cache.add(url);
     375    const cache_response = await cache.match(url);
     376    const cache_mime_type = (await cache_response.blob()).type;
     377    assert_equals(cache_mime_type, net_mime_type,
     378                  'network and cache response mime types should match');
     379  }, 'MIME type should be set from content-header correctly.');
     380
     381cache_test(async (cache) => {
     382    const url = '/dummy';
     383    const original_type = 'text/html';
     384    const init_with_headers = {
     385      headers: {
     386        'content-type': original_type
     387      }
     388    }
     389
     390    // Verify constructing a synthetic response with a content-type header
     391    // gets the correct mime type.
     392    const response = new Response('hello world', init_with_headers);
     393    const original_response_type = (await response.blob()).type;
     394    assert_true(original_response_type.includes(original_type),
     395                'original response should include the expected mime type');
     396
     397    // Verify overwriting the content-type header does not change the mime
     398    // type.  It should be fixed at Response construction time.
     399    const overwritten_response = new Response('hello world', init_with_headers);
     400    overwritten_response.headers.set('content-type', 'text/plain');
     401    const overwritten_response_type = (await overwritten_response.blob()).type;
     402    assert_equals(overwritten_response_type, original_response_type,
     403                  'original and overwritten response mime types should match');
     404
     405    // Verify the Response read from Cache uses the original mime type
     406    // computed when it was first constructed.
     407    const tmp = new Response('hello world', init_with_headers);
     408    tmp.headers.set('content-type', 'text/plain');
     409    await cache.put(url, tmp);
     410    const cache_response = await cache.match(url);
     411    const cache_mime_type = (await cache_response.blob()).type;
     412    assert_equals(cache_mime_type, original_response_type,
     413                  'original and cached overwritten response mime types ' +
     414                  'should match');
     415  }, 'MIME type should be frozen at response construction.');
     416
    340417done();
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-match.https-expected.txt

    r238592 r246363  
    1111PASS Cache.match supports ignoreMethod
    1212PASS Cache.match supports ignoreVary
     13FAIL Cache.match does not support cacheName option assert_false: Cache.match does not support cacheName option which was removed in CacheQueryOptions. expected false got true
    1314PASS Cache.match with URL containing fragment
    1415PASS Cache.match with string fragment "http" as query
     
    2223PASS Cache produces large Responses that can be cloned and read correctly.
    2324FAIL cors-exposed header should be stored correctly. assert_equals: expected (string) "bar" but got (object) null
     25FAIL MIME type should be set from content-header correctly. assert_equals: network and cache response mime types should match expected "text/html" but got ""
     26FAIL MIME type should be frozen at response construction. assert_equals: original and cached overwritten response mime types should match expected "text/html" but got ""
    2427
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-match.https-expected.txt

    r238592 r246363  
    1010PASS Cache.match supports ignoreMethod
    1111PASS Cache.match supports ignoreVary
     12FAIL Cache.match does not support cacheName option assert_false: Cache.match does not support cacheName option which was removed in CacheQueryOptions. expected false got true
    1213PASS Cache.match with URL containing fragment
    1314PASS Cache.match with string fragment "http" as query
     
    2122PASS Cache produces large Responses that can be cloned and read correctly.
    2223FAIL cors-exposed header should be stored correctly. assert_equals: expected (string) "bar" but got (object) null
     24FAIL MIME type should be set from content-header correctly. assert_equals: network and cache response mime types should match expected "text/html" but got ""
     25FAIL MIME type should be frozen at response construction. assert_equals: original and cached overwritten response mime types should match expected "text/html" but got ""
    2326
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-match.https-expected.txt

    r238592 r246363  
    1010PASS Cache.match supports ignoreMethod
    1111PASS Cache.match supports ignoreVary
     12FAIL Cache.match does not support cacheName option assert_false: Cache.match does not support cacheName option which was removed in CacheQueryOptions. expected false got true
    1213PASS Cache.match with URL containing fragment
    1314PASS Cache.match with string fragment "http" as query
     
    2122PASS Cache produces large Responses that can be cloned and read correctly.
    2223FAIL cors-exposed header should be stored correctly. assert_equals: expected (string) "bar" but got (object) null
     24FAIL MIME type should be set from content-header correctly. assert_equals: network and cache response mime types should match expected "text/html" but got ""
     25FAIL MIME type should be frozen at response construction. assert_equals: original and cached overwritten response mime types should match expected "text/html" but got ""
    2326
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/Service-Worker-Allowed-header.https-expected.txt

    r238592 r246363  
    55PASS Registering outside Service-Worker-Allowed path
    66PASS Registering outside Service-Worker-Allowed path with parent reference
    7 PASS Service-Worker-Allowed is cross-origin to script, registering on a normally allowed scope
    8 PASS Service-Worker-Allowed is cross-origin to script, registering on a normally disallowed scope
     7FAIL Service-Worker-Allowed is cross-origin to script, registering on a normally allowed scope assert_unreached: Should have rejected: undefined Reached unreachable code
     8FAIL Service-Worker-Allowed is cross-origin to script, registering on a normally disallowed scope assert_unreached: Should have rejected: undefined Reached unreachable code
    99PASS Service-Worker-Allowed is cross-origin to page, same-origin to script
    1010
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/Service-Worker-Allowed-header.https.html

    r238592 r246363  
    1818}
    1919
    20 promise_test(async t => {
    21   const script = build_script_url('/allowed-path');
    22   const scope = '/allowed-path';
    23   const registration = await service_worker_unregister_and_register(
    24       t, script, scope);
    25   assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
    26   assert_equals(registration.scope, normalizeURL(scope));
    27   return registration.unregister();
    28 }, 'Registering within Service-Worker-Allowed path');
     20// register_test is a promise_test that registers a service worker.
     21function register_test(script, scope, description) {
     22  promise_test(async t => {
     23    t.add_cleanup(() => {
     24      return service_worker_unregister(t, scope);
     25    });
    2926
    30 promise_test(async t => {
    31   const script = build_script_url(new URL('/allowed-path', document.location));
    32   const scope = '/allowed-path';
    33   const registration = await service_worker_unregister_and_register(
    34       t, script, scope);
    35   assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
    36   assert_equals(registration.scope, normalizeURL(scope));
    37   return registration.unregister();
    38 }, 'Registering within Service-Worker-Allowed path (absolute URL)');
     27    const registration = await service_worker_unregister_and_register(
     28        t, script, scope);
     29    assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
     30    assert_equals(registration.scope, normalizeURL(scope));
     31  }, description);
     32}
    3933
    40 promise_test(async t => {
    41   const script = build_script_url('../allowed-path-with-parent');
    42   const scope = 'allowed-path-with-parent';
    43   const registration = await service_worker_unregister_and_register(
    44       t, script, scope);
    45   assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
    46   assert_equals(registration.scope, normalizeURL(scope));
    47   return registration.unregister();
    48 }, 'Registering within Service-Worker-Allowed path with parent reference');
     34// register_fail_test is like register_test but expects a SecurityError.
     35function register_fail_test(script, scope, description) {
     36  promise_test(async t => {
     37    t.add_cleanup(() => {
     38      return service_worker_unregister(t, scope);
     39    });
    4940
    50 promise_test(async t => {
    51   const script = build_script_url('../allowed-path');
    52   const scope = '/disallowed-path';
    53   await service_worker_unregister(t, scope);
    54   return promise_rejects(t,
    55       'SecurityError',
    56       navigator.serviceWorker.register(script, {scope: scope}),
    57       'register should fail');
    58 }, 'Registering outside Service-Worker-Allowed path');
     41    await service_worker_unregister(t, scope);
     42    await promise_rejects(t,
     43                          'SecurityError',
     44                          navigator.serviceWorker.register(script, {scope}));
     45  }, description);
     46}
    5947
    60 promise_test(async t => {
    61   const script = build_script_url('../allowed-path-with-parent');
    62   const scope = '/allowed-path-with-parent';
    63   await service_worker_unregister(t, scope);
    64   return promise_rejects(t,
    65       'SecurityError',
    66       navigator.serviceWorker.register(script, {scope: scope}),
    67       'register should fail');
    68 }, 'Registering outside Service-Worker-Allowed path with parent reference');
     48register_test(
     49    build_script_url('/allowed-path'),
     50    '/allowed-path',
     51    'Registering within Service-Worker-Allowed path');
    6952
    70 promise_test(async t => {
    71   const script = build_script_url(
    72       host_info.HTTPS_REMOTE_ORIGIN + '/');
    73   const scope = 'resources/this-scope-is-normally-allowed'
    74   const registration = await service_worker_unregister_and_register(
    75       t, script, scope);
    76   assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
    77   assert_equals(registration.scope, normalizeURL(scope));
    78   return registration.unregister();
    79 }, 'Service-Worker-Allowed is cross-origin to script, registering on a normally allowed scope');
     53register_test(
     54    build_script_url(new URL('/allowed-path', document.location)),
     55    '/allowed-path',
     56    'Registering within Service-Worker-Allowed path (absolute URL)');
    8057
    81 promise_test(async t => {
    82   const script = build_script_url(
    83       host_info.HTTPS_REMOTE_ORIGIN + '/');
    84   const scope = '/this-scope-is-normally-disallowed'
    85   const registration = await service_worker_unregister_and_register(
    86       t, script, scope);
    87   assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
    88   assert_equals(registration.scope, normalizeURL(scope));
    89   return registration.unregister();
    90 }, 'Service-Worker-Allowed is cross-origin to script, registering on a normally disallowed scope');
     58register_test(
     59    build_script_url('../allowed-path-with-parent'),
     60    'allowed-path-with-parent',
     61    'Registering within Service-Worker-Allowed path with parent reference');
    9162
    92 promise_test(async t => {
    93   const script = build_script_url(
    94       host_info.HTTPS_REMOTE_ORIGIN + '/cross-origin/',
    95       host_info.HTTPS_REMOTE_ORIGIN);
    96   const scope = '/cross-origin/';
    97   await service_worker_unregister(t, scope);
    98   return promise_rejects(t,
    99       'SecurityError',
    100       navigator.serviceWorker.register(script, {scope: scope}),
    101       'register should fail');
    102 }, 'Service-Worker-Allowed is cross-origin to page, same-origin to script');
     63register_fail_test(
     64    build_script_url('../allowed-path'),
     65    '/disallowed-path',
     66    'Registering outside Service-Worker-Allowed path'),
    10367
     68register_fail_test(
     69    build_script_url('../allowed-path-with-parent'),
     70    '/allowed-path-with-parent',
     71    'Registering outside Service-Worker-Allowed path with parent reference');
     72
     73register_fail_test(
     74    build_script_url(host_info.HTTPS_REMOTE_ORIGIN + '/'),
     75    'resources/this-scope-is-normally-allowed',
     76    'Service-Worker-Allowed is cross-origin to script, registering on a normally allowed scope');
     77
     78register_fail_test(
     79    build_script_url(host_info.HTTPS_REMOTE_ORIGIN + '/'),
     80    '/this-scope-is-normally-disallowed',
     81    'Service-Worker-Allowed is cross-origin to script, registering on a normally disallowed scope');
     82
     83register_fail_test(
     84    build_script_url(host_info.HTTPS_REMOTE_ORIGIN + '/cross-origin/',
     85                     host_info.HTTPS_REMOTE_ORIGIN),
     86    '/cross-origin/',
     87    'Service-Worker-Allowed is cross-origin to page, same-origin to script');
    10488</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/postmessage.https.html

    r220223 r246363  
    1313    return service_worker_unregister_and_register(t, script, scope)
    1414      .then(function(r) {
     15          t.add_cleanup(function() {
     16              return service_worker_unregister(t, scope);
     17            });
     18
    1519          registration = r;
     20
    1621          return wait_for_state(t, registration.installing, 'activated');
    1722        })
     
    2934      .then(function(result) {
    3035          assert_equals(result, 'OK');
    31           return service_worker_unregister_and_done(t, scope);
    3236        });
    3337  }, 'Post loopback messages');
     
    4246    return service_worker_unregister_and_register(t, script1, scope)
    4347      .then(function(r) {
     48          t.add_cleanup(function() {
     49              return service_worker_unregister(t, scope);
     50            });
     51
    4452          registration = r;
    4553          return wait_for_state(t, registration.installing, 'activated');
     
    7078          assert_equals(result, 'OK');
    7179          frame.remove();
    72           return service_worker_unregister_and_done(t, scope);
    7380        });
    7481  }, 'Post messages among service workers');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https.html

    r202471 r246363  
    1212    return service_worker_unregister_and_register(t, script, scope)
    1313      .then(function(registration) {
     14          t.add_cleanup(function() {
     15              return service_worker_unregister(t, scope);
     16            });
     17
    1418          return wait_for_state(t, registration.installing, 'redundant');
    1519        })
     
    2226            undefined,
    2327            'After unregister(), the registration should not found');
    24           return service_worker_unregister_and_done(t, scope);
    2528        });
    2629  }, 'Unregister on script evaluation');
     
    3235    return service_worker_unregister_and_register(t, script, scope)
    3336      .then(function(registration) {
     37          t.add_cleanup(function() {
     38              return service_worker_unregister(t, scope);
     39            });
     40
    3441          return wait_for_state(t, registration.installing, 'redundant');
    3542        })
     
    4249            undefined,
    4350            'After unregister(), the registration should not found');
    44           return service_worker_unregister_and_done(t, scope);
    4551        });
    4652  }, 'Unregister on installing event');
     
    5258    return service_worker_unregister_and_register(t, script, scope)
    5359      .then(function(registration) {
     60          t.add_cleanup(function() {
     61              return service_worker_unregister(t, scope);
     62            });
     63
    5464          return wait_for_state(t, registration.installing, 'redundant');
    5565        })
     
    6272            undefined,
    6373            'After unregister(), the registration should not found');
    64           return service_worker_unregister_and_done(t, scope);
    6574        });
    6675  }, 'Unregister on activate event');
     
    7584    return service_worker_unregister_and_register(t, script, scope)
    7685      .then(function(registration) {
     86          t.add_cleanup(function() {
     87              return service_worker_unregister(t, scope);
     88            });
     89
    7790          return wait_for_state(t, registration.installing, 'activated');
    7891        })
     
    121134          frame.remove();
    122135          new_frame.remove();
    123           return service_worker_unregister_and_done(t, scope);
    124136        })
    125137  }, 'Unregister controlling service worker');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https.html

    r202471 r246363  
    1414    return service_worker_unregister_and_register(t, script, scope)
    1515      .then(function(r) {
     16          t.add_cleanup(function() {
     17              return service_worker_unregister(t, scope);
     18            });
     19
    1620          registration = r;
    1721          return wait_for_state(t, registration.installing, 'activated');
     
    3943          frame1.remove();
    4044          frame2.remove();
    41           return service_worker_unregister_and_done(t, scope);
    4245        });
    4346  }, 'Update a registration on ServiceWorkerGlobalScope');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/about-blank-replacement.https.html

    r238592 r246363  
    6161async function doAsyncTest(t, scope) {
    6262  let reg = await service_worker_unregister_and_register(t, worker, scope);
     63
     64  t.add_cleanup(() => service_worker_unregister(t, scope));
     65
    6366  await wait_for_state(t, reg.installing, 'activated');
    6467
     
    97100
    98101  frame.remove();
    99   await service_worker_unregister_and_done(t, scope);
    100102}
    101103
     
    127129
    128130  let reg = await service_worker_unregister_and_register(t, worker, scope);
     131
     132  t.add_cleanup(() => service_worker_unregister(t, scope));
     133
    129134  await wait_for_state(t, reg.installing, 'activated');
    130135
     
    148153
    149154  frame.remove();
    150   await service_worker_unregister_and_done(t, scope);
    151155}, 'Initial about:blank is controlled, exposed to clients.matchAll(), and ' +
    152156   'final Client is not controlled by a service worker.');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activate-event-after-install-state-change.https.html

    r202471 r246363  
    1212  return service_worker_unregister_and_register(t, script, scope)
    1313    .then(function(registration) {
     14        t.add_cleanup(function() {
     15            return service_worker_unregister(t, scope);
     16          });
     17
    1418        var sw = registration.installing;
    1519
     
    2428        }));
    2529      })
    26     .then(function() {
    27         return service_worker_unregister_and_done(t, scope);
    28       })
    2930    .catch(unreached_rejection(t));
    3031  }, 'installed event should be fired before activating service worker');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/appcache-ordering-main.https.html

    r238592 r246363  
    66<script>
    77
    8 var INSTALL_APPCACHE_URL = "resources/appcache-ordering.install.html";
    98var IS_APPCACHED_URL = "resources/appcache-ordering.is-appcached.html";
    109var SERVICE_WORKER_SCOPE = "resources/appcache-ordering";
     
    1514
    1615var frames = [];
    17 
    18 // Called by the INSTALL_APPCACHE_URL child frame.
    19 function notify_appcache_installed(success) {
    20   if (success)
    21     resolve_install_appcache();
    22   else
    23     reject_install_appcache();
    24 }
    25 
    26 function install_appcache() {
    27   return new Promise(function(resolve, reject) {
    28       var frame = document.createElement('iframe');
    29       frames.push(frame);
    30       frame.src = INSTALL_APPCACHE_URL;
    31       document.body.appendChild(frame);
    32       resolve_install_appcache = function() {
    33           document.body.removeChild(frame);
    34           resolve();
    35         };
    36       reject_install_appcache = function() {
    37           document.body.removeChild(frame);
    38           reject();
    39         };
    40   });
    41 }
    4216
    4317var resolve_is_appcached = undefined;
     
    6438    return service_worker_unregister(t, SERVICE_WORKER_SCOPE)
    6539      .then(function() {
    66           return install_appcache();
     40          return install_appcache_ordering_manifest();
    6741        })
    6842      .then(function() {
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-fetch.https.html

    r220223 r246363  
    88<script>
    99
    10 promise_test(function(t) {
    11   var frame;
    12   var resource = 'simple.txt';
     10async function try_fetch(fetch_func, path) {
     11  let response;
     12  try {
     13   response = await fetch_func(path);
     14  } catch (err) {
     15    throw (`fetch() threw: ${err}`);
     16  }
    1317
    14   var worker;
    15   var scope = 'resources/';
    16   var script = 'resources/claim-worker.js';
     18  let response_text;
     19  try {
     20   response_text = await response.text();
     21  } catch (err) {
     22   throw (`text() threw: ${err}`);
     23  }
    1724
    18   return Promise.resolve()
    19     // Create the test iframe.
    20     .then(() => with_iframe('resources/blank.html'))
    21     .then(f => frame = f)
     25  return response_text;
     26}
    2227
    23     // Check the controller and test with fetch.
    24     .then(() => assert_equals(frame.contentWindow.navigator.controller,
    25                               undefined,
    26                               'Should have no controller.'))
    27     .then(() => frame.contentWindow.fetch(resource))
    28     .then(response => response.text())
    29     .then(response_text => assert_equals(response_text,
    30                                          'a simple text file\n',
    31                                          'fetch() should not be intercepted.'))
     28promise_test(async function(t) {
     29  let frame;
     30  const scope = 'resources/';
     31  const script = 'resources/claim-worker.js';
     32  t.add_cleanup(async () => {
     33    if (frame)
     34      frame.remove();
     35    return service_worker_unregister(t, scope);
     36  });
    3237
    33     // Register a service worker.
    34     .then(() => service_worker_unregister_and_register(t, script, scope))
    35     .then(r => worker = r.installing)
    36     .then(() => wait_for_state(t, worker, 'activated'))
     38  const resource = 'simple.txt';
    3739
    38     // Let the service worker claim the iframe.
    39     .then(() => {
    40       var channel = new MessageChannel();
    41       var saw_message = new Promise(function(resolve) {
    42         channel.port1.onmessage = t.step_func(function(e) {
    43           assert_equals(e.data, 'PASS',
    44                         'Worker call to claim() should fulfill.');
    45           resolve();
    46         });
    47       });
    48       worker.postMessage({port: channel.port2}, [channel.port2]);
    49       return saw_message;
    50     })
     40  // Create the test frame.
     41  await service_worker_unregister(t, scope);
     42  frame = await with_iframe('resources/blank.html');
    5143
    52     // Check the controller and test with fetch.
    53     .then(() => frame.contentWindow.navigator.serviceWorker.getRegistration(scope))
    54     .then(r => assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
    55                              r.active,
    56                              'Test iframe should be claimed.'))
    57     .then(() => frame.contentWindow.fetch(resource))
    58     .then(response => response.text())
    59     .then(response_text => assert_equals(response_text,
    60                                          'Intercepted!',
    61                                          'fetch() should be intercepted.'))
     44  // Check the controller and test with fetch.
     45  assert_equals(frame.contentWindow.navigator.controller, undefined,
     46                'Should have no controller.');
     47  let response;
     48  try {
     49    response = await try_fetch(frame.contentWindow.fetch, resource);
     50  } catch (err) {
     51    assert_unreached(`uncontrolled fetch failed: ${err}`);
     52  }
     53  assert_equals(response, 'a simple text file\n',
     54                'fetch() should not be intercepted.');
    6255
    63     // Cleanup this testcase.
    64     .then(() => frame.remove())
    65     .then(() => service_worker_unregister_and_done(t, scope));
    66 }, 'fetch() should be intercepted after the client is claimed.')
     56  // Register a service worker.
     57  const registration = await navigator.serviceWorker.register(script, {scope});
     58  const worker = registration.installing;
     59  await wait_for_state(t, worker, 'activated');
     60
     61  // Tell the service worker to claim the iframe.
     62  const saw_message = new Promise((resolve) => {
     63    const channel = new MessageChannel();
     64    channel.port1.onmessage = t.step_func((event) => {
     65      resolve(event.data);
     66    });
     67    worker.postMessage({port: channel.port2}, [channel.port2]);
     68  });
     69  const data = await saw_message;
     70  assert_equals(data, 'PASS', 'Worker call to claim() should fulfill.');
     71
     72  // Check the controller and test with fetch.
     73  const controller = frame.contentWindow.navigator.serviceWorker.controller;
     74  assert_true(controller instanceof frame.contentWindow.ServiceWorker,
     75              'iframe should be controlled.');
     76  try {
     77    response = await try_fetch(frame.contentWindow.fetch, resource);
     78  } catch (err) {
     79    assert_unreached(`controlled fetch failed: ${err}`);
     80  }
     81  assert_equals(response, 'Intercepted!',
     82                'fetch() should be intercepted.');
     83}, 'fetch() should be intercepted after the client is claimed.');
    6784
    6885</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-not-using-registration.https.html

    r220223 r246363  
    1616        t, init_worker_url, init_scope)
    1717      .then(function(registration) {
     18          t.add_cleanup(function() {
     19              return service_worker_unregister(t, init_scope);
     20            });
     21
    1822          return wait_for_state(t, registration.installing, 'activated');
    1923        })
     
    3640        })
    3741      .then(function(registration) {
     42          t.add_cleanup(function() {
     43              return service_worker_unregister(t, claim_scope);
     44            });
     45
    3846          claim_worker = registration.installing;
    3947          claim_registration = registration;
     
    6876          frame2.remove();
    6977          return claim_registration.unregister();
    70         })
    71       .then(function() {
    72           return service_worker_unregister_and_done(t, init_scope);
    7378        });
    7479  }, 'Test claim client which is not using registration');
     
    8792        })
    8893      .then(function(registration) {
     94          t.add_cleanup(function() {
     95              return service_worker_unregister(t, claim_scope);
     96            });
     97
    8998          claim_worker = registration.installing;
    9099          return wait_for_state(t, registration.installing, 'activated');
     
    95104        })
    96105      .then(function() {
     106          t.add_cleanup(function() {
     107              return service_worker_unregister(t, scope);
     108            });
     109
    97110          var channel = new MessageChannel();
    98111          var saw_message = new Promise(function(resolve) {
     
    112125              'registration exists');
    113126          frame.remove();
    114           return service_worker_unregister(t, claim_scope);
    115         })
    116       .then(function() {
    117           return service_worker_unregister_and_done(t, scope);
    118127        });
    119128  }, 'Test claim client when there\'s a longer-matched registration not ' +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-shared-worker-fetch.https.html

    r222307 r246363  
    3131    // Register a service worker.
    3232    .then(() => service_worker_unregister_and_register(t, script, scope))
    33     .then(r => worker = r.installing)
    34     .then(() => wait_for_state(t, worker, 'activated'))
     33    .then(r => {
     34        t.add_cleanup(() => service_worker_unregister(t, scope));
    3535
     36        worker = r.installing;
     37
     38        return wait_for_state(t, worker, 'activated')
     39      })
    3640    // Let the service worker claim the iframe and the shared worker.
    3741    .then(() => {
     
    6165
    6266    // Cleanup this testcase.
    63     .then(() => frame.remove())
    64     .then(() => service_worker_unregister_and_done(t, scope));
     67    .then(() => frame.remove());
    6568}, 'fetch() in SharedWorker should be intercepted after the client is claimed.')
    6669
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-using-registration.https.html

    r220223 r246363  
    1414    return service_worker_unregister_and_register(t, url1, scope)
    1515      .then(function(registration) {
     16          t.add_cleanup(function() {
     17              return service_worker_unregister(t, scope);
     18            });
     19
    1620          return wait_for_state(t, registration.installing, 'activated');
    1721        })
     
    5155          frame.remove();
    5256          return sw_registration.unregister();
    53         })
    54       .then(function() {
    55           return service_worker_unregister_and_done(t, scope);
    5657        });
    5758  }, 'Test worker claims client which is using another registration');
     
    6465    return service_worker_unregister_and_register(t, url1, scope)
    6566      .then(function(registration) {
     67          t.add_cleanup(function() {
     68              return service_worker_unregister(t, scope);
     69            });
     70
    6671          return wait_for_state(t, registration.installing, 'activated');
    6772        })
     
    9297      .then(function() {
    9398          frame.remove();
    94           return service_worker_unregister_and_done(t, scope);
    9599        });
    96100  }, 'Test for the waiting worker claims a client which is using the the ' +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-client-types.https.html

    r222307 r246363  
    5555        t, 'resources/clients-matchall-worker.js', scope)
    5656      .then(function(registration) {
     57          t.add_cleanup(function() {
     58              return service_worker_unregister(t, scope);
     59            });
     60
    5761          return wait_for_state(t, registration.installing, 'activated');
    5862        })
     
    6771      .then(function() {
    6872          frame.remove();
    69           return service_worker_unregister_and_done(t, scope);
    70         })
    71       .catch(unreached_rejection(t));
     73        });
    7274  }, 'Verify matchAll() with window client type');
    7375
     
    7779        t, 'resources/clients-matchall-worker.js', scope)
    7880      .then(function(registration) {
     81          t.add_cleanup(function() {
     82              return service_worker_unregister(t, scope);
     83            });
     84
    7985          return wait_for_state(t, registration.installing, 'activated');
    8086        })
     
    113119      .then(function() {
    114120          frame.remove();
    115           return service_worker_unregister_and_done(t, scope);
    116121        });
    117122}, 'Verify matchAll() with {window, sharedworker, worker} client types');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-order.https.html

    r238592 r246363  
    124124  let extraWindowResult;
    125125  return service_worker_unregister_and_register(t, script, opts.scope).then(swr => {
     126    t.add_cleanup(() => service_worker_unregister(t, opts.scope));
     127
    126128    worker = swr.installing;
    127129    return wait_for_state(t, worker, 'activated');
     
    144146    frameResultList.forEach(result => result.top.remove());
    145147    extraWindowResult.top.remove();
    146   }).then(_ => {
    147     return service_worker_unregister_and_done(t, opts.scope);
    148148  }).catch(e => {
    149149    if (frameResultList) {
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/controller-on-reload.https.html

    r220223 r246363  
    1414    return service_worker_unregister(t, scope)
    1515      .then(function() {
     16          t.add_cleanup(function() {
     17              return service_worker_unregister(t, scope);
     18            });
     19
    1620          return with_iframe(scope);
    1721        })
     
    4953          assert_equals(frameRegistration.active, controller);
    5054          frame.remove();
    51           service_worker_unregister_and_done(t, scope);
    5255        });
    5356  }, 'controller is set upon reload after registration');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https-expected.txt

    r238592 r246363  
    11
    22
    3 PASS Test calling waitUntil in a different task without an existing extension throws
    4 FAIL Test calling waitUntil in a different microtask without an existing extension throws assert_equals: expected "InvalidStateError" but got "OK"
    5 PASS Test calling waitUntil in a different task with an existing extension succeeds
    6 PASS Test calling waitUntil with an existing extension promise handler succeeds
    7 FAIL Test calling waitUntil at the end of the microtask turn throws assert_equals: expected "InvalidStateError" but got "OK"
     3PASS Test calling waitUntil in a task at the end of the event handler without an existing extension throws
     4PASS Test calling waitUntil in a microtask at the end of the event handler without an existing extension suceeds
     5PASS Test calling waitUntil in a different task an existing extension succeeds
     6PASS Test calling waitUntil at the end of an existing extension promise handler succeeds (event is still being dispatched)
     7PASS Test calling waitUntil in a microtask at the end of an existing extension promise handler succeeds (event is still being dispatched)
     8PASS Test calling waitUntil in an existing extension promise handler succeeds (event is not being dispatched)
     9PASS Test calling waitUntil in a microtask at the end of an existing extension promise handler throws (event is not being dispatched)
    810PASS Test calling waitUntil after the current extension expired in a different task fails
    911PASS Test calling waitUntil on a script constructed ExtendableEvent throws exception
    1012PASS Test calling waitUntil asynchronously with pending respondWith promise.
    11 PASS Test calling waitUntil synchronously inside microtask of respondWith promise.
    12 FAIL Test calling waitUntil asynchronously inside microtask of respondWith promise. assert_equals: expected "InvalidStateError" but got "OK"
     13PASS Test calling waitUntil synchronously inside microtask of respondWith promise (event is being dispatched).
     14PASS Test calling waitUntil asynchronously inside microtask of respondWith promise (event is being dispatched).
     15PASS Test calling waitUntil synchronously inside microtask of respondWith promise (event is not being dispatched).
     16PASS Test calling waitUntil asynchronously inside microtask of respondWith promise (event is not being dispatched).
    1317
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https.html

    r238592 r246363  
    11<!DOCTYPE html>
     2<meta name="timeout" content="long">
    23<script src="/resources/testharness.js"></script>
    34<script src="resources/testharness-helpers.js"></script>
     
    5758
    5859promise_test(msg_event_test.bind(this, 'no-current-extension-different-task'),
    59   'Test calling waitUntil in a different task without an existing extension throws');
     60  'Test calling waitUntil in a task at the end of the event handler without an existing extension throws');
    6061
    6162promise_test(msg_event_test.bind(this, 'no-current-extension-different-microtask'),
    62   'Test calling waitUntil in a different microtask without an existing extension throws');
     63  'Test calling waitUntil in a microtask at the end of the event handler without an existing extension suceeds');
    6364
    6465promise_test(msg_event_test.bind(this, 'current-extension-different-task'),
    65   'Test calling waitUntil in a different task with an existing extension succeeds');
     66  'Test calling waitUntil in a different task an existing extension succeeds');
    6667
    67 promise_test(msg_event_test.bind(this, 'current-extension-expired-same-microtask-turn'),
    68   'Test calling waitUntil with an existing extension promise handler succeeds');
     68promise_test(msg_event_test.bind(this, 'during-event-dispatch-current-extension-expired-same-microtask-turn'),
     69  'Test calling waitUntil at the end of an existing extension promise handler succeeds (event is still being dispatched)');
    6970
    70 // The promise handler will queue a new microtask after the check for new
    71 // extensions was performed.
    72 promise_test(msg_event_test.bind(this, 'current-extension-expired-same-microtask-turn-extra'),
    73   'Test calling waitUntil at the end of the microtask turn throws');
     71promise_test(msg_event_test.bind(this, 'during-event-dispatch-current-extension-expired-same-microtask-turn-extra'),
     72  'Test calling waitUntil in a microtask at the end of an existing extension promise handler succeeds (event is still being dispatched)');
     73
     74promise_test(msg_event_test.bind(this, 'after-event-dispatch-current-extension-expired-same-microtask-turn'),
     75  'Test calling waitUntil in an existing extension promise handler succeeds (event is not being dispatched)');
     76
     77promise_test(msg_event_test.bind(this, 'after-event-dispatch-current-extension-expired-same-microtask-turn-extra'),
     78  'Test calling waitUntil in a microtask at the end of an existing extension promise handler throws (event is not being dispatched)');
    7479
    7580promise_test(msg_event_test.bind(this, 'current-extension-expired-different-task'),
     
    8186promise_test(function(t) {
    8287    var testBody = function(worker) {
    83       return with_iframe('./resources/pending-respondwith-async-waituntil/dummy.html');
     88      return with_iframe('./resources/pending-respondwith-async-waituntil');
    8489    }
    8590    return runTest(t, 'pending-respondwith-async-waituntil', testBody);
     
    8893promise_test(function(t) {
    8994    var testBody = function(worker) {
    90       return with_iframe('./resources/respondwith-microtask-sync-waituntil/dummy.html');
     95      return with_iframe('./resources/during-event-dispatch-respondwith-microtask-sync-waituntil');
    9196    }
    92     return runTest(t, 'respondwith-microtask-sync-waituntil', testBody);
    93   }, 'Test calling waitUntil synchronously inside microtask of respondWith promise.');
     97    return runTest(t, 'during-event-dispatch-respondwith-microtask-sync-waituntil', testBody);
     98  }, 'Test calling waitUntil synchronously inside microtask of respondWith promise (event is being dispatched).');
    9499
    95100promise_test(function(t) {
    96101    var testBody = function(worker) {
    97       return with_iframe('./resources/respondwith-microtask-async-waituntil/dummy.html');
     102      return with_iframe('./resources/during-event-dispatch-respondwith-microtask-async-waituntil');
    98103    }
    99     return runTest(t, 'respondwith-microtask-async-waituntil', testBody);
    100   }, 'Test calling waitUntil asynchronously inside microtask of respondWith promise.');
     104    return runTest(t, 'during-event-dispatch-respondwith-microtask-async-waituntil', testBody);
     105  }, 'Test calling waitUntil asynchronously inside microtask of respondWith promise (event is being dispatched).');
    101106
     107promise_test(function(t) {
     108    var testBody = function(worker) {
     109      return with_iframe('./resources/after-event-dispatch-respondwith-microtask-sync-waituntil');
     110    }
     111    return runTest(t, 'after-event-dispatch-respondwith-microtask-sync-waituntil', testBody);
     112  }, 'Test calling waitUntil synchronously inside microtask of respondWith promise (event is not being dispatched).');
    102113
     114promise_test(function(t) {
     115    var testBody = function(worker) {
     116      return with_iframe('./resources/after-event-dispatch-respondwith-microtask-async-waituntil');
     117    }
     118    return runTest(t, 'after-event-dispatch-respondwith-microtask-async-waituntil', testBody);
     119  }, 'Test calling waitUntil asynchronously inside microtask of respondWith promise (event is not being dispatched).');
    103120</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-canvas-tainting-video-cache.https.html

    r238592 r246363  
    22<meta charset="utf-8">
    33<title>Service Worker: canvas tainting of the fetched video using cache responses</title>
     4<meta name="timeout" content="long">
    45<script src="/resources/testharness.js"></script>
    56<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-canvas-tainting-video.https.html

    r238592 r246363  
    22<meta charset="utf-8">
    33<title>Service Worker: canvas tainting of the fetched video</title>
     4<meta name="timeout" content="long">
    45<script src="/resources/testharness.js"></script>
    56<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-csp.https.html

    r220223 r246363  
    3333    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
    3434      .then(function(registration) {
     35          t.add_cleanup(function() {
     36              return service_worker_unregister(t, SCOPE);
     37            });
     38
    3539          return wait_for_state(t, registration.installing, 'activated');
    3640        })
     
    106110      .then(function() {
    107111          frame.remove();
    108           service_worker_unregister_and_done(t, SCOPE);
    109112        });
    110113  }, 'Verify CSP control of fetch() in a Service Worker');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-after-navigation-within-page.https.html

    r202471 r246363  
    1616    return service_worker_unregister_and_register(t, worker, scope)
    1717      .then(function(reg) {
     18          t.add_cleanup(function() {
     19              return service_worker_unregister(t, scope);
     20            });
     21
    1822          return wait_for_state(t, reg.installing, 'activated');
    1923        })
     
    3135          assert_equals(response, 'intercepted by service worker');
    3236          frame.remove();
    33           return service_worker_unregister_and_done(t, scope);
    3437        })
    3538  }, 'Service Worker should respond to fetch event after the hash changes');
     
    4447    return service_worker_unregister_and_register(t, worker, scope)
    4548      .then(function(reg) {
     49          t.add_cleanup(function() {
     50              return service_worker_unregister(t, scope);
     51            });
     52
    4653          return wait_for_state(t, reg.installing, 'activated');
    4754        })
     
    5966          assert_equals(response, 'intercepted by service worker');
    6067          frame.remove();
    61           return service_worker_unregister_and_done(t, scope);
    6268        })
    6369  }, 'Service Worker should respond to fetch event after the pushState');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-async-respond-with.https-expected.txt

    r227425 r246363  
     1CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: cancelled
    12
    2 PASS Calling respondWith asynchronously throws an exception
     3Harness Error (FAIL), message = cancelled
    34
     5PASS global setup
     6PASS respondWith in a task throws InvalidStateError
     7PASS respondWith in a microtask does not throw
     8PASS global cleanup
     9
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-async-respond-with.https.html

    r220223 r246363  
    11<!DOCTYPE html>
     2<html>
     3<title>respondWith cannot be called asynchronously</title>
    24<script src="/resources/testharness.js"></script>
    35<script src="/resources/testharnessreport.js"></script>
    46<script src="resources/test-helpers.sub.js"></script>
    57<script>
    6 promise_test(function(t) {
    7     var script = 'resources/fetch-event-async-respond-with-worker.js';
    8     var scope = 'resources/simple.html';
     8// This file has tests that call respondWith() asynchronously.
    99
    10     return service_worker_unregister_and_register(t, script, scope)
    11       .then(function(registration) {
    12           return wait_for_state(t, registration.installing, 'activated');
    13         })
    14       .then(function() {
    15           return with_iframe(scope);
    16         })
    17       .then(function(frame) {
    18           add_completion_callback(function() { frame.remove(); });
    19           var channel = new MessageChannel();
    20           var saw_message = new Promise(function(resolve) {
    21               channel.port1.onmessage = function(e) { resolve(e.data); }
    22             });
    23           var worker = frame.contentWindow.navigator.serviceWorker.controller;
     10let frame;
     11let worker;
     12const script = 'resources/fetch-event-async-respond-with-worker.js';
     13const scope = 'resources/simple.html';
    2414
    25           worker.postMessage({port: channel.port2}, [channel.port2]);
    26           return saw_message;
    27         })
    28       .then(function(message) {
    29           assert_equals(message, 'PASS');
    30           return service_worker_unregister_and_done(t, scope);
    31         })
    32   }, 'Calling respondWith asynchronously throws an exception');
     15// Global setup: this must be the first promise_test.
     16promise_test(async (t) => {
     17  const registration =
     18      await service_worker_unregister_and_register(t, script, scope);
     19  worker = registration.installing;
     20  await wait_for_state(t, worker, 'activated');
     21  frame = await with_iframe(scope);
     22}, 'global setup');
     23
     24// Waits for a single message from the service worker and then removes the
     25// message handler. Not safe for concurrent use.
     26function wait_for_message() {
     27  return new Promise((resolve) => {
     28    const handler = (event) => {
     29      navigator.serviceWorker.removeEventListener('message', handler);
     30      resolve(event.data);
     31    };
     32    navigator.serviceWorker.addEventListener('message', handler);
     33  });
     34}
     35
     36// Does one test case. It fetches |url|. The service worker gets a fetch event
     37// for |url| and attempts to call respondWith() asynchronously. It reports back
     38// to the test whether an exception was thrown.
     39async function do_test(url) {
     40  // Send a message to tell the worker a new test case is starting.
     41  const message = wait_for_message();
     42  worker.postMessage('initializeMessageHandler');
     43  const response = await message;
     44  assert_equals(response, 'messageHandlerInitialized');
     45
     46  // Start a fetch.
     47  frame.contentWindow.fetch(url);
     48
     49  // Receive the test result from the service worker.
     50  return wait_for_message();
     51};
     52
     53promise_test(async (t) => {
     54  const result = await do_test('respondWith-in-task');
     55  assert_true(result.didThrow, 'should throw');
     56  assert_equals(result.error, 'InvalidStateError');
     57}, 'respondWith in a task throws InvalidStateError');
     58
     59promise_test(async (t) => {
     60  const result = await do_test('respondWith-in-microtask');
     61  assert_equals(result.didThrow, false, 'should not throw');
     62}, 'respondWith in a microtask does not throw');
     63
     64// Global cleanup: the final promise_test.
     65promise_test(async (t) => {
     66  if (frame)
     67    frame.remove();
     68  await service_worker_unregister(t, scope);
     69}, 'global cleanup');
    3370</script>
     71</html>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-network-error.https.html

    r220223 r246363  
    2323    return service_worker_unregister_and_register(t, script, scope)
    2424      .then(function(registration) {
     25          t.add_cleanup(function() {
     26              return service_worker_unregister(t, scope);
     27            });
     28
    2529          return wait_for_state(t, registration.installing, 'activated');
    2630        })
     
    3539          frame.remove();
    3640          assert_equals(result, 'PASS');
    37           return service_worker_unregister_and_done(t, scope);
    3841        });
    3942  }, 'Rejecting the fetch event or using preventDefault() causes a network ' +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https-expected.txt

    r226397 r246363  
    1 CONSOLE MESSAGE: line 32: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
     1CONSOLE MESSAGE: line 29: [blocked] The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was not allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    22
    3 CONSOLE MESSAGE: line 54: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    4 
    5 CONSOLE MESSAGE: line 76: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    6 
    7 CONSOLE MESSAGE: line 98: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    8 
    9 CONSOLE MESSAGE: line 120: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    10 
    11 CONSOLE MESSAGE: line 132: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    12 
    13 CONSOLE MESSAGE: line 197: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    14 
    15 CONSOLE MESSAGE: line 231: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    16 
    17 CONSOLE MESSAGE: line 32: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    18 
    19 CONSOLE MESSAGE: line 54: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    20 
    21 CONSOLE MESSAGE: line 76: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    22 
    23 CONSOLE MESSAGE: line 98: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    24 
    25 CONSOLE MESSAGE: line 120: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    26 
    27 CONSOLE MESSAGE: line 132: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    28 
    29 CONSOLE MESSAGE: line 197: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
    30 
    31 CONSOLE MESSAGE: line 231: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
     3CONSOLE MESSAGE: line 29: Not allowed to request resource
     4CONSOLE MESSAGE: line 29: Fetch API cannot load http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull due to access control checks.
    325
    336
    34 PASS Service Worker responds to fetch event with the referrer policy
     7FAIL Service Worker responds to fetch event with the referrer policy promise_test: Unhandled rejection with value: object "TypeError: Not allowed to request resource"
    358PASS Service Worker should respond to fetch with the default referrer policy
    369PASS Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present - Default Referrer
    37 PASS Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request - Default Referrer
    38 PASS Service Worker should respond to fetch with the referrer with "" - Default Referrer
    39 PASS Service Worker should respond to fetch with no referrer with "" - Default Referrer
    40 PASS Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request - Default Referrer
    41 PASS Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request - Default Referrer
    42 PASS Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request - Default Referrer
    43 PASS Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request - Default Referrer
    44 PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request - Default Referrer
    45 PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request - Default Referrer
    46 PASS Service Worker should respond to fetch with no referrer with "unsafe-url" - Default Referrer
    47 PASS Service Worker should respond to fetch with no referrer URL with "no-referrer" - Default Referrer
    48 PASS Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request - Default Referrer
    49 PASS Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request - Default Referrer
    50 PASS Service Worker should respond to fetch with the referrer origin  with "strict-origin" and a HTTPS cross origin request - Default Referrer
    51 PASS Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request - Default Referrer
    52 PASS Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request - Default Referrer
    53 PASS Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request - Default Referrer
    54 PASS Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request - Default Referrer
    55 PASS Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request - Default Referrer
    56 PASS Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present - Custom Referrer
    57 PASS Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request - Custom Referrer
    58 PASS Service Worker should respond to fetch with the referrer with "" - Custom Referrer
    59 PASS Service Worker should respond to fetch with no referrer with "" - Custom Referrer
    60 PASS Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request - Custom Referrer
    61 PASS Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request - Custom Referrer
    62 PASS Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request - Custom Referrer
    63 PASS Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request - Custom Referrer
    64 PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request - Custom Referrer
    65 PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request - Custom Referrer
    66 PASS Service Worker should respond to fetch with no referrer with "unsafe-url" - Custom Referrer
    67 PASS Service Worker should respond to fetch with no referrer URL with "no-referrer" - Custom Referrer
    68 PASS Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request - Custom Referrer
    69 PASS Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request - Custom Referrer
    70 PASS Service Worker should respond to fetch with the referrer origin  with "strict-origin" and a HTTPS cross origin request - Custom Referrer
    71 PASS Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request - Custom Referrer
    72 PASS Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request - Custom Referrer
    73 PASS Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request - Custom Referrer
    74 PASS Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request - Custom Referrer
    75 PASS Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request - Custom Referrer
    7610
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https.html

    r238592 r246363  
    77<script>
    88var worker = 'resources/fetch-event-test-worker.js';
    9 
    10 if (window.internals && window.internals.settings)
    11     internals.settings.setAllowDisplayOfInsecureContent(true);
    129
    1310function do_test(referrer, value, expected, name)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-argument.https.html

    r220223 r246363  
    2323    return service_worker_unregister_and_register(t, script, scope)
    2424      .then(function(registration) {
     25          t.add_cleanup(function() {
     26              return service_worker_unregister(t, scope);
     27            });
     28
    2529          return wait_for_state(t, registration.installing, 'activated');
    2630        })
     
    3539          frame.remove();
    3640          assert_equals(result, 'PASS');
    37           return service_worker_unregister_and_done(t, scope);
    3841        });
    3942  }, 'respondWith() takes either a Response or a promise that resolves ' +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-body-loaded-in-chunk.https.html

    r227870 r246363  
    22<meta charset="utf-8">
    33<title>respondWith with a response whose body is being loaded from the network by chunks</title>
     4<meta name="timeout" content="long">
    45<script src="/resources/testharness.js"></script>
    56<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html

    r220223 r246363  
    1111    return service_worker_unregister_and_register(t, script, scope)
    1212      .then(function(registration) {
     13          t.add_cleanup(function() {
     14              return service_worker_unregister(t, scope);
     15            });
     16
    1317          return wait_for_state(t, registration.installing, 'activated');
    1418        })
     
    2933      .then(function(message) {
    3034          assert_equals(message, 'PASS');
    31           return service_worker_unregister_and_done(t, scope);
    3235        })
    3336  }, 'respondWith() invokes stopImmediatePropagation()');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-throws-after-respond-with.https.html

    r220223 r246363  
    1313    return service_worker_unregister_and_register(t, workerscript, scope)
    1414      .then(function(reg) {
     15          t.add_cleanup(function() {
     16              return service_worker_unregister(t, scope);
     17            });
     18
    1519          return wait_for_state(t, reg.installing, 'activated')
    1620            .then(() => reg.active);
     
    2832      .then(function(frame) {
    2933        assert_true(frame.contentDocument.body.innerHTML.includes("intercepted"));
    30         service_worker_unregister_and_done(t, scope);
    3134      })
    3235  }, 'Fetch event handler throws after a successful respondWith()');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-css-base-url.https-expected.txt

    r227425 r246363  
    11
     2PASS global setup
     3FAIL base URL when service worker does respondWith(fetch(responseUrl)). assert_equals: referrer expected "https://localhost:9443/service-workers/service-worker/resources/fetch-request-css-base-url-style.css?fetch" but got "https://localhost:9443/service-workers/service-worker/resources/fetch-request-css-base-url-iframe.html?fetch"
     4FAIL base URL when service worker does respondWith(new Response()). assert_equals: referrer expected "https://localhost:9443/service-workers/service-worker/resources/request-url-path/fetch-request-css-base-url-style.css?newResponse" but got "https://localhost:9443/service-workers/service-worker/resources/fetch-request-css-base-url-iframe.html?newResponse"
     5PASS cleanup global state
    26
    3 FAIL CSS's base URL must be the request URL even when fetched from other URL. assert_equals: The base URL while loading the images referred from CSS must be the request URL of CSS. expected "https://localhost:9443/service-workers/service-worker/resources/dummy.png" but got "https://127.0.0.1:9443/service-workers/service-worker/resources/dummy.png"
    4 
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-css-base-url.https.html

    r238592 r246363  
    11<!DOCTYPE html>
    2 <title>Service Worker: CSS's base URL must be the request URL even when fetched from other URL</title>
     2<title>Service Worker: CSS's base URL must be the response URL</title>
    33<script src="/resources/testharness.js"></script>
    44<script src="/resources/testharnessreport.js"></script>
    5 <script src="/common/get-host-info.sub.js"></script>
    65<script src="resources/test-helpers.sub.js?pipe=sub"></script>
    76<script>
    8 promise_test(function(t) {
    9     var SCOPE = 'resources/fetch-request-css-base-url-iframe.html';
    10     var SCRIPT = 'resources/fetch-request-css-base-url-worker.js';
    11     var worker;
    12     var testDonePromise;
     7const SCOPE = 'resources/fetch-request-css-base-url-iframe.html';
     8const SCRIPT = 'resources/fetch-request-css-base-url-worker.js';
     9let worker;
    1310
    14     return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
    15       .then(function(registration) {
    16           t.add_cleanup(function() {
    17               return service_worker_unregister(t, SCOPE);
    18             });
     11var signalMessage;
     12function getNextMessage() {
     13  return new Promise(resolve => { signalMessage = resolve; });
     14}
    1915
    20           worker = registration.installing;
    21           return wait_for_state(t, worker, 'activated');
    22         })
    23       .then(function() {
    24           return new Promise(function(resolve) {
    25               var channel = new MessageChannel();
    26               testDonePromise = new Promise(function(resolveTestDone) {
    27                 channel.port1.onmessage = t.step_func(function(msg) {
    28                   if (msg.data.ready) {
    29                     resolve();
    30                     return;
    31                   }
    32                   var result = msg.data;
    33                   var base = get_host_info()['HTTPS_ORIGIN'] + base_path();
    34                   assert_equals(
    35                     result.url,
    36                     base + 'resources/dummy.png',
    37                     'The base URL while loading the images referred from CSS ' +
    38                     'must be the request URL of CSS.');
    39                   assert_equals(
    40                     result.referrer,
    41                     base + 'resources/fetch-request-css-base-url-style.css',
    42                     'While loading the image defined in CSS the referrer must ' +
    43                     'be the request URL of CSS.');
    44                   resolveTestDone();
    45                 });
    46               });
    47               worker.postMessage(
    48                 {port: channel.port2}, [channel.port2]);
    49             });
    50         })
    51       .then(function() { return with_iframe(SCOPE); })
    52       .then(function(f) {
    53           return testDonePromise.then(function() {
    54             f.remove();
    55           });
    56         });
    57   }, 'CSS\'s base URL must be the request URL even when fetched from other URL.');
     16promise_test(async (t) => {
     17  const registration = await service_worker_unregister_and_register(
     18      t, SCRIPT, SCOPE);
     19  worker = registration.installing;
     20  await wait_for_state(t, worker, 'activated');
     21}, 'global setup');
     22
     23// Creates a test concerning the base URL of a stylesheet. It loads a
     24// stylesheet from a controlled page. The stylesheet makes a subresource
     25// request for an image. The service worker messages back the details of the
     26// image request in order to test the base URL.
     27//
     28// The request URL for the stylesheet is under "resources/request-url-path/".
     29// The service worker may respond in a way such that the response URL is
     30// different to the request URL.
     31function base_url_test(params) {
     32  promise_test(async (t) => {
     33    let frame;
     34    t.add_cleanup(() => {
     35      if (frame)
     36        frame.remove();
     37    });
     38
     39    // Ask the service worker to message this page once it gets the request
     40    // for the image.
     41    let channel = new MessageChannel();
     42    const sawPong = getNextMessage();
     43    channel.port1.onmessage = (event) => {
     44      signalMessage(event.data);
     45    };
     46    worker.postMessage({port:channel.port2},[channel.port2]);
     47
     48    // It sends a pong back immediately. This ping/pong protocol helps deflake
     49    // the test for browsers where message/fetch ordering isn't guaranteed.
     50    assert_equals('pong', await sawPong);
     51
     52    // Load the frame which will load the stylesheet that makes the image
     53    // request.
     54    const sawResult = getNextMessage();
     55    frame = await with_iframe(params.framePath);
     56    const result = await sawResult;
     57
     58    // Test the image request.
     59    const base = new URL('.', document.location).href;
     60    assert_equals(result.url,
     61                  base + params.expectImageRequestPath,
     62                  'request');
     63    assert_equals(result.referrer,
     64                  base + params.expectImageRequestReferrer,
     65                  'referrer');
     66  }, params.description);
     67}
     68
     69const cssFile = 'fetch-request-css-base-url-style.css';
     70
     71base_url_test({
     72  framePath: SCOPE + '?fetch',
     73  expectImageRequestPath: 'resources/dummy.png',
     74  expectImageRequestReferrer: `resources/${cssFile}?fetch`,
     75  description: 'base URL when service worker does respondWith(fetch(responseUrl)).'});
     76
     77base_url_test({
     78  framePath: SCOPE + '?newResponse',
     79  expectImageRequestPath: 'resources/request-url-path/dummy.png',
     80  expectImageRequestReferrer: `resources/request-url-path/${cssFile}?newResponse`,
     81  description: 'base URL when service worker does respondWith(new Response()).'});
     82
     83// Cleanup step: this must be the last promise_test.
     84promise_test(async (t) => {
     85  return service_worker_unregister(t, SCOPE);
     86}, 'cleanup global state');
    5887</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-redirect.https.html

    r226792 r246363  
    7575    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
    7676      .then(function(registration) {
     77          t.add_cleanup(() => service_worker_unregister(t, SCOPE));
     78
    7779          worker = registration.installing;
    7880          return wait_for_state(t, worker, 'activated');
     
    182184      .then(function() {
    183185          frame.remove();
    184           service_worker_unregister_and_done(t, SCOPE);
    185186        });
    186187  }, 'Verify redirect mode of Fetch API and ServiceWorker FetchEvent.');
     
    209210    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
    210211      .then(function(registration) {
     212          t.add_cleanup(() => service_worker_unregister(t, SCOPE));
     213
    211214          worker = registration.installing;
    212215          return wait_for_state(t, worker, 'activated');
     
    276279      .then(function() {
    277280          frame.remove();
    278           service_worker_unregister_and_done(t, SCOPE);
    279281        });
    280282  }, 'Verify redirected of Response(Fetch API) and ServiceWorker FetchEvent.');
     
    303305    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
    304306      .then(function(registration) {
     307          t.add_cleanup(() => service_worker_unregister(t, SCOPE));
     308
    305309          worker = registration.installing;
    306310          return wait_for_state(t, worker, 'activated');
     
    376380      .then(function() {
    377381          frame.remove();
    378           service_worker_unregister_and_done(t, SCOPE);
    379382        });
    380383  }, 'Verify redirected of Response(Fetch API), Cache API and ServiceWorker ' +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt

    r224453 r246363  
    55PASS getRegistration with a cross origin URL
    66PASS Register then Unregister then getRegistration
     7PASS Register then Unregister then getRegistration in controlled iframe
    78
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https.html

    r238592 r246363  
    8989  }, 'Register then Unregister then getRegistration');
    9090
     91
     92promise_test(async function(t) {
     93  const scope = 'resources/scope/getregistration/register-unregister';
     94  const registration = await service_worker_unregister_and_register(
     95    t, 'resources/empty-worker.js', scope
     96  );
     97
     98  const frame = await with_iframe(scope);
     99  t.add_cleanup(() => frame.remove());
     100
     101  const frameNav = frame.contentWindow.navigator;
     102  await registration.unregister();
     103  const value = await frameNav.serviceWorker.getRegistration(scope);
     104
     105  assert_equals(value, undefined, 'getRegistration should resolve with undefined');
     106}, 'Register then Unregister then getRegistration in controlled iframe');
     107
    91108</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-resource-map.https-expected.txt

    r224132 r246363  
    11
    22PASS import the same script URL multiple times
     3PASS call importScripts() with multiple arguments
    34
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-resource-map.https.html

    r220223 r246363  
    11<!DOCTYPE html>
    2 <meta charset="utf-8">
     2<meta charset="utf-8" />
    33<title>Tests for importScripts: script resource map</title>
    44<script src="/resources/testharness.js"></script>
     
    66<script src="resources/test-helpers.sub.js"></script>
    77<body>
    8 <script>
    9 // This test registers a worker that imports a script multiple times. The
    10 // script should be stored on the first import and thereafter that stored
    11 // script should be loaded. The worker asserts that the stored script was
    12 // loaded; if the assert fails then registration fails.
    13 promise_test(t => {
    14     const scope = 'resources/import-scripts-resource-map';
    15     return service_worker_unregister(t, scope)
    16       .then(() => {
    17           return navigator.serviceWorker.register(
    18               'resources/import-scripts-resource-map-worker.js', {scope: scope});
    19         })
    20       .then(r => r.unregister());
    21   }, 'import the same script URL multiple times');
    22 </script>
     8  <script>
     9    // This test registers a worker that imports a script multiple times. The
     10    // script should be stored on the first import and thereafter that stored
     11    // script should be loaded. The worker asserts that the stored script was
     12    // loaded; if the assert fails then registration fails.
     13
     14    promise_test(async t => {
     15      const SCOPE = "resources/import-scripts-resource-map";
     16      const SCRIPT = "resources/import-scripts-resource-map-worker.js";
     17      await service_worker_unregister(t, SCOPE);
     18      const registration = await navigator.serviceWorker.register(SCRIPT, {
     19        scope: SCOPE
     20      });
     21      await registration.unregister();
     22    }, "import the same script URL multiple times");
     23
     24    promise_test(async t => {
     25      const SCOPE = "resources/import-scripts-diff-resource-map";
     26      const SCRIPT = "resources/import-scripts-diff-resource-map-worker.js";
     27      await service_worker_unregister(t, SCOPE);
     28      const registration = await navigator.serviceWorker.register(SCRIPT, {
     29        scope: SCOPE
     30      });
     31      await registration.unregister();
     32    }, "call importScripts() with multiple arguments");
     33  </script>
    2334</body>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/interfaces-window.https.html

    r238592 r246363  
    11<!DOCTYPE html>
    22<title>Service Worker: Interfaces</title>
     3<meta name="timeout" content="long">
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multiple-update.https.html

    r223273 r246363  
    1616    return service_worker_unregister_and_register(t, expected_url, scope)
    1717      .then(function(r) {
     18          t.add_cleanup(function() {
     19              return service_worker_unregister(t, scope);
     20            });
     21
    1822          registration = r;
    1923          return wait_for_state(t, registration.installing, 'activated');
     
    8690          assert_equals(registration.active.scriptURL, expected_url,
    8791                        'active should still exist after update found.');
    88 
    89           return service_worker_unregister_and_done(t, scope);
    9092        });
    9193  }, 'Trigger multiple updates.');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https.html

    r238592 r246363  
    669669
    670670
     671// SW responds with a fetch from a different url.
     672// SW: event.respondWith(fetch(params['url']));
     673url2 = SCOPE1;
     674url1 = SCOPE1 + 'sw=fetch-url&url=' + encodeURIComponent(url2);
     675redirect_test(
     676    url1,
     677    url1,
     678    [
     679      [
     680        {url: url1, resultingClientIdTag: 'x'}
     681      ],
     682      [],
     683      []
     684    ],
     685    'x',
     686    'SW-fetched response from different URL, same-origin same-scope.');
     687
     688
    671689// Opaque redirect.
    672690// SW: event.respondWith(fetch(
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/performance-timeline.https.html

    r220223 r246363  
    1818  let frame;
    1919  return service_worker_unregister_and_register(t, script, scope)
    20     .then(reg => wait_for_state(t, reg.installing, 'activated'))
     20    .then(reg => {
     21        t.add_cleanup(() => service_worker_unregister(t, scope));
     22
     23        return wait_for_state(t, reg.installing, 'activated');
     24      })
    2125    .then(_ => with_iframe(scope))
    2226    .then(f => {
     
    4044                  'Slow service worker request should measure increased delay.');
    4145      frame.remove();
    42       return service_worker_unregister_and_done(t, scope);
    4346    })
    4447}, 'empty service worker fetch event included in performance timings');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/postmessage-to-client-message-queue.https.html

    r238592 r246363  
    142142    description)
    143143{
    144     function later_state(state1, state2) {
     144    function assert_state_less_than_equal(state1, state2, explanation) {
    145145        const states = ['init', 'install', 'start', 'finish', 'loaded'];
    146146        const index1 = states.indexOf(state1);
    147147        const index2 = states.indexOf(state2);
    148         const max_index = Math.max(index1, index2);
    149         return states[max_index];
     148        if (index1 > index2)
     149          assert_unreached(explanation);
    150150    }
    151151
     
    162162        // Wait for all messages to get dispatched on the child's
    163163        // ServiceWorkerContainer and then verify that each message
    164         // was dispatched while the child was in the correct state.
     164        // was dispatched after |earliest_dispatch|.
    165165        const report = await t.frame.report;
    166166        ['init', 'install', 'start'].forEach(state => {
    167             const dispatch = later_state(state, earliest_dispatch);
    168             assert_equals(report[state], dispatch,
    169                           `Message sent in state '${state}' dispatched in state '${dispatch}'`);
     167            const explanation = `Message sent in state '${state}' was dispatched in '${report[state]}', should be dispatched no earlier than '${earliest_dispatch}'`;
     168            assert_state_less_than_equal(earliest_dispatch,
     169                                         report[state],
     170                                         explanation);
    170171        });
    171172    }, description);
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/postmessage.https-expected.txt

    r238592 r246363  
    44PASS postMessage a transferable ArrayBuffer between ServiceWorker and Client over MessagePort
    55FAIL postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client promise_test: Unhandled rejection with value: object "TypeError: Type error"
     6FAIL postMessage to a redundant worker promise_test: Unhandled rejection with value: object "InvalidStateError: Service Worker state is redundant"
    67
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/postmessage.https.html

    r238592 r246363  
    4040          assert_equals(e.data, 'quit');
    4141          return registration.unregister(scope);
    42         })
    43       .then(() => { return wait_for_state(t, worker, 'redundant'); })
    44       .then(() => {
    45           assert_equals(worker.state, 'redundant');
    46           assert_throws(
    47             {name:'InvalidStateError'},
    48             function() { worker.postMessage(''); },
    49             'Calling postMessage on a redundant ServiceWorker should ' +
    50                 'throw InvalidStateError.');
    5142        });
    5243  }, 'postMessage to a ServiceWorker (and back via MessagePort)');
     
    179170  }, 'postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client');
    180171
     172  promise_test(async t => {
     173    const firstScript = 'resources/postmessage-echo-worker.js?one';
     174    const secondScript = 'resources/postmessage-echo-worker.js?two';
     175    const scope = 'resources/';
     176
     177    const registration = await service_worker_unregister_and_register(t, firstScript, scope);
     178    t.add_cleanup(() => registration.unregister());
     179    const firstWorker = registration.installing;
     180
     181    const messagePromise = new Promise(resolve => {
     182      navigator.serviceWorker.addEventListener('message', (event) => {
     183        resolve(event.data);
     184      }, {once: true});
     185    });
     186
     187    await wait_for_state(t, firstWorker, 'activated');
     188    await navigator.serviceWorker.register(secondScript, {scope});
     189    const secondWorker = registration.installing;
     190    await wait_for_state(t, firstWorker, 'redundant');
     191
     192    // postMessage() to a redundant worker should be dropped silently.
     193    // Historically, this threw an exception.
     194    firstWorker.postMessage('firstWorker');
     195
     196    // To test somewhat that it was not received, send a message to another
     197    // worker and check that we get a reply for that one.
     198    secondWorker.postMessage('secondWorker');
     199    const data = await messagePromise;
     200    assert_equals(data, 'secondWorker');
     201  }, 'postMessage to a redundant worker');
    181202</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ready.https-expected.txt

    r225577 r246363  
    1010PASS ready after a longer matched registration registered
    1111PASS access ready after it has been resolved
    12 PASS access ready on uninstalling registration that is resurrected
     12FAIL resolve ready after unregistering and reregistering assert_not_equals: Registrations should be different got disallowed value object "[object ServiceWorkerRegistration]"
     13FAIL resolve ready before unregistering and reregistering assert_equals: Resolves with the first registration expected "https://localhost:9443/service-workers/service-worker/resources/empty-worker.js" but got "https://localhost:9443/service-workers/service-worker/resources/empty-worker.js?2"
    1314
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ready.https.html

    r224156 r246363  
    251251
    252252promise_test(async function(t) {
    253     var url = 'resources/empty-worker.js';
    254     var matched_scope = 'resources/blank.html?ready-after-resurrect';
    255 
    256     let reg1 = await service_worker_unregister_and_register(t, url, matched_scope);
    257     add_completion_callback(function() {
    258         reg1.unregister();
    259       });
    260     await wait_for_state(t, reg1.installing, 'activated');
    261 
    262     // Hold the worker alive with a controlled worker
    263     let frame = await with_iframe(matched_scope);
    264     add_completion_callback(function() {
    265         frame.remove();
    266       });
    267 
    268     // Doom the registration as uninstalling.
    269     await reg1.unregister();
    270 
    271     // Access the ready promise while the registration is doomed.
    272     let readyPromise = frame.contentWindow.navigator.serviceWorker.ready;
    273 
    274     // Resurrect the doomed registration;
    275     let reg2 = await service_worker_unregister_and_register(t, url, matched_scope);
    276     assert_equals(reg1, reg2, 'existing registration should be resurrected');
    277 
    278     // We are trying to test if the ready promise ever resolves here.  Use
    279     // an explicit timeout check here rather than forcing a full infrastructure
    280     // level timeout.
    281     let timeoutId;
    282     let timeoutPromise = new Promise(resolve => {
    283       timeoutId = setTimeout(_ => {
    284         timeoutId = null;
    285         resolve();
    286       }, 500);
    287     });
    288 
    289     // This should resolve immediately since there is an alive registration
    290     // with an active promise for the matching scope.
    291     await Promise.race([readyPromise, timeoutPromise]);
    292 
    293     assert_not_equals(timeoutId, null,
    294                       'ready promise should resolve before timeout');
    295     clearTimeout(timeoutId);
    296 
    297     // We should get here and not time out.
    298 
    299   }, 'access ready on uninstalling registration that is resurrected');
     253  const url1 = 'resources/empty-worker.js';
     254  const url2 = url1 + '?2';
     255  const matched_scope = 'resources/blank.html?ready-after-unregister';
     256
     257  const reg1 = await service_worker_unregister_and_register(t, url1, matched_scope);
     258  t.add_cleanup(() => reg1.unregister());
     259
     260  await wait_for_state(t, reg1.installing, 'activating');
     261  // This registration will resolve all ready promises in clients that match the scope.
     262  // But there are no clients.
     263
     264  const frame = await with_iframe(matched_scope);
     265  t.add_cleanup(() => frame.remove());
     266
     267  await reg1.unregister();
     268
     269  // Access the ready promise while the registration is unregistering.
     270  const readyPromise = frame.contentWindow.navigator.serviceWorker.ready;
     271
     272  // Create a new registration.
     273  const reg2 = await navigator.serviceWorker.register(url2, { scope: matched_scope });
     274  t.add_cleanup(() => reg2.unregister());
     275  // This registration will resolve all ready promises in clients that match the scope.
     276  // That includes frame's client.
     277
     278  const readyReg = await readyPromise;
     279
     280  assert_equals(readyReg.active.scriptURL, reg2.active.scriptURL, 'Resolves with the second registration');
     281  assert_not_equals(reg1, reg2, 'Registrations should be different');
     282}, 'resolve ready after unregistering and reregistering');
     283
     284promise_test(async function(t) {
     285  const url1 = 'resources/empty-worker.js';
     286  const url2 = url1 + '?2';
     287  const matched_scope = 'resources/blank.html?ready-after-unregister';
     288
     289  const frame = await with_iframe(matched_scope);
     290  t.add_cleanup(() => frame.remove());
     291
     292  const reg1 = await service_worker_unregister_and_register(t, url1, matched_scope);
     293  t.add_cleanup(() => reg1.unregister());
     294
     295  await wait_for_state(t, reg1.installing, 'activated');
     296  // This registration will resolve all ready promises in clients that match the scope.
     297  // That includes frame's client.
     298
     299  const reg1Active = reg1.active;
     300
     301  await reg1.unregister();
     302
     303  // Access the ready promise while the registration is unregistering.
     304  const readyPromise = frame.contentWindow.navigator.serviceWorker.ready;
     305
     306  // Create a new registration.
     307  const reg2 = await navigator.serviceWorker.register(url2, { scope: matched_scope });
     308  t.add_cleanup(() => reg2.unregister());
     309  // This registration will resolve all ready promises in clients that match the scope.
     310  // That includes frame's client, but its ready promise has already resolved.
     311
     312  const readyReg = await readyPromise;
     313
     314  assert_equals(readyReg.active.scriptURL, reg1Active.scriptURL, 'Resolves with the first registration');
     315  assert_not_equals(reg1, reg2, 'Registrations should be different');
     316}, 'resolve ready before unregistering and reregistering');
    300317</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-default-scope.https.html

    r202471 r246363  
    5353      .then(
    5454        function(registration) {
     55          t.add_cleanup(function() {
     56              return service_worker_unregister(t, registration.scope);
     57            });
     58
    5559          assert_unreached('register should fail');
    56           service_worker_unregister_and_done(t, registration.scope);
    5760        },
    5861        function(error) {
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https.html

    r202471 r246363  
    1717    return navigator.serviceWorker.register(bad_script, {scope: scope})
    1818      .then(function(r) {
     19          t.add_cleanup(function() {
     20              return service_worker_unregister(t, scope);
     21            });
     22
    1923          registration = r;
    2024          assert_equals(registration.installing.scriptURL,
     
    4852          return wait_for_state(t, registration.installing, 'activated');
    4953        })
    50       .then(function() {
    51           return service_worker_unregister_and_done(t, scope);
    52         })
    5354  }, 'register worker that calls waitUntil with a promise that never ' +
    5455     'resolves in oninstall');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-end-to-end.https.html

    r202471 r246363  
    1212    var lastServiceWorkerState = '';
    1313    var receivedMessageFromPort = '';
    14     var currentChangeCount = 0;
    1514
    1615    assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer);
    1716    assert_equals(typeof navigator.serviceWorker.register, 'function');
    1817    assert_equals(typeof navigator.serviceWorker.getRegistration, 'function');
    19 
    20     navigator.serviceWorker.oncurrentchange = function() {
    21         ++currentChangeCount;
    22     };
    2318
    2419    service_worker_unregister_and_register(
     
    7671                                'Service worker should pass through all states');
    7772
    78             assert_equals(currentChangeCount, 0,
    79                           'Should not see current changes since document is out of scope');
    80 
    8173            assert_equals(receivedMessageFromPort, 'Ack for: registering doc');
    8274
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https.html

    r222307 r246363  
    11<!DOCTYPE html>
    22<title>Service Worker: Registration (MIME types)</title>
     3<meta name="timeout" content="long">
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-updateviacache.https-expected.txt

    r238592 r246363  
    2424PASS access-updateViaCache-after-unregister-all
    2525PASS access-updateViaCache-after-unregister-none
     26FAIL updateViaCache is not updated if register() rejects assert_equals: after update attempt expected "imports" but got "none"
    2627
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-updateviacache.https.html

    r238592 r246363  
    185185  }
    186186
     187  promise_test(async t => {
     188    await cleanup();
     189    t.add_cleanup(cleanup);
     190
     191    const registration = await navigator.serviceWorker.register(
     192        'resources/empty.js',
     193        {scope: SCOPE});
     194    assert_equals(registration.updateViaCache, 'imports',
     195                  'before update attempt');
     196
     197    const fail = navigator.serviceWorker.register(
     198        'resources/malformed-worker.py?parse-error',
     199        {scope: SCOPE, updateViaCache: 'none'});
     200    await promise_rejects(t, new TypeError(), fail);
     201    assert_equals(registration.updateViaCache, 'imports',
     202                  'after update attempt');
     203  }, 'updateViaCache is not updated if register() rejects');
    187204</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resource-timing.sub.https.html

    r244776 r246363  
    1515    const url = options.mode === 'cross-origin' ? crossOriginUrl(options.resource)
    1616                                      : resourceUrl(options.resource);
    17     const entryList = options.performance.getEntriesByName(url);
     17    const entryList = options.performance.getEntriesByName(url, 'resource');
    1818    if (options.should_no_performance_entry) {
    1919        // The performance timeline may not have an entry for a resource
     
    137137test(() => {
    138138    const url = resourceUrl('resources/test-helpers.sub.js');
    139     const entry = window.performance.getEntriesByName(url)[0];
     139    const entry = window.performance.getEntriesByName(url, 'resource')[0];
    140140    assert_equals(entry.workerStart, 0, 'Non-controlled');
    141141}, 'Non-controlled resource loads');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/appcache-ordering.manifest

    r202471 r246363  
    22
    33appcache-ordering.is-appcached.html
     4blank.html
    45
    56FALLBACK:
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/claim-worker.js

    r220223 r246363  
    1515
    1616self.addEventListener('fetch', function(event) {
    17     event.respondWith(new Response('Intercepted!'));
    18 });
     17    if (!/404/.test(event.request.url))
     18      event.respondWith(new Response('Intercepted!'));
     19  });
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/extendable-event-async-waituntil.js

    r222307 r246363  
    1 // controlled by 'init'/'done' messages.
     1// This worker calls waitUntil() and respondWith() asynchronously and
     2// reports back to the test whether they threw.
     3//
     4// These test cases are confusing. Bear in mind that the event is active
     5// (calling waitUntil() is allowed) if:
     6// * The pending promise count is not 0, or
     7// * The event dispatch flag is set.
     8
     9// Controlled by 'init'/'done' messages.
    210var resolveLockPromise;
    311var port;
     
    1523        resolveLockPromise();
    1624        break;
     25
     26      // Throws because waitUntil() is called in a task after event dispatch
     27      // finishes.
    1728      case 'no-current-extension-different-task':
    1829        async_task_waituntil(event).then(reportResultExpecting('InvalidStateError'));
    1930        break;
     31
     32      // OK because waitUntil() is called in a microtask that runs after the
     33      // event handler runs, while the event dispatch flag is still set.
    2034      case 'no-current-extension-different-microtask':
    21         async_microtask_waituntil(event).then(reportResultExpecting('InvalidStateError'));
    22         break;
     35        async_microtask_waituntil(event).then(reportResultExpecting('OK'));
     36        break;
     37
     38      // OK because the second waitUntil() is called while the first waitUntil()
     39      // promise is still pending.
    2340      case 'current-extension-different-task':
    2441        event.waitUntil(new Promise((res) => { resolveTestPromise = res; }));
    2542        async_task_waituntil(event).then(reportResultExpecting('OK')).then(resolveTestPromise);
    2643        break;
    27       case 'current-extension-expired-same-microtask-turn':
     44
     45      // OK because all promises involved resolve "immediately", so the second
     46      // waitUntil() is called during the microtask checkpoint at the end of
     47      // event dispatching, when the event dispatch flag is still set.
     48      case 'during-event-dispatch-current-extension-expired-same-microtask-turn':
    2849        waitPromise = Promise.resolve();
    2950        event.waitUntil(waitPromise);
     
    3152          .then(reportResultExpecting('OK'))
    3253        break;
    33       case 'current-extension-expired-same-microtask-turn-extra':
    34         // The promise handler queues a new microtask *after* the check for new
    35         // extensions was performed.
     54
     55      // OK for the same reason as above.
     56      case 'during-event-dispatch-current-extension-expired-same-microtask-turn-extra':
    3657        waitPromise = Promise.resolve();
     58        event.waitUntil(waitPromise);
     59        waitPromise.then(() => { return async_microtask_waituntil(event); })
     60          .then(reportResultExpecting('OK'))
     61        break;
     62
     63
     64      // OK because the pending promise count is decremented in a microtask
     65      // queued upon fulfillment of the first waitUntil() promise, so the second
     66      // waitUntil() is called while the pending promise count is still
     67      // positive.
     68      case 'after-event-dispatch-current-extension-expired-same-microtask-turn':
     69        waitPromise = makeNewTaskPromise();
     70        event.waitUntil(waitPromise);
     71        waitPromise.then(() => { return sync_waituntil(event); })
     72          .then(reportResultExpecting('OK'))
     73        break;
     74
     75      // Throws because the second waitUntil() is called after the pending
     76      // promise count was decremented to 0.
     77      case 'after-event-dispatch-current-extension-expired-same-microtask-turn-extra':
     78        waitPromise = makeNewTaskPromise();
    3779        event.waitUntil(waitPromise);
    3880        waitPromise.then(() => { return async_microtask_waituntil(event); })
    3981          .then(reportResultExpecting('InvalidStateError'))
    4082        break;
     83
     84      // Throws because the second waitUntil() is called in a new task, after
     85      // first waitUntil() promise settled and the event dispatch flag is unset.
    4186      case 'current-extension-expired-different-task':
    4287        event.waitUntil(Promise.resolve());
    4388        async_task_waituntil(event).then(reportResultExpecting('InvalidStateError'));
    4489        break;
     90
    4591      case 'script-extendable-event':
    4692        self.dispatchEvent(new ExtendableEvent('nontrustedevent'));
     
    5298
    5399self.addEventListener('fetch', function(event) {
    54     if (event.request.url.indexOf('pending-respondwith-async-waituntil') != -1) {
     100  const path = new URL(event.request.url).pathname;
     101  const step = path.substring(path.lastIndexOf('/') + 1);
     102  let response;
     103  switch (step) {
     104    // OK because waitUntil() is called while the respondWith() promise is still
     105    // unsettled, so the pending promise count is positive.
     106    case 'pending-respondwith-async-waituntil':
    55107      var resolveFetch;
    56       let response = new Promise((res) => { resolveFetch = res; });
     108      response = new Promise((res) => { resolveFetch = res; });
    57109      event.respondWith(response);
    58110      async_task_waituntil(event)
    59111        .then(reportResultExpecting('OK'))
    60112        .then(() => { resolveFetch(new Response('OK')); });
    61     } else if (event.request.url.indexOf('respondwith-microtask-sync-waituntil') != -1) {
     113      break;
     114
     115    // OK because all promises involved resolve "immediately", so waitUntil() is
     116    // called during the microtask checkpoint at the end of event dispatching,
     117    // when the event dispatch flag is still set.
     118    case 'during-event-dispatch-respondwith-microtask-sync-waituntil':
    62119      response = Promise.resolve(new Response('RESP'));
    63120      event.respondWith(response);
    64121      response.then(() => { return sync_waituntil(event); })
    65         .then(reportResultExpecting('OK'))
    66     } else if (event.request.url.indexOf('respondwith-microtask-async-waituntil') != -1) {
     122        .then(reportResultExpecting('OK'));
     123      break;
     124
     125    // OK because all promises involved resolve "immediately", so waitUntil() is
     126    // called during the microtask checkpoint at the end of event dispatching,
     127    // when the event dispatch flag is still set.
     128    case 'during-event-dispatch-respondwith-microtask-async-waituntil':
    67129      response = Promise.resolve(new Response('RESP'));
     130      event.respondWith(response);
     131      response.then(() => { return async_microtask_waituntil(event); })
     132        .then(reportResultExpecting('OK'));
     133      break;
     134
     135    // OK because the pending promise count is decremented in a microtask queued
     136    // upon fulfillment of the respondWith() promise, so waitUntil() is called
     137    // while the pending promise count is still positive.
     138    case 'after-event-dispatch-respondwith-microtask-sync-waituntil':
     139      response = makeNewTaskPromise().then(() => {return new Response('RESP');});
     140      event.respondWith(response);
     141      response.then(() => { return sync_waituntil(event); })
     142        .then(reportResultExpecting('OK'));
     143      break;
     144
     145
     146    // Throws because waitUntil() is called after the pending promise count was
     147    // decremented to 0.
     148    case 'after-event-dispatch-respondwith-microtask-async-waituntil':
     149      response = makeNewTaskPromise().then(() => {return new Response('RESP');});
    68150      event.respondWith(response);
    69151      response.then(() => { return async_microtask_waituntil(event); })
    70152        .then(reportResultExpecting('InvalidStateError'))
    71     }
    72   });
     153      break;
     154  }
     155});
    73156
    74157self.addEventListener('nontrustedevent', function(event) {
     
    119202  });
    120203}
     204
     205// Returns a promise that settles in a separate task.
     206function makeNewTaskPromise() {
     207  return new Promise(resolve => {
     208    setTimeout(resolve, 0);
     209  });
     210}
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-event-async-respond-with-worker.js

    r220223 r246363  
    1 var result;
     1// This worker attempts to call respondWith() asynchronously after the
     2// fetch event handler finished. It reports back to the test whether
     3// an exception was thrown.
    24
    3 self.addEventListener('message', function(event) {
    4     event.data.port.postMessage(result);
     5// These get reset at the start of a test case.
     6let reportResult;
     7
     8// The test page sends a message to tell us that a new test case is starting.
     9// We expect a fetch event after this.
     10self.addEventListener('message', (event) => {
     11  // Ensure tests run mutually exclusive.
     12  if (reportResult) {
     13    event.source.postMessage('testAlreadyRunning');
     14    return;
     15  }
     16
     17  const resultPromise = new Promise((resolve) => {
     18    reportResult = resolve;
     19    // Tell the client that everything is initialized and that it's safe to
     20    // proceed with the test without relying on the order of events (which some
     21    // browsers like Chrome may not guarantee).
     22    event.source.postMessage('messageHandlerInitialized');
    523  });
    624
     25  // Keep the worker alive until the test case finishes, and report
     26  // back the result to the test page.
     27  event.waitUntil(resultPromise.then(result => {
     28    reportResult = null;
     29    event.source.postMessage(result);
     30  }));
     31});
     32
     33// Calls respondWith() and reports back whether an exception occurred.
     34function tryRespondWith(event) {
     35  try {
     36    event.respondWith(new Response());
     37    reportResult({didThrow: false});
     38  } catch (error) {
     39    reportResult({didThrow: true, error: error.name});
     40  }
     41}
     42
     43function respondWithInTask(event) {
     44  setTimeout(() => {
     45    tryRespondWith(event);
     46  }, 0);
     47}
     48
     49function respondWithInMicrotask(event) {
     50  Promise.resolve().then(() => {
     51    tryRespondWith(event);
     52  });
     53}
     54
    755self.addEventListener('fetch', function(event) {
    8     setTimeout(function() {
    9         try {
    10           event.respondWith(new Response());
    11           result = 'FAIL: did not throw';
    12         } catch (error) {
    13           if (error.name == 'InvalidStateError')
    14             result = 'PASS';
    15           else
    16             result = 'FAIL: Unexpected exception: ' + error;
    17         }
    18       }, 0);
    19   });
     56  const path = new URL(event.request.url).pathname;
     57  const test = path.substring(path.lastIndexOf('/') + 1);
     58
     59  // If this is a test case, try respondWith() and report back to the test page
     60  // the result.
     61  if (test == 'respondWith-in-task') {
     62    respondWithInTask(event);
     63  } else if (test == 'respondWith-in-microtask') {
     64    respondWithInMicrotask(event);
     65  }
     66});
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-event-network-fallback-worker.js

    r238592 r246363  
    11self.addEventListener('fetch', () => {
    2     // Do nothing.
    3   });
     2  // Do nothing.
     3});
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-request-css-base-url-iframe.html

    r220223 r246363  
    1 <link href="./fetch-request-css-base-url-style.css" rel="stylesheet" type="text/css">
     1<html>
     2<head>
     3<title>iframe for css base url test</title>
     4</head>
     5<body>
     6<script>
     7// Load a stylesheet. Create it dynamically so we can construct the href URL
     8// dynamically.
     9const link = document.createElement('link');
     10link.rel = 'stylesheet';
     11link.type = 'text/css';
     12// Add "request-url-path" to the path to help distinguish the request URL from
     13// the response URL. Add |document.location.search| (chosen by the test main
     14// page) to tell the service worker how to respond to the request.
     15link.href = 'request-url-path/fetch-request-css-base-url-style.css' +
     16    document.location.search;
     17document.head.appendChild(link);
     18</script>
     19</body>
     20</html>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-request-css-base-url-worker.js

    r220223 r246363  
    1 importScripts('/common/get-host-info.sub.js');
    2 importScripts('test-helpers.sub.js');
     1let source;
     2let resolveDone;
     3let done = new Promise(resolve => resolveDone = resolve);
    34
    4 var port = undefined;
     5// The page messages this worker to ask for the result. Keep the worker alive
     6// via waitUntil() until the result is sent.
     7self.addEventListener('message', event => {
     8  source = event.data.port;
     9  source.postMessage('pong');
     10  event.waitUntil(done);
     11});
    512
    6 self.onmessage = function(e) {
    7   var message = e.data;
    8   if ('port' in message) {
    9     port = message.port;
    10     port.postMessage({ready: true});
     13self.addEventListener('fetch', event => {
     14  const url = new URL(event.request.url);
     15
     16  // For the CSS file, respond in a way that may change the response URL,
     17  // depending on |url.search|.
     18  const cssPath = 'request-url-path/fetch-request-css-base-url-style.css';
     19  if (url.pathname.indexOf(cssPath) != -1) {
     20    // Respond with a different URL, deleting "request-url-path/".
     21    if (url.search == '?fetch') {
     22      event.respondWith(fetch('fetch-request-css-base-url-style.css'));
     23    }
     24    // Respond with new Response().
     25    else if (url.search == '?newResponse') {
     26      const styleString = 'body { background-image: url("./dummy.png");}';
     27      const headers = {'content-type': 'text/css'};
     28      event.respondWith(new Response(styleString, headers));
     29    }
    1130  }
    12 };
    1331
    14 self.addEventListener('fetch', function(event) {
    15     var url = event.request.url;
    16     if (url.indexOf('fetch-request-css-base-url-style.css') != -1) {
    17       event.respondWith(fetch(
    18         get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() +
    19         'fetch-request-css-base-url-style.css',
    20         {mode: 'no-cors'}));
    21     } else if (url.indexOf('dummy.png') != -1) {
    22       port.postMessage({
    23           url: event.request.url,
    24           referrer: event.request.referrer
    25         });
    26     }
    27   });
     32  // The image request indicates what the base URL of the CSS was. Message the
     33  // result back to the test page.
     34  else if (url.pathname.indexOf('dummy.png') != -1) {
     35    // For some reason |source| is undefined here when running the test manually
     36    // in Firefox. The test author experimented with both using Client
     37    // (event.source) and MessagePort to try to get the test to pass, but
     38    // failed.
     39    source.postMessage({
     40      url: event.request.url,
     41      referrer: event.request.referrer
     42    });
     43    resolveDone();
     44  }
     45});
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/service-worker-csp-worker.py

    r220223 r246363  
    1717                'Importing the other origins script should fail.');
    1818  }, 'importScripts test for default-src');
     19
     20test(function() {
     21    assert_throws(EvalError(),
     22                  function() { eval('1 + 1'); },
     23                  'eval() should throw EvalError.')
     24    assert_throws(EvalError(),
     25                  function() { new Function('1 + 1'); },
     26                  'new Function() should throw EvalError.')
     27  }, 'eval test for default-src');
    1928
    2029async_test(function(t) {
     
    6473  }, 'importScripts test for script-src');
    6574
     75test(function() {
     76    assert_throws(EvalError(),
     77                  function() { eval('1 + 1'); },
     78                  'eval() should throw EvalError.')
     79    assert_throws(EvalError(),
     80                  function() { new Function('1 + 1'); },
     81                  'new Function() should throw EvalError.')
     82  }, 'eval test for script-src');
     83
    6684async_test(function(t) {
    6785    fetch(host_info.HTTPS_REMOTE_ORIGIN +
     
    110128  }, 'importScripts test for connect-src');
    111129
     130test(function() {
     131    var eval_failed = false;
     132    try {
     133      eval('1 + 1');
     134      new Function('1 + 1');
     135    } catch(e) {
     136      eval_failed = true;
     137    }
     138    assert_false(eval_failed,
     139                 'connect-src without unsafe-eval should not block eval().');
     140  }, 'eval test for connect-src');
     141
    112142async_test(function(t) {
    113143    fetch(host_info.HTTPS_REMOTE_ORIGIN +
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/test-helpers.sub.js

    r238592 r246363  
    7676
    7777  return new Promise(test.step_func(function(resolve) {
    78       registration.addEventListener('updatefound', test.step_func(function() {
    79           resolve(registration.installing);
    80         }));
     78      var handler = test.step_func(function() {
     79        registration.removeEventListener('updatefound', handler);
     80        resolve(registration.installing);
     81      });
     82      registration.addEventListener('updatefound', handler);
    8183    }));
    8284}
     
    277279  await registration.unregister();
    278280}
     281
     282// This installs resources/appcache-ordering.manifest.
     283function install_appcache_ordering_manifest() {
     284  let resolve_install_appcache;
     285  let reject_install_appcache;
     286
     287  // This is notified by the child iframe, i.e. appcache-ordering.install.html,
     288  // that's to be created below.
     289  window.notify_appcache_installed = success => {
     290    if (success)
     291      resolve_install_appcache();
     292    else
     293      reject_install_appcache();
     294  };
     295
     296  return new Promise((resolve, reject) => {
     297      const frame = document.createElement('iframe');
     298      frame.src = 'resources/appcache-ordering.install.html';
     299      document.body.appendChild(frame);
     300      resolve_install_appcache = function() {
     301          document.body.removeChild(frame);
     302          resolve();
     303        };
     304      reject_install_appcache = function() {
     305          document.body.removeChild(frame);
     306          reject();
     307        };
     308  });
     309}
     310
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-during-installation-worker.js

    r238592 r246363  
    11'use strict';
    22
    3 const installMayFinish = new Promise(resolve => {
    4     self.finishInstall = resolve;
     3const installEventFired = new Promise(resolve => {
     4  self.fireInstallEvent = resolve;
    55});
    66
    7 let report = { installEventFired: false };
     7const installFinished = new Promise(resolve => {
     8  self.finishInstall = resolve;
     9});
    810
    911addEventListener('install', event => {
    10     report.installEventFired = true;
    11     let attemptUpdate = registration.update().catch(exception => {
    12         report.exception = exception.name;
    13     });
    14     event.waitUntil(Promise.all([installMayFinish, attemptUpdate]));
     12  fireInstallEvent();
     13  event.waitUntil(installFinished);
    1514});
    1615
    1716addEventListener('message', event => {
    18     if (event.data === 'finishInstall') {
     17  // Use a dedicated MessageChannel for every request so senders can wait for
     18  // individual requests to finish, and concurrent requests (to different
     19  // workers) don't cause race conditions.
     20  const port = event.data;
     21  port.onmessage = (event) => {
     22    switch (event.data) {
     23      case 'awaitInstallEvent':
     24        installEventFired.then(() => {
     25            port.postMessage('installEventFired');
     26        });
     27        break;
     28
     29      case 'finishInstall':
     30        installFinished.then(() => {
     31            port.postMessage('installFinished');
     32        });
    1933        finishInstall();
    20     } else {
    21         event.source.postMessage(report);
     34        break;
     35
     36      case 'callUpdate': {
     37        const channel = new MessageChannel();
     38        registration.update().then(() => {
     39            channel.port2.postMessage({
     40                success: true,
     41            });
     42        }).catch((exception) => {
     43            channel.port2.postMessage({
     44                success: false,
     45                exception: exception.name,
     46            });
     47        });
     48        port.postMessage(channel.port1, [channel.port1]);
     49        break;
     50      }
     51
     52      default:
     53        port.postMessage('Unexpected command ' + event.data);
     54        break;
    2255    }
     56  };
    2357});
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/w3c-import.log

    r238592 r246363  
    147147/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-waits-for-activate-worker.js
    148148/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/frame-for-getregistrations.html
     149/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/get-resultingClientId-worker.js
    149150/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/http-to-https-redirect-and-register-iframe.html
    150151/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/iframe-with-image.html
    151152/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/immutable-prototype-serviceworker.js
    152153/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-mime-type-worker.py
     154/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-relative.xsl
     155/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-scripts-diff-resource-map-worker.js
    153156/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-scripts-echo.py
     157/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-scripts-get.py
    154158/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-scripts-mime-types-worker.js
    155159/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/import-scripts-redirect-import.js
     
    222226/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/postmessage-blob-url.js
    223227/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/postmessage-dictionary-transferables-worker.js
     228/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/postmessage-echo-worker.js
    224229/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/postmessage-msgport-to-client-worker.js
    225230/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/postmessage-to-client-worker.js
     
    275280/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/success.py
    276281/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/test-helpers.sub.js
     282/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/test-request-headers-worker.js
     283/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/test-request-headers-worker.py
    277284/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/testharness-helpers.js
     285/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/trickle.py
    278286/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/unregister-controller-page.html
    279287/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-claim-worker.py
    280288/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-during-installation-worker.js
     289/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-during-installation-worker.py
     290/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-fetch-worker.py
    281291/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py
    282292/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/update-max-aged-worker.py
     
    301311/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/worker-testharness.js
    302312/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/worker_interception_redirect_webworker.py
     313/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/xhr-iframe.html
     314/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/xhr-response-url-worker.js
     315/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/xsl-base-url-iframe.xml
     316/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/xsl-base-url-worker.js
     317/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/xslt-pass.xsl
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/worker-interception-iframe.https.html

    r238592 r246363  
    11<script src="/common/get-host-info.sub.js"></script>
     2<script src="/resources/testharness.js"></script>
    23<script src="test-helpers.sub.js?pipe=sub"></script>
    34<script>
     
    1213        })
    1314      .then(function(data) {
    14           window.parent.postMessage({results: data}, host_info['HTTPS_ORIGIN']);
     15          assert_equals(data, "This load was successfully intercepted.");
    1516        });
    1617}
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/worker-load-interceptor.js

    r220223 r246363  
    99        event.respondWith(new Response(response_text));
    1010    } else if (url.indexOf("synthesized-response.js") != -1) {
    11         event.respondWith(new Response(response_script));
     11      event.respondWith(new Response(
     12          response_script,
     13          {headers: {'Content-Type': 'application/javascript'}}));
    1214    }
    1315};
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/service-worker-csp-connect.https-expected.txt

    r226628 r246363  
    22PASS CSP test for connect-src in ServiceWorkerGlobalScope
    33PASS importScripts test for connect-src
     4PASS eval test for connect-src
    45PASS Fetch test for connect-src
    56PASS Redirected fetch test for connect-src
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/service-worker-csp-default.https-expected.txt

    r226628 r246363  
    22PASS CSP test for default-src in ServiceWorkerGlobalScope
    33PASS importScripts test for default-src
     4PASS eval test for default-src
    45PASS Fetch test for default-src
    56PASS Redirected fetch test for default-src
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/service-worker-csp-script.https-expected.txt

    r226628 r246363  
    22PASS CSP test for script-src in ServiceWorkerGlobalScope
    33PASS importScripts test for script-src
     4PASS eval test for script-src
    45PASS Fetch test for script-src
    56PASS Redirected fetch test for script-src
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/serviceworker-message-event-historical.https.html

    r220223 r246363  
    1111    return service_worker_unregister_and_register(t, url, scope)
    1212      .then(function(r) {
     13          t.add_cleanup(function() {
     14              return service_worker_unregister(t, scope);
     15            });
     16
    1317          return wait_for_state(t, r.installing, 'activated');
    1418        })
     
    3640              worker.postMessage('PING');
    3741            });
    38         })
    39       .then(function() {
    40           return service_worker_unregister_and_done(t, scope);
    4142        });
    4243  }, 'Test MessageEvent supplants ServiceWorkerMessageEvent.');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/shared-worker-controlled.https.html

    r220223 r246363  
    1313    return service_worker_unregister_and_register(t, service_worker, scope)
    1414      .then(function(r) {
     15          t.add_cleanup(function() {
     16              return service_worker_unregister(t, scope);
     17            });
     18
    1519          return wait_for_state(t, r.installing, 'activated');
    1620        })
     
    2529      .then(function(data) {
    2630          assert_equals(data, 'intercepted by service worker');
    27           service_worker_unregister_and_done(t, scope);
    2831        });
    2932  }, 'Verify subresource loads in SharedWorker are controlled by a Service Worker');
     
    3639    return service_worker_unregister_and_register(t, service_worker, scope)
    3740      .then(function(r) {
     41          t.add_cleanup(function() {
     42              return service_worker_unregister(t, scope);
     43            });
     44
    3845          return wait_for_state(t, r.installing, 'activated');
    3946        })
     
    4855      .then(function(data) {
    4956          assert_equals(data, 'worker loading intercepted by service worker');
    50           service_worker_unregister_and_done(t, scope);
    5157        });
    5258  }, 'Verify SharedWorker construction is controlled by a Service Worker');
     
    5965    return service_worker_unregister_and_register(t, service_worker, scope)
    6066      .then(function(r) {
     67          t.add_cleanup(function() {
     68              return service_worker_unregister(t, scope);
     69            });
     70
    6171          return wait_for_state(t, r.installing, 'activated');
    6272        })
     
    7181      .then(function(data) {
    7282          assert_equals(data, 'worker loading intercepted by service worker');
    73           service_worker_unregister_and_done(t, scope);
    7483        });
    7584  }, 'Verify importScripts from SharedWorker is controlled by a Service Worker');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-installed.https.html

    r220223 r246363  
    3434    return service_worker_unregister_and_register(t, url1, scope)
    3535      .then(function(r) {
     36          t.add_cleanup(function() {
     37              return service_worker_unregister(t, scope);
     38            });
     39
    3640          return wait_for_state(t, r.installing, 'activated');
    3741        })
     
    6165      .then(function() {
    6266          frame.remove();
    63           return service_worker_unregister_and_done(t, scope);
    6467        });
    6568  }, 'Test skipWaiting when a installed worker is waiting');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-using-registration.https.html

    r238592 r246363  
    11<!DOCTYPE html>
    22<title>Service Worker: Skip waiting using registration</title>
     3<meta name="timeout" content="long">
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
     
    5960          assert_not_equals(sw_registration.active, null,
    6061                            'Registration active worker should not be null');
    61           fetch_tests_from_worker(sw_registration.active);
     62          return fetch_tests_from_worker(sw_registration.active);
    6263        });
    6364  }, 'Test skipWaiting while a client is using the registration');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https.html

    r238592 r246363  
    11<!DOCTYPE html>
    22<title>Service Worker: Skip waiting without using registration</title>
     3<meta name="timeout" content="long">
    34<script src="/resources/testharness.js"></script>
    45<script src="/resources/testharnessreport.js"></script>
     
    3738          assert_not_equals(sw_registration.active, null,
    3839                            'Registration active worker should not be null');
    39           fetch_tests_from_worker(sw_registration.active);
     40          return fetch_tests_from_worker(sw_registration.active);
    4041        });
    4142  }, 'Test skipWaiting while a client is not being controlled');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting.https.html

    r220223 r246363  
    1515    return service_worker_unregister_and_register(t, url1, scope)
    1616      .then(function(registration) {
     17          t.add_cleanup(function() {
     18              return service_worker_unregister(t, scope);
     19            });
     20
    1721          sw_registration = registration;
    1822          return wait_for_state(t, registration.installing, 'activated');
     
    4953          assert_equals(sw_registration.active.scriptURL, normalizeURL(url3),
    5054                        'Worker with url3 should be activated');
    51           return service_worker_unregister_and_done(t, scope);
    5255        });
    5356  }, 'Test skipWaiting with both active and waiting workers');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https-expected.txt

    r238592 r246363  
    11
    22PASS Registering a new script URL while an unregistered registration is in use
    3 PASS Registering a new script URL that 404s does resurrect an unregistered registration
    4 PASS Registering a new script URL that fails to install does resurrect an unregistered registration
     3FAIL Registering a new script URL that 404s does not resurrect unregistered registration assert_equals: Document should not be controlled expected null but got object "[object ServiceWorker]"
     4FAIL Registering a new script URL that fails to install does not resurrect unregistered registration assert_equals: registration.active expected null but got object "[object ServiceWorker]"
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register-new-script.https.html

    r238592 r246363  
    66var worker_url = 'resources/empty-worker.js';
    77
    8 async_test(function(t) {
    9     var scope = 'resources/scope/unregister-then-register-new-script-that-exists';
    10     var new_worker_url = worker_url + '?new';
    11     var iframe;
    12     var registration;
    13     var new_registration;
     8promise_test(async function(t) {
     9  const scope = 'resources/scope/unregister-then-register-new-script-that-exists';
     10  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     11  t.add_cleanup(() => registration.unregister());
    1412
    15     service_worker_unregister_and_register(t, worker_url, scope)
    16       .then(function(r) {
    17           registration = r;
    18           return wait_for_state(t, r.installing, 'activated');
    19         })
    20       .then(function() {
    21           return with_iframe(scope);
    22         })
    23       .then(function(frame) {
    24           iframe = frame;
    25           return registration.unregister();
    26         })
    27       .then(function() {
    28           return navigator.serviceWorker.register(new_worker_url,
    29                                                   { scope: scope });
    30         })
    31       .then(function(r) {
    32           new_registration = r;
    33           assert_equals(registration.installing.scriptURL,
    34                         normalizeURL(new_worker_url),
    35                         'before activated registration.installing');
    36           assert_equals(registration.waiting, null,
    37                         'before activated registration.waiting');
    38           assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
    39                         'before activated registration.active');
    40           assert_equals(new_registration.installing.scriptURL,
    41                         normalizeURL(new_worker_url),
    42                         'before activated new_registration.installing');
    43           assert_equals(new_registration.waiting, null,
    44                         'before activated new_registration.waiting');
    45           assert_equals(new_registration.active.scriptURL,
    46                         normalizeURL(worker_url),
    47                         'before activated new_registration.active');
    48           iframe.remove();
    49           return wait_for_state(t, registration.installing, 'activated');
    50         })
    51       .then(function() {
    52           assert_equals(new_registration.installing, null,
    53                         'after activated new_registration.installing');
    54           assert_equals(new_registration.waiting, null,
    55                         'after activated new_registration.waiting');
    56           assert_equals(new_registration.active.scriptURL,
    57                         normalizeURL(new_worker_url),
    58                         'after activated new_registration.active');
    59           return with_iframe(scope);
    60         })
    61       .then(function(frame) {
    62           assert_equals(
    63               frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
    64               normalizeURL(new_worker_url),
    65               'the new worker should control a new document');
    66           frame.remove();
    67           return registration.unregister();
    68         })
    69       .then(function() {
    70           t.done();
    71         })
    72       .catch(unreached_rejection(t));
     13  const newWorkerURL = worker_url + '?new';
     14  await wait_for_state(t, registration.installing, 'activated');
     15
     16  const iframe = await with_iframe(scope);
     17  t.add_cleanup(() => iframe.remove());
     18
     19  await registration.unregister();
     20
     21  const newRegistration = await navigator.serviceWorker.register(newWorkerURL, { scope });
     22  t.add_cleanup(() => newRegistration.unregister());
     23
     24  assert_equals(
     25    registration.installing.scriptURL,
     26    normalizeURL(newWorkerURL),
     27    'before activated registration.installing'
     28  );
     29  assert_equals(
     30    registration.waiting,
     31    null,
     32    'before activated registration.waiting'
     33  );
     34  assert_equals(
     35    registration.active.scriptURL,
     36    normalizeURL(worker_url),
     37    'before activated registration.active'
     38  );
     39  assert_equals(
     40    newRegistration.installing.scriptURL,
     41    normalizeURL(newWorkerURL),
     42    'before activated newRegistration.installing'
     43  );
     44  assert_equals(
     45    newRegistration.waiting,
     46    null,
     47    'before activated newRegistration.waiting'
     48  );
     49  assert_equals(
     50    newRegistration.active.scriptURL,
     51    normalizeURL(worker_url),
     52    'before activated newRegistration.active'
     53  );
     54  iframe.remove();
     55
     56  await wait_for_state(t, registration.installing, 'activated');
     57
     58  assert_equals(
     59    newRegistration.installing,
     60    null,
     61    'after activated newRegistration.installing'
     62  );
     63  assert_equals(
     64    newRegistration.waiting,
     65    null,
     66    'after activated newRegistration.waiting'
     67  );
     68  assert_equals(
     69    newRegistration.active.scriptURL,
     70    normalizeURL(newWorkerURL),
     71    'after activated newRegistration.active'
     72  );
     73
     74  const newIframe = await with_iframe(scope);
     75  t.add_cleanup(() => newIframe.remove());
     76
     77  assert_equals(
     78    newIframe.contentWindow.navigator.serviceWorker.controller.scriptURL,
     79    normalizeURL(newWorkerURL),
     80    'the new worker should control a new document'
     81  );
    7382}, 'Registering a new script URL while an unregistered registration is in use');
    7483
    75 async_test(function(t) {
    76     var scope = 'resources/scope/unregister-then-register-new-script-that-404s';
    77     var iframe;
    78     var registration;
     84promise_test(async function(t) {
     85  const scope = 'resources/scope/unregister-then-register-new-script-that-404s';
     86  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     87  t.add_cleanup(() => registration.unregister());
    7988
    80     service_worker_unregister_and_register(t, worker_url, scope)
    81       .then(function(r) {
    82           registration = r;
    83           return wait_for_state(t, r.installing, 'activated');
    84         })
    85       .then(function() {
    86           return with_iframe(scope);
    87         })
    88       .then(function(frame) {
    89           iframe = frame;
    90           return registration.unregister();
    91         })
    92       .then(function() {
    93           // Step 5.1 of Register clears the uninstall flag before fetching
    94           // the script:
    95           //
    96           //  https://w3c.github.io/ServiceWorker/#register-algorithm
    97           var promise = navigator.serviceWorker.register('this-will-404',
    98                                                          { scope: scope });
    99           return promise;
    100         })
    101       .then(
    102         function() {
    103           assert_unreached('register should reject the promise');
    104         },
    105         function() {
    106           assert_equals(registration.installing, null,
    107                         'registration.installing');
    108           assert_equals(registration.waiting, null,
    109                         'registration.waiting');
    110           assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
    111                         'registration.active');
    112           iframe.remove();
    113           return with_iframe(scope);
    114         })
    115       .then(function(frame) {
    116           assert_equals(
    117               frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
    118               normalizeURL(worker_url),
    119               'the original worker should control a new document');
    120           frame.remove();
    121           return registration.unregister();
    122         })
    123       .then(function() {
    124           t.done();
    125         })
    126       .catch(unreached_rejection(t));
    127 }, 'Registering a new script URL that 404s does resurrect an ' +
    128        'unregistered registration');
     89  await wait_for_state(t, registration.installing, 'activated');
    12990
    130 async_test(function(t) {
    131     var scope = 'resources/scope/unregister-then-register-reject-install-worker';
    132     var iframe;
    133     var registration;
     91  const iframe = await with_iframe(scope);
     92  t.add_cleanup(() => iframe.remove());
    13493
    135     service_worker_unregister_and_register(t, worker_url, scope)
    136       .then(function(r) {
    137           registration = r;
    138           return wait_for_state(t, r.installing, 'activated');
    139         })
    140       .then(function() {
    141           return with_iframe(scope);
    142         })
    143       .then(function(frame) {
    144           iframe = frame;
    145           return registration.unregister();
    146         })
    147       .then(function() {
    148           // Step 5.1 of Register clears the uninstall flag before firing
    149           // the install event:
    150           //
    151           //  https://w3c.github.io/ServiceWorker/#register-algorithm
    152           var promise = navigator.serviceWorker.register(
    153               'resources/reject-install-worker.js', { scope: scope });
    154           return promise;
    155         })
    156       .then(function(r) {
    157           registration = r;
    158           return wait_for_state(t, r.installing, 'redundant');
    159         })
    160       .then(function() {
    161           assert_equals(registration.installing, null,
    162                         'registration.installing');
    163           assert_equals(registration.waiting, null,
    164                         'registration.waiting');
    165           assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
    166                         'registration.active');
    167           iframe.remove();
    168           return with_iframe(scope);
    169         })
    170       .then(function(frame) {
    171           assert_equals(
    172               frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
    173               normalizeURL(worker_url),
    174               'the original worker should control a new document');
    175           frame.remove();
    176           return registration.unregister();
    177         })
    178       .then(function() {
    179           t.done();
    180         })
    181       .catch(unreached_rejection(t));
    182   }, 'Registering a new script URL that fails to install does resurrect ' +
    183        'an unregistered registration');
     94  await registration.unregister();
     95
     96  await promise_rejects(
     97    t, new TypeError(),
     98    navigator.serviceWorker.register('this-will-404', { scope })
     99  );
     100
     101  assert_equals(registration.installing, null, 'registration.installing');
     102  assert_equals(registration.waiting, null, 'registration.waiting');
     103  assert_equals(registration.active.scriptURL, normalizeURL(worker_url), 'registration.active');
     104
     105  const newIframe = await with_iframe(scope);
     106  t.add_cleanup(() => newIframe.remove());
     107
     108  assert_equals(newIframe.contentWindow.navigator.serviceWorker.controller, null, 'Document should not be controlled');
     109}, 'Registering a new script URL that 404s does not resurrect unregistered registration');
     110
     111promise_test(async function(t) {
     112  const scope = 'resources/scope/unregister-then-register-reject-install-worker';
     113  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     114  t.add_cleanup(() => registration.unregister());
     115
     116  await wait_for_state(t, registration.installing, 'activated');
     117
     118  const iframe = await with_iframe(scope);
     119  t.add_cleanup(() => iframe.remove());
     120
     121  await registration.unregister();
     122
     123  const newRegistration = await navigator.serviceWorker.register(
     124    'resources/reject-install-worker.js', { scope }
     125  );
     126  t.add_cleanup(() => newRegistration.unregister());
     127
     128  await wait_for_state(t, newRegistration.installing, 'redundant');
     129
     130  assert_equals(registration.installing, null, 'registration.installing');
     131  assert_equals(registration.waiting, null, 'registration.waiting');
     132  assert_equals(registration.active, null, 'registration.active');
     133  assert_not_equals(registration, newRegistration, 'New registration is different');
     134}, 'Registering a new script URL that fails to install does not resurrect unregistered registration');
    184135</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt

    r224947 r246363  
    1 
    21
    32PASS Unregister then register resolves to a new value
    4 PASS Unregister then register resolves to the original value if the registration is in use.
    5 PASS Reloading the last controlled iframe after unregistration should ensure the deletion of the registration
     3FAIL Unregister then register does not resolve to the original value even if the registration is in use. assert_not_equals: Unregister and register should always create a new registration got disallowed value object "[object ServiceWorkerRegistration]"
    64PASS Unregister then register does not affect existing controllee
    7 PASS Unregister then register resurrects the registration
     5FAIL Unregister then register does not resurrect the registration assert_equals: Registration is new expected null but got object "[object ServiceWorker]"
    86
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https.html

    r238592 r246363  
    66var worker_url = 'resources/empty-worker.js';
    77
    8 promise_test(function(t) {
    9     var scope = 'resources/scope/re-register-resolves-to-new-value';
    10     var registration;
     8promise_test(async function(t) {
     9    const scope = 'resources/scope/re-register-resolves-to-new-value';
     10    const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     11    t.add_cleanup(() => registration.unregister());
    1112
    12     return service_worker_unregister_and_register(t, worker_url, scope)
    13       .then(function(r) {
    14           t.add_cleanup(function() {
    15               return service_worker_unregister(t, scope);
    16             });
     13    await wait_for_state(t, registration.installing, 'activated');
     14    await registration.unregister();
     15    const newRegistration = await navigator.serviceWorker.register(worker_url, { scope });
     16    t.add_cleanup(() => newRegistration.unregister());
    1717
    18           registration = r;
    19           return wait_for_state(t, r.installing, 'activated');
    20         })
    21       .then(function() {
    22           return registration.unregister();
    23         })
    24       .then(function() {
    25           return navigator.serviceWorker.register(worker_url, { scope: scope });
    26         })
    27       .then(function(new_registration) {
    28           assert_not_equals(registration, new_registration,
    29                             'register should resolve to a new value');
    30         });
     18    assert_not_equals(
     19      registration, newRegistration,
     20      'register should resolve to a new value'
     21    );
    3122  }, 'Unregister then register resolves to a new value');
    3223
    33 promise_test(function(t) {
    34     var scope = 'resources/scope/re-register-while-old-registration-in-use';
    35     var registration;
     24promise_test(async function(t) {
     25  const scope = 'resources/scope/re-register-while-old-registration-in-use';
     26  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     27  t.add_cleanup(() => registration.unregister());
    3628
    37     return service_worker_unregister_and_register(t, worker_url, scope)
    38       .then(function(r) {
    39           t.add_cleanup(function() {
    40               return service_worker_unregister(t, scope);
    41             });
     29  await wait_for_state(t, registration.installing, 'activated');
     30  const frame = await with_iframe(scope);
     31  t.add_cleanup(() => frame.remove());
    4232
    43           registration = r;
    44           return wait_for_state(t, r.installing, 'activated');
    45         })
    46       .then(function() {
    47           return with_iframe(scope);
    48         })
    49       .then(function(frame) {
    50           return registration.unregister();
    51         })
    52       .then(function() {
    53           return navigator.serviceWorker.register(worker_url, { scope: scope });
    54         })
    55       .then(function(new_registration) {
    56           assert_equals(registration, new_registration,
    57                         'new registration should resolve to the same registration');
    58         });
    59   }, 'Unregister then register resolves to the original value if the ' +
    60          'registration is in use.');
     33  await registration.unregister();
     34  const newRegistration = await navigator.serviceWorker.register(worker_url, { scope });
     35  t.add_cleanup(() => newRegistration.unregister());
    6136
    62 promise_test(function(t) {
    63     var scope = 'resources/scope/complete-unregistration-followed-by-' +
    64                 'reloading-controllee-iframe';
    65     var registration;
    66     var frame;
    67     var service_worker;
    68     return service_worker_unregister_and_register(t, worker_url, scope)
    69       .then(function(r) {
    70           t.add_cleanup(function() {
    71               return service_worker_unregister(t, scope);
    72             });
    73 
    74           registration = r;
    75           return wait_for_state(t, r.installing, 'activated');
    76         })
    77       .then(function() {
    78           return with_iframe(scope);
    79         })
    80       .then(function(f) {
    81           frame = f;
    82           return registration.unregister();
    83         })
    84       .then(function() {
    85           return new Promise(function(resolve) {
    86               frame.onload = resolve;
    87               frame.contentWindow.location.reload();
    88             });
    89         })
    90       .then(function() {
    91           var c = frame.contentWindow.navigator.serviceWorker.controller;
    92           assert_equals(c, null, 'a page after unregistration should not be ' +
    93                                  'controlled by service worker');
    94           return navigator.serviceWorker.getRegistration(scope);
    95         })
    96       .then(function(r) {
    97           assert_equals(r, undefined, 'getRegistration should return ' +
    98                                       'undefined after unregistration');
    99         });
    100 }, 'Reloading the last controlled iframe after unregistration should ensure ' +
    101    'the deletion of the registration');
     37  assert_not_equals(
     38    registration, newRegistration,
     39    'Unregister and register should always create a new registration'
     40  );
     41}, 'Unregister then register does not resolve to the original value even if the registration is in use.');
    10242
    10343promise_test(function(t) {
     
    11050      .then(function(r) {
    11151          t.add_cleanup(function() {
    112               return service_worker_unregister(t, scope);
    113             });
     52            return service_worker_unregister(t, scope);
     53          });
    11454
    11555          registration = r;
     
    13979  }, 'Unregister then register does not affect existing controllee');
    14080
    141 promise_test(function(t) {
    142     var scope = 'resources/scope/resurrection';
    143     var iframe;
    144     var registration;
     81promise_test(async function(t) {
     82  const scope = 'resources/scope/resurrection';
     83  const altWorkerURL = worker_url + '?alt';
     84  const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     85  t.add_cleanup(() => registration.unregister());
    14586
    146     return service_worker_unregister_and_register(t, worker_url, scope)
    147       .then(function(r) {
    148           t.add_cleanup(function() {
    149               return service_worker_unregister(t, scope);
    150             });
     87  await wait_for_state(t, registration.installing, 'activating');
     88  const iframe = await with_iframe(scope);
     89  t.add_cleanup(() => iframe.remove());
    15190
    152           registration = r;
    153           return wait_for_state(t, r.installing, 'activated');
    154         })
    155       .then(function() {
    156           return with_iframe(scope);
    157         })
    158       .then(function(frame) {
    159           iframe = frame;
    160           return registration.unregister();
    161         })
    162       .then(function() {
    163           return navigator.serviceWorker.register(worker_url, { scope: scope });
    164         })
    165       .then(function() {
    166           iframe.remove();
    167           return with_iframe(scope);
    168         })
    169       .then(function(frame) {
    170           assert_not_equals(
    171               frame.contentWindow.navigator.serviceWorker.controller, null,
    172               'document should have a controller');
    173           frame.remove();
    174         });
    175   }, 'Unregister then register resurrects the registration');
     91  await registration.unregister();
     92  const newRegistration = await navigator.serviceWorker.register(altWorkerURL, { scope });
     93  t.add_cleanup(() => newRegistration.unregister());
     94
     95  assert_equals(newRegistration.active, null, 'Registration is new');
     96
     97  await wait_for_state(t, newRegistration.installing, 'activating');
     98
     99  const newIframe = await with_iframe(scope);
     100  t.add_cleanup(() => newIframe.remove());
     101
     102  const iframeController = iframe.contentWindow.navigator.serviceWorker.controller;
     103  const newIframeController = newIframe.contentWindow.navigator.serviceWorker.controller;
     104
     105  assert_not_equals(iframeController, newIframeController, 'iframes have different controllers');
     106}, 'Unregister then register does not resurrect the registration');
    176107</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-redirect.https.html

    r238592 r246363  
    22<meta charset="utf-8">
    33<title>Service Worker: Update should be triggered after redirects during navigation</title>
     4<meta name="timeout" content="long">
    45<script src="/resources/testharness.js"></script>
    56<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-oneday.https.html

    r223273 r246363  
    1818    return service_worker_unregister_and_register(t, expected_url, scope)
    1919      .then(function(r) {
     20          t.add_cleanup(function() {
     21              return service_worker_unregister(t, scope);
     22            });
     23
    2024          registration = r;
    2125          return wait_for_state(t, registration.installing, 'activated');
     
    4246       .then(function() {
    4347          frame.remove();
    44           return service_worker_unregister_and_done(t, scope);
    4548       })
    4649  }, 'Update should be triggered after a functional event when last update time is over 24 hours');
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-bytecheck.https.html

    r228255 r246363  
    22<meta charset=utf-8>
    33<title></title>
     4<meta name="timeout" content="long">
    45<script src="/resources/testharness.js"></script>
    56<script src="resources/testharness-helpers.js"></script>
     
    4445      // Register a service worker.
    4546      .then(_ => service_worker_unregister_and_register(t, script, scope))
    46       .then(r => swr = r)
    47       .then(_ => wait_for_update(t, swr))
     47      .then(r => {
     48        t.add_cleanup(() => service_worker_unregister(t, scope));
     49        swr = r;
     50        return wait_for_update(t, swr);
     51      })
    4852      .then(w => sw = w)
    4953      .then(_ => wait_for_state(t, sw, 'activated'))
     
    6569                              swr.installing],
    6670                             [sw, null, null]);
    67       })
    68 
    69       // Unregister the service worker.
    70       .then(_ => service_worker_unregister_and_done(t, scope));
     71      });
    7172  }, `Test(cors: ${s.cors}, main: ${s.main}, imported: ${s.imported})`));
    7273}, Promise.resolve());
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-not-allowed.https.html

    r238592 r246363  
    66'use strict';
    77
     8function send_message_to_worker_and_wait_for_response(worker, message) {
     9  return new Promise(resolve => {
     10    // Use a dedicated channel for every request to avoid race conditions on
     11    // concurrent requests.
     12    const channel = new MessageChannel();
     13    worker.postMessage(channel.port1, [channel.port1]);
     14
     15    let messageReceived = false;
     16    channel.port2.onmessage = event => {
     17      assert_false(messageReceived, 'Already received response for ' + message);
     18      messageReceived = true;
     19      resolve(event.data);
     20    };
     21    channel.port2.postMessage(message);
     22  });
     23}
     24
     25async function ensure_install_event_fired(worker) {
     26  const response = await send_message_to_worker_and_wait_for_response(worker, 'awaitInstallEvent');
     27  assert_equals('installEventFired', response);
     28  assert_equals('installing', worker.state, 'Expected worker to be installing.');
     29}
     30
     31async function finish_install(worker) {
     32  await ensure_install_event_fired(worker);
     33  const response = await send_message_to_worker_and_wait_for_response(worker, 'finishInstall');
     34  assert_equals('installFinished', response);
     35}
     36
     37async function activate_service_worker(t, worker) {
     38  await finish_install(worker);
     39  // By waiting for both states at the same time, the test fails
     40  // quickly if the installation fails, avoiding a timeout.
     41  await Promise.race([wait_for_state(t, worker, 'activated'),
     42                      wait_for_state(t, worker, 'redundant')]);
     43  assert_equals('activated', worker.state, 'Service worker should be activated.');
     44}
     45
     46async function update_within_service_worker(worker) {
     47  // This function returns a Promise that resolves when update()
     48  // has been called but is not necessarily finished yet.
     49  // Call finish() on the returned object to wait for update() settle.
     50  const port = await send_message_to_worker_and_wait_for_response(worker, 'callUpdate');
     51  let messageReceived = false;
     52  return {
     53    finish: () => {
     54      return new Promise(resolve => {
     55        port.onmessage = event => {
     56          assert_false(messageReceived, 'Update already finished.');
     57          messageReceived = true;
     58          resolve(event.data);
     59        };
     60      });
     61    },
     62  };
     63}
     64
     65async function update_from_client_and_await_installing_version(test, registration) {
     66  const updatefound = wait_for_update(test, registration);
     67  registration.update();
     68  await updatefound;
     69  return registration.installing;
     70}
     71
    872async function spin_up_service_worker(test) {
    9     const script = 'resources/update-during-installation-worker.js';
    10     const scope = 'resources/blank.html';
     73  const script = 'resources/update-during-installation-worker.py';
     74  const scope = 'resources/blank.html';
    1175
    12     let registration = await service_worker_unregister_and_register(test, script, scope);
    13     test.add_cleanup(() => {
    14         if (registration.installing) {
    15             registration.installing.postMessage('finishInstall');
    16         }
    17         registration.unregister();
    18     });
     76  const registration = await service_worker_unregister_and_register(test, script, scope);
     77  test.add_cleanup(async () => {
     78    if (registration.installing) {
     79      // If there is an installing worker, we need to finish installing it.
     80      // Otherwise, the tests fails with an timeout because unregister() blocks
     81      // until the install-event-handler finishes.
     82      const worker = registration.installing;
     83      await send_message_to_worker_and_wait_for_response(worker, 'awaitInstallEvent');
     84      await send_message_to_worker_and_wait_for_response(worker, 'finishInstall');
     85    }
     86    return registration.unregister();
     87  });
    1988
    20     return registration;
     89  return registration;
    2190}
    2291
    2392promise_test(async t => {
    24     const registration = await spin_up_service_worker(t);
    25     const worker = registration.installing;
     93  const registration = await spin_up_service_worker(t);
     94  const worker = registration.installing;
     95  await ensure_install_event_fired(worker);
    2696
    27     // spin_up_service_worker installs a cleanup hook that ensures the
    28     // worker finished its installation by sending it a
    29     // 'finishInstall' message, thus making sure that the registration
    30     // will be cleanly removed at the end of the test.
    31     assert_equals(worker.state, 'installing');
    32     promise_rejects(t, 'InvalidStateError', registration.update());
    33 }, 'ServiceWorkerRegistration.update() from client throws while installing service worker.')
     97  const result = registration.update();
     98  await activate_service_worker(t, worker);
     99  return result;
     100}, 'ServiceWorkerRegistration.update() from client succeeds while installing service worker.');
    34101
    35102promise_test(async t => {
    36     const registration = await spin_up_service_worker(t);
    37     const worker = registration.installing;
    38     worker.postMessage('finishInstall');
     103  const registration = await spin_up_service_worker(t);
     104  const worker = registration.installing;
     105  await ensure_install_event_fired(worker);
    39106
    40     // By waiting for both states at the same time, the test fails
    41     // quickly if the installation fails, avoiding a timeout.
    42     await Promise.race([wait_for_state(t, worker, 'activated'),
    43                         wait_for_state(t, worker, 'redundant')]);
    44     assert_equals(worker.state, 'activated', 'Service worker should be activated.');
     107  // Add event listener to fail the test if update() succeeds.
     108  const updatefound = t.step_func(async () => {
     109    registration.removeEventListener('updatefound', updatefound);
     110    // Activate new worker so non-compliant browsers don't fail with timeout.
     111    await activate_service_worker(t, registration.installing);
     112    assert_unreached("update() should have failed");
     113  });
     114  registration.addEventListener('updatefound', updatefound);
    45115
    46     const response = await new Promise(resolve => {
    47         navigator.serviceWorker.onmessage = event => { resolve(event.data); };
    48         worker.postMessage('PING');
    49     });
     116  const update = await update_within_service_worker(worker);
     117  // Activate worker to ensure update() finishes and the test doesn't timeout
     118  // in non-compliant browsers.
     119  await activate_service_worker(t, worker);
    50120
    51     // We check that the service worker instance that replied to the
    52     // message is the same one that received the 'install' event since
    53     // it's possible for them to be two distinct execution
    54     // environments.
    55     assert_true(response.installEventFired, 'Service worker should have been installed.');
    56     assert_equals(response.exception, 'InvalidStateError', 'update() should have thrown.');
     121  const response = await update.finish();
     122  assert_false(response.success, 'update() should have failed.');
     123  assert_equals('InvalidStateError', response.exception, 'update() should have thrown InvalidStateError.');
    57124}, 'ServiceWorkerRegistration.update() from installing service worker throws.');
     125
     126promise_test(async t => {
     127  const registration = await spin_up_service_worker(t);
     128  const worker1 = registration.installing;
     129  await activate_service_worker(t, worker1);
     130
     131  const worker2 = await update_from_client_and_await_installing_version(t, registration);
     132  await ensure_install_event_fired(worker2);
     133
     134  const update = await update_within_service_worker(worker1);
     135  // Activate the new version so that update() finishes and the test doesn't timeout.
     136  await activate_service_worker(t, worker2);
     137  const response = await update.finish();
     138  assert_true(response.success, 'update() from active service worker should have succeeded.');
     139}, 'ServiceWorkerRegistration.update() from active service worker succeeds while installing service worker.');
    58140</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-registration-with-type.https-expected.txt

    r238592 r246363  
    11
    2 FAIL Update the registration with a different script type (classic => module). promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: guid"
    3 FAIL Update the registration with a different script type (module => classic). promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: guid"
     2FAIL Update the registration with a different script type (classic => module). promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'secondWorker.postMessage')"
     3FAIL Update the registration with a different script type (module => classic). promise_test: Unhandled rejection with value: object "TypeError: SyntaxError: Unexpected token '*'. import call expects exactly one argument."
    44PASS Update the registration with a different script type (classic => module) and with a same main script.
    55PASS Update the registration with a different script type (module => classic) and with a same main script.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-registration-with-type.https.html

    r238592 r246363  
    33<title>Service Worker: Update the registration with a different script type.</title>
    44<!-- common.js is for guid() -->
    5 <script src="/mixed-content/generic/common.js"></script>
     5<script src="/common/security-features/resources/common.js"></script>
    66<script src="/resources/testharness.js"></script>
    77<script src="/resources/testharnessreport.js"></script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/w3c-import.log

    r238592 r246363  
    2323/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/appcache-ordering-main.https.html
    2424/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https.html
     25/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-fetch-with-appcache.https.html
    2526/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-fetch.https.html
    2627/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-not-using-registration.https.html
     
    3334/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-client-types.https.html
    3435/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-cross-origin.https.html
     36/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https.html
    3537/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get.https.html
    3638/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-matchall-client-types.https.html
     
    4446/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/controller-on-reload.https.html
    4547/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/controller-with-no-fetch-event-handler.https.html
     48/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/data-transfer-files.https.html
    4649/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/dedicated-worker-service-worker-interception.https.html
    4750/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/detached-context.https.html
     
    148151/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https.html
    149152/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https.html
     153/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-schedule-job.https.html
    150154/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-scope.https.html
    151155/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-script-url.https.html
     
    157161/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/request-end-to-end.https.html
    158162/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resource-timing-cross-origin.https.html
    159 /LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resource-timing.https.html
     163/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resource-timing.sub.https.html
    160164/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/respond-with-body-accessed-response.https.html
    161165/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/sandboxed-iframe-fetch-event.https.html
     
    187191/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-bytecheck.https.html
    188192/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-missing-import-scripts.https.html
     193/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-no-cache-request-headers.https.html
    189194/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-not-allowed.https.html
     195/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-on-navigation.https.html
    190196/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-recovery.https.html
    191197/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-registration-with-type.https.html
     
    201207/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/worker-interception-redirect.https.html
    202208/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/worker-interception.https.html
     209/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/xhr-response-url.https.html
     210/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/xsl-base-url.https.html
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/websocket.https-expected.txt

    r224218 r246363  
    33
    44
    5 FAIL Verify WebSocket handshake channel does not get intercepted assert_unreached: unexpected rejection: [object Event] Reached unreachable code
     5FAIL Verify WebSocket handshake channel does not get intercepted promise_test: Unhandled rejection with value: object "[object Event]"
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/windowclient-navigate.https.html

    r238592 r246363  
    110110    }
    111111
    112     var cleanup = function() {
     112    test.add_cleanup(function() {
    113113      if (client_frame && client_frame) {
    114114        client_frame.remove();
     
    128128        return registration.unregister();
    129129      }
    130     };
     130    });
    131131
    132     var test_body = with_iframe(parameters.src_url)
     132    return with_iframe(parameters.src_url)
    133133      .then(function(frame) {
    134134          client_frame = frame;
     
    162162          assert_equals(response.data, parameters.expected);
    163163        });
    164 
    165     // Ensure that test "clean up" is deferred until after the test body
    166     // executes. `Test#add_cleanup` cannot be used for this purpose because the
    167     // operation is asynchronous, and `add_cleanup` does not support
    168     // asynchronous operations at the time of this writing. See
    169     // https://github.com/web-platform-tests/wpt/issues/6075
    170     // Ensure also that test failure is not hidden by successful cleanup
    171     // operation.
    172     return test_body
    173       .then(cleanup, cleanup)
    174       .then(function() { return test_body; });
    175164  }, parameters.description);
    176165}
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/worker-interception.https-expected.txt

    r238592 r246363  
    1 
     1CONSOLE MESSAGE: line 1: ReferenceError: Can't find variable: Worker
    22
    33FAIL Verify worker script from uncontrolled document is intercepted by Service Worker promise_test: Unhandled rejection with value: undefined
     
    55PASS Verify worker script intercepted by cors response fails
    66PASS Verify worker script intercepted by no-cors cross-origin response fails
    7 PASS Verify worker loads from controlled document are intercepted by Service Worker
     7FAIL Verify worker loads from controlled document are intercepted by Service Worker assert_equals: expected "finish" but got "failure:[object ErrorEvent]"
    88
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/worker-interception.https.html

    r238592 r246363  
    1313    return service_worker_unregister_and_register(t, service_worker, scope)
    1414      .then(function(r) {
     15          t.add_cleanup(function() {
     16              return service_worker_unregister(t, scope);
     17            });
     18
    1519          return wait_for_state(t, r.installing, 'activated');
    1620        })
     
    2933      .then(function(data) {
    3034          assert_equals(data, 'worker loading intercepted by service worker');
    31           service_worker_unregister_and_done(t, scope);
    3235        });
    3336  }, 'Verify worker script from uncontrolled document is intercepted by Service Worker');
     
    4043    return service_worker_unregister_and_register(t, service_worker, scope)
    4144      .then(function(r) {
     45          t.add_cleanup(function() {
     46              return service_worker_unregister(t, scope);
     47            });
     48
    4249          return wait_for_state(t, r.installing, 'activated');
    4350        })
     
    5663      .then(function(data) {
    5764          assert_equals(data, 'dummy-worker-script loaded');
    58           service_worker_unregister_and_done(t, scope);
    5965        });
    6066  }, 'Verify worker script intercepted by same-origin response succeeds');
     
    7379          var watcher = new EventWatcher(t, w, ['message', 'error']);
    7480          return watcher.wait_for('error');
    75         })
    76       .then(function() {
    77           service_worker_unregister_and_done(t, scope);
    78        });
     81        });
    7982  }, 'Verify worker script intercepted by cors response fails');
    8083
     
    8689    return service_worker_unregister_and_register(t, service_worker, scope)
    8790      .then(function(r) {
     91          t.add_cleanup(function() {
     92              return service_worker_unregister(t, scope);
     93            });
     94
    8895          return wait_for_state(t, r.installing, 'activated');
    8996        })
     
    9299          var watcher = new EventWatcher(t, w, ['message', 'error']);
    93100          return watcher.wait_for('error');
    94         })
    95       .then(function() {
    96           service_worker_unregister_and_done(t, scope);
    97        });
     101        });
    98102  }, 'Verify worker script intercepted by no-cors cross-origin response fails');
    99103
     
    103107    var scope = 'resources/';
    104108
    105     window.addEventListener('message', t.step_func(on_message), false);
    106     function on_message(e) {
    107       assert_equals(e.data.results, "This load was successfully intercepted.");
    108       t.done();
    109     }
    110 
    111109    return service_worker_unregister_and_register(t, service_worker, scope)
    112110      .then(function(r) {
     111          t.add_cleanup(function() {
     112              return service_worker_unregister(t, scope);
     113            });
     114
    113115          return wait_for_state(t, r.installing, 'activated');
    114116        })
     
    127129      .then(function(data) {
    128130          assert_equals(data.results, 'finish');
    129           service_worker_unregister_and_done(t, scope);
    130131        });
    131132  }, 'Verify worker loads from controlled document are intercepted by Service Worker');
  • trunk/LayoutTests/tests-options.json

    r246330 r246363  
    17011701        "slow"
    17021702    ],
     1703    "imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https.html": [
     1704        "slow"
     1705    ],
     1706    "imported/w3c/web-platform-tests/service-workers/service-worker/fetch-canvas-tainting-video-cache.https.html": [
     1707        "slow"
     1708    ],
     1709    "imported/w3c/web-platform-tests/service-workers/service-worker/fetch-canvas-tainting-video.https.html": [
     1710        "slow"
     1711    ],
    17031712    "imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-redirect.https.html": [
    17041713        "slow"
    17051714    ],
     1715    "imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-respond-with-body-loaded-in-chunk.https.html": [
     1716        "slow"
     1717    ],
    17061718    "imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event.https.html": [
    17071719        "slow"
     
    17251737        "slow"
    17261738    ],
     1739    "imported/w3c/web-platform-tests/service-workers/service-worker/interfaces-window.https.html": [
     1740        "slow"
     1741    ],
    17271742    "imported/w3c/web-platform-tests/service-workers/service-worker/local-url-inherit-controller.https.html": [
    17281743        "slow"
     
    17341749        "slow"
    17351750    ],
     1751    "imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https.html": [
     1752        "slow"
     1753    ],
    17361754    "imported/w3c/web-platform-tests/service-workers/service-worker/registration-updateviacache.https.html": [
    17371755        "slow"
    17381756    ],
     1757    "imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-using-registration.https.html": [
     1758        "slow"
     1759    ],
     1760    "imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https.html": [
     1761        "slow"
     1762    ],
    17391763    "imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html": [
     1764        "slow"
     1765    ],
     1766    "imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-redirect.https.html": [
     1767        "slow"
     1768    ],
     1769    "imported/w3c/web-platform-tests/service-workers/service-worker/update-bytecheck.https.html": [
    17401770        "slow"
    17411771    ],
Note: See TracChangeset for help on using the changeset viewer.