1563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark#!/usr/bin/ruby 2563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# iExploder - Generates bad HTML files to perform QA for web browsers. 3563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Developed for the Mozilla Foundation. 4563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark##################### 5563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 6563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Copyright (c) 2006 Thomas Stromberg <thomas%stromberg.org> 7563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 8563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# This software is provided 'as-is', without any express or implied warranty. 9563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# In no event will the authors be held liable for any damages arising from the 10563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# use of this software. 11563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 12563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# Permission is granted to anyone to use this software for any purpose, 13563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# including commercial applications, and to alter it and redistribute it 14563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# freely, subject to the following restrictions: 15563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 16563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 1. The origin of this software must not be misrepresented; you must not 17563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# claim that you wrote the original software. If you use this software in a 18563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# product, an acknowledgment in the product documentation would be appreciated 19563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# but is not required. 20563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 21563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 2. Altered source versions must be plainly marked as such, and must not be 22563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# misrepresented as being the original software. 23563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 24563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark# 3. This notice may not be removed or altered from any source distribution. 25563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 26563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkrequire 'webrick' 27563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkrequire 'iexploder'; 28563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkrequire 'config'; 29563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 30563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkinclude WEBrick 31563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark### THE INTERACTION ################################## 32563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark$ie_preload = IExploder.new($HTML_MAX_TAGS, $HTML_MAX_ATTRS, $CSS_MAX_PROPS) 33563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark$ie_preload.readTagFiles() 34563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark$ie_preload.url='/iexploder.cgi' 35563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 36563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkif ARGV[0] 37563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark port = ARGV[0].to_i 38563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkelse 39563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark port = 2000 40563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkend 41563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 42563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkputs "* iExploder #{$VERSION} will be available at http://localhost:#{port}" 43563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkputs "* Max Tags: #$HTML_MAX_TAGS Max Attrs: #$HTML_MAX_ATTRS Max Props: #$CSS_MAX_PROPS" 44563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkputs 45563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 46563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarks = HTTPServer.new( :Port => port ) 47563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkclass IEServlet < HTTPServlet::AbstractServlet 48563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark def do_GET(req, res) 49563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie = $ie_preload.dup 50563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.test_num = req.query['test'].to_i 51563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.subtest_num = req.query['subtest'].to_i || 0 52563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.random_mode = req.query['random'] 53563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.lookup_mode = req.query['lookup'] 54563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.stop_num = req.query['stop'].to_i 55563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark ie.setRandomSeed 56563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 57563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark res['Content-Type'] = 'text/html' 58563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark res.body = ie.buildPage() 59563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark end 60563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkend 61563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 62563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkclass IEForm < HTTPServlet::AbstractServlet 63563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark def do_GET(req, res) 64563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark res['Content-Type'] = 'text/html' 65563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark res.body = File.open("index.html").readlines.join("\n") 66563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark end 67563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarkend 68563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 69563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 70563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 71563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarks.mount("/iexploder.cgi", IEServlet) 72563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarks.mount("/", IEForm) 73563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarktrap("INT") { s.shutdown } 74563af33bc48281d19dce701398dbb88cb54fd7ecCary Clark 75563af33bc48281d19dce701398dbb88cb54fd7ecCary Clarks.start 76