tree: ab2a2b0a5c8bef5a42d4ab2f1985646c91c325df [path history] [tgz]
  1. META.yml
  4. SharedWorker-MessageEvent-source.any.js
  5. SharedWorker-constructor.html
  6. SharedWorker-detach-frame-in-error-event.html
  7. SharedWorker-exception-propagation.html
  8. SharedWorker-exception.html
  9. SharedWorker-replace-EventHandler.any.js
  10. SharedWorker-script-error.html
  11. SharedWorker-simple.html
  12. SharedWorkerPerformanceNow.html
  13. SharedWorker_blobUrl.html
  14. SharedWorker_dataUrl.html
  15. Worker-base64.any.js
  16. Worker-call.worker.js
  17. Worker-constructor-proto.any.js
  18. Worker-custom-event.any.js
  19. Worker-formdata.any.js
  20. Worker-location.sub.any.js
  21. Worker-messageport.html
  22. Worker-multi-port.html
  23. Worker-nested-importScripts-error.html
  24. Worker-replace-event-handler.any.js
  25. Worker-replace-global-constructor.any.js
  26. Worker-replace-self.any.js
  27. Worker-simultaneous-errors.html
  28. Worker-structure-message.html
  29. Worker-terminate-forever.html
  30. Worker-termination-with-port-messages.html
  31. Worker-timeout-cancel-order.html
  32. Worker-timeout-decreasing-order.html
  33. Worker-timeout-increasing-order.html
  34. WorkerGlobalScope-close.html
  35. WorkerGlobalScope_ErrorEvent_colno.htm
  36. WorkerGlobalScope_ErrorEvent_filename.htm
  37. WorkerGlobalScope_ErrorEvent_lineno.htm
  38. WorkerGlobalScope_ErrorEvent_message.htm
  39. WorkerGlobalScope_importScripts.htm
  40. WorkerGlobalScope_importScripts_NetworkErr.htm
  41. WorkerGlobalScope_importScripts_NosniffErr.htm
  42. WorkerGlobalScope_requestAnimationFrame.tentative.worker.js
  43. WorkerGlobalScope_setInterval.htm
  44. WorkerGlobalScope_setTimeout.htm
  45. WorkerLocation-origin.sub.window.js
  46. WorkerLocation.htm
  47. WorkerLocation_hash.htm
  48. WorkerLocation_hash_encoding.htm
  49. WorkerLocation_hash_nonexist.htm
  50. WorkerLocation_host.htm
  51. WorkerLocation_hostname.htm
  52. WorkerLocation_href.htm
  53. WorkerLocation_pathname.htm
  54. WorkerLocation_port.htm
  55. WorkerLocation_protocol.htm
  56. WorkerLocation_search.htm
  57. WorkerLocation_search_empty.htm
  58. WorkerLocation_search_fragment.htm
  59. WorkerLocation_search_nonexist.htm
  60. WorkerNavigator-hardware-concurrency.any.js
  61. WorkerNavigator.any.js
  62. WorkerNavigator_appName.htm
  63. WorkerNavigator_appVersion.htm
  64. WorkerNavigator_onLine.htm
  65. WorkerNavigator_platform.htm
  66. WorkerNavigator_userAgent.htm
  67. WorkerPerformanceNow.html
  68. Worker_ErrorEvent_bubbles_cancelable.htm
  69. Worker_ErrorEvent_error.htm
  70. Worker_ErrorEvent_filename.htm
  71. Worker_ErrorEvent_lineno.htm
  72. Worker_ErrorEvent_message.htm
  73. Worker_ErrorEvent_type.htm
  74. Worker_NosniffErr.htm
  75. Worker_basic.htm
  76. Worker_cross_origin_security_err.htm
  77. Worker_dispatchEvent_ErrorEvent.htm
  78. Worker_script_mimetype-expected.txt
  79. Worker_script_mimetype.htm
  80. Worker_terminate_event_queue.htm
  81. baseurl/
  82. constructors/
  83. data-url-shared-window.html
  84. data-url-shared.html
  85. data-url.html
  86. dedicated-worker-from-blob-url.window.js
  87. examples/
  88. importscripts_mime.any.js
  89. interfaces.worker-expected.txt
  90. interfaces/
  91. modules/
  92. name-property-expected.txt
  93. name-property.html
  94. nested_worker.worker.js
  95. nested_worker_close_from_parent_worker.html
  96. nested_worker_close_self.worker.js
  97. nested_worker_importScripts.worker.js
  98. nested_worker_sync_xhr.worker.js
  99. nested_worker_terminate_from_document.html
  100. non-automated/
  101. opaque-origin-expected.txt
  102. opaque-origin.html
  103. postMessage_DataCloneErr.htm
  104. postMessage_clone_port.htm
  105. postMessage_clone_port_error.htm
  106. postMessage_event_properties.htm
  107. postMessage_ports_readonly_array.htm
  108. postMessage_target_source.htm
  109. semantics/
  110. shared-worker-from-blob-url.window.js
  111. shared-worker-name-via-options-expected.txt
  112. shared-worker-name-via-options.html
  113. support/
  114. worker-performance.worker.js

Worker WPT tests

These are the workers (Worker, SharedWorker) tests for the Web workers chapter of the HTML Standard.

See also testharness.js API > Web Workers.

Note that because workers are defined in the HTML Standard, the idlharness.js tests are in /html/dom instead of here.

Writing *.any.js

The easiest and most recommended way to write tests for workers is to create .any.js-style tests.

Official doc: WPT > File Name Flags > Test Features.

  • Standard testharness.js-style can be used (and is enforced).
  • The same test can be run on window and many types of workers.
  • All glue code are automatically generated.
  • No need to care about how to create and communicate with each type of workers, thanks to fetch_tests_from_worker in testharness.js.

Converting existing tests into .any.js-style also has benefits:

  • Multiple tests can be merged into one.
  • Tests written for window can be run on workers with a very low development cost.

How to write tests

If you write testharness.js-based tests in foo.any.js and specify types of workers to be tested, the test can run on any of dedicated, shared and service workers.

See examples/general.any.js for example.

Even for testing specific features in a specific type of workers (e.g. shared worker's onconnect), .any.js-style tests can be used.

See examples/onconnect.any.js for example.

How to debug tests

Whether each individual test passed or failed, and its assertion failures (if any) are all reported in the final results.

console.log() might not appear in the test results and thus might not be useful for printf debugging. For example, in Chromium, this message

  • Appears (in stderr) on a window or a dedicated worker, but
  • Does NOT appear on a shared worker or a service worker.

How it works

.any.js-style tests use fetch_tests_from_worker functionality of testharness.js.

The WPT test server generates necessary glue code (including generated Document HTML and worker top-level scripts). See for the actual glue code.

Note that .any.js file is not the worker top-level script, and currently we cannot set response headers to the worker top-level script, e.g. to set Referrer Policy of the workers.

Writing *.worker.js

Similar to .any.js, you can also write .worker.js for tests only for dedicated workers. Almost the same as .any.js, except for the things listed below.

Official doc: WPT > File Name Flags > Test Features.

How to write tests

You have to write two things manually (which is generated in .any.js tests):

  • importScripts("/resources/testharness.js"); at the beginning.
  • done(); at the bottom.

Note: Even if you write async_test() or promise_test(), this global done() is always needed (this is different from async_test's done()) for dedicated workers and shared workers. See official doc: testharness.js API > Determining when all tests are complete.

See examples/general.worker.js for example.

How it works

.worker.js-style tests also use fetch_tests_from_worker functionality of testharness.js.

The WPT test server generates glue code in Document HTML-side, but not for worker top-level scripts. This is why you have to manually write importScripts() etc. See for the actual glue code.

Unlike *.any.js cases, the *.worker.js is the worker top-level script.

Using fetch_tests_from_worker

If you need more flexibility, writing tests using fetch_tests_from_worker is the way to go. For example, when

  • Additional processing is needed on the parent Document.
  • Workers should be created in a specific way.
  • You are writing non-WPT tests using testharness.js.

You have to write the main HTMLs and the worker scripts, but most of the glue code needed for running tests on workers are provided by fetch_tests_from_worker.

How to write tests


  • examples/fetch_tests_from_worker.html and examples/fetch_tests_from_worker.js.

Writing the whole tests manually

If fetch_tests_from_worker isn't suitable for your specific case (which should be rare but might be still possible), you have to write the whole tests, including the main Document HTML, worker scripts, and message passing code between them.

TODO: Supply the templates for writing this kind of tests.