tree: 0a84865d981017f02bb6fe3efe2cc343dd9319ac [path history] [tgz]
  1. baseurl/
  2. constructors/
  3. examples/
  4. interfaces/
  5. modules/
  6. multi-globals/
  7. non-automated/
  8. same-site-cookies/
  9. semantics/
  10. support/
  11. tentative/
  12. abrupt-completion.html
  13. data-url-shared-window.html
  14. data-url-shared.html
  15. data-url.html
  16. dedicated-worker-from-blob-url.window.js
  17. dedicated-worker-in-data-url-context.window-expected.txt
  18. dedicated-worker-in-data-url-context.window.js
  19. dedicated-worker-parse-error-failure-expected.txt
  20. dedicated-worker-parse-error-failure.html
  21. DIR_METADATA
  22. importscripts_mime.any.js
  23. importscripts_mime_local.any.js
  24. importscripts_mime_local.any.sharedworker-expected.txt
  25. importscripts_mime_local.any.worker-expected.txt
  26. META.yml
  27. name-property.html
  28. nested_worker.worker.js
  29. nested_worker_close_from_parent_worker.html
  30. nested_worker_close_self.worker.js
  31. nested_worker_importScripts.worker.js
  32. nested_worker_sync_xhr.worker.js
  33. nested_worker_terminate_from_document.html
  34. opaque-origin.html
  35. postMessage_block.https.html
  36. postMessage_block.https.html.headers
  37. postMessage_clone_port.htm
  38. postMessage_clone_port_error.htm
  39. postMessage_DataCloneErr.htm
  40. postMessage_event_properties.htm
  41. postMessage_ports_readonly_array.htm
  42. postMessage_target_source.htm
  43. README.md
  44. same-origin-check.sub.html
  45. shared-worker-from-blob-url.window.js
  46. shared-worker-in-data-url-context.window-expected.txt
  47. shared-worker-in-data-url-context.window.js
  48. shared-worker-name-via-options.html
  49. shared-worker-options-mismatch.html
  50. shared-worker-parse-error-failure.html
  51. shared-worker-partitioned-cookies.tentative.https.html
  52. shared-worker-partitioned.tentative.html
  53. SharedWorker-constructor.html
  54. SharedWorker-detach-frame-in-error-event.html
  55. SharedWorker-exception-propagation.html
  56. SharedWorker-exception.html
  57. SharedWorker-MessageEvent-source.any.js
  58. SharedWorker-replace-EventHandler.any.js
  59. SharedWorker-script-error.html
  60. SharedWorker-simple.html
  61. SharedWorker_blobUrl.html
  62. SharedWorker_dataUrl.html
  63. SharedWorkerPerformanceNow.html
  64. WEB_FEATURES.yml
  65. Worker-base64.any.js
  66. Worker-call.worker.js
  67. Worker-constructor-proto.any.js
  68. Worker-creation-happens-in-parallel.https-expected.txt
  69. Worker-creation-happens-in-parallel.https.html
  70. Worker-creation-happens-in-parallel.https.html.headers
  71. Worker-custom-event.any.js
  72. Worker-formdata.any.js
  73. Worker-location.sub.any.js
  74. Worker-messageport.html
  75. Worker-multi-port.html
  76. Worker-nested-importScripts-error.html
  77. worker-performance.worker.js
  78. Worker-postMessage-happens-in-parallel.https.html
  79. Worker-postMessage-happens-in-parallel.https.html.headers
  80. Worker-replace-event-handler.any.js
  81. Worker-replace-global-constructor.any.js
  82. Worker-replace-self.any.js
  83. worker-request-animation-frame.html
  84. Worker-simultaneous-errors.html
  85. Worker-structure-message.html
  86. Worker-terminate-forever-during-evaluation.html
  87. Worker-terminate-forever.html
  88. Worker-termination-with-port-messages.html
  89. Worker-timeout-cancel-order.html
  90. Worker-timeout-decreasing-order.html
  91. Worker-timeout-increasing-order.html
  92. Worker_basic.htm
  93. Worker_cross_origin_security_err-expected.txt
  94. Worker_cross_origin_security_err.htm
  95. Worker_dispatchEvent_ErrorEvent.htm
  96. Worker_ErrorEvent_bubbles_cancelable.htm
  97. Worker_ErrorEvent_error.htm
  98. Worker_ErrorEvent_filename.htm
  99. Worker_ErrorEvent_lineno.htm
  100. Worker_ErrorEvent_message.htm
  101. Worker_ErrorEvent_type.htm
  102. Worker_NosniffErr.htm
  103. Worker_script_mimetype.htm
  104. Worker_terminate_event_queue.htm
  105. WorkerGlobalScope-close.html
  106. WorkerGlobalScope_ErrorEvent_colno.htm
  107. WorkerGlobalScope_ErrorEvent_filename.htm
  108. WorkerGlobalScope_ErrorEvent_lineno.htm
  109. WorkerGlobalScope_ErrorEvent_message.htm
  110. WorkerGlobalScope_importScripts.htm
  111. WorkerGlobalScope_importScripts_NetworkErr.htm
  112. WorkerGlobalScope_importScripts_NosniffErr.htm
  113. WorkerGlobalScope_requestAnimationFrame.worker.js
  114. WorkerGlobalScope_setInterval.htm
  115. WorkerGlobalScope_setTimeout.htm
  116. WorkerLocation-origin.sub.window.js
  117. WorkerLocation.htm
  118. WorkerLocation_hash.htm
  119. WorkerLocation_hash_encoding.htm
  120. WorkerLocation_hash_nonexist.htm
  121. WorkerLocation_host.htm
  122. WorkerLocation_hostname.htm
  123. WorkerLocation_href.htm
  124. WorkerLocation_pathname.htm
  125. WorkerLocation_port.htm
  126. WorkerLocation_protocol.htm
  127. WorkerLocation_search.htm
  128. WorkerLocation_search_empty.htm
  129. WorkerLocation_search_fragment.htm
  130. WorkerLocation_search_nonexist.htm
  131. WorkerNavigator-hardware-concurrency.any.js
  132. WorkerNavigator.any.js
  133. WorkerNavigator_appName.htm
  134. WorkerNavigator_appVersion.htm
  135. WorkerNavigator_onLine.htm
  136. WorkerNavigator_platform.htm
  137. WorkerNavigator_userAgent.htm
  138. WorkerNavigator_userAgentData.http.html
  139. WorkerNavigator_userAgentData.https.html
  140. WorkerNavigator_userAgentData.https.tentative.html
  141. WorkerPerformanceNow.html
third_party/blink/web_tests/external/wpt/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.