Permalink
Browse files

Bug 793764 - Mozmill adds collected addons as string but not as list …

…to the report. r=jhammel
  • Loading branch information...
1 parent e341328 commit cc8dc7b7f4f53cae5bf470250bb02c5d450c8ca0 @whimboo whimboo committed Sep 24, 2012
@@ -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
@@ -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 () {
@@ -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];
@@ -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()
@@ -4,6 +4,7 @@ type = python
[include:cli/tests.ini]
[expectstacktest.py]
+[test_appinfo.py]
[test_bug690154.py]
[test_endTest.py]
[test_loggerListener.py]

0 comments on commit cc8dc7b

Please sign in to comment.