Browse Source

Use AppleScript to close Chrome.

Rob Sayre 14 years ago
parent
commit
42b7c7dfc6
  1. 23
      test/test.py
  2. 17
      test/test_slave.html

23
test/test.py

@ -2,7 +2,7 @@ import json, platform, os, shutil, sys, subprocess, tempfile, threading, time, u
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer import SocketServer
from optparse import OptionParser from optparse import OptionParser
from urlparse import urlparse from urlparse import urlparse, parse_qs
USAGE_EXAMPLE = "%prog" USAGE_EXAMPLE = "%prog"
@ -125,13 +125,18 @@ class PDFTestHandler(BaseHTTPRequestHandler):
self.sendFile(path, ext) self.sendFile(path, ext)
def do_POST(self): def do_POST(self):
numBytes = int(self.headers['Content-Length']) numBytes = int(self.headers['Content-Length'])
self.send_response(200) self.send_response(200)
self.send_header('Content-Type', 'text/plain') self.send_header('Content-Type', 'text/plain')
self.end_headers() self.end_headers()
url = urlparse(self.path)
if url.path == "/tellMeToQuit":
tellAppToQuit(url.path, url.query)
return
result = json.loads(self.rfile.read(numBytes)) result = json.loads(self.rfile.read(numBytes))
browser, id, failure, round, page, snapshot = result['browser'], result['id'], result['failure'], result['round'], result['page'], result['snapshot'] browser, id, failure, round, page, snapshot = result['browser'], result['id'], result['failure'], result['round'], result['page'], result['snapshot']
taskResults = State.taskResults[browser][id] taskResults = State.taskResults[browser][id]
@ -156,6 +161,19 @@ class PDFTestHandler(BaseHTTPRequestHandler):
State.done = (0 == State.remaining) State.done = (0 == State.remaining)
# Applescript hack to quit Chrome on Mac
def tellAppToQuit(path, query):
if platform.system() != "Darwin":
return
d = parse_qs(query)
path = d['path'][0]
cmd = """osascript<<END
tell application "%s"
quit
end tell
END""" % path
os.system(cmd)
class BaseBrowserCommand(object): class BaseBrowserCommand(object):
def __init__(self, browserRecord): def __init__(self, browserRecord):
self.name = browserRecord["name"] self.name = browserRecord["name"]
@ -293,6 +311,7 @@ def startBrowsers(browsers, options):
b.setup() b.setup()
print 'Launching', b.name print 'Launching', b.name
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile) qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
qs += '&path=' + b.path
b.start('http://localhost:8080/test/test_slave.html?'+ qs) b.start('http://localhost:8080/test/test_slave.html?'+ qs)
def teardownBrowsers(browsers): def teardownBrowsers(browsers):

17
test/test_slave.html

@ -6,7 +6,7 @@
<script type="text/javascript" src="/fonts.js"></script> <script type="text/javascript" src="/fonts.js"></script>
<script type="text/javascript" src="/glyphlist.js"></script> <script type="text/javascript" src="/glyphlist.js"></script>
<script type="application/javascript"> <script type="application/javascript">
var browser, canvas, currentTask, currentTaskIdx, failure, manifest, numPages, pdfDoc, stdout; var appPath, browser, canvas, currentTask, currentTaskIdx, failure, manifest, numPages, pdfDoc, stdout;
function queryParams() { function queryParams() {
var qs = window.location.search.substring(1); var qs = window.location.search.substring(1);
@ -23,12 +23,13 @@ function load() {
var params = queryParams(); var params = queryParams();
browser = params.browser; browser = params.browser;
manifestFile = params.manifestFile; manifestFile = params.manifestFile;
appPath = params.path;
canvas = document.createElement("canvas"); canvas = document.createElement("canvas");
canvas.mozOpaque = true; canvas.mozOpaque = true;
stdout = document.getElementById("stdout"); stdout = document.getElementById("stdout");
log("Harness thinks this browser is '"+ browser +"'\n"); log("Harness thinks this browser is '"+ browser + "' with path " + appPath + "\n");
log("Fetching manifest "+ manifestFile +"..."); log("Fetching manifest "+ manifestFile +"...");
var r = new XMLHttpRequest(); var r = new XMLHttpRequest();
@ -157,13 +158,21 @@ function snapshotCurrentPage(gfx) {
); );
} }
function sendQuitRequest() {
var r = new XMLHttpRequest();
r.open("POST", "/tellMeToQuit?path=" + escape(appPath), false);
r.send("");
}
function quitApp() { function quitApp() {
log("Done!"); log("Done!");
document.body.innerHTML = "Tests are finished. <h1>CLOSE ME!</h1>"; document.body.innerHTML = "Tests are finished. <h1>CLOSE ME!</h1>";
if (window.SpecialPowers) if (window.SpecialPowers) {
SpecialPowers.quitApplication(); SpecialPowers.quitApplication();
else } else {
sendQuitRequest();
window.close(); window.close();
}
} }
function done() { function done() {

Loading…
Cancel
Save