зеркало из https://github.com/mozilla/pjs.git
Bug 384192 - Simplify the approach to supporting cross-domain Mochitests by moving all the code into runtests.pl.in (so the harnesses don't have to do anything except use the profile created for them). r=robcee, approval not needed for testing changes during yellow
This commit is contained in:
Родитель
321010e664
Коммит
e6e5a5ec21
|
@ -99,6 +99,36 @@ use constant CHROMETESTS_URL => "http://" . TEST_SERVER_HOST . CHROME_PATH;
|
||||||
# (particularly after a build) takes forever.
|
# (particularly after a build) takes forever.
|
||||||
use constant SERVER_STARTUP_TIMEOUT => 45;
|
use constant SERVER_STARTUP_TIMEOUT => 45;
|
||||||
|
|
||||||
|
|
||||||
|
# Since some tests require cross-domain support in Mochitest, across ports,
|
||||||
|
# domains, subdomains, etc. we use a proxy autoconfig hack to map a bunch of
|
||||||
|
# servers onto localhost:8888. We have to grant them the same privileges as
|
||||||
|
# localhost:8888 here, since the browser only knows them as the URLs they're
|
||||||
|
# pretending to be.
|
||||||
|
my @servers = ("localhost:8888", # MUST be first -- see PAC pref-setting code
|
||||||
|
"example.org:80",
|
||||||
|
"test1.example.org:80",
|
||||||
|
"test2.example.org:80",
|
||||||
|
"sub1.test1.example.org:80",
|
||||||
|
"sub1.test2.example.org:80",
|
||||||
|
"sub2.test1.example.org:80",
|
||||||
|
"sub2.test2.example.org:80",
|
||||||
|
"example.org:8000",
|
||||||
|
"test1.example.org:8000",
|
||||||
|
"test2.example.org:8000",
|
||||||
|
"sub1.test1.example.org:8000",
|
||||||
|
"sub1.test2.example.org:8000",
|
||||||
|
"sub2.test1.example.org:8000",
|
||||||
|
"sub2.test2.example.org:8000",
|
||||||
|
"example.com:80",
|
||||||
|
"test1.example.com:80",
|
||||||
|
"test2.example.com:80",
|
||||||
|
"sub1.test1.example.com:80",
|
||||||
|
"sub1.test2.example.com:80",
|
||||||
|
"sub2.test1.example.com:80",
|
||||||
|
"sub2.test2.example.com:80");
|
||||||
|
|
||||||
|
|
||||||
my $profile = "mochitesttestingprofile";
|
my $profile = "mochitesttestingprofile";
|
||||||
my $profile_dir = "$FindBin::Bin/$profile";
|
my $profile_dir = "$FindBin::Bin/$profile";
|
||||||
|
|
||||||
|
@ -367,49 +397,43 @@ user_pref("browser.shell.checkDefaultBrowser", false);
|
||||||
user_pref("browser.warnOnQuit", false);
|
user_pref("browser.warnOnQuit", false);
|
||||||
PREFEND
|
PREFEND
|
||||||
|
|
||||||
#
|
# Grant God-power to all the servers on which tests can run.
|
||||||
# Since some tests require cross-domain support in Mochitest, across ports,
|
|
||||||
# domains, subdomains, etc. we have a proxying hack in cross-domain.js which
|
|
||||||
# maps a bunch of servers onto localhost:8888. We have to grant them the same
|
|
||||||
# privileges as localhost:8888 here, since the browser only knows them as the
|
|
||||||
# URLs they're pretending to be. See cross-domain.js for the other copy of
|
|
||||||
# this list.
|
|
||||||
#
|
|
||||||
# KEEP THESE TWO LISTS IN SYNC!
|
|
||||||
#
|
|
||||||
my @servers = ("http://localhost:8888",
|
|
||||||
"http://example.org:80",
|
|
||||||
"http://test1.example.org:80",
|
|
||||||
"http://test2.example.org:80",
|
|
||||||
"http://sub1.test1.example.org:80",
|
|
||||||
"http://sub1.test2.example.org:80",
|
|
||||||
"http://sub2.test1.example.org:80",
|
|
||||||
"http://sub2.test2.example.org:80",
|
|
||||||
"http://example.org:8000",
|
|
||||||
"http://test1.example.org:8000",
|
|
||||||
"http://test2.example.org:8000",
|
|
||||||
"http://sub1.test1.example.org:8000",
|
|
||||||
"http://sub1.test2.example.org:8000",
|
|
||||||
"http://sub2.test1.example.org:8000",
|
|
||||||
"http://sub2.test2.example.org:8000",
|
|
||||||
"http://example.com:80",
|
|
||||||
"http://test1.example.com:80",
|
|
||||||
"http://test2.example.com:80",
|
|
||||||
"http://sub1.test1.example.com:80",
|
|
||||||
"http://sub1.test2.example.com:80",
|
|
||||||
"http://sub2.test1.example.com:80",
|
|
||||||
"http://sub2.test2.example.com:80");
|
|
||||||
my $i = 1;
|
my $i = 1;
|
||||||
my $server;
|
my $server;
|
||||||
foreach $server (@servers) {
|
foreach $server (@servers) {
|
||||||
$pref_content .= <<SERVERPREFEND;
|
$pref_content .= <<SERVERPREFEND;
|
||||||
user_pref("capability.principal.codebase.p$i.granted", "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite UniversalPreferencesRead UniversalPreferencesWrite UniversalFileRead");
|
user_pref("capability.principal.codebase.p$i.granted", "UniversalXPConnect UniversalBrowserRead UniversalBrowserWrite UniversalPreferencesRead UniversalPreferencesWrite UniversalFileRead");
|
||||||
user_pref("capability.principal.codebase.p$i.id", "$server");
|
user_pref("capability.principal.codebase.p$i.id", "http://$server");
|
||||||
user_pref("capability.principal.codebase.p$i.subjectName", "");
|
user_pref("capability.principal.codebase.p$i.subjectName", "");
|
||||||
SERVERPREFEND
|
SERVERPREFEND
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Now actually create the preference to make the proxying happen, stripping
|
||||||
|
# off the first server because it's the one to which we proxy all the others.
|
||||||
|
my $quotedServers = join(", ", map("'" . $_ . "'", @servers[1 .. $#servers]));
|
||||||
|
|
||||||
|
my $pacURL = "data:text/plain,";
|
||||||
|
$pacURL .= "function FindProxyForURL(url, host) ";
|
||||||
|
$pacURL .= "{ ";
|
||||||
|
$pacURL .= " var servers = [$quotedServers]; ";
|
||||||
|
$pacURL .= " var regex = ";
|
||||||
|
$pacURL .= " new RegExp('http://(.*?(:\\\\\\\\d+)?)/'); ";
|
||||||
|
$pacURL .= " var matches = regex.exec(url); ";
|
||||||
|
$pacURL .= " var hostport = matches[1], port = matches[2]; ";
|
||||||
|
$pacURL .= " if (!port) ";
|
||||||
|
$pacURL .= " hostport += ':80'; ";
|
||||||
|
$pacURL .= " if (servers.indexOf(hostport) >= 0) ";
|
||||||
|
$pacURL .= " return 'PROXY localhost:8888'; ";
|
||||||
|
$pacURL .= " return 'DIRECT'; ";
|
||||||
|
$pacURL .= "}";
|
||||||
|
|
||||||
|
$pref_content .= <<PROXYPREFEND;
|
||||||
|
user_pref("network.proxy.type", 2);
|
||||||
|
user_pref("network.proxy.autoconfig_url", "$pacURL");
|
||||||
|
PROXYPREFEND
|
||||||
|
|
||||||
|
|
||||||
my $chrome_content = <<CHROMEEND;
|
my $chrome_content = <<CHROMEEND;
|
||||||
\@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
|
\@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
|
||||||
toolbar,
|
toolbar,
|
||||||
|
|
|
@ -401,8 +401,6 @@ function testListing(metadata, response)
|
||||||
src: "/tests/SimpleTest/TestRunner.js"}),
|
src: "/tests/SimpleTest/TestRunner.js"}),
|
||||||
SCRIPT({type: "text/javascript",
|
SCRIPT({type: "text/javascript",
|
||||||
src: "/tests/SimpleTest/MozillaFileLogger.js"}),
|
src: "/tests/SimpleTest/MozillaFileLogger.js"}),
|
||||||
SCRIPT({type: "text/javascript",
|
|
||||||
src: "/tests/SimpleTest/cross-domain.js"}),
|
|
||||||
SCRIPT({type: "text/javascript",
|
SCRIPT({type: "text/javascript",
|
||||||
src: "/tests/SimpleTest/quit.js"}),
|
src: "/tests/SimpleTest/quit.js"}),
|
||||||
SCRIPT({type: "text/javascript",
|
SCRIPT({type: "text/javascript",
|
||||||
|
|
|
@ -51,7 +51,6 @@ _SIMPLETEST_FILES = MozillaFileLogger.js \
|
||||||
TestRunner.js \
|
TestRunner.js \
|
||||||
setup.js \
|
setup.js \
|
||||||
EventUtils.js \
|
EventUtils.js \
|
||||||
cross-domain.js \
|
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
libs:: $(_SIMPLETEST_FILES)
|
libs:: $(_SIMPLETEST_FILES)
|
||||||
|
|
|
@ -1,258 +0,0 @@
|
||||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
||||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
|
||||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
* http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
||||||
* for the specific language governing rights and limitations under the
|
|
||||||
* License.
|
|
||||||
*
|
|
||||||
* The Original Code is the DomainMapper code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is
|
|
||||||
* Mozilla Corporation.
|
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
||||||
* the Initial Developer. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Jeff Walden <jwalden+code@mit.edu> (original author)
|
|
||||||
*
|
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
||||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
||||||
* the provisions above, a recipient may use your version of this file under
|
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
|
|
||||||
// http://kb.mozillazine.org/Network.proxy.autoconfig_url
|
|
||||||
// http://kb.mozillazine.org/Network.proxy.type
|
|
||||||
//
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
||||||
|
|
||||||
if (!this.Cc)
|
|
||||||
this.Cc = Components.classes;
|
|
||||||
if (!this.Ci)
|
|
||||||
this.Ci = Components.interfaces;
|
|
||||||
if (!this.Cr)
|
|
||||||
this.Cr = Components.results;
|
|
||||||
|
|
||||||
const PROXY_AUTOCONFIG_PREF = "network.proxy.autoconfig_url";
|
|
||||||
const PROXY_TYPE_PREF = "network.proxy.type";
|
|
||||||
const PROXY_TYPE_USE_PAC = 2;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps requests in the browser to particular domains/ports through other
|
|
||||||
* domains/ports in a customizable manner.
|
|
||||||
*/
|
|
||||||
function DomainMapper()
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Hash of host:port for mapped host/ports to host:port for the host:port
|
|
||||||
* which should be used instead.
|
|
||||||
*/
|
|
||||||
this._mappings = {};
|
|
||||||
|
|
||||||
/** Identifies the old proxy type, if any. */
|
|
||||||
this._oldProxyType = undefined;
|
|
||||||
|
|
||||||
/** Identifies the old PAC URL, if any. */
|
|
||||||
this._oldPAC = undefined;
|
|
||||||
|
|
||||||
/** True when mapping is enabled. */
|
|
||||||
this._enabled = false;
|
|
||||||
}
|
|
||||||
DomainMapper.prototype =
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Adds a mapping for requests to fromHost:fromPort so that they are
|
|
||||||
* actually made to toHost:toPort.
|
|
||||||
*/
|
|
||||||
addMapping: function(fromHost, fromPort, toHost, toPort)
|
|
||||||
{
|
|
||||||
this._mappings[fromHost + ":" + fromPort] = toHost + ":" + toPort;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a mapping for requests to fromHost:fromPort, if one exists; if
|
|
||||||
* none exists, this is a no-op.
|
|
||||||
*/
|
|
||||||
removeMapping: function(host, port)
|
|
||||||
{
|
|
||||||
delete this._mappings[host + ":" + port];
|
|
||||||
},
|
|
||||||
|
|
||||||
/** True if mapping functionality is enabled. */
|
|
||||||
get isEnabled()
|
|
||||||
{
|
|
||||||
return this._enabled;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables all registered mappings, or updates mappings if already enabled.
|
|
||||||
*/
|
|
||||||
enable: function()
|
|
||||||
{
|
|
||||||
if (this._enabled)
|
|
||||||
{
|
|
||||||
this.syncMappings();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
|
||||||
.getService(Ci.nsIPrefBranch);
|
|
||||||
|
|
||||||
// Change the proxy autoconfiguration URL first, if it's present
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this._oldPAC = prefs.getCharPref(PROXY_AUTOCONFIG_PREF);
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
this._oldPAC = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now change the proxy settings to use the PAC URL
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this._oldProxyType = prefs.getIntPref(PROXY_TYPE_PREF);
|
|
||||||
prefs.setIntPref(PROXY_TYPE_PREF, PROXY_TYPE_USE_PAC);
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
this._oldProxyType = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._enabled = true;
|
|
||||||
|
|
||||||
this.syncMappings();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates URL mappings currently in use with those specified when this was
|
|
||||||
* enabled.
|
|
||||||
*
|
|
||||||
* @throws NS_ERROR_UNEXPECTED
|
|
||||||
* if this method is called when mapping functionality is not enabled
|
|
||||||
*/
|
|
||||||
syncMappings: function()
|
|
||||||
{
|
|
||||||
if (!this._enabled)
|
|
||||||
throw Cr.NS_ERROR_UNEXPECTED;
|
|
||||||
|
|
||||||
var url = "data:text/plain,";
|
|
||||||
url += "function FindProxyForURL(url, host) ";
|
|
||||||
url += "{ ";
|
|
||||||
url += " var mappings = " + this._mappings.toSource() + "; ";
|
|
||||||
url += " var regex = new RegExp('http://(.*?(:\\\\d+)?)/'); ";
|
|
||||||
url += " var matches = regex.exec(url); ";
|
|
||||||
url += " var hostport = matches[1], port = matches[2]; ";
|
|
||||||
url += " if (!port) ";
|
|
||||||
url += " hostport += ':80'; ";
|
|
||||||
url += " if (hostport in mappings) ";
|
|
||||||
url += " return 'PROXY ' + mappings[hostport]; ";
|
|
||||||
url += " return 'DIRECT'; ";
|
|
||||||
url += "}";
|
|
||||||
|
|
||||||
Cc["@mozilla.org/preferences-service;1"]
|
|
||||||
.getService(Ci.nsIPrefBranch)
|
|
||||||
.setCharPref(PROXY_AUTOCONFIG_PREF, url);
|
|
||||||
},
|
|
||||||
|
|
||||||
/** Disables all domain mapping functionality. */
|
|
||||||
disable: function()
|
|
||||||
{
|
|
||||||
if (!this._enabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
|
||||||
.getService(Ci.nsIPrefBranch);
|
|
||||||
|
|
||||||
if (this._oldPAC !== undefined)
|
|
||||||
prefs.setCharPref(PROXY_AUTOCONFIG_PREF, this._oldPAC);
|
|
||||||
this._oldPAC = undefined;
|
|
||||||
|
|
||||||
prefs.setIntPref(PROXY_TYPE_PREF, this._oldProxyType);
|
|
||||||
this._oldProxyType = undefined;
|
|
||||||
|
|
||||||
this._enabled = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// BEGIN CROSS-DOMAIN CODE
|
|
||||||
//
|
|
||||||
// Various pieces of code must be able to test functionality when run on
|
|
||||||
// effectively arbitrary ports, hosts, etc. for cross-domain purposes,
|
|
||||||
// usually for security. We provide that support here, mapping the desired
|
|
||||||
// additional host/port pairs onto the original server at localhost:8888.
|
|
||||||
//
|
|
||||||
// We have chosen to "take over" the example.org and example.com domains here,
|
|
||||||
// because per RFC 2606, example.org is reserved for testing and other such
|
|
||||||
// activities and can be safely "hijacked" for cross-domain testing.
|
|
||||||
//
|
|
||||||
// The set of domains chosen here is mostly taken from an IRC conversation
|
|
||||||
// with bz and from <https://bugzilla.mozilla.org/show_bug.cgi?id=332179>;
|
|
||||||
// the original set was .org+80, and bz wanted a parallel .com and .org+8000.
|
|
||||||
//
|
|
||||||
// This list must be duplicated in runtests.pl.in to set the appropriate
|
|
||||||
// security preferences to not have to display privilege escalation prompts.
|
|
||||||
// KEEP THIS LIST IN SYNC WITH THAT ONE!
|
|
||||||
//
|
|
||||||
var mappedHostPorts =
|
|
||||||
[
|
|
||||||
{host: "example.org", port: 80},
|
|
||||||
{host: "test1.example.org", port: 80},
|
|
||||||
{host: "test2.example.org", port: 80},
|
|
||||||
{host: "sub1.test1.example.org", port: 80},
|
|
||||||
{host: "sub1.test2.example.org", port: 80},
|
|
||||||
{host: "sub2.test1.example.org", port: 80},
|
|
||||||
{host: "sub2.test2.example.org", port: 80},
|
|
||||||
{host: "example.org", port: 8000},
|
|
||||||
{host: "test1.example.org", port: 8000},
|
|
||||||
{host: "test2.example.org", port: 8000},
|
|
||||||
{host: "sub1.test1.example.org", port: 8000},
|
|
||||||
{host: "sub1.test2.example.org", port: 8000},
|
|
||||||
{host: "sub2.test1.example.org", port: 8000},
|
|
||||||
{host: "sub2.test2.example.org", port: 8000},
|
|
||||||
{host: "example.com", port: 80},
|
|
||||||
{host: "test1.example.com", port: 80},
|
|
||||||
{host: "test2.example.com", port: 80},
|
|
||||||
{host: "sub1.test1.example.com", port: 80},
|
|
||||||
{host: "sub1.test2.example.com", port: 80},
|
|
||||||
{host: "sub2.test1.example.com", port: 80},
|
|
||||||
{host: "sub2.test2.example.com", port: 80},
|
|
||||||
];
|
|
||||||
|
|
||||||
var crossDomain = new DomainMapper();
|
|
||||||
for (var i = 0, sz = mappedHostPorts.length; i < sz; i++)
|
|
||||||
{
|
|
||||||
var hostPort = mappedHostPorts[i];
|
|
||||||
crossDomain.addMapping(hostPort.host, hostPort.port, "localhost", 8888);
|
|
||||||
}
|
|
||||||
crossDomain.enable();
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
throw "privilege failure enabling cross-domain: " + e;
|
|
||||||
}
|
|
|
@ -99,10 +99,6 @@ function goQuitApplication()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// shut down cross-domain mapping (really reverts preference values)
|
|
||||||
if (typeof crossDomain != "undefined")
|
|
||||||
crossDomain.disable();
|
|
||||||
|
|
||||||
const kAppStartup = '@mozilla.org/toolkit/app-startup;1';
|
const kAppStartup = '@mozilla.org/toolkit/app-startup;1';
|
||||||
const kAppShell = '@mozilla.org/appshell/appShellService;1';
|
const kAppShell = '@mozilla.org/appshell/appShellService;1';
|
||||||
var appService;
|
var appService;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче