Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add JavaScriptTest namespace wrapper

  • Loading branch information...
commit 83ace50b9342e2cb216a3aad5b712850deeef8ca 1 parent c6e32d3
@madrobby madrobby authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add JavaScriptTest namespace wrapper
+
* Added test for JavaScript test runner
* Issue headers that prevent caching, #6218 [voidlock]
View
380 lib/javascript_test.rb
@@ -2,221 +2,225 @@
require 'thread'
require 'webrick'
-class Browser
- def supported?; true; end
- def setup ; end
- def open(url) ; end
- def teardown ; end
-
- def host
- require 'rbconfig'
- Config::CONFIG['host']
- end
+class JavaScriptTest
- def macos?
- host.include?('darwin')
- end
+ class Browser
+ def supported?; true; end
+ def setup ; end
+ def open(url) ; end
+ def teardown ; end
- def windows?
- host.include?('mswin')
+ def host
+ require 'rbconfig'
+ Config::CONFIG['host']
+ end
+
+ def macos?
+ host.include?('darwin')
+ end
+
+ def windows?
+ host.include?('mswin')
+ end
+
+ def linux?
+ host.include?('linux')
+ end
+
+ def applescript(script)
+ raise "Can't run AppleScript on #{host}" unless macos?
+ system "osascript -e '#{script}' 2>&1 >/dev/null"
+ end
end
- def linux?
- host.include?('linux')
- end
+ class FirefoxBrowser < Browser
+ def initialize(path='c:\Program Files\Mozilla Firefox\firefox.exe')
+ @path = path
+ end
- def applescript(script)
- raise "Can't run AppleScript on #{host}" unless macos?
- system "osascript -e '#{script}' 2>&1 >/dev/null"
- end
-end
-
-class FirefoxBrowser < Browser
- def initialize(path='c:\Program Files\Mozilla Firefox\firefox.exe')
- @path = path
- end
-
- def visit(url)
- applescript('tell application "Firefox" to Get URL "' + url + '"') if macos?
- system("#{@path} #{url}") if windows?
- system("firefox #{url}") if linux?
- end
-
- def to_s
- "Firefox"
- end
-end
-
-class SafariBrowser < Browser
- def supported?
- macos?
- end
+ def visit(url)
+ applescript('tell application "Firefox" to Get URL "' + url + '"') if macos?
+ system("#{@path} #{url}") if windows?
+ system("firefox #{url}") if linux?
+ end
- def setup
- applescript('tell application "Safari" to make new document')
+ def to_s
+ "Firefox"
+ end
end
- def visit(url)
- applescript('tell application "Safari" to set URL of front document to "' + url + '"')
- end
-
- def teardown
- #applescript('tell application "Safari" to close front document')
- end
-
- def to_s
- "Safari"
- end
-end
-
-class IEBrowser < Browser
- def initialize(path='C:\Program Files\Internet Explorer\IEXPLORE.EXE')
- @path = path
- end
+ class SafariBrowser < Browser
+ def supported?
+ macos?
+ end
+
+ def setup
+ applescript('tell application "Safari" to make new document')
+ end
+
+ def visit(url)
+ applescript('tell application "Safari" to set URL of front document to "' + url + '"')
+ end
- def setup
- if windows?
- puts %{
- MAJOR ANNOYANCE on Windows.
- You have to shut down the Internet Explorer manually after each test
- for the script to proceed.
- Any suggestions on fixing this is GREATLY appreaciated!
- Thank you for your understanding.
- }
+ def teardown
+ #applescript('tell application "Safari" to close front document')
end
- end
-
- def supported?
- windows?
- end
- def visit(url)
- system("#{@path} #{url}") if windows?
- end
-
- def to_s
- "Internet Explorer"
- end
-end
-
-class KonquerorBrowser < Browser
- def supported?
- linux?
+ def to_s
+ "Safari"
+ end
end
- def visit(url)
- system("kfmclient openURL #{url}")
- end
+ class IEBrowser < Browser
+ def initialize(path='C:\Program Files\Internet Explorer\IEXPLORE.EXE')
+ @path = path
+ end
+
+ def setup
+ if windows?
+ puts %{
+ MAJOR ANNOYANCE on Windows.
+ You have to shut down the Internet Explorer manually after each test
+ for the script to proceed.
+ Any suggestions on fixing this is GREATLY appreaciated!
+ Thank you for your understanding.
+ }
+ end
+ end
- def to_s
- "Konqueror"
- end
-end
-
-# shut up, webrick :-)
-class ::WEBrick::HTTPServer
- def access_log(config, req, res)
- # nop
+ def supported?
+ windows?
+ end
+
+ def visit(url)
+ system("#{@path} #{url}") if windows?
+ end
+
+ def to_s
+ "Internet Explorer"
+ end
end
-end
-class ::WEBrick::BasicLog
- def log(level, data)
- # nop
+
+ class KonquerorBrowser < Browser
+ def supported?
+ linux?
+ end
+
+ def visit(url)
+ system("kfmclient openURL #{url}")
+ end
+
+ def to_s
+ "Konqueror"
+ end
end
-end
-
-class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
- def do_GET(req, res)
- super
- res['etag'] = nil
- res['last-modified'] = Time.now + 1000
- res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0"'
- res['Pragma'] = 'no-cache'
- res['Expires'] = Time.now - 1000
+
+ # shut up, webrick :-)
+ class ::WEBrick::HTTPServer
+ def access_log(config, req, res)
+ # nop
+ end
end
-end
-
-class JavaScriptTestrunner
-
- def initialize(name=:test)
- @name = name
- @tests = []
- @browsers = []
- @result = true
-
- @queue = Queue.new
-
- result = []
-
- @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
- @server.mount_proc("/results") do |req, res|
- @queue.push(req.query['result'])
- res.body = "OK"
+ class ::WEBrick::BasicLog
+ def log(level, data)
+ # nop
end
- yield self if block_given?
-
- define
end
- def successful?
- @result
+ class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
+ def do_GET(req, res)
+ super
+ res['etag'] = nil
+ res['last-modified'] = Time.now + 1000
+ res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0"'
+ res['Pragma'] = 'no-cache'
+ res['Expires'] = Time.now - 1000
+ end
end
-
- def define
- trap("INT") { @server.shutdown }
- t = Thread.new { @server.start }
+
+ class Runner
+
+ def initialize(name=:test)
+ @name = name
+ @tests = []
+ @browsers = []
+ @result = true
+
+ @queue = Queue.new
+
+ result = []
+
+ @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
+ @server.mount_proc("/results") do |req, res|
+ @queue.push(req.query['result'])
+ res.body = "OK"
+ end
+ yield self if block_given?
+
+ define
+ end
- # run all combinations of browsers and tests
- @browsers.each do |browser|
- if browser.supported?
- browser.setup
- @tests.each do |test|
- browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f))
- result = @queue.pop
- puts "#{test} on #{browser}: #{result}"
- @result = false unless result == 'SUCCESS'
+ def successful?
+ @result
+ end
+
+ def define
+ trap("INT") { @server.shutdown }
+ t = Thread.new { @server.start }
+
+ # run all combinations of browsers and tests
+ @browsers.each do |browser|
+ if browser.supported?
+ browser.setup
+ @tests.each do |test|
+ browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f))
+ result = @queue.pop
+ puts "#{test} on #{browser}: #{result}"
+ @result = false unless result == 'SUCCESS'
+ end
+ browser.teardown
+ else
+ puts "Skipping #{browser}, not supported on this OS"
end
browser.teardown
- else
- puts "Skipping #{browser}, not supported on this OS"
end
- browser.teardown
+
+ @server.shutdown
+ t.join
end
-
- @server.shutdown
- t.join
- end
-
- def mount(path, dir=nil)
- dir ||= (Dir.pwd + path)
-
- @server.mount(path, NonCachingFileHandler, dir)
- end
-
- # test should be specified as a url
- def run(test)
- url = "/test/javascript/#{test}_test.html"
- unless File.exists?(RAILS_ROOT+url)
- raise "Missing test file #{url} for #{test}"
+
+ def mount(path, dir=nil)
+ dir ||= (Dir.pwd + path)
+
+ @server.mount(path, NonCachingFileHandler, dir)
end
- @tests << url
- end
-
- def browser(browser)
- browser =
- case(browser)
- when :firefox
- FirefoxBrowser.new
- when :safari
- SafariBrowser.new
- when :ie
- IEBrowser.new
- when :konqueror
- KonquerorBrowser.new
- else
- browser
+
+ # test should be specified as a url
+ def run(test)
+ url = "/test/javascript/#{test}_test.html"
+ unless File.exists?(RAILS_ROOT+url)
+ raise "Missing test file #{url} for #{test}"
end
-
- @browsers<<browser
+ @tests << url
+ end
+
+ def browser(browser)
+ browser =
+ case(browser)
+ when :firefox
+ FirefoxBrowser.new
+ when :safari
+ SafariBrowser.new
+ when :ie
+ IEBrowser.new
+ when :konqueror
+ KonquerorBrowser.new
+ else
+ browser
+ end
+
+ @browsers<<browser
+ end
end
+
end
View
2  tasks/javascript_test.rake
@@ -1,6 +1,6 @@
desc "Run tests for JavaScripts"
task 'test:javascripts' => :environment do
- JavaScriptTestrunner.new do |t|
+ JavaScriptTest::Runner.new do |t|
t.mount("/", RAILS_ROOT)
t.mount("/test", RAILS_ROOT+'/test')
View
4 test/javascript_test_test.rb
@@ -6,8 +6,8 @@
class JavascriptTestTest < Test::Unit::TestCase
- def test_javascript_testrunner
- runner = JavaScriptTestrunner.new do |t|
+ def test_javascript_test_runner
+ runner = JavaScriptTest::Runner.new do |t|
t.mount("/test", RAILS_ROOT+'/test')
t.mount('/test/javascript/assets', RAILS_ROOT+'/../assets')
t.run('test')
Please sign in to comment.
Something went wrong with that request. Please try again.