33require 'cgi'
44require 'json'
55require 'rbconfig'
6+ require 'yaml'
67
78# A barebones runner for testing across multiple browsers quickly.
89#
@@ -57,6 +58,26 @@ module Runner
5758 host = RbConfig ::CONFIG [ 'host' ]
5859 IS_WINDOWS = host . include? ( 'mswin' ) || host . include? ( 'mingw32' )
5960
61+ class << self
62+ PWD = Pathname . new ( File . dirname ( __FILE__ ) )
63+ CONFIG_FILE = PWD . join ( 'browsers.yml' )
64+
65+ unless CONFIG_FILE . exist?
66+ # Copy the sample config file to an actual config file.
67+ sample = PWD . join ( 'browsers.sample.yml' )
68+ File . open ( CONFIG_FILE , 'w' ) do |file |
69+ file . write ( File . read ( sample ) )
70+ end
71+ end
72+
73+ CONFIG = YAML ::load_file ( CONFIG_FILE )
74+
75+ def config
76+ CONFIG
77+ end
78+ end
79+
80+
6081 module Browsers
6182
6283 class Abstract
@@ -87,6 +108,15 @@ def linux?
87108 host . include? ( 'linux' )
88109 end
89110
111+ def configured_path
112+ browsers = Runner ::config [ 'browsers' ]
113+ browsers [ short_name . to_s ]
114+ end
115+
116+ def default_path
117+ nil
118+ end
119+
90120 def visit ( url )
91121 if windows?
92122 system ( %Q["#{ path } " "#{ url } "] )
@@ -106,6 +136,10 @@ def name
106136 linux? ? n . downcase : n
107137 end
108138
139+ def short_name
140+ nil
141+ end
142+
109143 def escaped_name
110144 name . gsub ( ' ' , '\ ' )
111145 end
@@ -114,15 +148,19 @@ def path
114148 if macos?
115149 File . expand_path ( "/Applications/#{ name } .app" )
116150 else
117- @path || nil
151+ configured_path || default_path || nil
118152 end
119153 end
120154 end
121155
122156 class Firefox < Abstract
123157
124- def initialize ( path = File . join ( ENV [ 'ProgramFiles' ] || 'c:\Program Files' , '\Mozilla Firefox\firefox.exe' ) )
125- @path = path
158+ def short_name
159+ :firefox
160+ end
161+
162+ def default_path
163+ 'C:\Program Files\Mozilla Firefox\firefox.exe'
126164 end
127165
128166 def supported?
@@ -133,6 +171,10 @@ def supported?
133171
134172 class IE < Abstract
135173
174+ def short_name
175+ :ie
176+ end
177+
136178 def setup
137179 require 'win32ole' if windows?
138180 end
@@ -155,6 +197,10 @@ def visit(url)
155197
156198 class Safari < Abstract
157199
200+ def short_name
201+ :safari
202+ end
203+
158204 def supported?
159205 macos?
160206 end
@@ -163,8 +209,12 @@ def supported?
163209
164210 class Chrome < Abstract
165211
166- def initialize ( path = nil )
167- @path = path || 'C:\Program Files\Google\Chrome\Application\chrome.exe'
212+ def short_name
213+ :chrome
214+ end
215+
216+ def default_path
217+ 'C:\Program Files\Google\Chrome\Application\chrome.exe'
168218 end
169219
170220 def name
@@ -175,8 +225,12 @@ def name
175225
176226 class Opera < Abstract
177227
178- def initialize ( path = 'C:\Program Files\Opera\Opera.exe' )
179- @path = path
228+ def short_name
229+ :opera
230+ end
231+
232+ def default_path
233+ 'C:\Program Files\Opera\launcher.exe'
180234 end
181235
182236 end
@@ -284,6 +338,7 @@ def run(browsers=nil, tests=nil, grep=nil)
284338 end
285339 if !browser . installed?
286340 puts "Skipping #{ browser . name } (not installed on this OS)"
341+ puts " (edit test/unit/browsers.yml if this is in error)"
287342 next
288343 end
289344 print "Running in #{ browser . name } ... "
0 commit comments