generate-object-fit-xul-tests.sh 3.8 KB

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