generate-object-fit-xul-tests.sh (3763B)
1 #!/bin/bash 2 # 3 # Any copyright is dedicated to the Public Domain. 4 # http://creativecommons.org/publicdomain/zero/1.0/ 5 # 6 # Script to generate XUL <image> reftest files, from corresponding reftest 7 # files that use <img>. 8 # 9 # This script expects to be run from this working directory: 10 # mozilla-central/layout/reftests/w3c-css/submitted/images3 11 12 XUL_REFTEST_PATH="../../../xul" 13 14 imageFileArr=("colors-16x8.png" "colors-8x16.png" 15 "colors-16x8.svg" "colors-8x16.svg" 16 "colors-16x8-noSize.svg" "colors-8x16-noSize.svg" 17 "colors-16x8-parDefault.svg" "colors-8x16-parDefault.svg") 18 numImageFiles=${#imageFileArr[@]} 19 20 # Copy image files 21 for ((i = 0; i < $numImageFiles; i++)); do 22 imageFileName=${imageFileArr[$i]} 23 imageDest=$XUL_REFTEST_PATH/$imageFileName 24 25 echo "Copying $imageDest." 26 hg cp support/$imageFileName $imageDest 27 done 28 29 # Add comment to reftest.list in dest directory: 30 reftestListFileName="$XUL_REFTEST_PATH/reftest.list" 31 echo " 32 # Tests for XUL <image> with 'object-fit' & 'object-position': 33 # These tests should be very similar to tests in our w3c-css/submitted/images3 34 # reftest directory. They live here because they use XUL, and it 35 # wouldn't be fair of us to make a W3C testsuite implicitly depend on XUL."\ 36 >> $reftestListFileName 37 38 # Loop across all object-fit tests that use <img> ("i" suffix): 39 for origTestName in object-fit*i.html; do 40 newTestName=$(echo $origTestName | 41 sed "s/i.html/.xul/") 42 43 # Find the corresponding reference case: 44 referenceName=$(echo $origTestName | 45 sed "s/i.html/-ref.html/") 46 47 # Generate reference file (dropping "support" subdir from image paths): 48 echo "Copying $referenceName to $XUL_REFTEST_PATH." 49 newReferenceFullPath=$XUL_REFTEST_PATH/$referenceName 50 hg cp $referenceName $newReferenceFullPath 51 sed -i "s,support/,," $newReferenceFullPath 52 53 # Generate testcase 54 # (converting <video poster="support/foo.png"> to <video src="foo.webm">): 55 echo "Generating $newTestName from $origTestName." 56 newTestFullPath=$XUL_REFTEST_PATH/$newTestName 57 hg cp $origTestName $newTestFullPath 58 59 # Replace doctype with XML decl: 60 sed -i "s/<!DOCTYPE html>/<?xml version=\"1.0\"?>/" $newTestFullPath 61 62 # Replace html tags with window tags: 63 sed -i "s,<html>,<window xmlns=\"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul\">," $newTestFullPath 64 sed -i "s,</html>,</window>," $newTestFullPath 65 66 # Delete a bunch of HTML (not XUL) / W3C-testsuite boilerplate: 67 sed -i "/head>/d" $newTestFullPath # Delete head open & close tags 68 sed -i "/body>/d" $newTestFullPath # Delete body open & close tags 69 sed -i "/<meta/d" $newTestFullPath # Delete meta charset tag 70 sed -i "/<title/d" $newTestFullPath # Delete title line 71 sed -i "/<link/d" $newTestFullPath # Delete link tags 72 73 # Add 4px to all sizes, since in XUL, sizes are for border-box 74 # instead of content-box. 75 sed -i "s/ 48px/ 52px/" $newTestFullPath 76 sed -i "s/ 32px/ 36px/" $newTestFullPath 77 sed -i "s/ 8px/ 12px/" $newTestFullPath 78 79 # Fix style open/close tags, and add 8px of padding on outer <window> to 80 # match our HTML reference case, and change style rule to target <image>: 81 sed -i "s, <style type=\"text/css\">,\<style xmlns=\"http://www.w3.org/1999/xhtml\"><![CDATA[\n window { padding: 8px; }," $newTestFullPath 82 sed -i "s, </style>,]]></style>," $newTestFullPath 83 sed -i "s/img {/image {/" $newTestFullPath 84 85 sed -i "s,support/,," $newTestFullPath 86 sed -i "s,<img\(.*\)>,<image\1/>," $newTestFullPath 87 sed -i "s, <!--,<hbox>\n <!--," $newTestFullPath 88 sed -i "s, <br>,</hbox>," $newTestFullPath 89 90 # Update reftest manifest: 91 echo "== $newTestName $referenceName" \ 92 >> $reftestListFileName 93 94 done