serviceworkerregistration-service-worker-image-slow-404.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Notifications: Showing a notification with an image that 404s after a slow redirect.</title>
  5. <script src="../resources/testharness.js"></script>
  6. <script src="../resources/testharnessreport.js"></script>
  7. <script src="../serviceworker/resources/test-helpers.js"></script>
  8. <script src="resources/test-helpers.js"></script>
  9. </head>
  10. <body>
  11. <script>
  12. // Tests that showing a notification with an image that creates a 404 response
  13. // after a slow redirect works properly, and does not block the actual display of it.
  14. async_test(function(test) {
  15. var scope = 'resources/scope/' + location.pathname,
  16. script = 'instrumentation-service-worker.js';
  17. testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
  18. getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(info) {
  19. // (1) Display a Web Notification through the Service Worker with
  20. // an image that 404s after a 200ms redirect to load.
  21. return sendCommand(info.port, {
  22. command: 'show',
  23. title: 'My Notification',
  24. options: { body: 'Hello, world!',
  25. icon: '/resources/slow-image.php?redirect_name=not_there.png&mimeType=image/png&sleep=200' }
  26. });
  27. }).then(function(data) {
  28. // (2) Confirm that the service worker displayed the notification successfully.
  29. assert_true(data.success);
  30. test.done();
  31. }).catch(unreached_rejection(test));
  32. }, 'Displaying a notification with an image that 404s after a slow redirect still resolves the promise.');
  33. </script>
  34. </body>
  35. </html>