use strict;
use Switch;
my $arg_count = $#ARGV + 1;
if ($arg_count ne 1) {
print "Usage:\n generate_mime_tests.pl < target_path >\n target_path".
" - path where the generated tests are to be placed";
exit;
}
my $target_path = $ARGV[0];
my $root = "resources/getpage.pl?";
my $content_type;
my $parameter;
my $source;
my $count;
my $current_expected = "";
my $query_description;
my $test_set_size = 14;
my @content_type = ("NULL",
"text/plain",
"text/html",
"image/gif",
"image/bmp",
"image/tif",
"image/png",
"image/jpg",
"application/x-shockwave-flash");
my @parameter = ("tag=img&content=type_gif.gif",
"tag=img&content=type_bmp.bmp",
"tag=img&content=type_tif.tif",
"tag=img&content=type_png.png",
"tag=img&content=type_jpg.jpg",
"tag=img&content=type_txt.txt",
"tag=embed&content=type_swf.swf",
"switch=nohtml&content=type_gif.gif",
"switch=nohtml&content=type_bmp.bmp",
"switch=nohtml&content=type_tif.tif",
"switch=nohtml&content=type_png.png",
"switch=nohtml&content=type_jpg.jpg",
"switch=nohtml&content=type_txt.txt",
"switch=nohtml&content=type_swf.swf");
my @expected = (
"html","html","html","html","html","html","html",
"void","void","image","void","void", "text","text",
"html","html","html","html","html","html","html",
"image","void","image","image","image","text","text",
"html","html","html","html","html","html","html",
"void","void","image","void","void", "text","text",
"html","html","html","html","html","html","html",
"image","void","image","image","image","text","text",
"rs", "rf", "rf", "rs", "rs", "rf", "rs",
"text","text","text","text", "text", "text","text",
"rs", "rf", "rf", "rs", "rs", "rf", "rs",
"text", "text","text", "text", "text", "text","text",
"void","void","void","void","void","void","void",
"void","void","void","void", "void", "void","void",
"void","void","void","void","void","void","void",
"image","void","void", "image","image","void","void",
"void","void","void","void","void","void","void",
"void","void","void","void", "void", "void","void",
"void","void","void","void","void","void","void",
"image","void","void", "image","image","void","void",
"void","void","void","void","void","void","void",
"void","void","void","void", "void", "void","void",
"void","void","void","void","void","void","void",
"void", "void","void", "void", "void", "void","void",
"void","void","void","void","void","void","void",
"void","void","void","void", "void", "void","void",
"void","void","void","void","void","void","void",
"image","void","void", "image","image","void","void",
"void","void","void","void","void","void","void",
"void","void","void","void", "void", "void","void",
"void","void","void","void","void","void","void",
"image","void","void", "image","void", "void","void",
"void","void","void","void","void","void","void",
"flash","void","void","flash","flash","void","flash",
"void","void","void","void","void","void","void",
"flash","void","void", "flash","flash","void","flash");
sub get_result_description
{
switch ($_[0]) {
case "void" { return "NOTHING";}
case "image" { return "an IMAGE";}
case "text" { return "simple TEXT";}
case "html" { return "an HTML as text";}
case "flash" { return "a FLASH object"}
case "rs" { return "been RENDERED CORRECTLY";}
case "rf" { return "been RENDERED INCORRECTLY";}
else { return "UNKNOWN";}
}
}
sub get_query_description
{
switch ($_[0]) {
case "tag=img&content=type_gif.gif" { return "HTML page with a GIF image";}
case "tag=img&content=type_bmp.bmp" { return "HTML page with a BMP image";}
case "tag=img&content=type_tif.tif" { return "HTML page with a TIF image";}
case "tag=img&content=type_png.png" { return "HTML page with a PNG image";}
case "tag=img&content=type_jpg.jpg" { return "HTML page with a JPEG image"}
case "tag=img&content=type_txt.txt" { return "HTML page";}
case "tag=embed&content=type_swf.swf" { return "an HTML page with a FLASH object";}
case "switch=nohtml&content=type_gif.gif" { return "GIF image and no HTML";}
case "switch=nohtml&content=type_bmp.bmp" { return "BMP image and no HTML";}
case "switch=nohtml&content=type_tif.tif" { return "TIF image and no HTML";}
case "switch=nohtml&content=type_png.png" { return "PNG image and no HTML";}
case "switch=nohtml&content=type_jpg.jpg" { return "JPEG image and no HTML"}
case "switch=nohtml&content=type_txt.txt" { return "simple TEXT and no HTML";}
case "switch=nohtml&content=type_swf.swf" { return "FLASH object and no HTML";}
else { return "UNKNOWN TYPE";}
}
}
my $iframe_index = 0;
foreach $content_type ( @content_type) {
my $infile = join "", "iframe/", $content_type, ".html";
$infile =~ tr/\//_/;
$infile = $target_path.$infile;
open OUT, "> $infile" or die "Failed to open file $infile";
print OUT "This HTML is used to test HTTP content-type \"$content_type\"".
" by having multiple iframes render different types of content for the".
" same HTTP content-type header.\n";
print OUT "<script>\n if(window.testRunner)\n " .
"window.testRunner.waitUntilDone();\n</script>\n";
print OUT "<html>\n<body>\n<br>Well here are the frames !<br>\n";
foreach $parameter ( @parameter ) {
if (($iframe_index > 0) && (0 == ($iframe_index % $test_set_size))) {
$iframe_index += $test_set_size;
}
$current_expected = get_result_description($expected[$iframe_index++]);
$source = join "", $root, "type=", $content_type, "&", $parameter;
$query_description = get_query_description($parameter);
print OUT "<br><br>This frame tests loading of a $query_description when the ".
"HTTP content-type is set to \"$content_type\" .<br> Expected : This ",
"iframe should have $current_expected .<br>\n<iframe src=\"$source\" ".
"height=\"300\" width=\"500\"></iframe>\n\n";
}
print OUT "</body>\n</html>\n";
print OUT "<script>\n if(window.testRunner)\n ".
"testRunner.notifyDone();\n</script>";
close OUT;
}
my $main_index = 0;
foreach $content_type ( @content_type) {
$count = 0;
foreach $parameter ( @parameter ) {
$count++;
if (0 == ($main_index % $test_set_size)) {
$main_index += $test_set_size;
}
$current_expected = get_result_description($expected[$main_index++]);
my $infile = join "", "main/", $content_type, $count, ".html";
$infile =~ tr/\//_/;
$source = join "", $root, "type=", $content_type, "&", $parameter;
$infile = $target_path.$infile;
$query_description = get_query_description($parameter);
open OUT, "> $infile" or die "Failed to open file $infile";
print OUT "This tests loading of a $query_description when the HTTP content-type".
" is set to \"$content_type\" .\n Expected : This page should have ".
"$current_expected .\n\n";
print OUT "<script>\n window.location=\"$source\";\n</script>\n";
close OUT;
}
}