Bug 894990 - Expose mochitest data file URL via SimpleTest.getTestFileURL. r=jmaher

This commit is contained in:
Alexandre Poirot 2013-09-12 10:48:32 -04:00
parent fb70fd5030
commit a6cb2f6e9a
3 changed files with 40 additions and 0 deletions

View File

@ -15,6 +15,7 @@ _TEST_FILES = \
test_SpecialPowersPushPermissions.html \
test_SpecialPowersPushPrefEnv.html \
file_SpecialPowersFrame1.html \
test_SimpleTestGetTestFileURL.html \
test_bug816847.html \
test_sanity_cleanup.html \
test_sanity_cleanup2.html \

View File

@ -279,6 +279,25 @@ SimpleTest.todo = function(condition, name, diag) {
SimpleTest._tests.push(test);
};
/*
* Returns the absolute URL to a test data file from where tests
* are served. i.e. the file doesn't necessarely exists where tests
* are executed.
* (For b2g and android, mochitest are executed on the device, while
* all mochitest html (and others) files are served from the test runner
* slave)
*/
SimpleTest.getTestFileURL = function(path) {
var lastSlashIdx = path.lastIndexOf("/") + 1;
var filename = path.substr(lastSlashIdx);
var location = window.location;
// Remove mochitest html file name from the path
var remotePath = location.pathname.replace(/\/[^\/]+?$/,"");
var url = location.origin +
remotePath + "/" + path;
return url;
};
SimpleTest._getCurrentTestURL = function() {
return parentRunner && parentRunner.currentTestURL ||
typeof gTestPath == "string" && gTestPath ||

View File

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for SpecialPowers extension</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var filename = "MyTestDataFile.txt";
var url = SimpleTest.getTestFileURL(filename);
is(url, document.location.href.replace(/test_SimpleTestGetTestFileURL\.html.*/, filename));
</script>
</pre>
</body>
</html>