Roll src/third_party/WebKit 640e652:eec14d5 (svn 200948:200949)
[chromium-blink-merge.git] / chrome / tools / test / generate_mime_tests.pl
blobaee6fd1b8004f3fd3e270b188368b8c9a26a80e1
1 #!/usr/bin/perl -w
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Technically, it's a third party.
8 # Copyright 2008, Google Inc.
9 # All rights reserved.
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are
13 # met:
15 # * Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # * Redistributions in binary form must reproduce the above
18 # copyright notice, this list of conditions and the following disclaimer
19 # in the documentation and/or other materials provided with the
20 # distribution.
21 # * Neither the name of Google Inc. nor the names of its
22 # contributors may be used to endorse or promote products derived from
23 # this software without specific prior written permission.
25 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 # Generate html files that will be used test MIME type handling using
38 # the layout test framework.
40 use strict;
41 use Switch; # used for switch-case program structure
43 my $arg_count = $#ARGV + 1;
45 # Make sure that only one command line argument is provided
46 if ($arg_count ne 1) {
47 print "Usage:\n generate_mime_tests.pl < target_path >\n target_path".
48 " - path where the generated tests are to be placed";
49 exit;
52 # Obtain target path from the command line
53 my $target_path = $ARGV[0];
55 # Set relative path of the page to be requested
56 my $root = "resources/getpage.pl?";
58 # Variables used in the script
59 my $content_type;
60 my $parameter;
61 my $source; # Temporary variable to hold source path
62 my $count; # Used to generate number appended to filenames
63 my $current_expected = ""; # Temporary storage for expected result
64 my $query_description;
66 # Number of tests each content type goes through, also determines the half
67 # size of the expected results matrix
68 my $test_set_size = 14;
70 # List of HTTP content types to be used in generating test HTMLs
71 my @content_type = ("NULL",
72 "text/plain",
73 "text/html",
74 "image/gif",
75 "image/bmp",
76 "image/tif",
77 "image/png",
78 "image/jpg",
79 "application/x-shockwave-flash");
81 # List of URL query parameters to be used in generating test HTMLs
82 my @parameter = ("tag=img&content=type_gif.gif",
83 "tag=img&content=type_bmp.bmp",
84 "tag=img&content=type_tif.tif",
85 "tag=img&content=type_png.png",
86 "tag=img&content=type_jpg.jpg",
87 "tag=img&content=type_txt.txt",
88 "tag=embed&content=type_swf.swf",
89 "switch=nohtml&content=type_gif.gif",
90 "switch=nohtml&content=type_bmp.bmp",
91 "switch=nohtml&content=type_tif.tif",
92 "switch=nohtml&content=type_png.png",
93 "switch=nohtml&content=type_jpg.jpg",
94 "switch=nohtml&content=type_txt.txt",
95 "switch=nohtml&content=type_swf.swf");
97 # Matrix with expected results of all tests.
98 # The matrix rows have four parts
99 # 1. iframe with a html
100 # 2. iframe without a html
101 # 3. content within a html page
102 # 4. content without a html
103 # Each part has the same sequence of column headers
104 my @expected = (
105 # gif bmp tif png jpg txt swf
106 # gif bmp tif png jpg txt swf
107 # gif bmp tif png jpg txt swf
108 # gif bmp tif png jpg txt swf
109 # NULL
110 "html","html","html","html","html","html","html", # iframe html
111 "void","void","image","void","void", "text","text", # iframe no html
112 "html","html","html","html","html","html","html", # html
113 "image","void","image","image","image","text","text", # no html
115 # text/plain
116 "html","html","html","html","html","html","html", # iframe html
117 "void","void","image","void","void", "text","text", # iframe no html
118 "html","html","html","html","html","html","html", # html
119 "image","void","image","image","image","text","text", # no html
121 # text/html
122 "rs", "rf", "rf", "rs", "rs", "rf", "rs", # iframe html
123 "text","text","text","text", "text", "text","text", # iframe no html
124 "rs", "rf", "rf", "rs", "rs", "rf", "rs", # html
125 "text", "text","text", "text", "text", "text","text", # no html
127 # image/gif
128 "void","void","void","void","void","void","void", # iframe html
129 "void","void","void","void", "void", "void","void", # iframe no html
130 "void","void","void","void","void","void","void", # html
131 "image","void","void", "image","image","void","void", # no html
133 # image/bmp
134 "void","void","void","void","void","void","void", # iframe html
135 "void","void","void","void", "void", "void","void", # iframe no html
136 "void","void","void","void","void","void","void", # html
137 "image","void","void", "image","image","void","void", # no html
139 # image/tif
140 "void","void","void","void","void","void","void", # iframe html
141 "void","void","void","void", "void", "void","void", # iframe no html
142 "void","void","void","void","void","void","void", # html
143 "void", "void","void", "void", "void", "void","void", # no html
145 # image/png
146 "void","void","void","void","void","void","void", # iframe html
147 "void","void","void","void", "void", "void","void", # iframe no html
148 "void","void","void","void","void","void","void", # html
149 "image","void","void", "image","image","void","void", # no html
151 # image/jpg
152 "void","void","void","void","void","void","void", # iframe html
153 "void","void","void","void", "void", "void","void", # iframe no html
154 "void","void","void","void","void","void","void", # html
155 "image","void","void", "image","void", "void","void", # no html
157 # application/x-shockwave-flash
158 "void","void","void","void","void","void","void", # iframe html
159 "flash","void","void","flash","flash","void","flash", # iframe no html
160 "void","void","void","void","void","void","void", # html
161 "flash","void","void", "flash","flash","void","flash");# no html
163 # get_description()
164 # Maps the expected word to an appropriate phrase.
165 # Used to generated verbal descriptions for expected results of every test.
166 # Input : expected result from the matrix
167 # Output : returns the associated description
168 sub get_result_description
170 switch ($_[0]) {
171 case "void" { return "NOTHING";}
172 case "image" { return "an IMAGE";}
173 case "text" { return "simple TEXT";}
174 case "html" { return "an HTML as text";}
175 case "flash" { return "a FLASH object"}
176 case "rs" { return "been RENDERED CORRECTLY";}
177 case "rf" { return "been RENDERED INCORRECTLY";}
178 else { return "UNKNOWN";}
182 # get_query_description()
183 # Maps the URL query to an appropriate phrase.
184 # Used to generated verbal descriptions for URL queries of every test.
185 # Input : URL query
186 # Output : returns the associated description
187 sub get_query_description
189 switch ($_[0]) {
190 case "tag=img&content=type_gif.gif" { return "HTML page with a GIF image";}
191 case "tag=img&content=type_bmp.bmp" { return "HTML page with a BMP image";}
192 case "tag=img&content=type_tif.tif" { return "HTML page with a TIF image";}
193 case "tag=img&content=type_png.png" { return "HTML page with a PNG image";}
194 case "tag=img&content=type_jpg.jpg" { return "HTML page with a JPEG image"}
195 case "tag=img&content=type_txt.txt" { return "HTML page";}
196 case "tag=embed&content=type_swf.swf" { return "an HTML page with a FLASH object";}
197 case "switch=nohtml&content=type_gif.gif" { return "GIF image and no HTML";}
198 case "switch=nohtml&content=type_bmp.bmp" { return "BMP image and no HTML";}
199 case "switch=nohtml&content=type_tif.tif" { return "TIF image and no HTML";}
200 case "switch=nohtml&content=type_png.png" { return "PNG image and no HTML";}
201 case "switch=nohtml&content=type_jpg.jpg" { return "JPEG image and no HTML"}
202 case "switch=nohtml&content=type_txt.txt" { return "simple TEXT and no HTML";}
203 case "switch=nohtml&content=type_swf.swf" { return "FLASH object and no HTML";}
204 else { return "UNKNOWN TYPE";}
208 # This loop generates one HTML page with multiple iframes in it.
209 # Generated one iframe for every parameter of every content type.
210 my $iframe_index = 0;
211 foreach $content_type ( @content_type) {
212 my $infile = join "", "iframe/", $content_type, ".html";
213 $infile =~ tr/\//_/;
214 $infile = $target_path.$infile;
216 open OUT, "> $infile" or die "Failed to open file $infile";
217 print OUT "This HTML is used to test HTTP content-type \"$content_type\"".
218 " by having multiple iframes render different types of content for the".
219 " same HTTP content-type header.\n";
220 print OUT "<script>\n if(window.testRunner)\n " .
221 "window.testRunner.waitUntilDone();\n</script>\n";
222 print OUT "<html>\n<body>\n<br>Well here are the frames !<br>\n";
224 foreach $parameter ( @parameter ) {
226 # Make sure to iterate only through the first half of the expected
227 # results matrix
228 if (($iframe_index > 0) && (0 == ($iframe_index % $test_set_size))) {
229 $iframe_index += $test_set_size;
231 $current_expected = get_result_description($expected[$iframe_index++]);
233 $source = join "", $root, "type=", $content_type, "&", $parameter;
234 $query_description = get_query_description($parameter);
235 print OUT "<br><br>This frame tests loading of a $query_description when the ".
236 "HTTP content-type is set to \"$content_type\" .<br> Expected : This ",
237 "iframe should have $current_expected .<br>\n<iframe src=\"$source\" ".
238 "height=\"300\" width=\"500\"></iframe>\n\n";
241 print OUT "</body>\n</html>\n";
242 print OUT "<script>\n if(window.testRunner)\n ".
243 "testRunner.notifyDone();\n</script>";
244 close OUT;
247 # This loop generates one HTML for every combination of content-type and
248 # parameter.
249 my $main_index = 0;
250 foreach $content_type ( @content_type) {
251 $count = 0;
252 foreach $parameter ( @parameter ) {
253 $count++;
255 # Make sure to iterate only through the second half of the expected
256 # results matrix
257 if (0 == ($main_index % $test_set_size)) {
258 $main_index += $test_set_size;
261 $current_expected = get_result_description($expected[$main_index++]);
263 my $infile = join "", "main/", $content_type, $count, ".html";
264 $infile =~ tr/\//_/;
265 $source = join "", $root, "type=", $content_type, "&", $parameter;
266 $infile = $target_path.$infile;
267 $query_description = get_query_description($parameter);
269 open OUT, "> $infile" or die "Failed to open file $infile";
270 print OUT "This tests loading of a $query_description when the HTTP content-type".
271 " is set to \"$content_type\" .\n Expected : This page should have ".
272 "$current_expected .\n\n";
273 print OUT "<script>\n window.location=\"$source\";\n</script>\n";
274 close OUT;