From 8b1669d5d60a610d5813541ee5f5b73eabfbbb09 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Wed, 22 Jun 2011 16:56:31 -0700 Subject: [PATCH 01/12] Change test.py to use an external browser_manifest.json file, and use OptionParser to handle the command line. --- browser_manifest.json | 7 +++ test.py | 104 ++++++++++++++++++++++++++++++------------ 2 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 browser_manifest.json diff --git a/browser_manifest.json b/browser_manifest.json new file mode 100644 index 000000000..79115d1a4 --- /dev/null +++ b/browser_manifest.json @@ -0,0 +1,7 @@ +[ + { + "name":"Firefox 5", + "path":"/Applications/Firefox.app", + "type":"firefox" + } +] \ No newline at end of file diff --git a/test.py b/test.py index 0c326ec09..8314bd794 100644 --- a/test.py +++ b/test.py @@ -1,18 +1,41 @@ -import json, os, sys, subprocess, urllib2 +import json, platform, os, sys, subprocess, urllib, urllib2 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +from optparse import OptionParser from urlparse import urlparse +USAGE_EXAMPLE = "%prog" + +ANAL = True +DEFAULT_MANIFEST_FILE = 'test_manifest.json' +DEFAULT_BROWSER_MANIFEST_FILE = 'browser_manifest.json' +REFDIR = 'ref' +TMPDIR = 'tmp' +VERBOSE = False + +class TestOptions(OptionParser): + def __init__(self, **kwargs): + OptionParser.__init__(self, **kwargs) + self.add_option("-m", "--masterMode", action="store_true", dest="masterMode", + help="Run the script in master mode.", default=False) + self.add_option("--manifestFile", action="store", type="string", dest="manifestFile", + help="A JSON file in the form of test_manifest.json (the default).") + self.add_option("--browserManifestFile", action="store", type="string", + dest="browserManifestFile", + help="A JSON file in the form of browser_manifest.json (the default).", + default=DEFAULT_BROWSER_MANIFEST_FILE) + self.set_usage(USAGE_EXAMPLE) + + def verifyOptions(self, options): + if options.masterMode and options.manifestFile: + self.error("--masterMode and --manifestFile must not be specified at the same time.") + options.manifestFile = DEFAULT_MANIFEST_FILE + return options + def prompt(question): '''Return True iff the user answered "yes" to |question|.''' inp = raw_input(question +' [yes/no] > ') return inp == 'yes' -ANAL = True -DEFAULT_MANIFEST_FILE = 'test_manifest.json' -REFDIR = 'ref' -TMPDIR = 'tmp' -VERBOSE = False - MIMEs = { '.css': 'text/css', '.html': 'text/html', @@ -100,13 +123,34 @@ class PDFTestHandler(BaseHTTPRequestHandler): State.done = (0 == State.remaining) +# this just does Firefox for now +class BrowserCommand(): + def __init__(self, browserRecord): + print browserRecord + self.name = browserRecord["name"] + self.path = browserRecord["path"] + self.type = browserRecord["type"] -def setUp(manifestFile, masterMode): + if platform.system() == "Darwin" and self.path.endswith(".app"): + self._fixupMacPath() + + if not os.path.exists(self.path): + throw("Path to browser '%s' does not exist." % self.path) + + def _fixupMacPath(self): + self.path = self.path + "/Contents/MacOS/firefox-bin" + +def makeBrowserCommands(browserManifestFile): + with open(browserManifestFile) as bmf: + browsers = [BrowserCommand(browser) for browser in json.load(bmf)] + return browsers + +def setUp(options): # Only serve files from a pdf.js clone assert not ANAL or os.path.isfile('pdf.js') and os.path.isdir('.git') - State.masterMode = masterMode - if masterMode and os.path.isdir(TMPDIR): + State.masterMode = options.masterMode + if options.masterMode and os.path.isdir(TMPDIR): print 'Temporary snapshot dir tmp/ is still around.' print 'tmp/ can be removed if it has nothing you need.' if prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'): @@ -114,14 +158,10 @@ def setUp(manifestFile, masterMode): assert not os.path.isdir(TMPDIR) - testBrowsers = [ b for b in - ( 'firefox5', ) -#'chrome12', 'chrome13', 'firefox4', 'firefox6','opera11' ): - if os.access(b, os.R_OK | os.X_OK) ] + testBrowsers = makeBrowserCommands(options.browserManifestFile) - mf = open(manifestFile) - manifestList = json.load(mf) - mf.close() + with open(options.manifestFile) as mf: + manifestList = json.load(mf) for item in manifestList: f, isLink = item['file'], item.get('link', False) @@ -140,22 +180,26 @@ def setUp(manifestFile, masterMode): print 'done' + print testBrowsers + for b in testBrowsers: - State.taskResults[b] = { } + State.taskResults[b.name] = { } for item in manifestList: id, rounds = item['id'], int(item['rounds']) State.manifest[id] = item taskResults = [ ] for r in xrange(rounds): taskResults.append([ ]) - State.taskResults[b][id] = taskResults + State.taskResults[b.name][id] = taskResults State.remaining = len(manifestList) + + for b in testBrowsers: - print 'Launching', b - qs = 'browser='+ b +'&manifestFile='+ manifestFile - subprocess.Popen(( os.path.abspath(os.path.realpath(b)), + print 'Launching', b.name + qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) + subprocess.Popen(( os.path.abspath(os.path.realpath(b.path)), 'http://localhost:8080/test_slave.html?'+ qs)) @@ -285,14 +329,14 @@ def processResults(): print 'done' -def main(args): - masterMode = False - manifestFile = DEFAULT_MANIFEST_FILE - if len(args) == 1: - masterMode = (args[0] == '-m') - manifestFile = args[0] if not masterMode else manifestFile +def main(): + optionParser = TestOptions() + options, args = optionParser.parse_args() + options = optionParser.verifyOptions(options) + if options == None: + sys.exit(1) - setUp(manifestFile, masterMode) + setUp(options) server = HTTPServer(('127.0.0.1', 8080), PDFTestHandler) while not State.done: @@ -301,4 +345,4 @@ def main(args): processResults() if __name__ == '__main__': - main(sys.argv[1:]) + main() From c3ef14bb2f3f500cedc64577b35bd09972a9b607 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Wed, 22 Jun 2011 17:12:02 -0700 Subject: [PATCH 02/12] remove some accidental print statements. --- test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test.py b/test.py index 8314bd794..75810f43e 100644 --- a/test.py +++ b/test.py @@ -126,7 +126,6 @@ class PDFTestHandler(BaseHTTPRequestHandler): # this just does Firefox for now class BrowserCommand(): def __init__(self, browserRecord): - print browserRecord self.name = browserRecord["name"] self.path = browserRecord["path"] self.type = browserRecord["type"] @@ -180,8 +179,6 @@ def setUp(options): print 'done' - print testBrowsers - for b in testBrowsers: State.taskResults[b.name] = { } for item in manifestList: From 5ae4857efd8ad907dedb6d8817affcae38818296 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Thu, 23 Jun 2011 09:05:51 -0700 Subject: [PATCH 03/12] Add new test directories. --- test/.gitignore | 0 test/pdfs/.gitignore | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/.gitignore create mode 100644 test/pdfs/.gitignore diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore new file mode 100644 index 000000000..e69de29bb From 0d5f92deedb16d3e8b85fc2c6dcf753f572cedd2 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Thu, 23 Jun 2011 09:10:06 -0700 Subject: [PATCH 04/12] Move some files around. --- browser_manifest.json => test/browser_manifest.json | 0 {tests => test/pdfs}/canvas.pdf | Bin {tests => test/pdfs}/pdf.pdf.link | 0 {tests => test/pdfs}/tracemonkey.pdf | Bin test.py => test/test.py | 0 test_manifest.json => test/test_manifest.json | 0 test_slave.html => test/test_slave.html | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename browser_manifest.json => test/browser_manifest.json (100%) rename {tests => test/pdfs}/canvas.pdf (100%) rename {tests => test/pdfs}/pdf.pdf.link (100%) rename {tests => test/pdfs}/tracemonkey.pdf (100%) rename test.py => test/test.py (100%) rename test_manifest.json => test/test_manifest.json (100%) rename test_slave.html => test/test_slave.html (100%) diff --git a/browser_manifest.json b/test/browser_manifest.json similarity index 100% rename from browser_manifest.json rename to test/browser_manifest.json diff --git a/tests/canvas.pdf b/test/pdfs/canvas.pdf similarity index 100% rename from tests/canvas.pdf rename to test/pdfs/canvas.pdf diff --git a/tests/pdf.pdf.link b/test/pdfs/pdf.pdf.link similarity index 100% rename from tests/pdf.pdf.link rename to test/pdfs/pdf.pdf.link diff --git a/tests/tracemonkey.pdf b/test/pdfs/tracemonkey.pdf similarity index 100% rename from tests/tracemonkey.pdf rename to test/pdfs/tracemonkey.pdf diff --git a/test.py b/test/test.py similarity index 100% rename from test.py rename to test/test.py diff --git a/test_manifest.json b/test/test_manifest.json similarity index 100% rename from test_manifest.json rename to test/test_manifest.json diff --git a/test_slave.html b/test/test_slave.html similarity index 100% rename from test_slave.html rename to test/test_slave.html From 0a8e1110a33cbe3c7f4be3ad259647a4fc69485f Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Thu, 23 Jun 2011 09:48:34 -0700 Subject: [PATCH 05/12] Modify paths of web resources to work with test resources more buried. --- test/browser_manifest.json | 2 +- test/test.py | 18 +++++++++--------- test/test_manifest.json | 8 ++++---- test/test_slave.html | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/browser_manifest.json b/test/browser_manifest.json index 79115d1a4..f11c97c11 100644 --- a/test/browser_manifest.json +++ b/test/browser_manifest.json @@ -1,6 +1,6 @@ [ { - "name":"Firefox 5", + "name":"firefox5", "path":"/Applications/Firefox.app", "type":"firefox" } diff --git a/test/test.py b/test/test.py index 75810f43e..acdd0c552 100644 --- a/test/test.py +++ b/test/test.py @@ -5,6 +5,9 @@ from urlparse import urlparse USAGE_EXAMPLE = "%prog" +# The local web server uses the git repo as the document root. +DOC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) + ANAL = True DEFAULT_MANIFEST_FILE = 'test_manifest.json' DEFAULT_BROWSER_MANIFEST_FILE = 'browser_manifest.json' @@ -73,15 +76,14 @@ class PDFTestHandler(BaseHTTPRequestHandler): def do_GET(self): url = urlparse(self.path) + print "GET",url # Ignore query string path, _ = url.path, url.query - cwd = os.getcwd() - path = os.path.abspath(os.path.realpath(cwd + os.sep + path)) - cwd = os.path.abspath(cwd) - prefix = os.path.commonprefix(( path, cwd )) + path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path)) + prefix = os.path.commonprefix(( path, DOC_ROOT )) _, ext = os.path.splitext(path) - if not (prefix == cwd + if not (prefix == DOC_ROOT and os.path.isfile(path) and ext in MIMEs): self.send_error(404) @@ -146,7 +148,7 @@ def makeBrowserCommands(browserManifestFile): def setUp(options): # Only serve files from a pdf.js clone - assert not ANAL or os.path.isfile('pdf.js') and os.path.isdir('.git') + assert not ANAL or os.path.isfile('../pdf.js') and os.path.isdir('../.git') State.masterMode = options.masterMode if options.masterMode and os.path.isdir(TMPDIR): @@ -191,13 +193,11 @@ def setUp(options): State.remaining = len(manifestList) - - for b in testBrowsers: print 'Launching', b.name qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) subprocess.Popen(( os.path.abspath(os.path.realpath(b.path)), - 'http://localhost:8080/test_slave.html?'+ qs)) + 'http://localhost:8080/test/test_slave.html?'+ qs)) def check(task, results, browser): diff --git a/test/test_manifest.json b/test/test_manifest.json index 036b7aafc..e4a7ada81 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1,21 +1,21 @@ [ { "id": "tracemonkey-eq", - "file": "tests/tracemonkey.pdf", + "file": "pdfs/tracemonkey.pdf", "rounds": 1, "type": "eq" }, { "id": "tracemonkey-fbf", - "file": "tests/tracemonkey.pdf", + "file": "pdfs/tracemonkey.pdf", "rounds": 2, "type": "fbf" }, { "id": "html5-canvas-cheat-sheet-load", - "file": "tests/canvas.pdf", + "file": "pdfs/canvas.pdf", "rounds": 1, "type": "load" }, { "id": "pdfspec-load", - "file": "tests/pdf.pdf", + "file": "pdfs/pdf.pdf", "link": true, "rounds": 1, "type": "load" diff --git a/test/test_slave.html b/test/test_slave.html index 06b911810..80e374709 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -1,9 +1,9 @@ pdf.js test slave - - - + + +