Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the way DOM parent pointers are handled #283

Merged
merged 14 commits into from
Jul 1, 2020
Merged
5 changes: 1 addition & 4 deletions packages/alfa-angular/src/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Type,
} from "@siteimprove/alfa-dom";
import { Request, Response } from "@siteimprove/alfa-http";
import { Option } from "@siteimprove/alfa-option";
import { Page } from "@siteimprove/alfa-web";

import { ComponentFixture } from "@angular/core/testing";
Expand All @@ -32,9 +31,7 @@ export namespace Angular {
return Page.of(
Request.empty(),
Response.empty(),
Document.of((self) => [
Element.fromElement(toElement(nativeElement), Option.of(self)),
]),
Document.of([Element.from(toElement(nativeElement))]),
Device.standard()
);
}
Expand Down
64 changes: 30 additions & 34 deletions packages/alfa-aria/test/get-name.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import { getName } from "../src/get-name";
const device = Device.standard();

test("getName() computes the text alternative of a button with text", (t) => {
const button = Element.fromElement(<button>Button</button>);
const button = <button>Button</button>;

t.deepEqual(getName(button, device).toArray(), [[Some.of("Button"), []]]);
});

test("getName() correctly resolves explicit roles", (t) => {
const button = Element.fromElement(<div role="button">Button</div>);
const button = <div role="button">Button</div>;

t.deepEqual(getName(button, device).toArray(), [[Some.of("Button"), []]]);
});

test("getName() computes the text alternative of a button with text within a span", (t) => {
const button = Element.fromElement(
const button = (
<button>
<span>Button</span>
</button>
Expand All @@ -33,7 +33,7 @@ test("getName() computes the text alternative of a button with text within a spa
});

test("getName() ignores non-visible nodes", (t) => {
const button = Element.fromElement(
const button = (
<button>
Button <span style={{ display: "none" }}>Hidden</span>
</button>
Expand All @@ -43,31 +43,29 @@ test("getName() ignores non-visible nodes", (t) => {
});

test("getName() computes the text alternative of a button with a title and no text", (t) => {
const button = Element.fromElement(<button title="Hello world" />);
const button = <button title="Hello world" />;

t.deepEqual(getName(button, device).toArray(), [
[Some.of("Hello world"), []],
]);
});

test("getName() computes the text alternative of a button with an aria-label", (t) => {
const button = Element.fromElement(
<button aria-label="Hello world">Button</button>
);
const button = <button aria-label="Hello world">Button</button>;

t.deepEqual(getName(button, device).toArray(), [
[Some.of("Hello world"), []],
]);
});

test("getName() falls through when aria-label is the empty string", (t) => {
const button = Element.fromElement(<button aria-label="">Button</button>);
const button = <button aria-label="">Button</button>;

t.deepEqual(getName(button, device).toArray(), [[Some.of("Button"), []]]);
});

test("getName() computes the text alternative of a button with an aria-labelledby", (t) => {
const div = Element.fromElement(
const div = (
<div>
<button aria-labelledby="h w">Button</button>
<p id="h">Hello</p>
Expand All @@ -83,15 +81,13 @@ test("getName() computes the text alternative of a button with an aria-labelledb
});

test("getName() falls through when no valid ID is found in aria-labelledby", (t) => {
const button = Element.fromElement(
<button aria-labelledby="h w">Button</button>
);
const button = <button aria-labelledby="h w">Button</button>;

t.deepEqual(getName(button, device).toArray(), [[Some.of("Button"), []]]);
});

test("getName() does not infitely recurse when recursive aria-labelledby references are encountered", (t) => {
const button = Element.fromElement(
const button = (
<button id="button">
Hello <span aria-labelledby="button">world</span>
</button>
Expand All @@ -103,61 +99,61 @@ test("getName() does not infitely recurse when recursive aria-labelledby referen
});

test("getName() returns none when a button has no text alternative", (t) => {
const button = Element.fromElement(<button />);
const button = <button />;

t.deepEqual(getName(button, device).toArray(), [[None, []]]);
});

test("getName() computes the text alternative of an image with an alt", (t) => {
const img = Element.fromElement(<img src="foo.png" alt="Hello world" />);
const img = <img src="foo.png" alt="Hello world" />;

t.deepEqual(getName(img, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() computes the text alternative of an image with a title", (t) => {
const img = Element.fromElement(<img src="foo.png" title="Hello world" />);
const img = <img src="foo.png" title="Hello world" />;

t.deepEqual(getName(img, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() returns none when an image has no text alternative", (t) => {
const img = Element.fromElement(<img src="foo.png" />);
const img = <img src="foo.png" />;

t.deepEqual(getName(img, device).toArray(), [[None, []]]);
});

test("getName() computes the text alternative of a paragraph with a title", (t) => {
const p = Element.fromElement(<p title="Hello world">Paragraph</p>);
const p = <p title="Hello world">Paragraph</p>;

t.deepEqual(getName(p, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() computes the text alternative of a paragraph with an aria-label", (t) => {
const p = Element.fromElement(<p aria-label="Hello world">Paragraph</p>);
const p = <p aria-label="Hello world">Paragraph</p>;

t.deepEqual(getName(p, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() returns none when a paragraph has no text alternative", (t) => {
const p = Element.fromElement(<p>Paragraph</p>);
const p = <p>Paragraph</p>;

t.deepEqual(getName(p, device).toArray(), [[None, []]]);
});

test("getName() computes the text alternative of an anchor with an href", (t) => {
const a = Element.fromElement(<a href="http://foo.com">Hello world</a>);
const a = <a href="http://foo.com">Hello world</a>;

t.deepEqual(getName(a, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() computes the text alternative of an anchor without an href", (t) => {
const a = Element.fromElement(<a>Hello world</a>);
const a = <a>Hello world</a>;

t.deepEqual(getName(a, device).toArray(), [[Some.of("Hello world"), []]]);
});

test("getName() computes the text alternative of an anchor with a labelled image", (t) => {
const a = Element.fromElement(
const a = (
<a href="http://foo.com">
<img alt="Hello world" />
</a>
Expand All @@ -167,7 +163,7 @@ test("getName() computes the text alternative of an anchor with a labelled image
});

test("getName() computes the text alternative of a table with a caption", (t) => {
const table = Element.fromElement(
const table = (
<table>
<caption>Hello world</caption>
<tbody>
Expand All @@ -182,7 +178,7 @@ test("getName() computes the text alternative of a table with a caption", (t) =>
});

test("getName() computes the text alternative of a figure with a figcaption", (t) => {
const figure = Element.fromElement(
const figure = (
<figure>
<img src="foo.png" alt="Foo" />
<figcaption>Hello world</figcaption>
Expand All @@ -195,7 +191,7 @@ test("getName() computes the text alternative of a figure with a figcaption", (t
});

test("getName() computes the text alternative of a fieldset with a legend", (t) => {
const fieldset = Element.fromElement(
const fieldset = (
<fieldset>
<legend>Hello world</legend>
<input type="submit" />
Expand All @@ -208,7 +204,7 @@ test("getName() computes the text alternative of a fieldset with a legend", (t)
});

test("getName() computes the text alternative of an input with an explicit label", (t) => {
const div = Element.fromElement(
const div = (
<div>
<label for="test">Hello world</label>
<input type="text" id="test" />
Expand All @@ -225,7 +221,7 @@ test("getName() computes the text alternative of an input with an explicit label
});

test("getName() computes the text alternative of an input with an implicit label", (t) => {
const label = Element.fromElement(
const label = (
<label>
Hello world
<input type="text" id="test" />
Expand All @@ -238,7 +234,7 @@ test("getName() computes the text alternative of an input with an implicit label
});

test("getName() computes the text alternative of an input with an explicit label that includes an embedded control", (t) => {
const div = Element.fromElement(
const div = (
<div>
<label for="test">
<textarea>Hello world</textarea>
Expand All @@ -257,7 +253,7 @@ test("getName() computes the text alternative of an input with an explicit label
});

test("getName() computes the text alternative of an SVG with a title element", (t) => {
const svg = Element.fromElement(
const svg = (
<svg>
<title>Hello world</title>
<g>
Expand All @@ -270,7 +266,7 @@ test("getName() computes the text alternative of an SVG with a title element", (
});

test("getName() computes the text alternative of an element with content in Shadow DOM", (t) => {
const div = Element.fromElement(
const div = (
<div>
<p id="foo">
<shadow>Hello world</shadow>
Expand All @@ -291,7 +287,7 @@ test("getName() computes the text alternative of an element with content in Shad
});

test("getName() correctly handles browser specific case sensitivity of roles", (t) => {
const button = Element.fromElement(<div role="Button">Button</div>);
const button = <div role="Button">Button</div>;

t.deepEqual(getName(button, device).toArray(), [
[Some.of("Button"), []],
Expand All @@ -300,7 +296,7 @@ test("getName() correctly handles browser specific case sensitivity of roles", (
});

test("getName() correctly handles aria-labelledby that points to aria-hidden=true", (t) => {
const button = Element.fromElement(
const button = (
<button aria-labelledby="foo">
<span id="foo" aria-hidden="true">
Hello world
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-cascade/src/cascade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export namespace Cascade {
const cache = Cache.empty<Device, Cache<Document | Shadow, Cascade>>();

export function from(node: Document | Shadow, device: Device): Cascade {
return cache.get(device, Cache.empty).get(node, () => {
return cache.get(device, Cache.empty).get(node.freeze(), () => {
const filter = AncestorFilter.empty();
const ruleTree = RuleTree.empty();
const selectorMap = SelectorMap.of([UserAgent, ...node.style], device);
Expand Down
5 changes: 3 additions & 2 deletions packages/alfa-cascade/src/selector-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ export class SelectorMap {
return;
}

const origin =
rule.owner === UserAgent ? Origin.UserAgent : Origin.Author;
const origin = rule.owner.includes(UserAgent)
? Origin.UserAgent
: Origin.Author;

order++;

Expand Down
Loading