initial import
[vuplus_webkit] / Tools / iExploder / iexploder-1.3.2 / htdocs / webserver.rb
1 #!/usr/bin/ruby
2 # iExploder - Generates bad HTML files to perform QA for web browsers.
3 # Developed for the Mozilla Foundation.
4 #####################
5 #
6 # Copyright (c) 2006 Thomas Stromberg <thomas%stromberg.org>
7
8 # This software is provided 'as-is', without any express or implied warranty.
9 # In no event will the authors be held liable for any damages arising from the
10 # use of this software.
11
12 # Permission is granted to anyone to use this software for any purpose,
13 # including commercial applications, and to alter it and redistribute it
14 # freely, subject to the following restrictions:
15
16 # 1. The origin of this software must not be misrepresented; you must not
17 # claim that you wrote the original software. If you use this software in a
18 # product, an acknowledgment in the product documentation would be appreciated
19 # but is not required.
20
21 # 2. Altered source versions must be plainly marked as such, and must not be
22 # misrepresented as being the original software.
23
24 # 3. This notice may not be removed or altered from any source distribution.
25
26 require 'webrick'
27 require 'iexploder';
28 require 'config';
29
30 include WEBrick
31 ### THE INTERACTION ##################################
32 $ie_preload = IExploder.new($HTML_MAX_TAGS, $HTML_MAX_ATTRS, $CSS_MAX_PROPS)
33 $ie_preload.readTagFiles()
34 $ie_preload.url='/iexploder.cgi'
35
36 if ARGV[0]
37         port = ARGV[0].to_i
38 else
39         port = 2000
40 end
41
42 puts "* iExploder #{$VERSION} will be available at http://localhost:#{port}"
43 puts "* Max Tags: #$HTML_MAX_TAGS Max Attrs: #$HTML_MAX_ATTRS Max Props: #$CSS_MAX_PROPS"
44 puts
45
46 s = HTTPServer.new( :Port => port )
47 class IEServlet < HTTPServlet::AbstractServlet
48     def do_GET(req, res)
49         ie = $ie_preload.dup
50         ie.test_num = req.query['test'].to_i
51         ie.subtest_num = req.query['subtest'].to_i || 0
52         ie.random_mode = req.query['random']
53         ie.lookup_mode = req.query['lookup']
54         ie.stop_num = req.query['stop'].to_i
55         ie.setRandomSeed
56         
57         res['Content-Type'] = 'text/html'  
58         res.body = ie.buildPage()
59     end
60 end
61
62 class IEForm < HTTPServlet::AbstractServlet
63     def do_GET(req, res)   
64         res['Content-Type'] = 'text/html'  
65         res.body = File.open("index.html").readlines.join("\n")
66     end
67 end
68
69
70
71 s.mount("/iexploder.cgi", IEServlet)
72 s.mount("/", IEForm)
73 trap("INT") { s.shutdown }
74
75 s.start