Bug 1823878 [wpt PR 34716] - Make a speech synthesis test fail fast and tinker with...
[gecko.git] / testing / web-platform / tests / css / css-images / support / generate-object-position-svg-tests.sh
blobe00385a4748c535bed5e7af0892d18399db894ce
1 #!/bin/bash
3 # Any copyright is dedicated to the Public Domain.
4 # http://creativecommons.org/publicdomain/zero/1.0/
6 # This is a script that I used to generate a suite of tests for the CSS
7 # properties "object-fit" and "object-position" (focusing on edge-case
8 # object-position values that require pixel rounding), using a template
9 # testcase file and reference case file.
11 # The reference case uses the "background-size" & "background-position"
12 # equivalent of the tested "object-fit" / "object-position" values.
14 FILE_PATH="./"
15 REFTEST_LIST_FILE="$FILE_PATH/reftest.list"
17 TEMPLATE_TESTCASE_FILENAME=$FILE_PATH/support/template-object-position-test.html
18 TEMPLATE_REFERENCE_FILENAME=$FILE_PATH/support/template-object-position-ref.html
20 imageFileFormat="svg"
22 # Array of image files to use for testing:
23 imageFileArr=("support/colors-16x8.svg" "support/colors-8x16.svg")
24 numImageFiles=${#imageFileArr[@]}
26 # Array of CSS classes to delete from the template, for a given image-file.
27 # DETAILS: The template files contain some elements/styles that exercise
28 # object-position x-values (op_x), and other elements/styles that exercise
29 # object-position y-values (op_y). But actually, we'll only have extra space
30 # for these percent values to resolve against in *one* dimension (since our
31 # image-files are rectangular, and the container element is square, and we
32 # scale the image up with "object-fit: contain"). So, we delete the
33 # elements/styles in the dimension where object-position % values will just
34 # resolve to 0 ("op_x" for the fat image, and "op_y" for the tall image).
35 classPatternToDeleteArr=("op_x" "op_y")
37 # Array of tag-names for elements that we'd like to test:
38 # (Also: array of a single-letter abbreviation for each element, an array of
39 # the close tag for each element -- if a close tag is needed -- and an array
40 # indicating the attribute that each element uses to specify its image source.)
41 tagNameArr=( "embed" "img" "object" "video" )
42 tagLetterArr=( "e" "i" "o" "p" )
43 tagCloseTokenArr=( "" "" "</object>" "</video>" )
44 tagSrcAttrArr=( "src" "src" "data" "poster" )
45 numTags=${#tagNameArr[@]}
47 for ((j = 0; j < $numImageFiles; j++)); do
48 imageFile=${imageFileArr[$j]}
50 classPatternToDelete=${classPatternToDeleteArr[$j]}
52 let testNum=$j+1
53 testNum="00$testNum" # zero-pad to 3 digits, per w3c convention
55 filenameStub="object-position-$imageFileFormat-$testNum"
57 # Generate a reference case:
58 filenameRef="$filenameStub-ref.html"
59 echo Generating ${filenameRef}.
60 cat $TEMPLATE_REFERENCE_FILENAME \
61 | sed "s,REPLACEME_IMAGE_FILENAME,$imageFile," \
62 | sed "/$classPatternToDelete/d" \
63 > $FILE_PATH/$filenameRef
65 # Generate a test for each of our tags:
66 for ((k = 0; k < $numTags; k++)); do
67 tagName=${tagNameArr[$k]}
68 tagLetter=${tagLetterArr[$k]}
69 tagCloseToken=${tagCloseTokenArr[$k]}
70 tagSrcAttr=${tagSrcAttrArr[$k]}
72 filenameTest="$filenameStub$tagLetter.html"
73 testTitle="various 'object-position' values on a fixed-size $tagName element, with a SVG image and 'object-fit:contain'."
74 echo Generating ${filenameTest}.
75 cat $TEMPLATE_TESTCASE_FILENAME \
76 | sed "s,REPLACEME_IMAGE_FILENAME,$imageFile," \
77 | sed "s/REPLACEME_TEST_TITLE/$testTitle/" \
78 | sed "s,REPLACEME_REFERENCE_FILENAME,$filenameRef," \
79 | sed "s/REPLACEME_CONTAINER_TAG/$tagName/" \
80 | sed "s,REPLACEME_CONTAINER_CLOSETAG,$tagCloseToken," \
81 | sed "s/REPLACEME_SRC_ATTR/$tagSrcAttr/" \
82 | sed "/$classPatternToDelete/d" \
83 > $FILE_PATH/$filenameTest
85 echo "== $filenameTest $filenameRef" \
86 >> $REFTEST_LIST_FILE
87 done
88 done