From: Rob Sayre Date: Wed, 29 Jun 2011 18:13:43 +0000 (-0700) Subject: Make the browser command dispatch table-driven and fix the --browser option. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a50136709f3187aed1622b931552fd5f5136c85c;p=pdf.js.git Make the browser command dispatch table-driven and fix the --browser option. --- diff --git a/test/test.py b/test/test.py index 5f75687..96ff816 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: