-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1902790 [wpt PR 46766] - [Clipboard] Move SVG format test to WPT …
…folder., a=testonly Automatic update from web-platform-tests [Clipboard] Move SVG format test to WPT folder. SVG format is now in the clipboard API spec[1], so move the test to WPT directory. [1] https://w3c.github.io/clipboard-apis/#optional-data-types-x Bug: 40708648 Change-Id: I92c162c405a0cfcb832d75d7829381e79931307a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5630343 Commit-Queue: Anupam Snigdha <[email protected]> Reviewed-by: Christine Hollingsworth <[email protected]> Cr-Commit-Position: refs/heads/main@{#1315440} -- wpt-commits: 765d24b6e947fc215d144a480ce29be861136719 wpt-pr: 46766
- Loading branch information
1 parent
18de87b
commit 90e69b5
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
testing/web-platform/tests/clipboard-apis/async-svg-read-write.tentative.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title> | ||
Async Clipboard write ([image/svg+xml ClipboardItem]) -> read and write svg tests | ||
</title> | ||
<link rel="help" href="https://w3c.github.io/clipboard-apis/#async-clipboard-api"> | ||
<body>Body needed for test_driver.click()</body> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="resources/user-activation.js"></script> | ||
<script> | ||
'use strict'; | ||
// This function removes extra spaces between tags in svg. For example, the | ||
// following svg: "<svg> <g> </g> </svg>" would turn into this | ||
// svg: "<svg> <g> </g> </svg>" | ||
// We remove the extra spaces because in svg they are considered equivalent, | ||
// but when we are comparing for equality the spaces make a difference. | ||
function reformatSvg(svgString) { | ||
return svgString.replace(/\>\s*\</g, '> <'); | ||
} | ||
|
||
async function readWriteTest(textInput) { | ||
await test_driver.set_permission({name: 'clipboard-read'}, 'granted'); | ||
await test_driver.set_permission({name: 'clipboard-write'}, 'granted'); | ||
const blobInput = new Blob([textInput.input], {type: 'image/svg+xml'}); | ||
const clipboardItem = new ClipboardItem({'image/svg+xml': blobInput}); | ||
await waitForUserActivation(); | ||
await navigator.clipboard.write([clipboardItem]); | ||
await waitForUserActivation(); | ||
const clipboardItems = | ||
await navigator.clipboard.read({type: 'image/svg+xml'}); | ||
|
||
const svg = clipboardItems[0]; | ||
assert_equals(svg.types.length, 1); | ||
assert_equals(svg.types[0], 'image/svg+xml'); | ||
|
||
const blobOutput = await svg.getType('image/svg+xml'); | ||
assert_equals(blobOutput.type, 'image/svg+xml'); | ||
|
||
const blobText = await (new Response(blobOutput)).text(); | ||
const outputSvg = reformatSvg(blobText); | ||
if ("expected" in textInput) { | ||
assert_equals(outputSvg, reformatSvg(textInput.expected)); | ||
} else { | ||
assert_equals(outputSvg, reformatSvg(textInput.input)); | ||
} | ||
} | ||
const testCases = [ | ||
{ input: '<svg></svg>' }, | ||
{ input: '<svg> <circle cx="50" cy="50" r="40"/> </svg>', | ||
expected: '<svg> <circle cx="50" cy="50" r="40"> </circle> </svg>' }, | ||
{ input: '<svg> <script>const a = 5;\<\/script> <a href="javascript:alert(2)"> test </a> </svg>', | ||
expected: '<svg> <a> test </a> </svg>' }, | ||
{ input: '<svg> <style>.foo {fill: green;}</style>' + | ||
'<circle class=\"foo\" cx=\"50\" cy=\"50\" r=\"40\" /> </svg>', | ||
// The extra style attributes is due to read-time sanitization. | ||
// We would like to improve the expectation but need a better sanitizer first. | ||
expected: '<svg style=\"color: rgb(0, 0, 0); font-size: medium;' + | ||
' font-style: normal; font-variant-ligatures: normal;' + | ||
' font-variant-caps: normal; font-weight: 400;' + | ||
' letter-spacing: normal; orphans: 2; text-align: start;' + | ||
' text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;' + | ||
' -webkit-text-stroke-width: 0px; white-space: normal;' + | ||
' text-decoration-thickness: initial; text-decoration-style: initial;' + | ||
' text-decoration-color: initial;\"> <circle class=\"foo\" cx=\"50\"' + | ||
' cy=\"50\" r=\"40\"> </circle> </svg>' }, | ||
]; | ||
|
||
promise_test(async t => { | ||
for (const testCase of testCases) { | ||
await readWriteTest(testCase); | ||
} | ||
}, 'Verify read and write of some image/svg+xml content'); | ||
</script> |