Skip to content

Commit a501367

Browse files
committed
Make the browser command dispatch table-driven and fix the --browser option.
1 parent 781bcb6 commit a501367

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

test/test.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,23 @@ def start(self, url):
237237

238238
def makeBrowserCommand(browser):
239239
path = browser["path"].lower()
240-
name = browser["name"].lower()
241-
if name.find("firefox") > -1 or path.find("firefox") > -1:
242-
return FirefoxBrowserCommand(browser)
243-
elif name.find("chrom") > -1 or path.find("chrom") > -1:
244-
return ChromeBrowserCommand(browser)
245-
else:
240+
name = browser["name"]
241+
if name is not None:
242+
name = name.lower()
243+
244+
types = {"firefox": FirefoxBrowserCommand,
245+
"chrome": ChromeBrowserCommand }
246+
command = None
247+
for key in types.keys():
248+
if (name and name.find(key) > -1) or path.find(key) > -1:
249+
command = types[key](browser)
250+
command.name = command.name or key
251+
252+
if command is None:
246253
raise Exception("Unrecognized browser: %s" % browser)
247254

255+
return command
256+
248257
def makeBrowserCommands(browserManifestFile):
249258
with open(browserManifestFile) as bmf:
250259
browsers = [makeBrowserCommand(browser) for browser in json.load(bmf)]
@@ -284,7 +293,7 @@ def setUp(options):
284293
if options.browserManifestFile:
285294
testBrowsers = makeBrowserCommands(options.browserManifestFile)
286295
elif options.browser:
287-
testBrowsers = [BrowserCommand({"path":options.browser, "name":"firefox"})]
296+
testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})]
288297
assert len(testBrowsers) > 0
289298

290299
with open(options.manifestFile) as mf:

0 commit comments

Comments
 (0)