author | Ed Morley <emorley@mozilla.com> |
Wed, 05 Jun 2013 11:49:44 +0100 | |
changeset 134136 | e49f78051ab4dc9cc0b00806a2c97f12102a1297 |
parent 134078 | ddb7b23166ef3ddafad31b326fd97bd8a2a9def4 (current diff) |
parent 134135 | 307d7abbf1c01e522a1cea8b6ba66421f2c2fcb3 (diff) |
child 134137 | de1f999797ab9cbeac96fc183ff4ea68f73edb51 |
push id | 29067 |
push user | ryanvm@gmail.com |
push date | Wed, 05 Jun 2013 20:37:20 +0000 |
treeherder | mozilla-inbound@72fbfb2f8e51 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
milestone | 24.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js +++ b/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js @@ -111,36 +111,61 @@ const GSM_SMS_STRICT_7BIT_CHARMAP = { const SELF = "5554"; SpecialPowers.setBoolPref("dom.sms.enabled", true); SpecialPowers.addPermission("sms", true, document); let sms = window.navigator.mozSms; ok(sms instanceof MozSmsManager); -function repeat(func, array, oncomplete) { - (function do_call(index) { - let next = index < (array.length - 1) ? do_call.bind(null, index + 1) : oncomplete; - array[index].push(next); - func.apply(null, array[index]); - })(0); -} +let tasks = { + // List of test fuctions. Each of them should call |tasks.next()| when + // completed or |tasks.finish()| to jump to the last one. + _tasks: [], + _nextTaskIndex: 0, + + push: function push(func) { + this._tasks.push(func); + }, -function testStrict7BitEncodingHelper(sent, received, next) { + next: function next() { + let index = this._nextTaskIndex++; + let task = this._tasks[index]; + try { + task(); + } catch (ex) { + ok(false, "test task[" + index + "] throws: " + ex); + // Run last task as clean up if possible. + if (index != this._tasks.length - 1) { + this.finish(); + } + } + }, + + finish: function finish() { + this._tasks[this._tasks.length - 1](); + }, + + run: function run() { + this.next(); + } +}; + +function testStrict7BitEncodingHelper(sent, received) { // The log message contains unicode and Marionette seems unable to process // it and throws: |UnicodeEncodeError: 'ascii' codec can't encode character // u'\xa5' in position 14: ordinal not in range(128)|. // //log("Testing '" + sent + "' => '" + received + "'"); let count = 0; function done(step) { count += step; if (count >= 2) { - window.setTimeout(next, 0); + window.setTimeout(tasks.next.bind(tasks), 0); } } sms.addEventListener("received", function onReceived(event) { event.target.removeEventListener("received", onReceived); let message = event.message; is(message.body, received, "received message.body"); @@ -156,58 +181,80 @@ function testStrict7BitEncodingHelper(se done(1); }); request.addEventListener("error", function onRequestError(event) { ok(false, "Can't send message out!!!"); done(2); }); } -function test_enabled() { +// Bug 877141 - If you send several spaces together in a sms, the other +// dipositive receives a "*" for each space. +// +// This function is called twice, with strict 7bit encoding enabled or +// disabled. Expect the same result in both sent and received text and with +// either strict 7bit encoding enabled or disabled. +function testBug877141() { + log("Testing bug 877141"); + let sent = "1 2 3"; + testStrict7BitEncodingHelper(sent, sent); +} + +tasks.push(function () { log("Testing with dom.sms.strict7BitEncoding enabled"); - SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", true); + tasks.next(); +}); - let cases = []; - // Test for combined string. +// Test for combined string. +tasks.push(function () { let sent = "", received = ""; for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) { sent += c; received += GSM_SMS_STRICT_7BIT_CHARMAP[c]; } - cases.push([sent, received]); + testStrict7BitEncodingHelper(sent, received); +}); - // When strict7BitEncoding is enabled, we should replace characters that - // can't be encoded with GSM 7-Bit alphabets with '*'. - cases.push(["\u65b0\u5e74\u5feb\u6a02", "****"]); // "Happy New Year" in Chinese. - - repeat(testStrict7BitEncodingHelper, cases, test_disabled); -} +// When strict7BitEncoding is enabled, we should replace characters that +// can't be encoded with GSM 7-Bit alphabets with '*'. +tasks.push(function () { + // "Happy New Year" in Chinese. + let sent = "\u65b0\u5e74\u5feb\u6a02", received = "****"; + testStrict7BitEncodingHelper(sent, received); +}); -function test_disabled() { +tasks.push(testBug877141); + +tasks.push(function () { log("Testing with dom.sms.strict7BitEncoding disabled"); - SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", false); + tasks.next(); +}); - let cases = []; - - // Test for combined string. +// Test for combined string. +tasks.push(function () { let sent = ""; for (let c in GSM_SMS_STRICT_7BIT_CHARMAP) { sent += c; } - cases.push([sent, sent]); - - cases.push(["\u65b0\u5e74\u5feb\u6a02", "\u65b0\u5e74\u5feb\u6a02"]); + testStrict7BitEncodingHelper(sent, sent); +}); - repeat(testStrict7BitEncodingHelper, cases, cleanUp); -} +tasks.push(function () { + // "Happy New Year" in Chinese. + let sent = "\u65b0\u5e74\u5feb\u6a02"; + testStrict7BitEncodingHelper(sent, sent); +}); -function cleanUp() { +tasks.push(testBug877141); + +// WARNING: All tasks should be pushed before this!!! +tasks.push(function cleanUp() { SpecialPowers.removePermission("sms", document); SpecialPowers.clearUserPref("dom.sms.enabled"); SpecialPowers.clearUserPref("dom.sms.strict7BitEncoding"); finish(); -} +}); -test_enabled(); +tasks.run();
--- a/dom/system/gonk/NetworkManager.js +++ b/dom/system/gonk/NetworkManager.js @@ -125,16 +125,23 @@ function isError(code) { return (type != NETD_COMMAND_PROCEEDING && type != NETD_COMMAND_OKAY); } function isComplete(code) { let type = netdResponseType(code); return (type != NETD_COMMAND_PROCEEDING); } +function defineLazyRegExp(obj, name, pattern) { + obj.__defineGetter__(name, function() { + delete obj[name]; + return obj[name] = new RegExp(pattern); + }); +} + /** * This component watches for network interfaces changing state and then * adjusts routes etc. accordingly. */ function NetworkManager() { this.networkInterfaces = {}; Services.obs.addObserver(this, TOPIC_INTERFACE_STATE_CHANGED, true); Services.obs.addObserver(this, TOPIC_INTERFACE_REGISTERED, true); @@ -211,16 +218,20 @@ function NetworkManager() { }, handleError: function (aErrorMessage) { debug("Error reading the 'tethering.wifi.enabled' setting: " + aErrorMessage); } }); ppmm.addMessageListener('NetworkInterfaceList:ListInterface', this); + + // Used in resolveHostname(). + defineLazyRegExp(this, "REGEXP_IPV4", "^\\d{1,3}(?:\\.\\d{1,3}){3}$"); + defineLazyRegExp(this, "REGEXP_IPV6", "^[\\da-fA-F]{4}(?::[\\da-fA-F]{4}){7}$"); } NetworkManager.prototype = { classID: NETWORKMANAGER_CID, classInfo: XPCOMUtils.generateCI({classID: NETWORKMANAGER_CID, contractID: NETWORKMANAGER_CONTRACTID, classDescription: "Network Manager", interfaces: [Ci.nsINetworkManager]}), QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkManager, @@ -606,27 +617,35 @@ NetworkManager.prototype = { hostnames: [network.dns1, network.dns2, network.httpProxyHost] }; this.worker.postMessage(options); }, resolveHostname: function resolveHostname(hosts) { let retval = []; - for(var i = 0; i < hosts.length; i++) { - let hostname = hosts[i].split('/')[2]; - if (!hostname) { + for (let hostname of hosts) { + try { + let uri = Services.io.newURI(hostname, null, null); + hostname = uri.host; + } catch (e) {} + + if (hostname.match(this.REGEXP_IPV4) || + hostname.match(this.REGEXP_IPV6)) { + retval.push(hostname); continue; } - let hostnameIps = gDNSService.resolve(hostname, 0); - while (hostnameIps.hasMore()) { - retval.push(hostnameIps.getNextAddrAsString()); - debug("Found IP at: " + JSON.stringify(retval)); - } + try { + let hostnameIps = gDNSService.resolve(hostname, 0); + while (hostnameIps.hasMore()) { + retval.push(hostnameIps.getNextAddrAsString()); + debug("Found IP at: " + JSON.stringify(retval)); + } + } catch (e) {} } return retval; }, addHostRouteWithResolve: function addHostRouteWithResolve(network, hosts) { debug("Going to add host route after dns resolution on " + network.name); let options = {