Bug 1150818 - Part 2: Load mozinfo.json into xpcshell tests. r=ted, a=test-only

--HG--
extra : transplant_source : %B0%D4d%DF%0F%0B%9E%22D%2B%F1W%18%0D%02%8B%2BZ%1CQ
This commit is contained in:
Hiroyuki Ikezoe 2015-08-20 16:06:00 -04:00
Родитель 428fac9246
Коммит db1ff5c959
4 изменённых файлов: 91 добавлений и 4 удалений

Просмотреть файл

@ -1214,6 +1214,7 @@ function do_load_child_test_harness()
let command =
"const _HEAD_JS_PATH=" + uneval(_HEAD_JS_PATH) + "; "
+ "const _HEAD_FILES=" + uneval(_HEAD_FILES) + "; "
+ "const _MOZINFO_JS_PATH=" + uneval(_MOZINFO_JS_PATH) + "; "
+ "const _TAIL_FILES=" + uneval(_TAIL_FILES) + "; "
+ "const _TEST_NAME=" + uneval(_TEST_NAME) + "; "
// We'll need more magic to get the debugger working in the child
@ -1519,3 +1520,29 @@ try {
prefs.deleteBranch("browser.devedition.theme.enabled");
}
} catch (e) { }
function _load_mozinfo() {
let mozinfoFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
mozinfoFile.initWithPath(_MOZINFO_JS_PATH);
let stream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
stream.init(mozinfoFile, -1, 0, 0);
let json = Components.classes["@mozilla.org/dom/json;1"]
.createInstance(Components.interfaces.nsIJSON);
let mozinfo = json.decodeFromStream(stream, stream.available());
stream.close();
return mozinfo;
}
Object.defineProperty(this, "mozinfo", {
configurable: true,
get() {
let _mozinfo = _load_mozinfo();
Object.defineProperty(this, "mozinfo", {
configurable: false,
value: _mozinfo
});
return _mozinfo;
}
});

Просмотреть файл

@ -71,6 +71,14 @@ class RemoteXPCShellTestThread(xpcshell.XPCShellTestThread):
self.log.info("profile dir is %s" % self.profileDir)
return self.profileDir
def setupMozinfoJS(self):
local = tempfile.mktemp()
mozinfo.output_to_file(local)
mozInfoJSPath = remoteJoin(self.profileDir, "mozinfo.json")
self.device.pushFile(local, mozInfoJSPath)
os.remove(local)
return mozInfoJSPath
def logCommand(self, name, completeCmd, testdir):
self.log.info("%s | full command: %r" % (name, completeCmd))
self.log.info("%s | current directory: %r" % (name, self.remoteHere))

Просмотреть файл

@ -392,6 +392,12 @@ class XPCShellTestThread(Thread):
self.log.info("profile dir is %s" % profileDir)
return profileDir
def setupMozinfoJS(self):
mozInfoJSPath = os.path.join(self.profileDir, 'mozinfo.json')
mozInfoJSPath = mozInfoJSPath.replace('\\', '\\\\')
mozinfo.output_to_file(mozInfoJSPath)
return mozInfoJSPath
def buildCmdHead(self, headfiles, tailfiles, xpcscmd):
"""
Build the command line arguments for the head and tail files,
@ -456,7 +462,8 @@ class XPCShellTestThread(Thread):
'-r', self.httpdManifest,
'-m',
'-s',
'-e', 'const _HEAD_JS_PATH = "%s";' % self.headJSPath
'-e', 'const _HEAD_JS_PATH = "%s";' % self.headJSPath,
'-e', 'const _MOZINFO_JS_PATH = "%s";' % self.mozInfoJSPath,
]
if self.testingModulesDir:
@ -633,14 +640,16 @@ class XPCShellTestThread(Thread):
self.appPath = None
test_dir = os.path.dirname(path)
self.buildXpcsCmd(test_dir)
head_files, tail_files = self.getHeadAndTailFiles(self.test_object)
cmdH = self.buildCmdHead(head_files, tail_files, self.xpcsCmd)
# Create a profile and a temp dir that the JS harness can stick
# a profile and temporary data in
self.profileDir = self.setupProfileDir()
self.tempDir = self.setupTempDir()
self.mozInfoJSPath = self.setupMozinfoJS()
self.buildXpcsCmd(test_dir)
head_files, tail_files = self.getHeadAndTailFiles(self.test_object)
cmdH = self.buildCmdHead(head_files, tail_files, self.xpcsCmd)
# The test file will have to be loaded after the head files.
cmdT = self.buildCmdTestFile(path)

Просмотреть файл

@ -349,7 +349,21 @@ add_task(function test_2() {
});
'''
LOAD_MOZINFO = '''
function run_test() {
do_check_neq(typeof mozinfo, undefined);
do_check_neq(typeof mozinfo.os, undefined);
}
'''
CHILD_MOZINFO = '''
function run_test () { run_next_test(); }
add_test(function test_child_mozinfo () {
run_test_in_child("test_mozinfo.js");
run_next_test();
});
'''
class XPCShellTestsTests(unittest.TestCase):
"""
Yes, these are unit tests for a unit test harness.
@ -1203,5 +1217,34 @@ add_test({
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
def testMozinfo(self):
"""
Check that mozinfo.json is loaded
"""
self.writeFile("test_mozinfo.js", LOAD_MOZINFO)
self.writeManifest(["test_mozinfo.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertEquals(0, self.x.todoCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
def testChildMozinfo(self):
"""
Check that mozinfo.json is loaded in child process
"""
self.writeFile("test_mozinfo.js", LOAD_MOZINFO)
self.writeFile("test_child_mozinfo.js", CHILD_MOZINFO)
self.writeManifest(["test_child_mozinfo.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertEquals(0, self.x.todoCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
if __name__ == "__main__":
unittest.main(verbosity=3)