tree: 94eb9060b6b81ff97fec0493be60a58d4fde7425 [path history] [tgz]
  1. baseurl/
  2. constructors/
  3. examples/
  4. interfaces/
  5. modules/
  6. multi-globals/
  7. non-automated/
  8. semantics/
  9. support/
  10. abrupt-completion-expected.txt
  11. abrupt-completion.html
  12. data-url-expected.txt
  13. data-url-shared-expected.txt
  14. data-url-shared-window.html
  15. data-url-shared.html
  16. data-url.html
  17. dedicated-worker-from-blob-url.window-expected.txt
  18. dedicated-worker-from-blob-url.window.html
  19. dedicated-worker-from-blob-url.window.js
  20. dedicated-worker-in-data-url-context.window-expected.txt
  21. dedicated-worker-in-data-url-context.window.html
  22. dedicated-worker-in-data-url-context.window.js
  23. dedicated-worker-parse-error-failure-expected.txt
  24. dedicated-worker-parse-error-failure.html
  25. importscripts_mime.any.js
  26. importscripts_mime.any.serviceworker-expected.txt
  27. importscripts_mime.any.serviceworker.html
  28. importscripts_mime.any.sharedworker-expected.txt
  29. importscripts_mime.any.sharedworker.html
  30. importscripts_mime.any.worker-expected.txt
  31. importscripts_mime.any.worker.html
  32. META.yml
  33. name-property-expected.txt
  34. name-property.html
  35. nested_worker.worker-expected.txt
  36. nested_worker.worker.html
  37. nested_worker.worker.js
  38. nested_worker_close_from_parent_worker-expected.txt
  39. nested_worker_close_from_parent_worker.html
  40. nested_worker_close_self.worker-expected.txt
  41. nested_worker_close_self.worker.html
  42. nested_worker_close_self.worker.js
  43. nested_worker_importScripts.worker-expected.txt
  44. nested_worker_importScripts.worker.html
  45. nested_worker_importScripts.worker.js
  46. nested_worker_sync_xhr.worker-expected.txt
  47. nested_worker_sync_xhr.worker.html
  48. nested_worker_sync_xhr.worker.js
  49. nested_worker_terminate_from_document-expected.txt
  50. nested_worker_terminate_from_document.html
  51. opaque-origin-expected.txt
  52. opaque-origin.html
  53. postMessage_block.https-expected.txt
  54. postMessage_block.https.html
  55. postMessage_block.https.html.headers
  56. postMessage_clone_port-expected.txt
  57. postMessage_clone_port.htm
  58. postMessage_clone_port_error-expected.txt
  59. postMessage_clone_port_error.htm
  60. postMessage_DataCloneErr-expected.txt
  61. postMessage_DataCloneErr.htm
  62. postMessage_event_properties-expected.txt
  63. postMessage_event_properties.htm
  64. postMessage_ports_readonly_array-expected.txt
  65. postMessage_ports_readonly_array.htm
  66. postMessage_target_source-expected.txt
  67. postMessage_target_source.htm
  68. README.md
  69. same-origin-check.sub-expected.txt
  70. same-origin-check.sub.html
  71. shared-worker-from-blob-url.window-expected.txt
  72. shared-worker-from-blob-url.window.html
  73. shared-worker-from-blob-url.window.js
  74. shared-worker-in-data-url-context.window-expected.txt
  75. shared-worker-in-data-url-context.window.html
  76. shared-worker-in-data-url-context.window.js
  77. shared-worker-name-via-options-expected.txt
  78. shared-worker-name-via-options.html
  79. shared-worker-options-mismatch-expected.txt
  80. shared-worker-options-mismatch.html
  81. shared-worker-parse-error-failure-expected.txt
  82. shared-worker-parse-error-failure.html
  83. shared-worker-partitioned.tentative-expected.txt
  84. shared-worker-partitioned.tentative.html
  85. SharedWorker-constructor-expected.txt
  86. SharedWorker-constructor.html
  87. SharedWorker-detach-frame-in-error-event-expected.txt
  88. SharedWorker-detach-frame-in-error-event.html
  89. SharedWorker-exception-expected.txt
  90. SharedWorker-exception-propagation-expected.txt
  91. SharedWorker-exception-propagation.html
  92. SharedWorker-exception.html
  93. SharedWorker-MessageEvent-source.any.js
  94. SharedWorker-MessageEvent-source.any.sharedworker-expected.txt
  95. SharedWorker-MessageEvent-source.any.sharedworker.html
  96. SharedWorker-replace-EventHandler.any.js
  97. SharedWorker-replace-EventHandler.any.sharedworker-expected.txt
  98. SharedWorker-replace-EventHandler.any.sharedworker.html
  99. SharedWorker-script-error-expected.txt
  100. SharedWorker-script-error.html
  101. SharedWorker-simple-expected.txt
  102. SharedWorker-simple.html
  103. SharedWorker_blobUrl-expected.txt
  104. SharedWorker_blobUrl.html
  105. SharedWorker_dataUrl-expected.txt
  106. SharedWorker_dataUrl.html
  107. SharedWorkerPerformanceNow-expected.txt
  108. SharedWorkerPerformanceNow.html
  109. w3c-import.log
  110. Worker-base64.any.js
  111. Worker-base64.any.serviceworker-expected.txt
  112. Worker-base64.any.serviceworker.html
  113. Worker-base64.any.sharedworker-expected.txt
  114. Worker-base64.any.sharedworker.html
  115. Worker-base64.any.worker-expected.txt
  116. Worker-base64.any.worker.html
  117. Worker-call.worker-expected.txt
  118. Worker-call.worker.html
  119. Worker-call.worker.js
  120. Worker-constructor-proto.any.js
  121. Worker-constructor-proto.any.serviceworker-expected.txt
  122. Worker-constructor-proto.any.serviceworker.html
  123. Worker-constructor-proto.any.sharedworker-expected.txt
  124. Worker-constructor-proto.any.sharedworker.html
  125. Worker-constructor-proto.any.worker-expected.txt
  126. Worker-constructor-proto.any.worker.html
  127. Worker-custom-event.any.js
  128. Worker-custom-event.any.serviceworker-expected.txt
  129. Worker-custom-event.any.serviceworker.html
  130. Worker-custom-event.any.sharedworker-expected.txt
  131. Worker-custom-event.any.sharedworker.html
  132. Worker-custom-event.any.worker-expected.txt
  133. Worker-custom-event.any.worker.html
  134. Worker-formdata.any.js
  135. Worker-formdata.any.worker-expected.txt
  136. Worker-formdata.any.worker.html
  137. Worker-location.sub.any.js
  138. Worker-location.sub.any.sharedworker-expected.txt
  139. Worker-location.sub.any.sharedworker.html
  140. Worker-location.sub.any.worker-expected.txt
  141. Worker-location.sub.any.worker.html
  142. Worker-messageport-expected.txt
  143. Worker-messageport.html
  144. Worker-multi-port-expected.txt
  145. Worker-multi-port.html
  146. Worker-nested-importScripts-error-expected.txt
  147. Worker-nested-importScripts-error.html
  148. worker-performance.worker-expected.txt
  149. worker-performance.worker.html
  150. worker-performance.worker.js
  151. Worker-replace-event-handler.any.js
  152. Worker-replace-event-handler.any.serviceworker-expected.txt
  153. Worker-replace-event-handler.any.serviceworker.html
  154. Worker-replace-event-handler.any.sharedworker-expected.txt
  155. Worker-replace-event-handler.any.sharedworker.html
  156. Worker-replace-event-handler.any.worker-expected.txt
  157. Worker-replace-event-handler.any.worker.html
  158. Worker-replace-global-constructor.any.js
  159. Worker-replace-global-constructor.any.serviceworker-expected.txt
  160. Worker-replace-global-constructor.any.serviceworker.html
  161. Worker-replace-global-constructor.any.sharedworker-expected.txt
  162. Worker-replace-global-constructor.any.sharedworker.html
  163. Worker-replace-global-constructor.any.worker-expected.txt
  164. Worker-replace-global-constructor.any.worker.html
  165. Worker-replace-self.any.js
  166. Worker-replace-self.any.serviceworker-expected.txt
  167. Worker-replace-self.any.serviceworker.html
  168. Worker-replace-self.any.sharedworker-expected.txt
  169. Worker-replace-self.any.sharedworker.html
  170. Worker-replace-self.any.worker-expected.txt
  171. Worker-replace-self.any.worker.html
  172. Worker-simultaneous-errors-expected.txt
  173. Worker-simultaneous-errors.html
  174. Worker-structure-message-expected.txt
  175. Worker-structure-message.html
  176. Worker-terminate-forever-during-evaluation-expected.txt
  177. Worker-terminate-forever-during-evaluation.html
  178. Worker-terminate-forever-expected.txt
  179. Worker-terminate-forever.html
  180. Worker-termination-with-port-messages-expected.txt
  181. Worker-termination-with-port-messages.html
  182. Worker-timeout-cancel-order-expected.txt
  183. Worker-timeout-cancel-order.html
  184. Worker-timeout-decreasing-order-expected.txt
  185. Worker-timeout-decreasing-order.html
  186. Worker-timeout-increasing-order-expected.txt
  187. Worker-timeout-increasing-order.html
  188. Worker_basic-expected.txt
  189. Worker_basic.htm
  190. Worker_cross_origin_security_err-expected.txt
  191. Worker_cross_origin_security_err.htm
  192. Worker_dispatchEvent_ErrorEvent-expected.txt
  193. Worker_dispatchEvent_ErrorEvent.htm
  194. Worker_ErrorEvent_bubbles_cancelable-expected.txt
  195. Worker_ErrorEvent_bubbles_cancelable.htm
  196. Worker_ErrorEvent_error-expected.txt
  197. Worker_ErrorEvent_error.htm
  198. Worker_ErrorEvent_filename-expected.txt
  199. Worker_ErrorEvent_filename.htm
  200. Worker_ErrorEvent_lineno-expected.txt
  201. Worker_ErrorEvent_lineno.htm
  202. Worker_ErrorEvent_message-expected.txt
  203. Worker_ErrorEvent_message.htm
  204. Worker_ErrorEvent_type-expected.txt
  205. Worker_ErrorEvent_type.htm
  206. Worker_NosniffErr-expected.txt
  207. Worker_NosniffErr.htm
  208. Worker_script_mimetype-expected.txt
  209. Worker_script_mimetype.htm
  210. Worker_terminate_event_queue-expected.txt
  211. Worker_terminate_event_queue.htm
  212. WorkerGlobalScope-close-expected.txt
  213. WorkerGlobalScope-close.html
  214. WorkerGlobalScope_ErrorEvent_colno-expected.txt
  215. WorkerGlobalScope_ErrorEvent_colno.htm
  216. WorkerGlobalScope_ErrorEvent_filename-expected.txt
  217. WorkerGlobalScope_ErrorEvent_filename.htm
  218. WorkerGlobalScope_ErrorEvent_lineno-expected.txt
  219. WorkerGlobalScope_ErrorEvent_lineno.htm
  220. WorkerGlobalScope_ErrorEvent_message-expected.txt
  221. WorkerGlobalScope_ErrorEvent_message.htm
  222. WorkerGlobalScope_importScripts-expected.txt
  223. WorkerGlobalScope_importScripts.htm
  224. WorkerGlobalScope_importScripts_NetworkErr-expected.txt
  225. WorkerGlobalScope_importScripts_NetworkErr.htm
  226. WorkerGlobalScope_importScripts_NosniffErr-expected.txt
  227. WorkerGlobalScope_importScripts_NosniffErr.htm
  228. WorkerGlobalScope_requestAnimationFrame.tentative.worker-expected.txt
  229. WorkerGlobalScope_requestAnimationFrame.tentative.worker.html
  230. WorkerGlobalScope_requestAnimationFrame.tentative.worker.js
  231. WorkerGlobalScope_setInterval-expected.txt
  232. WorkerGlobalScope_setInterval.htm
  233. WorkerGlobalScope_setTimeout-expected.txt
  234. WorkerGlobalScope_setTimeout.htm
  235. WorkerLocation-expected.txt
  236. WorkerLocation-origin.sub.window-expected.txt
  237. WorkerLocation-origin.sub.window.html
  238. WorkerLocation-origin.sub.window.js
  239. WorkerLocation.htm
  240. WorkerLocation_hash-expected.txt
  241. WorkerLocation_hash.htm
  242. WorkerLocation_hash_encoding-expected.txt
  243. WorkerLocation_hash_encoding.htm
  244. WorkerLocation_hash_nonexist-expected.txt
  245. WorkerLocation_hash_nonexist.htm
  246. WorkerLocation_host-expected.txt
  247. WorkerLocation_host.htm
  248. WorkerLocation_hostname-expected.txt
  249. WorkerLocation_hostname.htm
  250. WorkerLocation_href-expected.txt
  251. WorkerLocation_href.htm
  252. WorkerLocation_pathname-expected.txt
  253. WorkerLocation_pathname.htm
  254. WorkerLocation_port-expected.txt
  255. WorkerLocation_port.htm
  256. WorkerLocation_protocol-expected.txt
  257. WorkerLocation_protocol.htm
  258. WorkerLocation_search-expected.txt
  259. WorkerLocation_search.htm
  260. WorkerLocation_search_empty-expected.txt
  261. WorkerLocation_search_empty.htm
  262. WorkerLocation_search_fragment-expected.txt
  263. WorkerLocation_search_fragment.htm
  264. WorkerLocation_search_nonexist-expected.txt
  265. WorkerLocation_search_nonexist.htm
  266. WorkerNavigator-hardware-concurrency.any.js
  267. WorkerNavigator-hardware-concurrency.any.serviceworker-expected.txt
  268. WorkerNavigator-hardware-concurrency.any.serviceworker.html
  269. WorkerNavigator-hardware-concurrency.any.sharedworker-expected.txt
  270. WorkerNavigator-hardware-concurrency.any.sharedworker.html
  271. WorkerNavigator-hardware-concurrency.any.worker-expected.txt
  272. WorkerNavigator-hardware-concurrency.any.worker.html
  273. WorkerNavigator.any.js
  274. WorkerNavigator.any.serviceworker-expected.txt
  275. WorkerNavigator.any.serviceworker.html
  276. WorkerNavigator.any.sharedworker-expected.txt
  277. WorkerNavigator.any.sharedworker.html
  278. WorkerNavigator.any.worker-expected.txt
  279. WorkerNavigator.any.worker.html
  280. WorkerNavigator_appName-expected.txt
  281. WorkerNavigator_appName.htm
  282. WorkerNavigator_appVersion-expected.txt
  283. WorkerNavigator_appVersion.htm
  284. WorkerNavigator_onLine-expected.txt
  285. WorkerNavigator_onLine.htm
  286. WorkerNavigator_platform-expected.txt
  287. WorkerNavigator_platform.htm
  288. WorkerNavigator_userAgent-expected.txt
  289. WorkerNavigator_userAgent.htm
  290. WorkerNavigator_userAgentData.http-expected.txt
  291. WorkerNavigator_userAgentData.http.html
  292. WorkerNavigator_userAgentData.https-expected.txt
  293. WorkerNavigator_userAgentData.https.html
  294. WorkerPerformanceNow-expected.txt
  295. 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.