Add support for Google Chrome.
This commit is contained in:
parent
3213299f30
commit
d5ef6e1b05
42
test/test.py
42
test/test.py
@ -156,8 +156,7 @@ class PDFTestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
State.done = (0 == State.remaining)
|
||||
|
||||
# this just does Firefox for now
|
||||
class BrowserCommand():
|
||||
class BaseBrowserCommand(object):
|
||||
def __init__(self, browserRecord):
|
||||
self.name = browserRecord["name"]
|
||||
self.path = browserRecord["path"]
|
||||
@ -170,14 +169,9 @@ class BrowserCommand():
|
||||
if not os.path.exists(self.path):
|
||||
throw("Path to browser '%s' does not exist." % self.path)
|
||||
|
||||
def _fixupMacPath(self):
|
||||
self.path = os.path.join(self.path, "Contents", "MacOS", "firefox-bin")
|
||||
|
||||
def setup(self):
|
||||
self.tempDir = tempfile.mkdtemp()
|
||||
self.profileDir = os.path.join(self.tempDir, "profile")
|
||||
shutil.copytree(os.path.join(DOC_ROOT, "test", "resources", "firefox"),
|
||||
self.profileDir)
|
||||
|
||||
def teardown(self):
|
||||
# If the browser is still running, wait up to ten seconds for it to quit
|
||||
@ -194,6 +188,18 @@ class BrowserCommand():
|
||||
if self.tempDir is not None and os.path.exists(self.tempDir):
|
||||
shutil.rmtree(self.tempDir)
|
||||
|
||||
def start(self, url):
|
||||
raise Exception("Can't start BaseBrowserCommand")
|
||||
|
||||
class FirefoxBrowserCommand(BaseBrowserCommand):
|
||||
def _fixupMacPath(self):
|
||||
self.path = os.path.join(self.path, "Contents", "MacOS", "firefox-bin")
|
||||
|
||||
def setup(self):
|
||||
super(FirefoxBrowserCommand, self).setup()
|
||||
shutil.copytree(os.path.join(DOC_ROOT, "test", "resources", "firefox"),
|
||||
self.profileDir)
|
||||
|
||||
def start(self, url):
|
||||
cmds = [self.path]
|
||||
if platform.system() == "Darwin":
|
||||
@ -201,9 +207,29 @@ class BrowserCommand():
|
||||
cmds.extend(["-no-remote", "-profile", self.profileDir, url])
|
||||
self.process = subprocess.Popen(cmds)
|
||||
|
||||
class ChromeBrowserCommand(BaseBrowserCommand):
|
||||
def _fixupMacPath(self):
|
||||
self.path = os.path.join(self.path, "Contents", "MacOS", "Google Chrome")
|
||||
|
||||
def start(self, url):
|
||||
cmds = [self.path]
|
||||
cmds.extend(["--user-data-dir=%s" % self.profileDir,
|
||||
"--no-first-run", "--disable-sync", url])
|
||||
self.process = subprocess.Popen(cmds)
|
||||
|
||||
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:
|
||||
raise Exception("Unrecognized browser: %s" % browser)
|
||||
|
||||
def makeBrowserCommands(browserManifestFile):
|
||||
with open(browserManifestFile) as bmf:
|
||||
browsers = [BrowserCommand(browser) for browser in json.load(bmf)]
|
||||
browsers = [makeBrowserCommand(browser) for browser in json.load(bmf)]
|
||||
return browsers
|
||||
|
||||
def downloadLinkedPDFs(manifestList):
|
||||
|
Loading…
x
Reference in New Issue
Block a user