tree: f39761b520774310c3e0d970e77c10b8d335c323 [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. importscripts_mime.any.js
  18. importscripts_mime.any.worker-expected.txt
  19. importscripts_mime.any.worker.html
  20. META.yml
  21. name-property-expected.txt
  22. name-property.html
  23. nested_worker.worker-expected.txt
  24. nested_worker.worker.html
  25. nested_worker.worker.js
  26. nested_worker_close_from_parent_worker-expected.txt
  27. nested_worker_close_from_parent_worker.html
  28. nested_worker_close_self.worker-expected.txt
  29. nested_worker_close_self.worker.html
  30. nested_worker_close_self.worker.js
  31. nested_worker_importScripts.worker-expected.txt
  32. nested_worker_importScripts.worker.html
  33. nested_worker_importScripts.worker.js
  34. nested_worker_sync_xhr.worker-expected.txt
  35. nested_worker_sync_xhr.worker.html
  36. nested_worker_sync_xhr.worker.js
  37. nested_worker_terminate_from_document-expected.txt
  38. nested_worker_terminate_from_document.html
  39. opaque-origin-expected.txt
  40. opaque-origin.html
  41. postMessage_clone_port-expected.txt
  42. postMessage_clone_port.htm
  43. postMessage_clone_port_error-expected.txt
  44. postMessage_clone_port_error.htm
  45. postMessage_DataCloneErr-expected.txt
  46. postMessage_DataCloneErr.htm
  47. postMessage_event_properties-expected.txt
  48. postMessage_event_properties.htm
  49. postMessage_ports_readonly_array-expected.txt
  50. postMessage_ports_readonly_array.htm
  51. postMessage_target_source-expected.txt
  52. postMessage_target_source.htm
  53. README.md
  54. shared-worker-from-blob-url.window-expected.txt
  55. shared-worker-from-blob-url.window.html
  56. shared-worker-from-blob-url.window.js
  57. shared-worker-name-via-options-expected.txt
  58. shared-worker-name-via-options.html
  59. SharedWorker-constructor-expected.txt
  60. SharedWorker-constructor.html
  61. SharedWorker-detach-frame-in-error-event-expected.txt
  62. SharedWorker-detach-frame-in-error-event.html
  63. SharedWorker-exception-expected.txt
  64. SharedWorker-exception-propagation-expected.txt
  65. SharedWorker-exception-propagation.html
  66. SharedWorker-exception.html
  67. SharedWorker-MessageEvent-source.any-expected.txt
  68. SharedWorker-MessageEvent-source.any.html
  69. SharedWorker-MessageEvent-source.any.js
  70. SharedWorker-MessageEvent-source.any.worker-expected.txt
  71. SharedWorker-MessageEvent-source.any.worker.html
  72. SharedWorker-replace-EventHandler.any-expected.txt
  73. SharedWorker-replace-EventHandler.any.html
  74. SharedWorker-replace-EventHandler.any.js
  75. SharedWorker-replace-EventHandler.any.worker-expected.txt
  76. SharedWorker-replace-EventHandler.any.worker.html
  77. SharedWorker-script-error-expected.txt
  78. SharedWorker-script-error.html
  79. SharedWorker-simple-expected.txt
  80. SharedWorker-simple.html
  81. SharedWorker_blobUrl-expected.txt
  82. SharedWorker_blobUrl.html
  83. SharedWorker_dataUrl-expected.txt
  84. SharedWorker_dataUrl.html
  85. SharedWorkerPerformanceNow-expected.txt
  86. SharedWorkerPerformanceNow.html
  87. w3c-import.log
  88. Worker-base64.any.js
  89. Worker-base64.any.worker-expected.txt
  90. Worker-base64.any.worker.html
  91. Worker-call.worker-expected.txt
  92. Worker-call.worker.html
  93. Worker-call.worker.js
  94. Worker-constructor-proto.any.js
  95. Worker-constructor-proto.any.worker-expected.txt
  96. Worker-constructor-proto.any.worker.html
  97. Worker-custom-event.any.js
  98. Worker-custom-event.any.worker-expected.txt
  99. Worker-custom-event.any.worker.html
  100. Worker-formdata.any.js
  101. Worker-formdata.any.worker-expected.txt
  102. Worker-formdata.any.worker.html
  103. Worker-location.sub.any.js
  104. Worker-location.sub.any.worker-expected.txt
  105. Worker-location.sub.any.worker.html
  106. Worker-messageport-expected.txt
  107. Worker-messageport.html
  108. Worker-multi-port-expected.txt
  109. Worker-multi-port.html
  110. Worker-nested-importScripts-error-expected.txt
  111. Worker-nested-importScripts-error.html
  112. worker-performance.worker-expected.txt
  113. worker-performance.worker.html
  114. worker-performance.worker.js
  115. Worker-replace-event-handler.any.js
  116. Worker-replace-event-handler.any.worker-expected.txt
  117. Worker-replace-event-handler.any.worker.html
  118. Worker-replace-global-constructor.any.js
  119. Worker-replace-global-constructor.any.worker-expected.txt
  120. Worker-replace-global-constructor.any.worker.html
  121. Worker-replace-self.any.js
  122. Worker-replace-self.any.worker-expected.txt
  123. Worker-replace-self.any.worker.html
  124. Worker-simultaneous-errors-expected.txt
  125. Worker-simultaneous-errors.html
  126. Worker-structure-message-expected.txt
  127. Worker-structure-message.html
  128. Worker-terminate-forever-expected.txt
  129. Worker-terminate-forever.html
  130. Worker-termination-with-port-messages-expected.txt
  131. Worker-termination-with-port-messages.html
  132. Worker-timeout-cancel-order-expected.txt
  133. Worker-timeout-cancel-order.html
  134. Worker-timeout-decreasing-order-expected.txt
  135. Worker-timeout-decreasing-order.html
  136. Worker-timeout-increasing-order-expected.txt
  137. Worker-timeout-increasing-order.html
  138. Worker_basic-expected.txt
  139. Worker_basic.htm
  140. Worker_cross_origin_security_err-expected.txt
  141. Worker_cross_origin_security_err.htm
  142. Worker_dispatchEvent_ErrorEvent-expected.txt
  143. Worker_dispatchEvent_ErrorEvent.htm
  144. Worker_ErrorEvent_bubbles_cancelable-expected.txt
  145. Worker_ErrorEvent_bubbles_cancelable.htm
  146. Worker_ErrorEvent_error-expected.txt
  147. Worker_ErrorEvent_error.htm
  148. Worker_ErrorEvent_filename-expected.txt
  149. Worker_ErrorEvent_filename.htm
  150. Worker_ErrorEvent_lineno-expected.txt
  151. Worker_ErrorEvent_lineno.htm
  152. Worker_ErrorEvent_message-expected.txt
  153. Worker_ErrorEvent_message.htm
  154. Worker_ErrorEvent_type-expected.txt
  155. Worker_ErrorEvent_type.htm
  156. Worker_NosniffErr-expected.txt
  157. Worker_NosniffErr.htm
  158. Worker_script_mimetype-expected.txt
  159. Worker_script_mimetype.htm
  160. Worker_terminate_event_queue-expected.txt
  161. Worker_terminate_event_queue.htm
  162. WorkerGlobalScope-close-expected.txt
  163. WorkerGlobalScope-close.html
  164. WorkerGlobalScope_ErrorEvent_colno-expected.txt
  165. WorkerGlobalScope_ErrorEvent_colno.htm
  166. WorkerGlobalScope_ErrorEvent_filename-expected.txt
  167. WorkerGlobalScope_ErrorEvent_filename.htm
  168. WorkerGlobalScope_ErrorEvent_lineno-expected.txt
  169. WorkerGlobalScope_ErrorEvent_lineno.htm
  170. WorkerGlobalScope_ErrorEvent_message-expected.txt
  171. WorkerGlobalScope_ErrorEvent_message.htm
  172. WorkerGlobalScope_importScripts-expected.txt
  173. WorkerGlobalScope_importScripts.htm
  174. WorkerGlobalScope_importScripts_NetworkErr-expected.txt
  175. WorkerGlobalScope_importScripts_NetworkErr.htm
  176. WorkerGlobalScope_importScripts_NosniffErr-expected.txt
  177. WorkerGlobalScope_importScripts_NosniffErr.htm
  178. WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt
  179. WorkerGlobalScope_requestAnimationFrame.tentative.worker.html
  180. WorkerGlobalScope_requestAnimationFrame.tentative.worker.js
  181. WorkerGlobalScope_setInterval-expected.txt
  182. WorkerGlobalScope_setInterval.htm
  183. WorkerGlobalScope_setTimeout-expected.txt
  184. WorkerGlobalScope_setTimeout.htm
  185. WorkerLocation-expected.txt
  186. WorkerLocation-origin.sub.window-expected.txt
  187. WorkerLocation-origin.sub.window.html
  188. WorkerLocation-origin.sub.window.js
  189. WorkerLocation.htm
  190. WorkerLocation_hash-expected.txt
  191. WorkerLocation_hash.htm
  192. WorkerLocation_hash_encoding-expected.txt
  193. WorkerLocation_hash_encoding.htm
  194. WorkerLocation_hash_nonexist-expected.txt
  195. WorkerLocation_hash_nonexist.htm
  196. WorkerLocation_host-expected.txt
  197. WorkerLocation_host.htm
  198. WorkerLocation_hostname-expected.txt
  199. WorkerLocation_hostname.htm
  200. WorkerLocation_href-expected.txt
  201. WorkerLocation_href.htm
  202. WorkerLocation_pathname-expected.txt
  203. WorkerLocation_pathname.htm
  204. WorkerLocation_port-expected.txt
  205. WorkerLocation_port.htm
  206. WorkerLocation_protocol-expected.txt
  207. WorkerLocation_protocol.htm
  208. WorkerLocation_search-expected.txt
  209. WorkerLocation_search.htm
  210. WorkerLocation_search_empty-expected.txt
  211. WorkerLocation_search_empty.htm
  212. WorkerLocation_search_fragment-expected.txt
  213. WorkerLocation_search_fragment.htm
  214. WorkerLocation_search_nonexist-expected.txt
  215. WorkerLocation_search_nonexist.htm
  216. WorkerNavigator-hardware-concurrency.any.js
  217. WorkerNavigator-hardware-concurrency.any.worker-expected.txt
  218. WorkerNavigator-hardware-concurrency.any.worker.html
  219. WorkerNavigator.any.js
  220. WorkerNavigator.any.worker-expected.txt
  221. WorkerNavigator.any.worker.html
  222. WorkerNavigator_appName-expected.txt
  223. WorkerNavigator_appName.htm
  224. WorkerNavigator_appVersion-expected.txt
  225. WorkerNavigator_appVersion.htm
  226. WorkerNavigator_onLine-expected.txt
  227. WorkerNavigator_onLine.htm
  228. WorkerNavigator_platform-expected.txt
  229. WorkerNavigator_platform.htm
  230. WorkerNavigator_userAgent-expected.txt
  231. WorkerNavigator_userAgent.htm
  232. WorkerPerformanceNow-expected.txt
  233. 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.