From a50136709f3187aed1622b931552fd5f5136c85c Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Wed, 29 Jun 2011 11:13:43 -0700 Subject: [PATCH] Make the browser command dispatch table-driven and fix the --browser option. --- test/test.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/test.py b/test/test.py index 5f756877a..96ff81672 100644 --- a/test/test.py +++ b/test/test.py @@ -237,14 +237,23 @@ class ChromeBrowserCommand(BaseBrowserCommand): def makeBrowserCommand(browser): path = browser["path"].lower() - name = browser["name"].lower() - if name.find("firefox") > -1 or path.find("firefox") > -1: - return FirefoxBrowserCommand(browser) - elif name.find("chrom") > -1 or path.find("chrom") > -1: - return ChromeBrowserCommand(browser) - else: + name = browser["name"] + if name is not None: + name = name.lower() + + types = {"firefox": FirefoxBrowserCommand, + "chrome": ChromeBrowserCommand } + command = None + for key in types.keys(): + if (name and name.find(key) > -1) or path.find(key) > -1: + command = types[key](browser) + command.name = command.name or key + + if command is None: raise Exception("Unrecognized browser: %s" % browser) + return command + def makeBrowserCommands(browserManifestFile): with open(browserManifestFile) as bmf: browsers = [makeBrowserCommand(browser) for browser in json.load(bmf)] @@ -284,7 +293,7 @@ def setUp(options): if options.browserManifestFile: testBrowsers = makeBrowserCommands(options.browserManifestFile) elif options.browser: - testBrowsers = [BrowserCommand({"path":options.browser, "name":"firefox"})] + testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})] assert len(testBrowsers) > 0 with open(options.manifestFile) as mf: