tree: f4823a1a04d2991d8268652b890b74a6e16383ec [path history] [tgz]
  1. baseurl/
  2. constructors/
  3. examples/
  4. interfaces/
  5. modules/
  6. non-automated/
  7. semantics/
  8. support/
  9. data-url-expected.txt
  10. data-url-shared-expected.txt
  11. data-url-shared-window.html
  12. data-url-shared.html
  13. data-url.html
  14. dedicated-worker-from-blob-url.window-expected.txt
  15. dedicated-worker-from-blob-url.window.html
  16. dedicated-worker-from-blob-url.window.js
  17. META.yml
  18. name-property-expected.txt
  19. name-property.html
  20. nested_worker.worker-expected.txt
  21. nested_worker.worker.html
  22. nested_worker.worker.js
  23. nested_worker_close_from_parent_worker-expected.txt
  24. nested_worker_close_from_parent_worker.html
  25. nested_worker_close_self.worker-expected.txt
  26. nested_worker_close_self.worker.html
  27. nested_worker_close_self.worker.js
  28. nested_worker_importScripts.worker-expected.txt
  29. nested_worker_importScripts.worker.html
  30. nested_worker_importScripts.worker.js
  31. nested_worker_sync_xhr.worker-expected.txt
  32. nested_worker_sync_xhr.worker.html
  33. nested_worker_sync_xhr.worker.js
  34. nested_worker_terminate_from_document-expected.txt
  35. nested_worker_terminate_from_document.html
  36. opaque-origin-expected.txt
  37. opaque-origin.html
  38. postMessage_clone_port-expected.txt
  39. postMessage_clone_port.htm
  40. postMessage_clone_port_error-expected.txt
  41. postMessage_clone_port_error.htm
  42. postMessage_DataCloneErr-expected.txt
  43. postMessage_DataCloneErr.htm
  44. postMessage_event_properties-expected.txt
  45. postMessage_event_properties.htm
  46. postMessage_ports_readonly_array-expected.txt
  47. postMessage_ports_readonly_array.htm
  48. postMessage_target_source-expected.txt
  49. postMessage_target_source.htm
  50. README.md
  51. shared-worker-from-blob-url.window-expected.txt
  52. shared-worker-from-blob-url.window.html
  53. shared-worker-from-blob-url.window.js
  54. shared-worker-name-via-options-expected.txt
  55. shared-worker-name-via-options.html
  56. SharedWorker-constructor-expected.txt
  57. SharedWorker-constructor.html
  58. SharedWorker-detach-frame-in-error-event-expected.txt
  59. SharedWorker-detach-frame-in-error-event.html
  60. SharedWorker-exception-expected.txt
  61. SharedWorker-exception-propagation-expected.txt
  62. SharedWorker-exception-propagation.html
  63. SharedWorker-exception.html
  64. SharedWorker-script-error-expected.txt
  65. SharedWorker-script-error.html
  66. SharedWorker-simple-expected.txt
  67. SharedWorker-simple.html
  68. SharedWorker_blobUrl-expected.txt
  69. SharedWorker_blobUrl.html
  70. SharedWorker_dataUrl-expected.txt
  71. SharedWorker_dataUrl.html
  72. SharedWorkerPerformanceNow-expected.txt
  73. SharedWorkerPerformanceNow.html
  74. w3c-import.log
  75. Worker-call.worker-expected.txt
  76. Worker-call.worker.html
  77. Worker-call.worker.js
  78. Worker-messageport-expected.txt
  79. Worker-messageport.html
  80. Worker-multi-port-expected.txt
  81. Worker-multi-port.html
  82. Worker-nested-importScripts-error-expected.txt
  83. Worker-nested-importScripts-error.html
  84. worker-performance.worker-expected.txt
  85. worker-performance.worker.html
  86. worker-performance.worker.js
  87. Worker-simultaneous-errors-expected.txt
  88. Worker-simultaneous-errors.html
  89. Worker-structure-message-expected.txt
  90. Worker-structure-message.html
  91. Worker-terminate-forever-expected.txt
  92. Worker-terminate-forever.html
  93. Worker-termination-with-port-messages-expected.txt
  94. Worker-termination-with-port-messages.html
  95. Worker-timeout-cancel-order-expected.txt
  96. Worker-timeout-cancel-order.html
  97. Worker-timeout-decreasing-order-expected.txt
  98. Worker-timeout-decreasing-order.html
  99. Worker-timeout-increasing-order-expected.txt
  100. Worker-timeout-increasing-order.html
  101. Worker_basic-expected.txt
  102. Worker_basic.htm
  103. Worker_cross_origin_security_err-expected.txt
  104. Worker_cross_origin_security_err.htm
  105. Worker_dispatchEvent_ErrorEvent-expected.txt
  106. Worker_dispatchEvent_ErrorEvent.htm
  107. Worker_ErrorEvent_bubbles_cancelable-expected.txt
  108. Worker_ErrorEvent_bubbles_cancelable.htm
  109. Worker_ErrorEvent_error-expected.txt
  110. Worker_ErrorEvent_error.htm
  111. Worker_ErrorEvent_filename-expected.txt
  112. Worker_ErrorEvent_filename.htm
  113. Worker_ErrorEvent_lineno-expected.txt
  114. Worker_ErrorEvent_lineno.htm
  115. Worker_ErrorEvent_message-expected.txt
  116. Worker_ErrorEvent_message.htm
  117. Worker_ErrorEvent_type-expected.txt
  118. Worker_ErrorEvent_type.htm
  119. Worker_NosniffErr-expected.txt
  120. Worker_NosniffErr.htm
  121. Worker_script_mimetype-expected.txt
  122. Worker_script_mimetype.htm
  123. Worker_terminate_event_queue-expected.txt
  124. Worker_terminate_event_queue.htm
  125. WorkerGlobalScope-close-expected.txt
  126. WorkerGlobalScope-close.html
  127. WorkerGlobalScope_ErrorEvent_colno-expected.txt
  128. WorkerGlobalScope_ErrorEvent_colno.htm
  129. WorkerGlobalScope_ErrorEvent_filename-expected.txt
  130. WorkerGlobalScope_ErrorEvent_filename.htm
  131. WorkerGlobalScope_ErrorEvent_lineno-expected.txt
  132. WorkerGlobalScope_ErrorEvent_lineno.htm
  133. WorkerGlobalScope_ErrorEvent_message-expected.txt
  134. WorkerGlobalScope_ErrorEvent_message.htm
  135. WorkerGlobalScope_importScripts-expected.txt
  136. WorkerGlobalScope_importScripts.htm
  137. WorkerGlobalScope_importScripts_NetworkErr-expected.txt
  138. WorkerGlobalScope_importScripts_NetworkErr.htm
  139. WorkerGlobalScope_importScripts_NosniffErr-expected.txt
  140. WorkerGlobalScope_importScripts_NosniffErr.htm
  141. WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt
  142. WorkerGlobalScope_requestAnimationFrame.tentative.worker.html
  143. WorkerGlobalScope_requestAnimationFrame.tentative.worker.js
  144. WorkerGlobalScope_setInterval-expected.txt
  145. WorkerGlobalScope_setInterval.htm
  146. WorkerGlobalScope_setTimeout-expected.txt
  147. WorkerGlobalScope_setTimeout.htm
  148. WorkerLocation-expected.txt
  149. WorkerLocation.htm
  150. WorkerLocation_hash-expected.txt
  151. WorkerLocation_hash.htm
  152. WorkerLocation_hash_encoding-expected.txt
  153. WorkerLocation_hash_encoding.htm
  154. WorkerLocation_hash_nonexist-expected.txt
  155. WorkerLocation_hash_nonexist.htm
  156. WorkerLocation_host-expected.txt
  157. WorkerLocation_host.htm
  158. WorkerLocation_hostname-expected.txt
  159. WorkerLocation_hostname.htm
  160. WorkerLocation_href-expected.txt
  161. WorkerLocation_href.htm
  162. WorkerLocation_pathname-expected.txt
  163. WorkerLocation_pathname.htm
  164. WorkerLocation_port-expected.txt
  165. WorkerLocation_port.htm
  166. WorkerLocation_protocol-expected.txt
  167. WorkerLocation_protocol.htm
  168. WorkerLocation_search-expected.txt
  169. WorkerLocation_search.htm
  170. WorkerLocation_search_empty-expected.txt
  171. WorkerLocation_search_empty.htm
  172. WorkerLocation_search_fragment-expected.txt
  173. WorkerLocation_search_fragment.htm
  174. WorkerLocation_search_nonexist-expected.txt
  175. WorkerLocation_search_nonexist.htm
  176. WorkerNavigator_appName-expected.txt
  177. WorkerNavigator_appName.htm
  178. WorkerNavigator_appVersion-expected.txt
  179. WorkerNavigator_appVersion.htm
  180. WorkerNavigator_onLine-expected.txt
  181. WorkerNavigator_onLine.htm
  182. WorkerNavigator_platform-expected.txt
  183. WorkerNavigator_platform.htm
  184. WorkerNavigator_userAgent-expected.txt
  185. WorkerNavigator_userAgent.htm
  186. WorkerPerformanceNow-expected.txt
  187. WorkerPerformanceNow.html
LayoutTests/imported/w3c/web-platform-tests/workers/README.md

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 serve.py 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 serve.py 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

See

  • 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.