tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate-object-position-png-tests.sh (3738B)


      1 #!/bin/bash
      2 #
      3 # Any copyright is dedicated to the Public Domain.
      4 # http://creativecommons.org/publicdomain/zero/1.0/
      5 #
      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.
     10 #
     11 # The reference case uses the "background-size" & "background-position"
     12 # equivalent of the tested "object-fit" / "object-position" values.
     13 
     14 FILE_PATH="./"
     15 REFTEST_LIST_FILE="$FILE_PATH/reftest.list"
     16 
     17 TEMPLATE_TESTCASE_FILENAME=$FILE_PATH/support/template-object-position-test.html
     18 TEMPLATE_REFERENCE_FILENAME=$FILE_PATH/support/template-object-position-ref.html
     19 
     20 imageFileFormat="png"
     21 
     22 # Array of image files to use for testing:
     23 imageFileArr=("support/colors-16x8.png" "support/colors-8x16.png")
     24 numImageFiles=${#imageFileArr[@]}
     25 
     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")
     36 
     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[@]}
     46 
     47  for ((j = 0; j < $numImageFiles; j++)); do
     48    imageFile=${imageFileArr[$j]}
     49 
     50    classPatternToDelete=${classPatternToDeleteArr[$j]}
     51 
     52    let testNum=$j+1
     53    testNum="00$testNum" # zero-pad to 3 digits, per w3c convention
     54 
     55    filenameStub="object-position-$imageFileFormat-$testNum"
     56 
     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
     64 
     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]}
     71 
     72      filenameTest="$filenameStub$tagLetter.html"
     73      testTitle="various 'object-position' values on a fixed-size $tagName element, with a PNG 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
     84 
     85      echo "== $filenameTest $filenameRef" \
     86        >> $REFTEST_LIST_FILE
     87    done
     88  done