Bug 544097 Fixing up leaktest and profileserver tests to run with these changes r=ctalbert p=jmaher. Landed on CLOSED TREE
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -136,16 +136,21 @@ class Automation(object):
# We use the logging system here primarily because it'll handle multiple
# threads, which is needed to process the output of the server and application
# processes simultaneously.
handler = logging.StreamHandler(sys.stdout)
self.log.setLevel(logging.INFO)
self.log.addHandler(handler)
+ def setServerInfo(self, server = "mochi.test", httpPort = 8888, sslPort = 4443):
+ self.webServer = server
+ self.httpPort = httpPort
+ self.sslPort = sslPort
+
@property
def __all__(self):
return [
"UNIXISH",
"IS_WIN32",
"IS_MAC",
"log",
"runApp",
@@ -234,26 +239,24 @@ class Automation(object):
locations.append(Location(match.group("scheme"), match.group("host"),
match.group("port"), options))
if not seenPrimary:
raise SyntaxError(lineno + 1, "missing primary location")
return locations
+ def initializeProfile(self, profileDir, extraPrefs = [], useServerLocations = False):
+ " Sets up the standard testing profile."
- def initializeProfile(self, profileDir, extraPrefs = []):
- "Sets up the standard testing profile."
-
+ prefs = []
# Start with a clean slate.
shutil.rmtree(profileDir, True)
os.mkdir(profileDir)
- prefs = []
-
part = """\
user_pref("browser.dom.window.dump.enabled", true);
user_pref("dom.allow_scripts_to_close_windows", true);
user_pref("dom.disable_open_during_load", false);
user_pref("dom.max_script_run_time", 0); // no slow script dialogs
user_pref("dom.max_chrome_script_run_time", 0);
user_pref("dom.popup_maximum", -1);
user_pref("signed.applets.codebase_principal_support", true);
@@ -269,54 +272,64 @@ user_pref("javascript.options.jit.conten
user_pref("gfx.color_management.force_srgb", true);
user_pref("network.manage-offline-status", false);
user_pref("test.mousescroll", true);
user_pref("security.default_personal_cert", "Select Automatically"); // Need to client auth test be w/o any dialogs
user_pref("network.http.prompt-temp-redirect", false);
user_pref("media.cache_size", 100);
user_pref("security.warn_viewing_mixed", false);
-user_pref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
+user_pref("geo.wifi.uri", "http://%(server)s/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
user_pref("geo.wifi.testing", true);
user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others
// Make url-classifier updates so rare that they won't affect tests
user_pref("urlclassifier.updateinterval", 172800);
// Point the url-classifier to the local testing server for fast failures
-user_pref("browser.safebrowsing.provider.0.gethashURL", "http://mochi.test:8888/safebrowsing-dummy/gethash");
-user_pref("browser.safebrowsing.provider.0.keyURL", "http://mochi.test:8888/safebrowsing-dummy/newkey");
-user_pref("browser.safebrowsing.provider.0.lookupURL", "http://mochi.test:8888/safebrowsing-dummy/lookup");
-user_pref("browser.safebrowsing.provider.0.updateURL", "http://mochi.test:8888/safebrowsing-dummy/update");
-"""
-
+user_pref("browser.safebrowsing.provider.0.gethashURL", "http://%(server)s/safebrowsing-dummy/gethash");
+user_pref("browser.safebrowsing.provider.0.keyURL", "http://%(server)s/safebrowsing-dummy/newkey");
+user_pref("browser.safebrowsing.provider.0.lookupURL", "http://%(server)s/safebrowsing-dummy/lookup");
+user_pref("browser.safebrowsing.provider.0.updateURL", "http://%(server)s/safebrowsing-dummy/update");
+""" % { "server" : self.webServer + ":" + str(self.httpPort) }
prefs.append(part)
- locations = self.readLocations()
+ if useServerLocations == False:
+ part = """
+user_pref("capability.principal.codebase.p1.granted",
+ "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite \
+ UniversalPreferencesRead UniversalPreferencesWrite \
+ UniversalFileRead");
+user_pref("capability.principal.codebase.p1.id", "%(origin)s");
+user_pref("capability.principal.codebase.p1.subjectName", "");
+""" % { "origin": "http://" + self.webServer + ":" + str(self.httpPort) }
+ prefs.append(part)
+ else:
+ locations = self.readLocations()
- # Grant God-power to all the privileged servers on which tests run.
- privileged = filter(lambda loc: "privileged" in loc.options, locations)
- for (i, l) in itertools.izip(itertools.count(1), privileged):
- part = """
+ # Grant God-power to all the privileged servers on which tests run.
+ privileged = filter(lambda loc: "privileged" in loc.options, locations)
+ for (i, l) in itertools.izip(itertools.count(1), privileged):
+ part = """
user_pref("capability.principal.codebase.p%(i)d.granted",
"UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite \
UniversalPreferencesRead UniversalPreferencesWrite \
UniversalFileRead");
user_pref("capability.principal.codebase.p%(i)d.id", "%(origin)s");
user_pref("capability.principal.codebase.p%(i)d.subjectName", "");
""" % { "i": i,
"origin": (l.scheme + "://" + l.host + ":" + l.port) }
- prefs.append(part)
+ prefs.append(part)
- # We need to proxy every server but the primary one.
- origins = ["'%s://%s:%s'" % (l.scheme, l.host, l.port)
- for l in filter(lambda l: "primary" not in l.options, locations)]
- origins = ", ".join(origins)
+ # We need to proxy every server but the primary one.
+ origins = ["'%s://%s:%s'" % (l.scheme, l.host, l.port)
+ for l in filter(lambda l: "primary" not in l.options, locations)]
+ origins = ", ".join(origins)
- pacURL = """data:text/plain,
+ pacURL = """data:text/plain,
function FindProxyForURL(url, host)
{
var origins = [%(origins)s];
var regex = new RegExp('^([a-z][-a-z0-9+.]*)' +
'://' +
'(?:[^/@]*@)?' +
'(.*?)' +
'(?::(\\\\\\\\d+))?/');
@@ -335,25 +348,25 @@ function FindProxyForURL(url, host)
if (origins.indexOf(origin) < 0)
return 'DIRECT';
if (isHttp)
return 'PROXY 127.0.0.1:8888';
if (isHttps)
return 'PROXY 127.0.0.1:4443';
return 'DIRECT';
}""" % { "origins": origins }
- pacURL = "".join(pacURL.splitlines())
+ pacURL = "".join(pacURL.splitlines())
- part = """
+ part += """
user_pref("network.proxy.type", 2);
user_pref("network.proxy.autoconfig_url", "%(pacURL)s");
user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless to others
""" % {"pacURL": pacURL}
- prefs.append(part)
+ prefs.append(part)
for v in extraPrefs:
thispref = v.split("=")
if len(thispref) < 2:
print "Error: syntax error in --setpref=" + v
sys.exit(1)
part = 'user_pref("%s", %s);\n' % (thispref[0], thispref[1])
prefs.append(part)
--- a/build/leaktest.py.in
+++ b/build/leaktest.py.in
@@ -67,35 +67,18 @@ if __name__ == '__main__':
automation.log.info("Unable to open logfile " + opts[0][1] + \
"ONLY logging to stdout.")
httpd = EasyServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
t = threading.Thread(target=httpd.serve_forever)
t.setDaemon(True)
t.start()
- # since this requires localhost, we cannot use automation.initializeProfile
- try:
- os.makedirs(PROFILE_DIRECTORY)
- except:
- pass # leaf directory already exists
-
- prefsFile = open(PROFILE_DIRECTORY + "/" + "user.js", "w")
- prefsFile.write('user_pref("dom.popup_maximum", -1);')
- prefsFile.write('user_pref("dom.disable_open_during_load", false);')
- prefsFile.write('user_pref("browser.shell.checkDefaultBrowser", false);')
- prefsFile.write('user_pref("browser.warnOnQuit", false);')
- prefsFile.write('user_pref("dom.allow_scripts_to_close_windows", true);')
- prefsFile.write('user_pref("capability.principal.codebase.p0.granted", \
- "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite \
- UniversalPreferencesRead UniversalPreferencesWrite UniversalFileRead");\n')
- prefsFile.write('user_pref("capability.principal.codebase.p0.id", "http://localhost:%s");\n' % PORT)
- prefsFile.write('user_pref("capability.principal.codebase.p0.subjectName", "");\n')
- prefsFile.close()
-
+ automation.setServerInfo("localhost", PORT)
+ automation.initializeProfile(PROFILE_DIRECTORY)
browserEnv = automation.environment()
if not "XPCOM_DEBUG_BREAK" in browserEnv:
browserEnv["XPCOM_DEBUG_BREAK"] = "stack"
url = "http://localhost:%d/bloatcycle.html" % PORT
appPath = os.path.join(SCRIPT_DIR, automation.DEFAULT_APP)
status = automation.runApp(url, browserEnv, appPath, PROFILE_DIRECTORY,
# leaktest builds are slow, give up and
--- a/build/pgo/profileserver.py.in
+++ b/build/pgo/profileserver.py.in
@@ -57,17 +57,18 @@ class EasyServer(SocketServer.TCPServer)
allow_reuse_address = True
if __name__ == '__main__':
automation = Automation()
httpd = EasyServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
t = threading.Thread(target=httpd.serve_forever)
t.setDaemon(True) # don't hang on exit
t.start()
-
+
+ automation.setServerInfo("localhost", PORT)
automation.initializeProfile(PROFILE_DIRECTORY)
browserEnv = automation.environment()
browserEnv["XPCOM_DEBUG_BREAK"] = "warn"
url = "http://localhost:%d/index.html" % PORT
appPath = os.path.join(SCRIPT_DIR, automation.DEFAULT_APP)
status = automation.runApp(url, browserEnv, appPath, PROFILE_DIRECTORY, {},
# the profiling HTML doesn't output anything,
--- a/content/base/test/file_CSP_evalscript.sjs
+++ b/content/base/test/file_CSP_evalscript.sjs
@@ -9,22 +9,27 @@ function handleRequest(request, response
});
//avoid confusing cache behaviors
response.setHeader("Cache-Control", "no-cache", false);
if ("main" in query) {
var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Components.interfaces.nsIXMLHttpRequest);
+
//serve the main page with a CSP header!
- // -- anything served from 'self' (localhost:8888) will be allowed,
+ // -- anything served from 'self' (mochi.test:8888) will be allowed,
// -- anything served from other hosts (example.com:80) will be blocked.
// -- XHR tests are set up in the file_CSP_main.js file which is sourced.
response.setHeader("X-Content-Security-Policy",
"allow 'self'",
false);
- xhr.open("GET", "http://localhost:8888/tests/content/base/test/file_CSP_evalscript_main.html", false);
+ var proxy = "127.0.0.1";
+ if ("proxy" in query) {
+ proxy = query["proxy"];
+ }
+ xhr.open("GET", "http://" + proxy + "/tests/content/base/test/file_CSP_evalscript_main.html", false);
xhr.send(null);
if(xhr.status == 200) {
response.write(xhr.responseText);
}
}
}
--- a/content/base/test/test_CSP_evalscript.html
+++ b/content/base/test/test_CSP_evalscript.html
@@ -47,16 +47,27 @@ var checkTestResults = function() {
// ... otherwise, finish
SimpleTest.finish();
}
//////////////////////////////////////////////////////////////////////
// set up and go
SimpleTest.waitForExplicitFinish();
+//need to allow for arbitrary network servers, when PAC doesn't work
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+var ios = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService);
+var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
+ getService();
+
+var uri = ios.newURI("http://example.com", null, null);
+var pi = pps.resolve(uri, 0);
+var mozproxy = pi.host + ":" + pi.port;
+
// save this for last so that our listeners are registered.
// ... this loads the testbed of good and bad requests.
-document.getElementById('cspframe').src = 'file_CSP_evalscript.sjs?main';
+document.getElementById('cspframe').src = 'file_CSP_evalscript.sjs?main&proxy=' + mozproxy;
</script>
</pre>
</body>
</html>
--- a/testing/mochitest/runtests.py.in
+++ b/testing/mochitest/runtests.py.in
@@ -346,17 +346,17 @@ class Mochitest(object):
def getLogFilePath(self, logFile):
""" return the log file path relative to the device we are testing on, in most cases
it will be the full path on the local system
"""
return self.getFullPath(logFile)
def buildProfile(self, options):
""" create the profile and add optional chrome bits and files if requested """
- self.automation.initializeProfile(self.PROFILE_DIRECTORY, options.extraPrefs)
+ self.automation.initializeProfile(self.PROFILE_DIRECTORY, options.extraPrefs, useServerLocations = True)
manifest = self.addChromeToProfile(options)
self.copyExtraFilesToProfile(options)
return manifest
def buildBrowserEnv(self, options):
""" build the environment variables for the specific test and operating system """
browserEnv = self.automation.environment(xrePath = options.xrePath)
@@ -564,16 +564,17 @@ overlay chrome://browser/content/browser
dest = os.path.join(self.PROFILE_DIRECTORY, os.path.basename(abspath))
if os.path.isdir(abspath):
shutil.copytree(abspath, dest)
else:
shutil.copy(abspath, dest)
def main():
automation = Automation()
+ automation.setServerInfo()
mochitest = Mochitest(automation)
parser = MochitestOptions(automation, mochitest.SCRIPT_DIRECTORY)
options, args = parser.parse_args()
if options.totalChunks is not None and options.thisChunk is None:
parser.error("thisChunk must be specified when totalChunks is specified")
if options.totalChunks: