From f49666e9ba063d57bbd197aa78602824fbe46159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rolf=20Christian=20J=C3=B8rgensen?= <114920418+rcj-siteimprove@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:19:12 +0100 Subject: [PATCH] Assume audio is playing and that it has controls based on attributes (#1538) * Update audio applicability * Add tests for autoplay case * Update audio applicability It now ask about play button when controls attribute is present on element * Add changeset * Add tests for audio elements with autoplay and controls attributes These tests exemplify that the `is-playing` and `play-button` questions are not needed anymore for the rules to pass or fail when the relevant attributes are present. * Fix test --- .changeset/tasty-stingrays-grab.md | 5 + .../src/common/applicability/audio.ts | 28 ++-- .../alfa-rules/test/sia-r23/rule.spec.tsx | 135 ++++++++++++++++ .../alfa-rules/test/sia-r29/rule.spec.tsx | 153 ++++++++++++++++++ 4 files changed, 309 insertions(+), 12 deletions(-) create mode 100644 .changeset/tasty-stingrays-grab.md diff --git a/.changeset/tasty-stingrays-grab.md b/.changeset/tasty-stingrays-grab.md new file mode 100644 index 0000000000..b724e25746 --- /dev/null +++ b/.changeset/tasty-stingrays-grab.md @@ -0,0 +1,5 @@ +--- +"@siteimprove/alfa-rules": patch +--- + +**Changed:** Media rules R23 and R29 no longer asks if audio is playing or where the play buttons is when the attributes `autoplay` and `controls` are present respectively. diff --git a/packages/alfa-rules/src/common/applicability/audio.ts b/packages/alfa-rules/src/common/applicability/audio.ts index 335cb4b90b..344a7d0e9a 100644 --- a/packages/alfa-rules/src/common/applicability/audio.ts +++ b/packages/alfa-rules/src/common/applicability/audio.ts @@ -17,7 +17,7 @@ import { Style } from "@siteimprove/alfa-style"; import { Question } from "../act/question"; const { isPerceivableForAll } = DOM; -const { isElement, hasName, hasNamespace } = Element; +const { isElement, hasName, hasNamespace, hasAttribute } = Element; const { and } = Predicate; const { isRendered } = Style; const { getElementDescendants } = Query; @@ -44,17 +44,21 @@ export function audio( Question.of("is-audio-streaming", element).map((isStreaming) => isStreaming ? None - : Question.of("is-playing", element).map((isPlaying) => - isPlaying - ? Option.of(element) - : Question.of("play-button", element).map((playButton) => - playButton.some( - and(isElement, isPerceivableForAll(device)), - ) - ? Option.of(element) - : None, - ), - ), + : Question.of("is-playing", element) + .answerIf(hasAttribute("autoplay"), true) + .map((isPlaying) => + isPlaying + ? Option.of(element) + : Question.of("play-button", element) + .answerIf(hasAttribute("controls"), Option.of(element)) + .map((playButton) => + playButton.some( + and(isElement, isPerceivableForAll(device)), + ) + ? Option.of(element) + : None, + ), + ), ), ), ); diff --git a/packages/alfa-rules/test/sia-r23/rule.spec.tsx b/packages/alfa-rules/test/sia-r23/rule.spec.tsx index c60a0c6d19..7cc75c172f 100755 --- a/packages/alfa-rules/test/sia-r23/rule.spec.tsx +++ b/packages/alfa-rules/test/sia-r23/rule.spec.tsx @@ -37,6 +37,59 @@ test(`evaluate() passes an audio with perceivable transcript`, async (t) => { ); }); +test(`evaluate() passes an audio with autoplay attribute and with perceivable transcript`, async (t) => { + const target =