diff options
Diffstat (limited to 'testing/web-platform/tests/svg/struct/scripted')
4 files changed, 215 insertions, 0 deletions
diff --git a/testing/web-platform/tests/svg/struct/scripted/autofocus-attribute.svg b/testing/web-platform/tests/svg/struct/scripted/autofocus-attribute.svg new file mode 100644 index 0000000000..edf200c4c7 --- /dev/null +++ b/testing/web-platform/tests/svg/struct/scripted/autofocus-attribute.svg @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" + xmlns:h="http://www.w3.org/1999/xhtml"> + <title>Autofocus attribute</title> + <metadata> + <h:link rel="help" href="https://svgwg.org/svg2-draft/struct.html#autofocusattribute"/> + </metadata> + <h:script src="/resources/testharness.js"/> + <h:script src="/resources/testharnessreport.js"/> + <h:script src="/html/interaction/focus/the-autofocus-attribute/resources/utils.js"/> + <script><![CDATA[ +const SVG_NS = 'http://www.w3.org/2000/svg'; + +promise_test(async t => { + let w = window.open('blank.svg'); + await waitForLoad(w); + t.add_cleanup(() => { w.close(); }); + const svgA = w.document.createElementNS(SVG_NS, 'a'); + svgA.setAttribute('href', '#'); + svgA.setAttribute('autofocus', 'autofocus'); + w.document.documentElement.appendChild(svgA); + await waitUntilStableAutofocusState(w); + assert_equals(w.document.activeElement, svgA); +}, '<a> should support autofocus'); + +promise_test(async t => { + let w = window.open('blank.svg'); + await waitForLoad(w); + t.add_cleanup(() => { w.close(); }); + const path = w.document.createElementNS(SVG_NS, 'path'); + path.setAttribute('d', 'M0,0h8v8z'); + path.setAttribute('tabindex', '0'); + path.setAttribute('autofocus', 'autofocus'); + w.document.documentElement.appendChild(path); + await waitUntilStableAutofocusState(w); + assert_equals(w.document.activeElement, path); +}, 'Renderable element with tabindex should support autofocus'); + +promise_test(async t => { + let w = window.open('blank.svg'); + await waitForLoad(w); + t.add_cleanup(() => { w.close(); }); + let element = w.document.createElementNS(SVG_NS, 'metadata'); + element.setAttribute('tabindex', '0'); + element.setAttribute('autofocus', 'autofocus'); + w.document.documentElement.appendChild(element); + await waitUntilStableAutofocusState(w); + // https://html.spec.whatwg.org/C/#dom-documentorshadowroot-activeelement + // 6. If candidate's document element is non-null, then return that document + // element. + assert_equals(w.document.activeElement.tagName, 'svg'); +}, 'Never-rendered element with tabindex should not support autofocus'); +]]></script> +</svg> diff --git a/testing/web-platform/tests/svg/struct/scripted/blank.svg b/testing/web-platform/tests/svg/struct/scripted/blank.svg new file mode 100644 index 0000000000..9e560bdc5f --- /dev/null +++ b/testing/web-platform/tests/svg/struct/scripted/blank.svg @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg"></svg> diff --git a/testing/web-platform/tests/svg/struct/scripted/svg-getIntersectionList.svg b/testing/web-platform/tests/svg/struct/scripted/svg-getIntersectionList.svg new file mode 100644 index 0000000000..a360bad3d3 --- /dev/null +++ b/testing/web-platform/tests/svg/struct/scripted/svg-getIntersectionList.svg @@ -0,0 +1,31 @@ +<svg xmlns="http://www.w3.org/2000/svg" + xmlns:html="http://www.w3.org/1999/xhtml"> +<html:link rel="help" href="https://svgwg.org/svg2-draft/struct.html#__svg__SVGSVGElement__getIntersectionList"/> +<html:script src="/resources/testharness.js"/> +<html:script src="/resources/testharnessreport.js"/> +<html:link rel="stylesheet" href="/fonts/ahem.css"/> +<style> +text { + font-family: Ahem; + font-size: 100px; +} +</style> +<text x="0" y="80">Text0</text> +<text x="0" y="80" style="display:none">Text1</text> +<text x="0" y="80" pointer-events="none">Text2</text> +<text x="0" y="80">Text3</text> + +<script> +test(t => { + const svg = document.documentElement; + const rect = svg.createSVGRect(); + rect.x = 10; + rect.y = 70; + rect.width = 20; + rect.height = 20; + const texts = document.querySelectorAll('text'); + const list = svg.getIntersectionList(rect, null); + assert_array_equals(list, [texts[0], texts[3]]); +}, 'SVGSVGElement.getIntersectionList()'); +</script> +</svg> diff --git a/testing/web-platform/tests/svg/struct/scripted/use-load-error-events.tentative.html b/testing/web-platform/tests/svg/struct/scripted/use-load-error-events.tentative.html new file mode 100644 index 0000000000..9cbaa0e220 --- /dev/null +++ b/testing/web-platform/tests/svg/struct/scripted/use-load-error-events.tentative.html @@ -0,0 +1,128 @@ +<!doctype html> +<title>'load' and 'error' events for SVG <use></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/rendering-utils.js"></script> +<svg> + <defs> + <rect id="local" width="100" height="100" fill="blue"/> + </defs> +</svg> +<script> + function newUseElement() { + return document.createElementNS('http://www.w3.org/2000/svg', 'use'); + } + function makeWatcher(root, eventType, url) { + return new Promise(resolve => { + const watcher = newUseElement(); + watcher.addEventListener(eventType, resolve); + watcher.setAttribute('href', url); + root.appendChild(watcher); + }); + } + function expectEvents(t, element, event) { + return new EventWatcher(t, element, ['load', 'error']).wait_for(event); + } + const DATA_URL_PAYLOAD = + '<svg xmlns="http://www.w3.org/2000/svg"><rect id="green" fill="lime" width="100" height="50"/></svg>'; + const cookie = Date.now(); + let counter = 0; + function makeCookie(index) { + return `${cookie}-${index}`; + } + function getUrl(type) { + const cookie = makeCookie(counter++); + switch (type) { + case 'existing': + return `/images/colors.svg?${cookie}#green`; + case 'existing-data': + return `data:image/svg+xml,${DATA_URL_PAYLOAD}#green`; + case 'non-existing': + return `/images/this-file-should-not-exist.svg?${cookie}#green`; + case 'broken': + return `/images/fail.gif?${cookie}#green`; + } + } + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + expectEvents(t, use, []); + svg.appendChild(use).setAttribute('href', '#local'); + return waitForAtLeastOneFrame(); + }, document.title + ', local reference, existing'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + expectEvents(t, use, []); + svg.appendChild(use).setAttribute('href', '#local_not_there'); + return waitForAtLeastOneFrame(); + }, document.title + ', local reference, non-existing'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + const watcher = expectEvents(t, use, ['load']); + const url = getUrl('existing'); + svg.appendChild(use).setAttribute('href', url); + return watcher; + }, document.title + ', external reference, existing'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + const watcher = expectEvents(t, use, ['load']); + const url = getUrl('existing-data'); + svg.appendChild(use).setAttribute('href', url); + return watcher; + }, document.title + ', external data: URL reference, existing'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + const watcher = expectEvents(t, use, ['error']); + const url = getUrl('non-existing'); + svg.appendChild(use).setAttribute('href', url); + return watcher; + }, document.title + ', external reference, non-existing'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + const watcher = expectEvents(t, use, ['error']); + const url = getUrl('broken'); + svg.appendChild(use).setAttribute('href', url); + return watcher; + }, document.title + ', external reference, existing, parse error'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + expectEvents(t, use, []); + const url = getUrl('existing'); + svg.appendChild(use).setAttribute('href', url); + t.step_timeout(() => use.setAttribute('href', '#local')); + return makeWatcher(svg, 'load', url); + }, document.title + ', external reference, existing, changed to local reference while loading'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + expectEvents(t, use, []); + const url = getUrl('existing-data'); + svg.appendChild(use).setAttribute('href', url); + t.step_timeout(() => use.setAttribute('href', '#local')); + return makeWatcher(svg, 'load', url); + }, document.title + ', external data: URL reference, existing, changed to local reference while loading'); + + promise_test(t => { + const svg = document.querySelector('svg'); + const use = newUseElement(); + expectEvents(t, use, []); + const url = getUrl('non-existing'); + svg.appendChild(use).setAttribute('href', url); + t.step_timeout(() => use.setAttribute('href', '#local')); + return makeWatcher(svg, 'error', url); + }, document.title + ', external reference, non-existing, changed to local reference while loading'); +</script> |