From 20f2ebf6b22c2c6e6a07c9712571b645d0340038 Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Wed, 5 Jun 2013 17:20:50 +0800 Subject: [PATCH 1/3] Bug 879225: NetworkManager - extract hostname from various formats. r=gene --- dom/system/gonk/NetworkManager.js | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/dom/system/gonk/NetworkManager.js b/dom/system/gonk/NetworkManager.js index 3affc853603f..fa7c4290b15a 100644 --- a/dom/system/gonk/NetworkManager.js +++ b/dom/system/gonk/NetworkManager.js @@ -130,6 +130,13 @@ function isComplete(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. @@ -216,6 +223,10 @@ function NetworkManager() { }); 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, @@ -611,17 +622,25 @@ NetworkManager.prototype = { 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; From c9d308fc3fed43e72efad33eb17cb5438dcc2f1a Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Wed, 5 Jun 2013 17:42:42 +0800 Subject: [PATCH 2/3] Bug 877141 - add test cases for sending SMS with continuous space characters. r=gene --- .../marionette/test_strict_7bit_encoding.js | 109 +++++++++++++----- 1 file changed, 78 insertions(+), 31 deletions(-) diff --git a/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js b/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js index 0dc80f85cbb9..b0da1372144f 100644 --- a/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js +++ b/dom/mobilemessage/tests/marionette/test_strict_7bit_encoding.js @@ -116,15 +116,40 @@ 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, -function testStrict7BitEncodingHelper(sent, received, next) { + push: function push(func) { + this._tasks.push(func); + }, + + 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)|. @@ -135,7 +160,7 @@ function testStrict7BitEncodingHelper(sent, received, next) { function done(step) { count += step; if (count >= 2) { - window.setTimeout(next, 0); + window.setTimeout(tasks.next.bind(tasks), 0); } } @@ -161,53 +186,75 @@ function testStrict7BitEncodingHelper(sent, received, next) { }); } -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. +// 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); +}); - repeat(testStrict7BitEncodingHelper, cases, test_disabled); -} +tasks.push(testBug877141); -function test_disabled() { +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]); + testStrict7BitEncodingHelper(sent, sent); +}); - cases.push(["\u65b0\u5e74\u5feb\u6a02", "\u65b0\u5e74\u5feb\u6a02"]); +tasks.push(function () { + // "Happy New Year" in Chinese. + let sent = "\u65b0\u5e74\u5feb\u6a02"; + testStrict7BitEncodingHelper(sent, sent); +}); - repeat(testStrict7BitEncodingHelper, cases, cleanUp); -} +tasks.push(testBug877141); -function cleanUp() { +// 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(); From 0e85692770a987ba52b2cefbad6d53f4d7b41a20 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 5 Jun 2013 07:55:01 -0400 Subject: [PATCH 3/3] Bug 879529 - Fix thread priorities in B2G child processes. r=gsvelto Previously, suppose we were changing a process's priority from 18 to 1. If a task had priority 19, that should have changed to 2. But instead we changed it to 18! That's totally wrong. --- hal/gonk/GonkHal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index 8c2dce347082..0a60cf7da30d 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -1166,7 +1166,7 @@ SetNiceForPid(int aPid, int aNice) } int newtaskpriority = - std::max(origtaskpriority + aNice - origProcPriority, origProcPriority); + std::max(origtaskpriority - origProcPriority + aNice, aNice); rv = setpriority(PRIO_PROCESS, tid, newtaskpriority); if (rv) {