Supports :has() pseudo class matching

Add :has() pseudo class syntax support and matching logic behind a
runtime test feature (CSSPseudoHas)

<Syntax support>
Add syntax support for :has() pseudo class specified in Selectors 4.
 - https://www.w3.org/TR/selectors-4/#relational

:has() pseudo class takes a relatvie selector list as an argument.
 - :has(<relative-selector-list>)
 - <relative-selector-list> = <relative-selector>#
 - <relative-selector> = <combinator>? <complex-selector>

<relative-selector> is also specified in Selector 4, but it is not
supported yet.
 - https://www.w3.org/TR/selectors-4/#relative

So this CL only supports :has argument selectors starting with
descendant combinator. Argument selectors starting with other
combinators are not supported yet.
 - .a:has(.b)    : Supported
 - .a:has(> .b)  : Not supported yet
 - .a:has(~ .b)  : Not supported yet
 - .a:has(+ .b)  : Not supported yet

<Selector matching>
Add :has() pseudo class selector matching logic.

This CL suggests a stack-allocated :has() matching status cache
to prevent repetitive tree traversal and argument selector matching
operation.

The cache stores each element status as below.
 - Matched : Checked :has() and matched
 - Checked : Checked :has() but not matched
 - NotChecked : Not checked :has() (default)

This is the pseudo code of the matching operation for the :has
pseudo class with descendant relative argument selectors.
(e.g. ':has(.a)' or ':has(:scope .a)')

 ┬ Allocate cache on stack memory
 ├ Enter the style recalculation(or node selector API) sequence
 │  ├ ...
 │  ├ Enter the selector matching sequence
 │  │  ├ If matching :has pseudo class on an element
 │  │  │  └ Enter :has selector matching sequence
 │  │  │     ├ Get argument selector
 │  │  │     ├ Get element status from cache
 │  │  │     ├ If the element status is checked
 │  │  │     │  └ If the element status is matched
 │  │  │     │    └ Finish has pseudo class matching as matched
 │  │  │     ├ Else
 │  │  │     │  ├ Set the element status as checked
 │  │  │     │  └ Traverse all descendants of the element
 │  │  │     │    ├ Get the descendant status from cache
 │  │  │     │    ├ If the descendant status is checked
 │  │  │     │    │  └ If the descendant status is matched
 │  │  │     │    │    ├ Set the element status as matched
 │  │  │     │    │    └ Finish has pseudo class matching as matched
 │  │  │     │    └ Else
 │  │  │     │      ├ Set the descendant status as checked
 │  │  │     │      └ If the descendant matches the argument selector
 │  │  │     │        ├ Get start element of the shortest match
 │  │  │     │        ├ Traverse it's ancestors until met the element
 │  │  │     │        │  └ Set the ancestor status as matched
 │  │  │     │        ├ Set the element status as matched
 │  │  │     │        └ Finish has pseudo class matching as matched
 │  │  │     └ Finish has pseudo class matching as not matched
 │  │  └ Otherwise
 │  │     └ Do other selector matching sequence
 │  └ ...
 └ Release cache from stack memory

Other cases will be handled later in the separated CLs.
 - :has(> .a) or :has(:scope > .a)
 - :has(~ .a) or :has(:scope ~ .a)
 - :has(+ .a) or :has(:scope + .a)

This CL supports :has with the following javascript APIs.
 - querySelector
 - querySelectorAll
 - matches
 - closest

Changes in this CL were originally in the below 2 CLs. Those are
merged to prevent a web_test failure. (jquery/traversing.html)
 - https://chromium-review.googlesource.com/c/chromium/src/+/2648150
 - https://chromium-review.googlesource.com/c/chromium/src/+/2695192

Change-Id: I1992b70d86f47fc5f98437e1e6abea2da021ef6b
Bug: 669058
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2914717
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Byungwoo Lee <blee@igalia.com>
Cr-Commit-Position: refs/heads/master@{#888799}
2 files changed
tree: 2051f84c26a8ae30b7d509d78a1ff770786ac035
  1. .github/
  2. .well-known/
  3. accelerometer/
  4. accessibility/
  5. accname/
  6. acid/
  7. ambient-light/
  8. animation-worklet/
  9. annotation-model/
  10. annotation-protocol/
  11. annotation-vocab/
  12. apng/
  13. appmanifest/
  14. audio-output/
  15. background-fetch/
  16. BackgroundSync/
  17. badging/
  18. battery-status/
  19. beacon/
  20. bluetooth/
  21. clear-site-data/
  22. client-hints/
  23. clipboard-apis/
  24. common/
  25. compat/
  26. compression/
  27. compute-pressure/
  28. conformance-checkers/
  29. console/
  30. contacts/
  31. content-dpr/
  32. content-index/
  33. content-security-policy/
  34. contenteditable/
  35. cookie-store/
  36. cookies/
  37. core-aam/
  38. cors/
  39. credential-management/
  40. css/
  41. custom-elements/
  42. custom-state-pseudo-class/
  43. delegated-ink/
  44. density-size-correction/
  45. deprecation-reporting/
  46. device-memory/
  47. docs/
  48. document-policy/
  49. dom/
  50. domparsing/
  51. domxpath/
  52. dpub-aam/
  53. dpub-aria/
  54. editing/
  55. element-timing/
  56. encoding/
  57. encoding-detection/
  58. encrypted-media/
  59. entries-api/
  60. event-timing/
  61. eventsource/
  62. feature-policy/
  63. fetch/
  64. file-system-access/
  65. FileAPI/
  66. focus/
  67. font-access/
  68. fonts/
  69. forced-colors-mode/
  70. fullscreen/
  71. gamepad/
  72. generic-sensor/
  73. geolocation-API/
  74. geolocation-sensor/
  75. graphics-aam/
  76. gyroscope/
  77. hr-time/
  78. html/
  79. html-longdesc/
  80. html-media-capture/
  81. idle-detection/
  82. imagebitmap-renderingcontext/
  83. images/
  84. import-maps/
  85. IndexedDB/
  86. inert/
  87. infrastructure/
  88. input-device-capabilities/
  89. input-events/
  90. installedapp/
  91. interfaces/
  92. intersection-observer/
  93. intervention-reporting/
  94. is-input-pending/
  95. js/
  96. js-self-profiling/
  97. keyboard-lock/
  98. keyboard-map/
  99. largest-contentful-paint/
  100. layout-instability/
  101. lifecycle/
  102. loading/
  103. longtask-timing/
  104. magnetometer/
  105. managed/
  106. mathml/
  107. measure-memory/
  108. media/
  109. media-capabilities/
  110. media-playback-quality/
  111. media-source/
  112. mediacapture-depth/
  113. mediacapture-fromelement/
  114. mediacapture-image/
  115. mediacapture-insertable-streams/
  116. mediacapture-record/
  117. mediacapture-streams/
  118. mediasession/
  119. merchant-validation/
  120. mimesniff/
  121. mixed-content/
  122. mst-content-hint/
  123. native-io/
  124. navigation-timing/
  125. netinfo/
  126. network-error-logging/
  127. notifications/
  128. old-tests/
  129. orientation-event/
  130. orientation-sensor/
  131. origin-policy/
  132. page-lifecycle/
  133. page-visibility/
  134. paint-timing/
  135. payment-handler/
  136. payment-method-basic-card/
  137. payment-method-id/
  138. payment-request/
  139. performance-timeline/
  140. periodic-background-sync/
  141. permissions/
  142. permissions-policy/
  143. permissions-request/
  144. permissions-revoke/
  145. picture-in-picture/
  146. pointerevents/
  147. pointerlock/
  148. portals/
  149. preload/
  150. presentation-api/
  151. priority-hints/
  152. private-click-measurement/
  153. proximity/
  154. push-api/
  155. quirks/
  156. raw-sockets/
  157. referrer-policy/
  158. remote-playback/
  159. reporting/
  160. requestidlecallback/
  161. resize-observer/
  162. resource-timing/
  163. resources/
  164. sanitizer-api/
  165. savedata/
  166. screen-capture/
  167. screen-orientation/
  168. screen-wake-lock/
  169. screen_enumeration/
  170. scroll-animations/
  171. scroll-to-text-fragment/
  172. secure-contexts/
  173. secure-payment-confirmation/
  174. selection/
  175. serial/
  176. server-timing/
  177. service-workers/
  178. shadow-dom/
  179. shape-detection/
  180. signed-exchange/
  181. speech-api/
  182. storage/
  183. storage-access-api/
  184. streams/
  185. subresource-integrity/
  186. svg/
  187. svg-aam/
  188. timing-entrytypes-registry/
  189. tools/
  190. touch-events/
  191. trust-tokens/
  192. trusted-types/
  193. ua-client-hints/
  194. uievents/
  195. upgrade-insecure-requests/
  196. url/
  197. urlpattern/
  198. user-timing/
  199. vibration/
  200. video-rvfc/
  201. visual-viewport/
  202. wai-aria/
  203. wasm/
  204. web-animations/
  205. web-bundle/
  206. web-locks/
  207. web-nfc/
  208. web-otp/
  209. web-share/
  210. webaudio/
  211. webauthn/
  212. webcodecs/
  213. WebCryptoAPI/
  214. webdriver/
  215. webgl/
  216. webgpu/
  217. webhid/
  218. WebIDL/
  219. webmessaging/
  220. webmidi/
  221. webrtc/
  222. webrtc-encoded-transform/
  223. webrtc-extensions/
  224. webrtc-ice/
  225. webrtc-identity/
  226. webrtc-priority/
  227. webrtc-stats/
  228. webrtc-svc/
  229. websockets/
  230. webstorage/
  231. webtransport/
  232. webusb/
  233. webvr/
  234. webvtt/
  235. webxr/
  236. window-segments/
  237. workers/
  238. worklets/
  239. x-frame-options/
  240. xhr/
  241. .azure-pipelines.yml
  242. .gitattributes
  243. .gitignore
  244. .mailmap
  245. .pyup.yml
  246. .taskcluster.yml
  247. CODE_OF_CONDUCT.md
  248. CODEOWNERS
  249. CONTRIBUTING.md
  250. LICENSE.md
  251. lint.ignore
  252. README.md
  253. testharness_runner.html
  254. update-built-tests.sh
  255. wpt
  256. wpt.py
README.md

The web-platform-tests Project

Taskcluster CI Status documentation manifest Python 3

The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.

The most important sources of information and activity are:

  • github.com/web-platform-tests/wpt: the canonical location of the project's source code revision history and the discussion forum for changes to the code
  • web-platform-tests.org: the documentation website; details how to set up the project, how to write tests, how to give and receive peer review, how to serve as an administrator, and more
  • wpt.live: a public deployment of the test suite, allowing anyone to run the tests by visiting from an Internet-enabled browser of their choice
  • wpt.fyi: an archive of test results collected from an array of web browsers on a regular basis
  • Real-time chat room: the IRC chat room named #testing on irc.w3.org; includes participants located around the world, but busiest during the European working day; all discussion is archived here
  • Mailing list: a public and low-traffic discussion list
  • RFCs: a repo for requesting comments on substantial changes that would impact other stakeholders or users; people who work on WPT infra are encouraged to watch the repo.

If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.

Setting Up the Repo

Clone or otherwise get https://github.com/web-platform-tests/wpt.

Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).

Running the Tests

See the documentation website and in particular the system setup for running tests locally.

Command Line Tools

The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:

  • wpt serve - For starting the wpt http server
  • wpt run - For running tests in a browser
  • wpt lint - For running the lint against all tests
  • wpt manifest - For updating or generating a MANIFEST.json test manifest
  • wpt install - For installing the latest release of a browser or webdriver server on the local machine.
  • wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.

Windows Notes

On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).

python wpt [command]

Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.

Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.

Publication

The master branch is automatically synced to wpt.live and w3c-test.org.

Pull requests are automatically mirrored except those that modify sensitive resources (such as .py). The latter require someone with merge access to comment with “LGTM” or “w3c-test:mirror” to indicate the pull request has been checked.

Contributing

Save the Web, Write Some Tests!

Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.

The way to contribute is just as usual:

  • Fork this repository (and make sure you're still relatively in sync with it if you forked a while ago).
  • Create a branch for your changes: git checkout -b topic.
  • Make your changes.
  • Run ./wpt lint as described above.
  • Commit locally and push that to your repo.
  • Create a pull request based on the above.

Issues with web-platform-tests

If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!