Home | History | Annotate | Download | only in src
      1 #!/usr/bin/ruby
      2 # iExploder - Generates bad HTML files to perform QA for web browsers.
      3 #
      4 # Copyright 2010 Thomas Stromberg - All Rights Reserved.
      5 #
      6 # Licensed under the Apache License, Version 2.0 (the "License");
      7 # you may not use this file except in compliance with the License.
      8 # You may obtain a copy of the License at
      9 #
     10 #      http://www.apache.org/licenses/LICENSE-2.0
     11 #
     12 # Unless required by applicable law or agreed to in writing, software
     13 # distributed under the License is distributed on an "AS IS" BASIS,
     14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 # See the License for the specific language governing permissions and
     16 # limitations under the License.
     17 
     18 require 'cgi';
     19 require 'iexploder';
     20 
     21 $CONFIG_PATH = 'config.yaml'
     22 
     23 ie = IExploder.new($CONFIG_PATH)
     24 cgi = CGI.new("html4");
     25 ie.cgi_url=ENV['SCRIPT_NAME'] || '?'
     26 ie.browser=ENV['HTTP_USER_AGENT'] || 'unknown'
     27 ie.test_num = cgi.params['t'][0].to_i
     28 ie.subtest_data = cgi.params['s'][0] || nil
     29 ie.random_mode = cgi.params['r'][0]
     30 ie.lookup_mode = cgi.params['l'][0]
     31 ie.stop_num = cgi.params['x'][0] || nil
     32 ie.setRandomSeed()
     33 
     34 mime_type = cgi.params['m'][0] || nil
     35 if mime_type:
     36   header_options = ie.buildHeaders(mime_type)
     37   # The CGI library wants the Content-Type header to be named 'type'. It
     38   # will post two Content-Type headers otherwise.
     39   header_options['type'] = header_options['Content-Type'].dup
     40   header_options.delete('Content-Type')
     41   cgi.out(header_options) do
     42     ie.buildMediaFile(mime_type)
     43   end
     44 else
     45   cgi.out('type' => 'text/html') do
     46     ie.buildPage()
     47   end
     48 end
     49