Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 793764 - Mozmill adds collected addons as string but not as list …
Browse files Browse the repository at this point in the history
…to the report. r=jhammel
  • Loading branch information
whimboo committed Sep 24, 2012
1 parent e341328 commit cc8dc7b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
1 change: 1 addition & 0 deletions mozmill/mozmill/__init__.py
Expand Up @@ -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
Expand Down
35 changes: 5 additions & 30 deletions mozmill/mozmill/extension/resource/driver/mozmill.js
Expand Up @@ -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;
});
}

Expand All @@ -149,7 +124,7 @@ function getApplicationDetails() {
startupinfo: getStartupInfo()
};

return JSON.stringify(details);
return utils.convertToUnicode(JSON.stringify(details));
}

function cleanQuit () {
Expand Down
41 changes: 40 additions & 1 deletion mozmill/mozmill/extension/resource/stdlib/utils.js
Expand Up @@ -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",
Expand All @@ -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];
Expand Down
40 changes: 40 additions & 0 deletions 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()
1 change: 1 addition & 0 deletions mutt/mutt/tests/python/tests.ini
Expand Up @@ -4,6 +4,7 @@ type = python
[include:cli/tests.ini]

[expectstacktest.py]
[test_appinfo.py]
[test_bug690154.py]
[test_endTest.py]
[test_loggerListener.py]
Expand Down

0 comments on commit cc8dc7b

Please sign in to comment.