diff --git a/mozmill/mozmill/__init__.py b/mozmill/mozmill/__init__.py index 9a58cfa9..0cdfd52b 100644 --- a/mozmill/mozmill/__init__.py +++ b/mozmill/mozmill/__init__.py @@ -425,6 +425,7 @@ def get_appinfo(self, bridge): try: mozmill = jsbridge.JSObject(bridge, js_module_mozmill) app_info = json.loads(mozmill.getApplicationDetails()) + except JSBridgeDisconnectError: # We don't have to call report_disconnect here because # start_runner() will handle this exception diff --git a/mozmill/mozmill/extension/resource/driver/mozmill.js b/mozmill/mozmill/extension/resource/driver/mozmill.js index c971808e..fd6de07c 100644 --- a/mozmill/mozmill/extension/resource/driver/mozmill.js +++ b/mozmill/mozmill/extension/resource/driver/mozmill.js @@ -93,36 +93,11 @@ function getStartupInfo() { } // keep list of installed addons to send to jsbridge for test run report -var addons = "null"; // this will be JSON parsed -if (typeof AddonManager != "undefined") { - AddonManager.getAllAddons(function (addonList) { - var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] - .createInstance(Ci.nsIScriptableUnicodeConverter); - converter.charset = 'utf-8'; - - function replacer(key, value) { - if (typeof(value) == "string") { - try { - return converter.ConvertToUnicode(value); - } catch (e) { - var newstring = ''; - for (var i=0; i < value.length; i++) { - replacement = ''; - if ((32 <= value.charCodeAt(i)) && (value.charCodeAt(i) < 127)) { - // eliminate non-convertable characters; - newstring += value.charAt(i); - } else { - newstring += replacement; - } - } - return newstring; - } - } - - return value; - } +var addons = "null"; - addons = converter.ConvertToUnicode(JSON.stringify(addonList, replacer)); +if (typeof AddonManager != "undefined") { + AddonManager.getAllAddons(function (aAddonList) { + addons = aAddonList; }); } @@ -149,7 +124,7 @@ function getApplicationDetails() { startupinfo: getStartupInfo() }; - return JSON.stringify(details); + return utils.convertToUnicode(JSON.stringify(details)); } function cleanQuit () { diff --git a/mozmill/mozmill/extension/resource/stdlib/utils.js b/mozmill/mozmill/extension/resource/stdlib/utils.js index 85c9ff48..4a630302 100644 --- a/mozmill/mozmill/extension/resource/stdlib/utils.js +++ b/mozmill/mozmill/extension/resource/stdlib/utils.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var EXPORTED_SYMBOLS = ["Copy", "getChromeWindow", "getWindows", +var EXPORTED_SYMBOLS = ["convertToUnicode", "Copy", "getChromeWindow", "getWindows", "getWindowByTitle", "getWindowByType", "getWindowId", "getMethodInWindows", "getPreference", "setPreference", "sleep", "assert", "unwrapNode", "TimeoutError", "waitFor", @@ -22,6 +22,45 @@ var hwindow = Cc["@mozilla.org/appshell/appShellService;1"] var uuidgen = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); + +/** + * Converts the text from the source charset to Unicode. + * Non-convertable characters will be replaced by a question mark. + * + * @param {String} aText Text to convert + * @return {String} Unicode string + */ +function convertToUnicode(aText) { + var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); + converter.charset = 'utf-8'; + + function replacer(aKey, aValue) { + if (typeof(aValue) === "string") { + try { + return converter.ConvertToUnicode(aValue); + } catch (e) { + var newstring = ''; + for (var i = 0; i < aValue.length; i++) { + replacement = '?'; + if ((32 <= aValue.charCodeAt(i)) && (aValue.charCodeAt(i) < 127)) { + // eliminate non-convertable characters; + newstring += aValue.charAt(i); + } else { + newstring += replacement; + } + } + + return newstring; + } + } + + return aValue; + } + + return converter.ConvertToUnicode(aText, replacer); +} + function Copy (obj) { for (var n in obj) { this[n] = obj[n]; diff --git a/mutt/mutt/tests/python/test_appinfo.py b/mutt/mutt/tests/python/test_appinfo.py new file mode 100644 index 00000000..cf1031a8 --- /dev/null +++ b/mutt/mutt/tests/python/test_appinfo.py @@ -0,0 +1,40 @@ +import os +import unittest +import tempfile + +import mozmill + + +class ModuleTest(unittest.TestCase): + def make_test(self): + """make an example test to run""" + test = """var test_something = function() {}""" + fd, path = tempfile.mkstemp() + os.write(fd, test) + os.close(fd) + + return path + + def test_appinfo(self): + tests = [{'path': self.make_test()}] + + m = mozmill.MozMill.create() + m.run(tests) + results = m.finish() + + self.assertRegexpMatches(results.appinfo.get('application_id'), "^{.*}$") + self.assertIsInstance(results.appinfo.get('application_name'), unicode) + self.assertIsInstance(results.appinfo.get('application_version'), unicode) + self.assertIsInstance(results.appinfo.get('application_locale'), unicode) + self.assertRegexpMatches(results.appinfo.get('platform_buildid'), "^[0-9]*$") + self.assertIsInstance(results.appinfo.get('application_version'), unicode) + self.assertIsInstance(results.appinfo.get('startupinfo'), dict) + + addons = results.appinfo.get('addons') + self.assertIsInstance(addons, list) + self.assertGreaterEqual(len(addons), 2, + "At least Mozmill and JSBridge should be installed.") + + +if __name__ == '__main__': + unittest.main() diff --git a/mutt/mutt/tests/python/tests.ini b/mutt/mutt/tests/python/tests.ini index 2518505e..714ed312 100644 --- a/mutt/mutt/tests/python/tests.ini +++ b/mutt/mutt/tests/python/tests.ini @@ -4,6 +4,7 @@ type = python [include:cli/tests.ini] [expectstacktest.py] +[test_appinfo.py] [test_bug690154.py] [test_endTest.py] [test_loggerListener.py]