This commit is contained in:
Phil Ringnalda 2014-02-17 15:27:12 -08:00
Родитель dd5e4ae26d efd3a4681c
Коммит d15ea8727b
62 изменённых файлов: 2888 добавлений и 1784 удалений

Просмотреть файл

@ -12,7 +12,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="eda08beb3ba9a159843c70ffde0f9660ec351eb9"/>

Просмотреть файл

@ -11,7 +11,7 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="3d5c964015967ca8c86abe6dbbebee3cb82b1609"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="a314508e397c8f1814228d36259ea8708034444e"/>

Просмотреть файл

@ -12,7 +12,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="eda08beb3ba9a159843c70ffde0f9660ec351eb9"/>

Просмотреть файл

@ -1,4 +1,4 @@
{
"revision": "0818ccb401e793689adda5b6253e52fdeccba2f9",
"revision": "1adfbae4582a2cebf4b35c822044299aa8dd1026",
"repo_path": "/integration/gaia-central"
}

Просмотреть файл

@ -11,7 +11,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="84f2f2fce22605e17d511ff1767e54770067b5b5"/>

Просмотреть файл

@ -10,7 +10,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="84f2f2fce22605e17d511ff1767e54770067b5b5"/>

Просмотреть файл

@ -12,7 +12,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="84f2f2fce22605e17d511ff1767e54770067b5b5"/>

Просмотреть файл

@ -11,7 +11,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="84f2f2fce22605e17d511ff1767e54770067b5b5"/>

Просмотреть файл

@ -11,7 +11,7 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="3d5c964015967ca8c86abe6dbbebee3cb82b1609"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="a314508e397c8f1814228d36259ea8708034444e"/>

Просмотреть файл

@ -11,7 +11,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="bf497b7adfaa4c087d492acf7f143a61b5ec08e9"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="ae90f9b322509ee09fbd3963bd23e142845613ab"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="78b908b493bfe0b477e3d4f6edec8c46a2c0d096"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="84f2f2fce22605e17d511ff1767e54770067b5b5"/>

Просмотреть файл

@ -1005,8 +1005,13 @@ var gBrowserInit = {
}
// Note: loadOneOrMoreURIs *must not* be called if window.arguments.length >= 3.
// Such callers expect that window.arguments[0] is handled as a single URI.
else
else {
if (uriToLoad == "about:newtab" &&
Services.prefs.getBoolPref("browser.newtabpage.enabled")) {
Services.telemetry.getHistogramById("NEWTAB_PAGE_SHOWN").add(true);
}
loadOneOrMoreURIs(uriToLoad);
}
}
#ifdef MOZ_SAFE_BROWSING

Просмотреть файл

@ -85,6 +85,8 @@ let gPage = {
this._mutationObserver = new MutationObserver(() => {
if (this.allowBackgroundCaptures) {
Services.telemetry.getHistogramById("NEWTAB_PAGE_SHOWN").add(true);
for (let site of gGrid.sites) {
if (site) {
site.captureIfMissing();

Просмотреть файл

@ -92,15 +92,9 @@
#elif MOZ_MSVC_REDIST == 1700
@BINPATH@/msvcp110.dll
@BINPATH@/msvcr110.dll
#ifdef MOZ_METRO
@BINPATH@/vccorlib110.dll
#endif
#elif MOZ_MSVC_REDIST == 1800
@BINPATH@/msvcp120.dll
@BINPATH@/msvcr120.dll
#ifdef MOZ_METRO
@BINPATH@/vccorlib120.dll
#endif
#endif
#endif
#endif

Просмотреть файл

@ -659,10 +659,14 @@ void MediaDecoderStateMachine::SendStreamData()
if (mInfo.HasAudio()) {
AudioSegment* audio = new AudioSegment();
mediaStream->AddTrack(TRACK_AUDIO, mInfo.mAudio.mRate, 0, audio);
stream->mStream->DispatchWhenNotEnoughBuffered(TRACK_AUDIO,
GetStateMachineThread(), GetWakeDecoderRunnable());
}
if (mInfo.HasVideo()) {
VideoSegment* video = new VideoSegment();
mediaStream->AddTrack(TRACK_VIDEO, RATE_VIDEO, 0, video);
stream->mStream->DispatchWhenNotEnoughBuffered(TRACK_VIDEO,
GetStateMachineThread(), GetWakeDecoderRunnable());
}
stream->mStreamInitialized = true;
}

Просмотреть файл

@ -2200,7 +2200,9 @@ SourceMediaStream::DispatchWhenNotEnoughBuffered(TrackID aID,
}
if (data->mHaveEnough) {
data->mDispatchWhenNotEnough.AppendElement()->Init(aSignalThread, aSignalRunnable);
if (data->mDispatchWhenNotEnough.IsEmpty()) {
data->mDispatchWhenNotEnough.AppendElement()->Init(aSignalThread, aSignalRunnable);
}
} else {
aSignalThread->Dispatch(aSignalRunnable, 0);
}

Просмотреть файл

@ -672,7 +672,7 @@ public:
* Ensures that aSignalRunnable will be dispatched to aSignalThread
* when we don't have enough buffered data in the track (which could be
* immediately). Will dispatch the runnable immediately if the track
* does not exist.
* does not exist. No op if a runnable is already present for this track.
*/
void DispatchWhenNotEnoughBuffered(TrackID aID,
nsIThread* aSignalThread, nsIRunnable* aSignalRunnable);

Просмотреть файл

@ -2259,11 +2259,11 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults)
if (sPostGCEventsToObserver) {
NS_NAMED_MULTILINE_LITERAL_STRING(kJSONFmt,
MOZ_UTF16("{ \"timestamp\": %llu, ")
MOZ_UTF16("\"duration\": %llu, ")
MOZ_UTF16("\"max_slice_pause\": %llu, ")
MOZ_UTF16("\"total_slice_pause\": %llu, ")
MOZ_UTF16("\"max_finish_gc_duration\": %llu, ")
MOZ_UTF16("\"max_sync_skippable_duration\": %llu, ")
MOZ_UTF16("\"duration\": %lu, ")
MOZ_UTF16("\"max_slice_pause\": %lu, ")
MOZ_UTF16("\"total_slice_pause\": %lu, ")
MOZ_UTF16("\"max_finish_gc_duration\": %lu, ")
MOZ_UTF16("\"max_sync_skippable_duration\": %lu, ")
MOZ_UTF16("\"suspected\": %lu, ")
MOZ_UTF16("\"visited\": { ")
MOZ_UTF16("\"RCed\": %lu, ")

Просмотреть файл

@ -1557,47 +1557,14 @@ DataConnectionHandler.prototype = {
};
function RadioInterfaceLayer() {
let options = {
debug: debugPref,
cellBroadcastDisabled: false,
clirMode: RIL.CLIR_DEFAULT,
quirks: {
callstateExtraUint32:
libcutils.property_get("ro.moz.ril.callstate_extra_int", "false") === "true",
v5Legacy:
libcutils.property_get("ro.moz.ril.v5_legacy", "true") === "true",
requestUseDialEmergencyCall:
libcutils.property_get("ro.moz.ril.dial_emergency_call", "false") === "true",
simAppStateExtraFields:
libcutils.property_get("ro.moz.ril.simstate_extra_field", "false") === "true",
extraUint2ndCall:
libcutils.property_get("ro.moz.ril.extra_int_2nd_call", "false") == "true",
haveQueryIccLockRetryCount:
libcutils.property_get("ro.moz.ril.query_icc_count", "false") == "true",
sendStkProfileDownload:
libcutils.property_get("ro.moz.ril.send_stk_profile_dl", "false") == "true",
dataRegistrationOnDemand:
libcutils.property_get("ro.moz.ril.data_reg_on_demand", "false") == "true"
},
rilEmergencyNumbers: libcutils.property_get("ril.ecclist") ||
libcutils.property_get("ro.ril.ecclist")
};
try {
options.cellBroadcastDisabled =
Services.prefs.getBoolPref(kPrefCellBroadcastDisabled);
} catch(e) {}
try {
options.clirMode = Services.prefs.getIntPref(kPrefClirModePreference);
} catch(e) {}
let workerMessenger = new WorkerMessenger();
workerMessenger.init();
let numIfaces = this.numRadioInterfaces;
if (DEBUG) debug(numIfaces + " interfaces");
this.radioInterfaces = [];
for (let clientId = 0; clientId < numIfaces; clientId++) {
options.clientId = clientId;
this.radioInterfaces.push(new RadioInterface(options));
this.radioInterfaces.push(new RadioInterface(clientId, workerMessenger));
}
Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
@ -1672,25 +1639,17 @@ XPCOMUtils.defineLazyGetter(RadioInterfaceLayer.prototype,
return 1;
});
function WorkerMessenger(radioInterface, options) {
function WorkerMessenger() {
// Initial owning attributes.
this.radioInterface = radioInterface;
this.radioInterfaces = [];
this.tokenCallbackMap = {};
// Add a convenient alias to |radioInterface.debug()|.
this.debug = radioInterface.debug.bind(radioInterface);
if (DEBUG) this.debug("Starting RIL Worker[" + options.clientId + "]");
this.worker = new ChromeWorker("resource://gre/modules/ril_worker.js");
this.worker.onerror = this.onerror.bind(this);
this.worker.onmessage = this.onmessage.bind(this);
this.send("setInitialOptions", options);
gSystemWorkerManager.registerRilWorker(options.clientId, this.worker);
}
WorkerMessenger.prototype = {
radioInterface: null,
radioInterfaces: null,
worker: null,
// This gets incremented each time we send out a message.
@ -1699,9 +1658,53 @@ WorkerMessenger.prototype = {
// Maps tokens we send out with messages to the message callback.
tokenCallbackMap: null,
init: function() {
let options = {
debug: DEBUG,
cellBroadcastDisabled: false,
clirMode: RIL.CLIR_DEFAULT,
quirks: {
callstateExtraUint32:
libcutils.property_get("ro.moz.ril.callstate_extra_int", "false") === "true",
v5Legacy:
libcutils.property_get("ro.moz.ril.v5_legacy", "true") === "true",
requestUseDialEmergencyCall:
libcutils.property_get("ro.moz.ril.dial_emergency_call", "false") === "true",
simAppStateExtraFields:
libcutils.property_get("ro.moz.ril.simstate_extra_field", "false") === "true",
extraUint2ndCall:
libcutils.property_get("ro.moz.ril.extra_int_2nd_call", "false") == "true",
haveQueryIccLockRetryCount:
libcutils.property_get("ro.moz.ril.query_icc_count", "false") == "true",
sendStkProfileDownload:
libcutils.property_get("ro.moz.ril.send_stk_profile_dl", "false") == "true",
dataRegistrationOnDemand:
libcutils.property_get("ro.moz.ril.data_reg_on_demand", "false") == "true"
},
rilEmergencyNumbers: libcutils.property_get("ril.ecclist") ||
libcutils.property_get("ro.ril.ecclist")
};
try {
options.cellBroadcastDisabled =
Services.prefs.getBoolPref(kPrefCellBroadcastDisabled);
} catch(e) {}
try {
options.clirMode = Services.prefs.getIntPref(kPrefClirModePreference);
} catch(e) {}
this.send(null, "setInitialOptions", options);
},
debug: function(aClientId, aMessage) {
// We use the same debug subject with RadioInterface's here.
dump("-*- RadioInterface[" + aClientId + "]: " + aMessage + "\n");
},
onerror: function(event) {
if (DEBUG) {
this.debug("Got an error: " + event.filename + ":" +
this.debug("X", "Got an error: " + event.filename + ":" +
event.lineno + ": " + event.message + "\n");
}
event.preventDefault();
@ -1712,20 +1715,26 @@ WorkerMessenger.prototype = {
*/
onmessage: function(event) {
let message = event.data;
let clientId = message.rilMessageClientId;
if (clientId === null) {
return;
}
if (DEBUG) {
this.debug("Received message from worker: " + JSON.stringify(message));
this.debug(clientId, "Received message from worker: " + JSON.stringify(message));
}
let token = message.rilMessageToken;
if (token == null) {
// That's an unsolicited message. Pass to RadioInterface directly.
this.radioInterface.handleUnsolicitedWorkerMessage(message);
let radioInterface = this.radioInterfaces[clientId];
radioInterface.handleUnsolicitedWorkerMessage(message);
return;
}
let callback = this.tokenCallbackMap[message.rilMessageToken];
if (!callback) {
if (DEBUG) this.debug("Ignore orphan token: " + message.rilMessageToken);
if (DEBUG) this.debug(clientId, "Ignore orphan token: " + message.rilMessageToken);
return;
}
@ -1733,7 +1742,7 @@ WorkerMessenger.prototype = {
try {
keep = callback(message);
} catch(e) {
if (DEBUG) this.debug("callback throws an exception: " + e);
if (DEBUG) this.debug(clientId, "callback throws an exception: " + e);
}
if (!keep) {
@ -1741,6 +1750,16 @@ WorkerMessenger.prototype = {
}
},
registerClient: function(aClientId, aRadioInterface) {
if (DEBUG) this.debug(aClientId, "Starting RIL Worker");
// Keep a reference so that we can dispatch unsolicited messages to it.
this.radioInterfaces[aClientId] = aRadioInterface;
this.send(null, "registerClient", { clientId: aClientId });
gSystemWorkerManager.registerRilWorker(aClientId, this.worker);
},
/**
* Send arbitrary message to worker.
*
@ -1756,9 +1775,10 @@ WorkerMessenger.prototype = {
* value true to keep current token-callback mapping and wait for
* another worker reply, or false to remove the mapping.
*/
send: function(rilMessageType, message, callback) {
send: function(clientId, rilMessageType, message, callback) {
message = message || {};
message.rilMessageClientId = clientId;
message.rilMessageToken = this.token;
this.token++;
@ -1789,11 +1809,11 @@ WorkerMessenger.prototype = {
*
* @TODO: Bug 815526 - deprecate RILContentHelper.
*/
sendWithIPCMessage: function(msg, rilMessageType, ipcType) {
this.send(rilMessageType, msg.json.data, (function(reply) {
sendWithIPCMessage: function(clientId, msg, rilMessageType, ipcType) {
this.send(clientId, rilMessageType, msg.json.data, (function(reply) {
ipcType = ipcType || msg.name;
msg.target.sendAsyncMessage(ipcType, {
clientId: this.radioInterface.clientId,
clientId: clientId,
data: reply
});
return false;
@ -1801,9 +1821,14 @@ WorkerMessenger.prototype = {
}
};
function RadioInterface(options) {
this.clientId = options.clientId;
this.workerMessenger = new WorkerMessenger(this, options);
function RadioInterface(aClientId, aWorkerMessenger) {
this.clientId = aClientId;
this.workerMessenger = {
send: aWorkerMessenger.send.bind(aWorkerMessenger, aClientId),
sendWithIPCMessage:
aWorkerMessenger.sendWithIPCMessage.bind(aWorkerMessenger, aClientId),
};
aWorkerMessenger.registerClient(aClientId, this);
this.supportedNetworkTypes = this.getSupportedNetworkTypes();
@ -1896,7 +1921,7 @@ RadioInterface.prototype = {
Ci.nsIObserver,
Ci.nsISettingsServiceCallback]),
// A private WorkerMessenger instance.
// A private wrapped WorkerMessenger instance.
workerMessenger: null,
debug: function(s) {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -43,15 +43,11 @@ function newWorker(custom_ns) {
onmessage: undefined,
onerror: undefined,
CLIENT_ID: 0,
DEBUG: true
};
// The 'self' variable in a worker points to the worker's own namespace.
worker_ns.self = worker_ns;
// systemlibs.js utilizes ctypes for loading native libraries.
Cu.import("resource://gre/modules/ctypes.jsm", worker_ns);
// Copy the custom definitions over.
for (let key in custom_ns) {
worker_ns[key] = custom_ns[key];
@ -76,6 +72,9 @@ function newWorker(custom_ns) {
// Load the RIL worker itself.
worker_ns.importScripts("ril_worker.js");
// Register at least one client.
worker_ns.ContextPool.registerClient({ clientId: 0 });
return worker_ns;
}

Просмотреть файл

@ -15,18 +15,19 @@ const NEW_PIN = "1234";
*/
function newUint8Worker() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
worker.Buf.writeUint8 = function(value) {
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
@ -37,7 +38,8 @@ function newUint8Worker() {
add_test(function test_change_call_barring_password() {
let worker = newUint8Worker();
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
function do_test(facility, pin, newPin) {
buf.sendParcel = function fakeSendParcel () {
@ -55,7 +57,7 @@ add_test(function test_change_call_barring_password() {
};
let options = {facility: facility, pin: pin, newPin: newPin};
worker.RIL.changeCallBarringPassword(options);
context.RIL.changeCallBarringPassword(options);
}
do_test(ICC_CB_FACILITY_BA_ALL, PIN, NEW_PIN);
@ -73,15 +75,16 @@ add_test(function test_check_change_call_barring_password_result() {
}
});
worker.RIL.changeCallBarringPassword =
let context = worker.ContextPool._contexts[0];
context.RIL.changeCallBarringPassword =
function fakeChangeCallBarringPassword(options) {
barringPasswordOptions = options;
worker.RIL[REQUEST_CHANGE_BARRING_PASSWORD](0, {
context.RIL[REQUEST_CHANGE_BARRING_PASSWORD](0, {
rilRequestError: ERROR_SUCCESS
});
}
worker.RIL.changeCallBarringPassword({pin: PIN, newPin: NEW_PIN});
context.RIL.changeCallBarringPassword({pin: PIN, newPin: NEW_PIN});
run_next_test();
});

Просмотреть файл

@ -31,15 +31,15 @@ function add_test_incoming_parcel(parcel, handler) {
[0, 0, 0, 0]);
}
let context = worker.ContextPool._contexts[0];
// supports only requests less or equal than UINT8_MAX(255).
let buf = worker.Buf;
let buf = context.Buf;
let request = parcel[buf.PARCEL_SIZE_SIZE + buf.UINT32_SIZE];
worker.RIL[request] = function ril_request_handler() {
handler(worker);
worker.postMessage();
context.RIL[request] = function ril_request_handler() {
handler.apply(this, arguments);
};
worker.onRILMessage(parcel);
worker.onRILMessage(0, parcel);
// end of incoming parcel's trip, let's do next test.
run_next_test();
@ -48,28 +48,30 @@ function add_test_incoming_parcel(parcel, handler) {
// Test normal parcel handling.
add_test_incoming_parcel(null,
function test_normal_parcel_handling(worker) {
function test_normal_parcel_handling() {
let self = this;
do_check_throws(function normal_handler() {
// reads exactly the same size, should not throw anything.
worker.Buf.readInt32();
self.context.Buf.readInt32();
});
}
);
// Test parcel under read.
add_test_incoming_parcel(null,
function test_parcel_under_read(worker) {
function test_parcel_under_read() {
let self = this;
do_check_throws(function under_read_handler() {
// reads less than parcel size, should not throw.
worker.Buf.readUint16();
self.context.Buf.readUint16();
});
}
);
// Test parcel over read.
add_test_incoming_parcel(null,
function test_parcel_over_read(worker) {
let buf = worker.Buf;
function test_parcel_over_read() {
let buf = this.context.Buf;
// read all data available
while (buf.readAvailable > 0) {
@ -94,8 +96,9 @@ add_test(function test_incoming_parcel_buffer_overwritten() {
}
});
let context = worker.ContextPool._contexts[0];
// A convenient alias.
let buf = worker.Buf;
let buf = context.Buf;
// Allocate an array of specified size and set each of its elements to value.
function calloc(length, value) {
@ -108,7 +111,7 @@ add_test(function test_incoming_parcel_buffer_overwritten() {
// Do nothing in handleParcel().
let request = worker.REQUEST_VOICE_REGISTRATION_STATE;
worker.RIL[request] = null;
context.RIL[request] = null;
// Prepare two parcels, whose sizes are both smaller than the incoming buffer
// size but larger when combined, to trigger the bug.
@ -128,7 +131,7 @@ add_test(function test_incoming_parcel_buffer_overwritten() {
// First, send an incomplete pA and verifies related data pointer:
let p1 = pA.subarray(0, pA.length - 1);
worker.onRILMessage(p1);
worker.onRILMessage(0, p1);
// The parcel should not have been processed.
do_check_eq(buf.readAvailable, 0);
// buf.currentParcelSize should have been set because incoming data has more
@ -144,7 +147,7 @@ add_test(function test_incoming_parcel_buffer_overwritten() {
let p2 = new Uint8Array(1 + pB.length);
p2.set(pA.subarray(pA.length - 1), 0);
p2.set(pB, 1);
worker.onRILMessage(p2);
worker.onRILMessage(0, p2);
// The parcels should have been both consumed.
do_check_eq(buf.readAvailable, 0);
// No parcel data remains.
@ -160,8 +163,8 @@ add_test(function test_incoming_parcel_buffer_overwritten() {
// Test Buf.readUint8Array.
add_test_incoming_parcel(null,
function test_buf_readUint8Array(worker) {
let buf = worker.Buf;
function test_buf_readUint8Array() {
let buf = this.context.Buf;
let u8array = buf.readUint8Array(1);
do_check_eq(u8array instanceof Uint8Array, true);

Просмотреть файл

@ -23,15 +23,16 @@ function newWorkerWithParcel(parcelBuf) {
let index = 0; // index for read
let buf = parcelBuf;
worker.Buf.readUint8 = function() {
let context = worker.ContextPool._contexts[0];
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.readUint16 = function() {
context.Buf.readUint16 = function() {
return buf[index++];
};
worker.Buf.readInt32 = function() {
context.Buf.readInt32 = function() {
return buf[index++];
};
@ -50,7 +51,8 @@ add_test(function test_display() {
0x09, // length: 9
0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
0x6F, 0x00]);
let helper = worker.CdmaPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.CdmaPDUHelper;
let record = helper.decodeInformationRecord();
do_check_eq(record.display, "Test Info");
@ -72,7 +74,8 @@ add_test(function test_extended_display() {
0x9B, // Text
0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
0x66, 0x6F, 0x00]);
let helper = worker.CdmaPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.CdmaPDUHelper;
let record = helper.decodeInformationRecord();
do_check_eq(record.extendedDisplay.indicator, 1);
@ -103,7 +106,8 @@ add_test(function test_mixed() {
0x9B, // Text
0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
0x66, 0x6F, 0x00]);
let helper = worker.CdmaPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.CdmaPDUHelper;
let record = helper.decodeInformationRecord();
do_check_eq(record.display, "Test Info");

Просмотреть файл

@ -33,13 +33,14 @@ add_test(function test_ril_worker_GsmPDUHelper_readCbDataCodingScheme() {
}
});
let context = worker.ContextPool._contexts[0];
function test_dcs(dcs, encoding, language, hasLanguageIndicator, messageClass) {
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return dcs;
};
let msg = {};
worker.GsmPDUHelper.readCbDataCodingScheme(msg);
context.GsmPDUHelper.readCbDataCodingScheme(msg);
do_check_eq(msg.dcs, dcs);
do_check_eq(msg.encoding, encoding);
@ -49,12 +50,12 @@ add_test(function test_ril_worker_GsmPDUHelper_readCbDataCodingScheme() {
}
function test_dcs_throws(dcs) {
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return dcs;
};
do_check_throws(function() {
worker.GsmPDUHelper.readCbDataCodingScheme({});
context.GsmPDUHelper.readCbDataCodingScheme({});
}, "Unsupported CBS data coding scheme: " + dcs);
}
@ -142,12 +143,13 @@ add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() {
}
});
let context = worker.ContextPool._contexts[0];
function test_data(options, expected) {
let readIndex = 0;
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return options[3][readIndex++];
};
worker.Buf.readUint8Array = function(length) {
context.Buf.readUint8Array = function(length) {
let array = new Uint8Array(length);
for (let i = 0; i < length; i++) {
array[i] = this.readUint8();
@ -160,7 +162,7 @@ add_test(function test_ril_worker_GsmPDUHelper_readGsmCbData() {
language: options[1],
hasLanguageIndicator: options[2]
};
worker.GsmPDUHelper.readGsmCbData(msg, options[3].length);
context.GsmPDUHelper.readGsmCbData(msg, options[3].length);
do_check_eq(msg.body, expected[0]);
do_check_eq(msg.data == null, expected[1] == null);
@ -218,7 +220,8 @@ add_test(function test_ril_worker__checkCellBroadcastMMISettable() {
}
});
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
function test(from, to, expected) {
do_check_eq(expected, ril._checkCellBroadcastMMISettable(from, to));
@ -268,7 +271,8 @@ add_test(function test_ril_worker__mergeCellBroadcastConfigs() {
}
});
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
function test(olist, from, to, expected) {
let result = ril._mergeCellBroadcastConfigs(olist, from, to);

Просмотреть файл

@ -16,27 +16,28 @@ add_test(function test_ril_worker_cellbroadcast_activate() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
let parcelTypes = [];
let org_newParcel = worker.Buf.newParcel;
worker.Buf.newParcel = function(type, options) {
let org_newParcel = context.Buf.newParcel;
context.Buf.newParcel = function(type, options) {
parcelTypes.push(type);
org_newParcel.apply(this, arguments);
};
function setup(isCdma) {
worker.RIL._isCdma = isCdma;
worker.RIL.cellBroadcastDisabled = false;
worker.RIL.mergedCellBroadcastConfig = [1, 2, 4, 7]; // 1, 4-6
context.RIL._isCdma = isCdma;
context.RIL.cellBroadcastDisabled = false;
context.RIL.mergedCellBroadcastConfig = [1, 2, 4, 7]; // 1, 4-6
parcelTypes = [];
}
function test(isCdma, expectedRequest) {
setup(isCdma);
worker.RIL.setCellBroadcastDisabled({disabled: true});
context.RIL.setCellBroadcastDisabled({disabled: true});
// Makesure that request parcel is sent out.
do_check_neq(parcelTypes.indexOf(expectedRequest), -1);
do_check_eq(worker.RIL.cellBroadcastDisabled, true);
do_check_eq(context.RIL.cellBroadcastDisabled, true);
}
test(false, REQUEST_GSM_SMS_BROADCAST_ACTIVATION);
@ -55,6 +56,7 @@ add_test(function test_ril_worker_cellbroadcast_config() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
function U32ArrayFromParcelArray(pa) {
do_print(pa);
@ -82,8 +84,8 @@ add_test(function test_ril_worker_cellbroadcast_config() {
do_check_eq(u32Parcel.slice(3).toString(), expected);
};
worker.RIL._isCdma = isCdma;
worker.RIL.setSmsBroadcastConfig(configs);
context.RIL._isCdma = isCdma;
context.RIL.setSmsBroadcastConfig(configs);
// Makesure that request parcel is sent out.
do_check_true(found);
@ -113,12 +115,13 @@ add_test(function test_ril_worker_cellbroadcast_merge_config() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
function test(isCdma, configs, expected) {
worker.RIL._isCdma = isCdma;
worker.RIL.cellBroadcastConfigs = configs;
worker.RIL._mergeAllCellBroadcastConfigs();
do_check_eq(worker.RIL.mergedCellBroadcastConfig.toString(), expected);
context.RIL._isCdma = isCdma;
context.RIL.cellBroadcastConfigs = configs;
context.RIL._mergeAllCellBroadcastConfigs();
do_check_eq(context.RIL.mergedCellBroadcastConfig.toString(), expected);
}
let configs = {

Просмотреть файл

@ -16,7 +16,8 @@ function toaFromString(number) {
// Do nothing
}
});
return worker.RIL._toaFromString(number);
let context = worker.ContextPool._contexts[0];
return context.RIL._toaFromString(number);
}
add_test(function test_toaFromString_empty() {
@ -73,14 +74,15 @@ function _getWorker() {
add_test(function test_setCallForward_unconditional() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallForward = function fakeSetCallForward(options) {
worker.RIL[REQUEST_SET_CALL_FORWARD](0, {
context.RIL.setCallForward = function fakeSetCallForward(options) {
context.RIL[REQUEST_SET_CALL_FORWARD](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.setCallForward({
context.RIL.setCallForward({
action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_REGISTRATION,
reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
serviceClass: ICC_SERVICE_CLASS_VOICE,
@ -99,23 +101,24 @@ add_test(function test_setCallForward_unconditional() {
add_test(function test_queryCallForwardStatus_unconditional() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallForward = function fakeSetCallForward(options) {
worker.RIL[REQUEST_SET_CALL_FORWARD](0, {
context.RIL.setCallForward = function fakeSetCallForward(options) {
context.RIL[REQUEST_SET_CALL_FORWARD](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.Buf.readString = function fakeReadString() {
context.Buf.readString = function fakeReadString() {
return "+34666222333";
};
worker.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
worker.Buf.int32Array = [
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.Buf.int32Array = [
0, // rules.timeSeconds
145, // rules.toa
49, // rules.serviceClass
@ -123,12 +126,12 @@ add_test(function test_queryCallForwardStatus_unconditional() {
1, // rules.active
1 // rulesLength
];
worker.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryCallForwardStatus({
context.RIL.queryCallForwardStatus({
action: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_ACTION_QUERY_STATUS,
reason: Ci.nsIDOMMozMobileCFInfo.CALL_FORWARD_REASON_UNCONDITIONAL,
serviceClass: ICC_SERVICE_CLASS_VOICE,

Просмотреть файл

@ -29,22 +29,23 @@ function _getWorker() {
add_test(function test_queryCLIP_provisioned() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.queryCLIP = function fakeQueryCLIP(options) {
worker.Buf.int32Array = [
context.RIL.queryCLIP = function fakeQueryCLIP(options) {
context.Buf.int32Array = [
1, // CLIP provisioned.
1 // Length.
];
worker.RIL[REQUEST_QUERY_CLIP](1, {
context.RIL[REQUEST_QUERY_CLIP](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryCLIP({});
context.RIL.queryCLIP({});
let postedMessage = workerHelper.postedMessage;
@ -57,22 +58,23 @@ add_test(function test_queryCLIP_provisioned() {
add_test(function test_getCLIP_error_generic_failure_invalid_length() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.queryCLIP = function fakeQueryCLIP(options) {
worker.Buf.int32Array = [
context.RIL.queryCLIP = function fakeQueryCLIP(options) {
context.Buf.int32Array = [
1, // CLIP provisioned.
0 // Length.
];
worker.RIL[REQUEST_QUERY_CLIP](1, {
context.RIL[REQUEST_QUERY_CLIP](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryCLIP({});
context.RIL.queryCLIP({});
let postedMessage = workerHelper.postedMessage;

Просмотреть файл

@ -38,15 +38,16 @@ function _getWorker() {
add_test(function test_setCLIR_success() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCLIR = function fakeSetCLIR(options) {
worker.RIL[REQUEST_SET_CLIR](0, {
context.RIL.setCLIR = function fakeSetCLIR(options) {
context.RIL[REQUEST_SET_CLIR](0, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.setCLIR({
context.RIL.setCLIR({
clirMode: CLIR_DEFAULT
});
@ -61,15 +62,16 @@ add_test(function test_setCLIR_success() {
add_test(function test_setCLIR_generic_failure() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCLIR = function fakeSetCLIR(options) {
worker.RIL[REQUEST_SET_CLIR](0, {
context.RIL.setCLIR = function fakeSetCLIR(options) {
context.RIL[REQUEST_SET_CLIR](0, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_GENERIC_FAILURE
});
};
worker.RIL.setCLIR({
context.RIL.setCLIR({
clirMode: CLIR_DEFAULT
});
@ -84,25 +86,26 @@ add_test(function test_setCLIR_generic_failure() {
add_test(function test_getCLIR_n0_m1() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.getCLIR = function fakeGetCLIR(options) {
worker.Buf.int32Array = [
context.RIL.getCLIR = function fakeGetCLIR(options) {
context.Buf.int32Array = [
1, // Presentation indicator is used according to the subscription
// of the CLIR service.
0, // CLIR provisioned in permanent mode.
2 // Length.
];
worker.RIL[REQUEST_GET_CLIR](1, {
context.RIL[REQUEST_GET_CLIR](1, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.getCLIR({});
context.RIL.getCLIR({});
let postedMessage = workerHelper.postedMessage;
@ -116,25 +119,26 @@ add_test(function test_getCLIR_n0_m1() {
add_test(function test_getCLIR_error_generic_failure_invalid_length() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.getCLIR = function fakeGetCLIR(options) {
worker.Buf.int32Array = [
context.RIL.getCLIR = function fakeGetCLIR(options) {
context.Buf.int32Array = [
1, // Presentation indicator is used according to the subscription
// of the CLIR service.
0, // CLIR provisioned in permanent mode.
0 // Length (invalid one).
];
worker.RIL[REQUEST_GET_CLIR](1, {
context.RIL[REQUEST_GET_CLIR](1, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.getCLIR({});
context.RIL.getCLIR({});
let postedMessage = workerHelper.postedMessage;

Просмотреть файл

@ -29,14 +29,15 @@ function _getWorker() {
add_test(function test_setCallWaiting_success() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
worker.RIL[REQUEST_SET_CALL_WAITING](0, {
context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
context.RIL[REQUEST_SET_CALL_WAITING](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.setCallWaiting({
context.RIL.setCallWaiting({
enabled: true
});
@ -51,14 +52,15 @@ add_test(function test_setCallWaiting_success() {
add_test(function test_setCallWaiting_generic_failure() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
worker.RIL[REQUEST_SET_CALL_WAITING](0, {
context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
context.RIL[REQUEST_SET_CALL_WAITING](0, {
rilRequestError: ERROR_GENERIC_FAILURE
});
};
worker.RIL.setCallWaiting({
context.RIL.setCallWaiting({
enabled: true
});
@ -73,23 +75,24 @@ add_test(function test_setCallWaiting_generic_failure() {
add_test(function test_queryCallWaiting_success_enabled_true() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
worker.Buf.int32Array = [
context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
context.Buf.int32Array = [
1, // serviceClass
1, // enabled
1 // length
];
worker.RIL[REQUEST_QUERY_CALL_WAITING](1, {
context.RIL[REQUEST_QUERY_CALL_WAITING](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryCallWaiting({});
context.RIL.queryCallWaiting({});
let postedMessage = workerHelper.postedMessage;
@ -103,23 +106,24 @@ add_test(function test_queryCallWaiting_success_enabled_true() {
add_test(function test_queryCallWaiting_success_enabled_false() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
worker.Buf.int32Array = [
context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
context.Buf.int32Array = [
1, // serviceClass
0, // enabled
1 // length
];
worker.RIL[REQUEST_QUERY_CALL_WAITING](1, {
context.RIL[REQUEST_QUERY_CALL_WAITING](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryCallWaiting({});
context.RIL.queryCallWaiting({});
let postedMessage = workerHelper.postedMessage;

Просмотреть файл

@ -56,14 +56,15 @@ function fireTimeout() {
add_test(function test_enter_emergencyCbMode() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
// Do it twice. Should always send the event.
for (let i = 0; i < 2; ++i) {
worker.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
let postedMessage = workerHelper.postedMessage;
// Should store the mode.
do_check_eq(worker.RIL._isInEmergencyCbMode, true);
do_check_eq(context.RIL._isInEmergencyCbMode, true);
// Should notify change.
do_check_eq(postedMessage.rilMessageType, "emergencyCbModeChange");
@ -71,7 +72,7 @@ add_test(function test_enter_emergencyCbMode() {
do_check_eq(postedMessage.timeoutMs, TIMEOUT_VALUE);
// Should start timer.
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
}
run_next_test();
@ -80,20 +81,21 @@ add_test(function test_enter_emergencyCbMode() {
add_test(function test_exit_emergencyCbMode() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
worker.RIL[UNSOLICITED_EXIT_EMERGENCY_CALLBACK_MODE]();
context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
context.RIL[UNSOLICITED_EXIT_EMERGENCY_CALLBACK_MODE]();
let postedMessage = workerHelper.postedMessage;
// Should store the mode.
do_check_eq(worker.RIL._isInEmergencyCbMode, false);
do_check_eq(context.RIL._isInEmergencyCbMode, false);
// Should notify change.
do_check_eq(postedMessage.rilMessageType, "emergencyCbModeChange");
do_check_eq(postedMessage.active, false);
// Should clear timer.
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, null);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null);
run_next_test();
});
@ -101,13 +103,14 @@ add_test(function test_exit_emergencyCbMode() {
add_test(function test_request_exit_emergencyCbMode_when_timeout() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(worker.RIL._isInEmergencyCbMode, true);
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(context.RIL._isInEmergencyCbMode, true);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
let parcelTypes = [];
worker.Buf.newParcel = function(type, options) {
context.Buf.newParcel = function(type, options) {
parcelTypes.push(type);
};
@ -115,7 +118,7 @@ add_test(function test_request_exit_emergencyCbMode_when_timeout() {
fireTimeout();
// Should clear timeout event.
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, null);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null);
// Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE.
do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1);
@ -126,22 +129,23 @@ add_test(function test_request_exit_emergencyCbMode_when_timeout() {
add_test(function test_request_exit_emergencyCbMode_when_dial() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(worker.RIL._isInEmergencyCbMode, true);
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(context.RIL._isInEmergencyCbMode, true);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
let parcelTypes = [];
worker.Buf.newParcel = function(type, options) {
context.Buf.newParcel = function(type, options) {
parcelTypes.push(type);
};
// Dial non-emergency call.
worker.RIL.dial({number: "0912345678",
context.RIL.dial({number: "0912345678",
isDialEmergency: false});
// Should clear timeout event.
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, null);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null);
// Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE.
do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1);
@ -152,25 +156,26 @@ add_test(function test_request_exit_emergencyCbMode_when_dial() {
add_test(function test_request_exit_emergencyCbMode_explicitly() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(worker.RIL._isInEmergencyCbMode, true);
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
do_check_eq(context.RIL._isInEmergencyCbMode, true);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
let parcelTypes = [];
worker.Buf.newParcel = function(type, options) {
context.Buf.newParcel = function(type, options) {
parcelTypes.push(type);
};
worker.RIL.handleChromeMessage({rilMessageType: "exitEmergencyCbMode"});
worker.RIL[REQUEST_EXIT_EMERGENCY_CALLBACK_MODE](1, {
context.RIL.handleChromeMessage({rilMessageType: "exitEmergencyCbMode"});
context.RIL[REQUEST_EXIT_EMERGENCY_CALLBACK_MODE](1, {
rilMessageType: "exitEmergencyCbMode",
rilRequestError: ERROR_SUCCESS
});
let postedMessage = workerHelper.postedMessage;
// Should clear timeout event.
do_check_eq(worker.RIL._exitEmergencyCbModeTimeoutID, null);
do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null);
// Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE.
do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1);

Просмотреть файл

@ -15,15 +15,16 @@ function newUint8Worker() {
let index = 0; // index for read
let buf = [];
worker.Buf.writeUint8 = function(value) {
let context = worker.ContextPool._contexts[0];
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
@ -37,8 +38,9 @@ function newUint8Worker() {
*/
add_test(function test_read_icc_ucs2_string() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// 0x80
let text = "TEST";
@ -76,8 +78,9 @@ add_test(function test_read_icc_ucs2_string() {
*/
add_test(function test_read_dialling_number() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let str = "123456789";
helper.readHexOctet = function() {
@ -101,8 +104,9 @@ add_test(function test_read_dialling_number() {
*/
add_test(function test_read_8bit_unpacked_to_string() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
@ -166,8 +170,9 @@ add_test(function test_read_8bit_unpacked_to_string() {
*/
add_test(function test_write_string_to_8bit_unpacked() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
// Length of trailing 0xff.
@ -212,8 +217,9 @@ add_test(function test_write_string_to_8bit_unpacked() {
*/
add_test(function test_write_string_to_8bit_unpacked_with_max_octets_written() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
@ -251,8 +257,9 @@ add_test(function test_write_string_to_8bit_unpacked_with_max_octets_written() {
*/
add_test(function test_read_alpha_identifier() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// UCS2: 0x80
let text = "TEST";
@ -295,8 +302,9 @@ add_test(function test_read_alpha_identifier() {
*/
add_test(function test_write_alpha_identifier() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
// Length of trailing 0xff.
let ffLen = 2;
@ -341,9 +349,10 @@ add_test(function test_write_alpha_identifier() {
*/
add_test(function test_read_alpha_id_dialling_number() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let buf = context.Buf;
const recordSize = 32;
function testReadAlphaIdDiallingNumber(contact) {
@ -381,7 +390,8 @@ add_test(function test_read_alpha_id_dialling_number() {
*/
add_test(function test_write_alpha_id_dialling_number() {
let worker = newUint8Worker();
let helper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.ICCPDUHelper;
const recordSize = 32;
// Write a normal contact.
@ -443,7 +453,8 @@ add_test(function test_write_alpha_id_dialling_number() {
*/
add_test(function test_write_dialling_number() {
let worker = newUint8Worker();
let helper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.ICCPDUHelper;
// with +
let number = "+123456";
@ -470,8 +481,9 @@ add_test(function test_write_dialling_number() {
*/
add_test(function test_read_number_with_length() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let number = "123456789";
iccHelper.readDiallingNumber = function(numLen) {
@ -493,8 +505,9 @@ add_test(function test_read_number_with_length() {
*/
add_test(function test_write_number_with_length() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
function test(number, expectedNumber) {
expectedNumber = expectedNumber || number;
@ -537,7 +550,8 @@ add_test(function test_write_number_with_length() {
*/
add_test(function test_write_timestamp() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
// current date
let dateInput = new Date();
@ -576,7 +590,8 @@ add_test(function test_write_timestamp() {
*/
add_test(function test_octect_BCD() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
// 23
let number = 23;
@ -606,13 +621,15 @@ add_test(function test_octect_BCD() {
*/
add_test(function test_is_icc_service_available() {
let worker = newUint8Worker();
let ICCUtilsHelper = worker.ICCUtilsHelper;
let context = worker.ContextPool._contexts[0];
let ICCUtilsHelper = context.ICCUtilsHelper;
let RIL = context.RIL;
function test_table(sst, geckoService, simEnabled, usimEnabled) {
worker.RIL.iccInfoPrivate.sst = sst;
worker.RIL.appType = CARD_APPTYPE_SIM;
RIL.iccInfoPrivate.sst = sst;
RIL.appType = CARD_APPTYPE_SIM;
do_check_eq(ICCUtilsHelper.isICCServiceAvailable(geckoService), simEnabled);
worker.RIL.appType = CARD_APPTYPE_USIM;
RIL.appType = CARD_APPTYPE_USIM;
do_check_eq(ICCUtilsHelper.isICCServiceAvailable(geckoService), usimEnabled);
}
@ -628,7 +645,8 @@ add_test(function test_is_icc_service_available() {
*/
add_test(function test_is_gsm_8bit_alphabet() {
let worker = newUint8Worker();
let ICCUtilsHelper = worker.ICCUtilsHelper;
let context = worker.ContextPool._contexts[0];
let ICCUtilsHelper = context.ICCUtilsHelper;
const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
@ -644,8 +662,9 @@ add_test(function test_is_gsm_8bit_alphabet() {
*/
add_test(function test_icc_get_card_lock_state_fdn() {
let worker = newUint8Worker();
let ril = worker.RIL;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let buf = context.Buf;
buf.sendParcel = function() {
// Request Type.
@ -681,8 +700,9 @@ add_test(function test_icc_get_card_lock_state_fdn() {
add_test(function test_get_network_name_from_icc() {
let worker = newUint8Worker();
let RIL = worker.RIL;
let ICCUtilsHelper = worker.ICCUtilsHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCUtilsHelper = context.ICCUtilsHelper;
function testGetNetworkNameFromICC(operatorData, expectedResult) {
let result = ICCUtilsHelper.getNetworkNameFromICC(operatorData.mcc,
@ -780,8 +800,9 @@ add_test(function test_path_id_for_spid_and_spn() {
postMessage: function(message) {
// Do nothing
}});
let RIL = worker.RIL;
let ICCFileHelper = worker.ICCFileHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCFileHelper = context.ICCFileHelper;
// Test SIM
RIL.appType = CARD_APPTYPE_SIM;
@ -804,7 +825,8 @@ add_test(function test_path_id_for_spid_and_spn() {
*/
add_test(function test_parse_pbr_tlvs() {
let worker = newUint8Worker();
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pbrTlvs = [
{tag: ICC_USIM_TYPE1_TAG,
@ -842,7 +864,7 @@ add_test(function test_parse_pbr_tlvs() {
},
];
let pbr = worker.ICCUtilsHelper.parsePbrTlvs(pbrTlvs);
let pbr = context.ICCUtilsHelper.parsePbrTlvs(pbrTlvs);
do_check_eq(pbr.adn.fileId, 0x4F3a);
do_check_eq(pbr.iap.fileId, 0x4F25);
do_check_eq(pbr.pbc.fileId, 0x4F09);
@ -860,8 +882,9 @@ add_test(function test_parse_pbr_tlvs() {
*/
add_test(function test_load_linear_fixed_ef() {
let worker = newUint8Worker();
let ril = worker.RIL;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let io = context.ICCIOHelper;
io.getResponse = function fakeGetResponse(options) {
// When recordSize is provided, loadLinearFixedEF should call iccIO directly.
@ -882,8 +905,9 @@ add_test(function test_load_linear_fixed_ef() {
*/
add_test(function test_load_linear_fixed_ef() {
let worker = newUint8Worker();
let ril = worker.RIL;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let io = context.ICCIOHelper;
io.getResponse = function fakeGetResponse(options) {
do_check_true(true);
@ -904,10 +928,11 @@ add_test(function test_load_linear_fixed_ef() {
*/
add_test(function test_read_pbr() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let record = worker.ICCRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let pbr_1 = [
@ -970,10 +995,11 @@ add_test(function test_read_pbr() {
*/
add_test(function test_read_email() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let record = worker.ICCRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
@ -1027,20 +1053,21 @@ add_test(function test_update_email() {
const fileId = 0x4f50;
const NUM_TESTS = 2;
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = worker.ICCRecordHelper;
let buf = worker.Buf;
let ioHelper = worker.ICCIOHelper;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let pbr = {email: {fileId: fileId, fileType: ICC_USIM_TYPE1_TAG},
adn: {sfi: 1}};
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
@ -1115,10 +1142,11 @@ add_test(function test_update_email() {
*/
add_test(function test_read_anr() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let record = worker.ICCRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
@ -1169,20 +1197,21 @@ add_test(function test_update_anr() {
const fileId = 0x4f11;
const NUM_TESTS = 2;
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = worker.ICCRecordHelper;
let buf = worker.Buf;
let ioHelper = worker.ICCIOHelper;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let pbr = {anr0: {fileId: fileId, fileType: ICC_USIM_TYPE1_TAG},
adn: {sfi: 1}};
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
@ -1259,10 +1288,11 @@ add_test(function test_update_anr() {
*/
add_test(function test_read_iap() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let record = worker.ICCRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let recordSize;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
@ -1317,17 +1347,18 @@ add_test(function test_update_iap() {
const recordNumber = 1;
const fileId = 0x4f17;
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
let recordHelper = worker.ICCRecordHelper;
let buf = worker.Buf;
let ioHelper = worker.ICCIOHelper;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let count = 0;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
@ -1390,11 +1421,12 @@ add_test(function test_update_iap() {
*/
add_test(function test_update_adn_like() {
let worker = newUint8Worker();
let ril = worker.RIL;
let record = worker.ICCRecordHelper;
let io = worker.ICCIOHelper;
let pdu = worker.ICCPDUHelper;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let record = context.ICCRecordHelper;
let io = context.ICCIOHelper;
let pdu = context.ICCPDUHelper;
let buf = context.Buf;
ril.appType = CARD_APPTYPE_SIM;
const recordSize = 0x20;
@ -1402,7 +1434,7 @@ add_test(function test_update_adn_like() {
// Override.
io.updateLinearFixedEF = function(options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
@ -1472,10 +1504,11 @@ add_test(function test_update_adn_like() {
*/
add_test(function test_find_free_record_id() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let recordHelper = worker.ICCRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
function writeRecord (record) {
// Write data size
@ -1529,13 +1562,15 @@ add_test(function test_find_free_record_id() {
*/
add_test(function test_read_icc_contacts() {
let worker = newUint8Worker();
let record = worker.ICCRecordHelper;
let contactHelper = worker.ICCContactHelper;
let context = worker.ContextPool._contexts[0];
let record = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
let ril = context.RIL;
function do_test(aSimType, aContactType, aExpectedContact, aEnhancedPhoneBook) {
worker.RIL.appType = aSimType;
worker.RIL._isCdma = (aSimType === CARD_APPTYPE_RUIM);
worker.RIL.iccInfoPrivate.cst = (aEnhancedPhoneBook) ?
ril.appType = aSimType;
ril._isCdma = (aSimType === CARD_APPTYPE_RUIM);
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ?
[0x0, 0x0C, 0x0, 0x0, 0x0]:
[0x0, 0x00, 0x0, 0x0, 0x0];
@ -1640,15 +1675,16 @@ add_test(function test_update_icc_contact() {
const ANR0_RECORD_ID = 30;
let worker = newUint8Worker();
let recordHelper = worker.ICCRecordHelper;
let contactHelper = worker.ICCContactHelper;
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
let ril = context.RIL;
function do_test(aSimType, aContactType, aContact, aPin2, aFileType, aEnhancedPhoneBook) {
worker.RIL.appType = aSimType;
worker.RIL._isCdma = (aSimType === CARD_APPTYPE_RUIM);
worker.RIL.iccInfoPrivate.cst = (aEnhancedPhoneBook) ?
[0x0, 0x0C, 0x0, 0x0, 0x0]:
[0x0, 0x00, 0x0, 0x0, 0x0];
ril.appType = aSimType;
ril._isCdma = (aSimType === CARD_APPTYPE_RUIM);
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ? [0x0, 0x0C, 0x0, 0x0, 0x0]
: [0x0, 0x00, 0x0, 0x0, 0x0];
recordHelper.readPBR = function(onsuccess, onerror) {
if (aFileType === ICC_USIM_TYPE1_TAG) {
@ -1793,8 +1829,9 @@ add_test(function test_update_icc_contact_with_remove_type1_attr() {
const ANR0_RECORD_ID = 30;
let worker = newUint8Worker();
let recordHelper = worker.ICCRecordHelper;
let contactHelper = worker.ICCContactHelper;
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
onsuccess();
@ -1866,8 +1903,9 @@ add_test(function test_update_icc_contact_with_remove_type1_attr() {
*/
add_test(function test_find_free_icc_contact_sim() {
let worker = newUint8Worker();
let recordHelper = worker.ICCRecordHelper;
let contactHelper = worker.ICCContactHelper;
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
// Correct record Id starts with 1, so put a null element at index 0.
let records = [null];
const MAX_RECORDS = 3;
@ -1916,8 +1954,9 @@ add_test(function test_find_free_icc_contact_sim() {
*/
add_test(function test_find_free_icc_contact_usim() {
let worker = newUint8Worker();
let recordHelper = worker.ICCRecordHelper;
let contactHelper = worker.ICCContactHelper;
let context = worker.ContextPool._contexts[0];
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
const ADN1_FILE_ID = 0x6f3a;
const ADN2_FILE_ID = 0x6f3b;
const MAX_RECORDS = 3;
@ -1968,7 +2007,8 @@ add_test(function test_find_free_icc_contact_usim() {
*/
add_test(function test_error_message_read_icc_contact () {
let worker = newUint8Worker();
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
function do_test(options, expectedErrorMsg) {
ril.sendChromeMessage = function(message) {
@ -1997,7 +2037,8 @@ add_test(function test_error_message_read_icc_contact () {
*/
add_test(function test_error_message_update_icc_contact() {
let worker = newUint8Worker();
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
const ICCID = "123456789";
ril.iccInfo.iccid = ICCID;
@ -2023,12 +2064,12 @@ add_test(function test_error_message_update_icc_contact() {
do_test({contactType: "fdn", contact: {contactId: ICCID + "1"}}, GECKO_ERROR_SIM_PIN2);
// Error 5, No free record found in EF_ADN.
let record = worker.ICCRecordHelper;
let record = context.ICCRecordHelper;
record.readPBR = function(onsuccess, onerror) {
onsuccess([{adn: {fileId: 0x4f3a}}]);
};
let io = worker.ICCIOHelper;
let io = context.ICCIOHelper;
io.loadLinearFixedEF = function(options) {
options.totalRecords = 1;
options.p1 = 1;
@ -2063,9 +2104,10 @@ add_test(function test_error_message_update_icc_contact() {
add_test(function test_personalization_state() {
let worker = newUint8Worker();
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
worker.ICCRecordHelper.readICCID = function fakeReadICCID() {};
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testPersonalization(cardPersoState, geckoCardState) {
let iccStatus = {
@ -2105,9 +2147,10 @@ add_test(function test_personalization_state() {
*/
add_test(function test_card_app_state() {
let worker = newUint8Worker();
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
worker.ICCRecordHelper.readICCID = function fakeReadICCID() {};
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testCardAppState(cardAppState, geckoCardState) {
let iccStatus = {
@ -2144,9 +2187,10 @@ add_test(function test_card_app_state() {
*/
add_test(function test_icc_permanent_blocked() {
let worker = newUint8Worker();
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
worker.ICCRecordHelper.readICCID = function fakeReadICCID() {};
context.ICCRecordHelper.readICCID = function fakeReadICCID() {};
function testPermanentBlocked(pin1_replaced, universalPINState, pin1) {
let iccStatus = {
@ -2182,11 +2226,12 @@ add_test(function test_icc_permanent_blocked() {
*/
add_test(function test_set_icc_card_lock_facility_lock() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
worker.RILQUIRKS_V5_LEGACY = false;
let aid = "123456789";
let ril = worker.RIL;
let ril = context.RIL;
ril.aid = aid;
let buf = worker.Buf;
let buf = context.Buf;
let GECKO_CARDLOCK_TO_FACILITIY_LOCK = {};
GECKO_CARDLOCK_TO_FACILITIY_LOCK[GECKO_CARDLOCK_PIN] = ICC_CB_FACILITY_SIM;
@ -2243,8 +2288,9 @@ add_test(function test_set_icc_card_lock_facility_lock() {
*/
add_test(function test_unlock_card_lock_corporateLocked() {
let worker = newUint8Worker();
let ril = worker.RIL;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let buf = context.Buf;
const pin = "12345678";
const puk = "12345678";
@ -2292,7 +2338,8 @@ add_test(function test_unlock_card_lock_corporateLocked() {
*/
add_test(function test_mcc_mnc_parsing() {
let worker = newUint8Worker();
let helper = worker.ICCUtilsHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.ICCUtilsHelper;
function do_test(imsi, mncLength, expectedMcc, expectedMnc) {
let result = helper.parseMccMncFromImsi(imsi, mncLength);
@ -2327,11 +2374,12 @@ add_test(function test_mcc_mnc_parsing() {
*/
add_test(function test_reading_ad_and_parsing_mcc_mnc() {
let worker = newUint8Worker();
let record = worker.SimRecordHelper;
let helper = worker.GsmPDUHelper;
let ril = worker.RIL;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let record = context.SimRecordHelper;
let helper = context.GsmPDUHelper;
let ril = context.RIL;
let buf = context.Buf;
let io = context.ICCIOHelper;
function do_test(mncLengthInEf, imsi, expectedMcc, expectedMnc) {
ril.iccInfoPrivate.imsi = imsi;
@ -2374,11 +2422,12 @@ add_test(function test_reading_ad_and_parsing_mcc_mnc() {
add_test(function test_reading_optional_efs() {
let worker = newUint8Worker();
let record = worker.SimRecordHelper;
let gsmPdu = worker.GsmPDUHelper;
let ril = worker.RIL;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let record = context.SimRecordHelper;
let gsmPdu = context.GsmPDUHelper;
let ril = context.RIL;
let buf = context.Buf;
let io = context.ICCIOHelper;
function buildSST(supportedEf) {
let sst = [];
@ -2464,9 +2513,10 @@ add_test(function test_reading_optional_efs() {
*/
add_test(function test_fetch_sim_recodes() {
let worker = newWorker();
let RIL = worker.RIL;
let iccRecord = worker.ICCRecordHelper;
let simRecord = worker.SimRecordHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let iccRecord = context.ICCRecordHelper;
let simRecord = context.SimRecordHelper;
function testFetchSimRecordes(expectCalled) {
let ifCalled = [];
@ -2501,10 +2551,11 @@ add_test(function test_fetch_sim_recodes() {
add_test(function test_fetch_icc_recodes() {
let worker = newWorker();
let RIL = worker.RIL;
let iccRecord = worker.ICCRecordHelper;
let simRecord = worker.SimRecordHelper;
let ruimRecord = worker.RuimRecordHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let iccRecord = context.ICCRecordHelper;
let simRecord = context.SimRecordHelper;
let ruimRecord = context.RuimRecordHelper;
let fetchTag = 0x00;
simRecord.fetchSimRecords = function() {
@ -2535,10 +2586,11 @@ add_test(function test_fetch_icc_recodes() {
*/
add_test(function test_read_mwis() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let recordHelper = worker.SimRecordHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let recordHelper = context.SimRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
let mwisData;
let postedMessage;
@ -2604,18 +2656,19 @@ add_test(function test_read_mwis() {
*/
add_test(function test_update_mwis() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let ril = worker.RIL;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
ril.appType = CARD_APPTYPE_USIM;
ril.iccInfoPrivate.mwis = [0x00, 0x00, 0x00, 0x00, 0x00];
let recordHelper = worker.SimRecordHelper;
let buf = worker.Buf;
let ioHelper = worker.ICCIOHelper;
let recordHelper = context.SimRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
let recordSize = ril.iccInfoPrivate.mwis.length;
let recordNum = 1;
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = worker.ICCFileHelper.getEFPath(options.fileId);
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
@ -2736,18 +2789,19 @@ add_test(function test_read_new_sms_on_sim() {
return _worker;
},
fakeWokerBuffer: function() {
let context = _worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
_worker.Buf.writeUint8 = function(value) {
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
_worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
_worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
_worker.Buf.getReadAvailable = function() {
context.Buf.getReadAvailable = function() {
return buf.length - index;
};
}
@ -2756,8 +2810,9 @@ add_test(function test_read_new_sms_on_sim() {
let workerHelper = newSmsOnSimWorkerHelper();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.ICCIOHelper.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
context.ICCIOHelper.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
// SimStatus: Unread, SMSC:+0123456789, Sender: +9876543210, Text: How are you?
let SimSmsPduHex = "0306911032547698040A9189674523010000208062917314080CC8F71D14969741F977FD07"
// In 4.2.25 EF_SMS Short Messages of 3GPP TS 31.102:
@ -2770,7 +2825,7 @@ add_test(function test_read_new_sms_on_sim() {
workerHelper.fakeWokerBuffer();
worker.Buf.writeString(SimSmsPduHex);
context.Buf.writeString(SimSmsPduHex);
options.recordSize = 176; // Record length is fixed to 176 bytes.
if (options.callback) {
@ -2799,7 +2854,7 @@ add_test(function test_read_new_sms_on_sim() {
}
function do_test() {
worker.onRILMessage(newSmsOnSimParcel());
worker.onRILMessage(0, newSmsOnSimParcel());
let postedMessage = workerHelper.postedMessage;
@ -2820,8 +2875,9 @@ add_test(function test_read_new_sms_on_sim() {
*/
add_test(function test_fcp_template_for_transparent_structure() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let tag_test = [
0x62,
@ -2857,8 +2913,9 @@ add_test(function test_fcp_template_for_transparent_structure() {
*/
add_test(function test_fcp_template_for_linear_fixed_structure() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let tag_test = [
0x62,
@ -2893,9 +2950,10 @@ add_test(function test_fcp_template_for_linear_fixed_structure() {
add_test(function test_icc_io_get_response_for_transparent_structure() {
let worker = newUint8Worker();
let buf = worker.Buf;
let iccioHelper = worker.ICCIOHelper;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let iccioHelper = context.ICCIOHelper;
let pduHelper = context.GsmPDUHelper;
let responseArray = [
// SIM response.
@ -2927,9 +2985,10 @@ add_test(function test_icc_io_get_response_for_transparent_structure() {
add_test(function test_icc_io_get_response_for_linear_fixed_structure() {
let worker = newUint8Worker();
let buf = worker.Buf;
let iccioHelper = worker.ICCIOHelper;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let iccioHelper = context.ICCIOHelper;
let pduHelper = context.GsmPDUHelper;
let responseArray = [
// SIM response.

Просмотреть файл

@ -16,7 +16,8 @@ function parseMMI(mmi) {
// Do nothing
}
});
return worker.RIL._parseMMI(mmi);
let context = worker.ContextPool._contexts[0];
return context.RIL._parseMMI(mmi);
}
function getWorker() {
@ -42,11 +43,12 @@ function getWorker() {
function testSendMMI(mmi, error) {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
do_print("worker.postMessage " + worker.postMessage);
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({rilMessageType: "sendMMI", mmi: mmi});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({rilMessageType: "sendMMI", mmi: mmi});
let postedMessage = workerhelper.postedMessage;
@ -371,25 +373,26 @@ add_test(function test_sendMMI_invalid() {
add_test(function test_sendMMI_short_code() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let ussdOptions;
worker.RIL.sendUSSD = function fakeSendUSSD(options){
context.RIL.sendUSSD = function fakeSendUSSD(options){
ussdOptions = options;
worker.RIL[REQUEST_SEND_USSD](0, {
context.RIL[REQUEST_SEND_USSD](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "**"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "**"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "**");
do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
do_check_true(worker.RIL._ussdSession);
do_check_true(context.RIL._ussdSession);
run_next_test();
});
@ -403,15 +406,16 @@ add_test(function test_sendMMI_dial_string() {
function setCallForwardSuccess(mmi) {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallForward = function fakeSetCallForward(options) {
worker.RIL[REQUEST_SET_CALL_FORWARD](0, {
context.RIL.setCallForward = function fakeSetCallForward(options) {
context.RIL[REQUEST_SET_CALL_FORWARD](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: mmi});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: mmi});
let postedMessage = workerhelper.postedMessage;
@ -434,17 +438,18 @@ add_test(function test_sendMMI_call_forwarding_deactivation() {
add_test(function test_sendMMI_call_forwarding_interrogation() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.Buf.readString = function fakeReadString() {
context.Buf.readString = function fakeReadString() {
return "+34666222333";
};
worker.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
worker.Buf.int32Array = [
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.Buf.int32Array = [
0, // rules.timeSeconds
145, // rules.toa
49, // rules.serviceClass
@ -452,13 +457,13 @@ add_test(function test_sendMMI_call_forwarding_interrogation() {
1, // rules.active
1 // rulesLength
];
worker.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*#21#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
@ -476,19 +481,20 @@ add_test(function test_sendMMI_call_forwarding_interrogation() {
add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
context.Buf.readInt32 = function fakeReadUint32() {
return 0;
};
worker.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
worker.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
context.RIL[REQUEST_QUERY_CALL_FORWARD_STATUS](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*#21#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#21#"});
let postedMessage = workerhelper.postedMessage;
@ -544,15 +550,16 @@ add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
add_test(function test_sendMMI_change_PIN() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.changeICCPIN = function fakeChangeICCPIN(options) {
worker.RIL[REQUEST_ENTER_SIM_PIN](0, {
context.RIL.changeICCPIN = function fakeChangeICCPIN(options) {
context.RIL[REQUEST_ENTER_SIM_PIN](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "**04*1234*4567*4567#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "**04*1234*4567*4567#"});
let postedMessage = workerhelper.postedMessage;
@ -589,15 +596,16 @@ add_test(function test_sendMMI_change_PIN_new_PIN_mismatch() {
add_test(function test_sendMMI_change_PIN2() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.changeICCPIN2 = function fakeChangeICCPIN2(options){
worker.RIL[REQUEST_ENTER_SIM_PIN2](0, {
context.RIL.changeICCPIN2 = function fakeChangeICCPIN2(options){
context.RIL[REQUEST_ENTER_SIM_PIN2](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "**042*1234*4567*4567#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "**042*1234*4567*4567#"});
let postedMessage = workerhelper.postedMessage;
@ -634,15 +642,16 @@ add_test(function test_sendMMI_change_PIN2_new_PIN2_mismatch() {
add_test(function test_sendMMI_unblock_PIN() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.enterICCPUK = function fakeEnterICCPUK(options){
worker.RIL[REQUEST_ENTER_SIM_PUK](0, {
context.RIL.enterICCPUK = function fakeEnterICCPUK(options){
context.RIL[REQUEST_ENTER_SIM_PUK](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "**05*1234*4567*4567#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "**05*1234*4567*4567#"});
let postedMessage = workerhelper.postedMessage;
@ -679,15 +688,16 @@ add_test(function test_sendMMI_unblock_PIN_new_PIN_mismatch() {
add_test(function test_sendMMI_unblock_PIN2() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.enterICCPUK2 = function fakeEnterICCPUK2(options){
worker.RIL[REQUEST_ENTER_SIM_PUK2](0, {
context.RIL.enterICCPUK2 = function fakeEnterICCPUK2(options){
context.RIL[REQUEST_ENTER_SIM_PUK2](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "**052*1234*4567*4567#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "**052*1234*4567*4567#"});
let postedMessage = workerhelper.postedMessage;
@ -724,16 +734,17 @@ add_test(function test_sendMMI_unblock_PIN2_new_PIN_mismatch() {
add_test(function test_sendMMI_get_IMEI() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
worker.RIL.getIMEI = function getIMEI(options){
context.RIL.getIMEI = function getIMEI(options){
mmiOptions = options;
worker.RIL[REQUEST_SEND_USSD](0, {
context.RIL[REQUEST_SEND_USSD](0, {
rilRequestError: ERROR_SUCCESS,
});
};
worker.RIL.sendMMI({mmi: "*#06#"});
context.RIL.sendMMI({mmi: "*#06#"});
let postedMessage = workerhelper.postedMessage;
@ -747,16 +758,17 @@ add_test(function test_sendMMI_get_IMEI() {
add_test(function test_sendMMI_get_IMEI_error() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
worker.RIL.getIMEI = function getIMEI(options){
context.RIL.getIMEI = function getIMEI(options){
mmiOptions = options;
worker.RIL[REQUEST_SEND_USSD](0, {
context.RIL[REQUEST_SEND_USSD](0, {
rilRequestError: ERROR_RADIO_NOT_AVAILABLE,
});
};
worker.RIL.sendMMI({mmi: "*#06#"});
context.RIL.sendMMI({mmi: "*#06#"});
let postedMessage = workerhelper.postedMessage;
@ -770,21 +782,22 @@ add_test(function test_sendMMI_get_IMEI_error() {
add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32List = function fakeReadUint32List() {
context.Buf.readInt32List = function fakeReadUint32List() {
return [1];
};
worker.RIL.queryICCFacilityLock =
context.RIL.queryICCFacilityLock =
function fakeQueryICCFacilityLock(options){
worker.RIL[REQUEST_QUERY_FACILITY_LOCK](1, {
context.RIL[REQUEST_QUERY_FACILITY_LOCK](1, {
rilMessageType: "sendMMI",
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*#33#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#33#"});
let postedMessage = workerhelper.postedMessage;
@ -800,20 +813,21 @@ add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
add_test(function test_sendMMI_call_barring_BAIC_activation() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
worker.RIL.setICCFacilityLock =
context.RIL.setICCFacilityLock =
function fakeSetICCFacilityLock(options){
mmiOptions = options;
worker.RIL[REQUEST_SET_FACILITY_LOCK](0, {
context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
rilMessageType: "sendMMI",
procedure: MMI_PROCEDURE_ACTIVATION,
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*33#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*33#"});
let postedMessage = workerhelper.postedMessage;
@ -827,20 +841,21 @@ add_test(function test_sendMMI_call_barring_BAIC_activation() {
add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let mmiOptions;
worker.RIL.setICCFacilityLock =
context.RIL.setICCFacilityLock =
function fakeSetICCFacilityLock(options){
mmiOptions = options;
worker.RIL[REQUEST_SET_FACILITY_LOCK](0, {
context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
rilMessageType: "sendMMI",
procedure: MMI_PROCEDURE_DEACTIVATION,
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "#33#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "#33#"});
let postedMessage = workerhelper.postedMessage;
@ -860,24 +875,25 @@ add_test(function test_sendMMI_call_barring_BAIC_procedure_not_supported() {
add_test(function test_sendMMI_USSD() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let ussdOptions;
worker.RIL.sendUSSD = function fakeSendUSSD(options){
context.RIL.sendUSSD = function fakeSendUSSD(options){
ussdOptions = options;
worker.RIL[REQUEST_SEND_USSD](0, {
context.RIL[REQUEST_SEND_USSD](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*123#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*123#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "*123#");
do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
do_check_true(worker.RIL._ussdSession);
do_check_true(context.RIL._ussdSession);
run_next_test();
});
@ -885,24 +901,25 @@ add_test(function test_sendMMI_USSD() {
add_test(function test_sendMMI_USSD_error() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
let ussdOptions;
worker.RIL.sendUSSD = function fakeSendUSSD(options){
context.RIL.sendUSSD = function fakeSendUSSD(options){
ussdOptions = options;
worker.RIL[REQUEST_SEND_USSD](0, {
context.RIL[REQUEST_SEND_USSD](0, {
rilRequestError: ERROR_GENERIC_FAILURE
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*123#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*123#"});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "*123#");
do_check_eq (postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
do_check_false(postedMessage.success);
do_check_false(worker.RIL._ussdSession);
do_check_false(context.RIL._ussdSession);
run_next_test();
});
@ -910,15 +927,16 @@ add_test(function test_sendMMI_USSD_error() {
function setCallWaitingSuccess(mmi) {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
worker.RIL[REQUEST_SET_CALL_WAITING](0, {
context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
context.RIL[REQUEST_SET_CALL_WAITING](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: mmi});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: mmi});
let postedMessage = workerhelper.postedMessage;
@ -953,24 +971,25 @@ add_test(function test_sendMMI_call_waiting_erasure() {
add_test(function test_sendMMI_call_waiting_interrogation() {
let workerhelper = getWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32 = function fakeReadUint32() {
return worker.Buf.int32Array.pop();
context.Buf.readInt32 = function fakeReadUint32() {
return context.Buf.int32Array.pop();
};
worker.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
worker.Buf.int32Array = [
context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
context.Buf.int32Array = [
7, // serviceClass
1, // enabled
2 // length
];
worker.RIL[REQUEST_QUERY_CALL_WAITING](1, {
context.RIL[REQUEST_QUERY_CALL_WAITING](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.radioState = GECKO_RADIOSTATE_READY;
worker.RIL.sendMMI({mmi: "*#43#"});
context.RIL.radioState = GECKO_RADIOSTATE_READY;
context.RIL.sendMMI({mmi: "*#43#"});
let postedMessage = workerhelper.postedMessage;

Просмотреть файл

@ -12,18 +12,19 @@ function run_test() {
*/
function newUint8Worker() {
let worker = newWorker();
let context = worker.ContextPool._contexts[0];
let index = 0; // index for read
let buf = [];
worker.Buf.writeUint8 = function(value) {
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
@ -37,12 +38,13 @@ function newUint8Worker() {
*/
add_test(function test_is_ruim_service_available() {
let worker = newWorker();
worker.RIL._isCdma = true;
worker.RIL.appType = CARD_APPTYPE_RUIM;
let context = worker.ContextPool._contexts[0];
context.RIL._isCdma = true;
context.RIL.appType = CARD_APPTYPE_RUIM;
function test_table(cst, geckoService, enabled) {
worker.RIL.iccInfoPrivate.cst = cst;
do_check_eq(worker.ICCUtilsHelper.isICCServiceAvailable(geckoService),
context.RIL.iccInfoPrivate.cst = cst;
do_check_eq(context.ICCUtilsHelper.isICCServiceAvailable(geckoService),
enabled);
}
@ -59,8 +61,9 @@ add_test(function test_is_ruim_service_available() {
*/
add_test(function test_ruim_file_path_id() {
let worker = newWorker();
let RIL = worker.RIL;
let ICCFileHelper = worker.ICCFileHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCFileHelper = context.ICCFileHelper;
RIL.appType = CARD_APPTYPE_RUIM;
do_check_eq(ICCFileHelper.getEFPath(ICC_EF_CSIM_CST),
@ -71,8 +74,9 @@ add_test(function test_ruim_file_path_id() {
add_test(function test_fetch_ruim_recodes() {
let worker = newWorker();
let RIL = worker.RIL;
let ruimHelper = worker.RuimRecordHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ruimHelper = context.RuimRecordHelper;
function testFetchRuimRecordes(expectCalled) {
let ifCalled = [];
@ -115,9 +119,10 @@ add_test(function test_fetch_ruim_recodes() {
*/
add_test(function test_decode_imsi_value() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
function testDecodeImsiValue(encoded, length, expect) {
let decoded = worker.RuimRecordHelper.decodeIMSIValue(encoded, length);
let decoded = context.RuimRecordHelper.decodeIMSIValue(encoded, length);
do_check_eq(expect, decoded);
}
@ -145,9 +150,10 @@ add_test(function test_decode_imsi_value() {
*/
add_test(function test_get_imsi_m() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
function testDecodeImsi(encodedImsi, expectedImsi) {
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
@ -167,8 +173,8 @@ add_test(function test_get_imsi_m() {
}
};
worker.RuimRecordHelper.getIMSI_M();
let imsi = worker.RIL.iccInfoPrivate.imsi;
context.RuimRecordHelper.getIMSI_M();
let imsi = context.RIL.iccInfoPrivate.imsi;
do_check_eq(expectedImsi, imsi)
}
@ -187,9 +193,10 @@ add_test(function test_get_imsi_m() {
*/
add_test(function test_read_cdmahome() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
let cdmaHome = [0xc1, 0x34, 0xff, 0xff, 0x00];
@ -214,8 +221,8 @@ add_test(function test_read_cdmahome() {
};
function testCdmaHome(expectedSystemIds, expectedNetworkIds) {
worker.RuimRecordHelper.readCDMAHome();
let cdmaHome = worker.RIL.cdmaHome;
context.RuimRecordHelper.readCDMAHome();
let cdmaHome = context.RIL.cdmaHome;
for (let i = 0; i < expectedSystemIds.length; i++) {
do_check_eq(cdmaHome.systemId[i], expectedSystemIds[i]);
do_check_eq(cdmaHome.networkId[i], expectedNetworkIds[i]);
@ -234,9 +241,10 @@ add_test(function test_read_cdmahome() {
*/
add_test(function test_read_cdmaspn() {
let worker = newUint8Worker();
let helper = worker.GsmPDUHelper;
let buf = worker.Buf;
let io = worker.ICCIOHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
function testReadSpn(file, expectedSpn, expectedDisplayCondition) {
io.loadTransparentEF = function fakeLoadTransparentEF(options) {
@ -256,9 +264,9 @@ add_test(function test_read_cdmaspn() {
}
};
worker.RuimRecordHelper.readSPN();
do_check_eq(worker.RIL.iccInfo.spn, expectedSpn);
do_check_eq(worker.RIL.iccInfoPrivate.spnDisplayCondition,
context.RuimRecordHelper.readSPN();
do_check_eq(context.RIL.iccInfo.spn, expectedSpn);
do_check_eq(context.RIL.iccInfoPrivate.spnDisplayCondition,
expectedDisplayCondition);
}
@ -297,8 +305,9 @@ add_test(function test_cdma_spn_display_condition() {
// Do nothing
}
});
let RIL = worker.RIL;
let ICCUtilsHelper = worker.ICCUtilsHelper;
let context = worker.ContextPool._contexts[0];
let RIL = context.RIL;
let ICCUtilsHelper = context.ICCUtilsHelper;
// Set cdma.
RIL._isCdma = true;

Просмотреть файл

@ -118,8 +118,9 @@ function newWriteHexOctetAsUint8Worker() {
}
});
worker.GsmPDUHelper.writeHexOctet = function(value) {
worker.Buf.writeUint8(value);
let context = worker.ContextPool._contexts[0];
context.GsmPDUHelper.writeHexOctet = function(value) {
context.Buf.writeUint8(value);
};
return worker;
@ -139,7 +140,7 @@ function add_test_receiving_sms(expected, pdu) {
do_print("expect: " + expected);
do_print("pdu: " + pdu);
worker.onRILMessage(newSmsParcel(pdu));
worker.onRILMessage(0, newSmsParcel(pdu));
run_next_test();
});
@ -154,8 +155,9 @@ function test_receiving_7bit_alphabets(lst, sst) {
}
let ril = test_receiving_7bit_alphabets__ril;
let worker = test_receiving_7bit_alphabets__worker;
let helper = worker.GsmPDUHelper;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let buf = context.Buf;
function get7bitRawBytes(expected) {
buf.outgoingIndex = 0;
@ -183,11 +185,12 @@ function test_receiving_7bit_alphabets(lst, sst) {
function test_receiving_ucs2_alphabets(text) {
let worker = test_receiving_7bit_alphabets__worker;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
function getUCS2RawBytes(expected) {
buf.outgoingIndex = 0;
worker.GsmPDUHelper.writeUCS2String(expected);
context.GsmPDUHelper.writeUCS2String(expected);
let subArray = buf.outgoingBytes.subarray(0, buf.outgoingIndex);
return Array.slice(subArray);
@ -220,8 +223,9 @@ test_receiving_ucs2_alphabets(ucs2str);
// Bug 820220: B2G SMS: wrong order and truncated content in multi-part messages
add_test(function test_sendSMS_UCS2_without_langIndex_langShiftIndex_defined() {
let worker = newWriteHexOctetAsUint8Worker();
let context = worker.ContextPool._contexts[0];
worker.Buf.sendParcel = function() {
context.Buf.sendParcel = function() {
// Each sendParcel() call represents one outgoing segment of a multipart
// SMS message. Here, we have the first segment send, so it's "Hello "
// only.
@ -242,7 +246,7 @@ add_test(function test_sendSMS_UCS2_without_langIndex_langShiftIndex_defined() {
run_next_test();
};
worker.RIL.sendSMS({
context.RIL.sendSMS({
number: "1",
segmentMaxSeq: 2,
fullBody: "Hello World!",

Просмотреть файл

@ -190,10 +190,11 @@ function pduToParcelData(cdmaPduHelper, pdu) {
add_test(function test_processCdmaSmsStatusReport() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
function test_StatusReport(errorClass, msgStatus) {
let msgId = 0;
let sentSmsMap = worker.RIL._pendingSentSmsMap;
let sentSmsMap = context.RIL._pendingSentSmsMap;
sentSmsMap[msgId] = {};
@ -226,7 +227,7 @@ add_test(function test_processCdmaSmsStatusReport() {
msgStatus: msgStatus
};
worker.RIL._processCdmaSmsStatusReport(message);
context.RIL._processCdmaSmsStatusReport(message);
let postedMessage = workerHelper.postedMessage;
@ -263,8 +264,9 @@ add_test(function test_processCdmaSmsStatusReport() {
add_test(function test_processCdmaSmsWapPush() {
let workerHelper = _getWorker(),
worker = workerHelper.worker,
bitBufferHelper = worker.BitBufferHelper,
cdmaPduHelper = worker.CdmaPDUHelper;
context = worker.ContextPool._contexts[0],
bitBufferHelper = context.BitBufferHelper,
cdmaPduHelper = context.CdmaPDUHelper;
function test_CdmaSmsWapPdu(wdpData, reversed) {
let orig_address = "0987654321",
@ -293,7 +295,7 @@ add_test(function test_processCdmaSmsWapPush() {
data: hexStringToBytes(hexString) })
};
worker.onRILMessage(newSmsParcel(cdmaPduHelper, pdu));
worker.onRILMessage(0, newSmsParcel(cdmaPduHelper, pdu));
}
let postedMessage = workerHelper.postedMessage;
@ -319,4 +321,4 @@ add_test(function test_processCdmaSmsWapPush() {
test_CdmaSmsWapPdu(["000102030405060708090A0B0C0D0E0F", "0F0E0D0C0B0A09080706050403020100"], true);
run_next_test();
});
});

Просмотреть файл

@ -19,11 +19,12 @@ add_test(function test_CdmaPDUHelper_encodeUserDataReplyOption() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
let testDataBuffer = [];
worker.BitBufferHelper.startWrite(testDataBuffer);
context.BitBufferHelper.startWrite(testDataBuffer);
let helper = worker.CdmaPDUHelper;
let helper = context.CdmaPDUHelper;
helper.encodeUserDataReplyOption({requestStatusReport: true});
let expectedDataBuffer = [PDU_CDMA_MSG_USERDATA_REPLY_OPTION, 0x01, 0x40];
@ -49,11 +50,12 @@ add_test(function test_CdmaPDUHelper_decodeUserDataMsgStatus() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
let helper = worker.CdmaPDUHelper;
let helper = context.CdmaPDUHelper;
function test_MsgStatus(octet) {
let testDataBuffer = [octet];
worker.BitBufferHelper.startRead(testDataBuffer);
context.BitBufferHelper.startRead(testDataBuffer);
let result = helper.decodeUserDataMsgStatus();
do_check_eq(result.errorClass, octet >>> 6);
@ -85,10 +87,11 @@ add_test(function test_CdmaPDUHelper_decodeCdmaPDUMsg_Shift_jis() {
// Do nothing
}
});
let context = worker.ContextPool._contexts[0];
let helper = worker.CdmaPDUHelper;
let helper = context.CdmaPDUHelper;
function test_decodePDUMsg(testDataBuffer, expected, encoding, msgType, msgBodySize) {
worker.BitBufferHelper.startRead(testDataBuffer);
context.BitBufferHelper.startRead(testDataBuffer);
let result = helper.decodeCdmaPDUMsg(encoding, msgType, msgBodySize);
do_check_eq(result, expected);
}

Просмотреть файл

@ -20,7 +20,8 @@ add_test(function test_GsmPDUHelper_readDataCodingScheme() {
}
});
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
function test_dcs(dcs, encoding, messageClass, mwi) {
helper.readHexOctet = function() {
return dcs;
@ -159,7 +160,8 @@ add_test(function test_GsmPDUHelper_writeStringAsSeptets() {
}
});
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
helper.resetOctetWritten = function() {
helper.octetsWritten = 0;
};
@ -196,10 +198,10 @@ add_test(function test_GsmPDUHelper_readAddress() {
postMessage: function(message) {
// Do nothing
}
});
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
function test_address(addrHex, addrString) {
let uint16Array = [];
let ix = 0;
@ -207,7 +209,7 @@ add_test(function test_GsmPDUHelper_readAddress() {
uint16Array[i] = addrHex[i].charCodeAt();
}
worker.Buf.readUint16 = function(){
context.Buf.readUint16 = function(){
if(ix >= uint16Array.length) {
do_throw("out of range in uint16Array");
}

Просмотреть файл

@ -27,7 +27,8 @@ add_test(function test_RadioInterface__countGsm7BitSeptets() {
}
});
let helper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
helper.resetOctetWritten = function() {
helper.octetsWritten = 0;
};

Просмотреть файл

@ -29,6 +29,7 @@ function _getWorker() {
add_test(function test_notification() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
function Call(callIndex, number) {
this.callIndex = callIndex;
@ -69,7 +70,7 @@ add_test(function test_notification() {
do_print('Test case info: ' + JSON.stringify(testInfo));
// Set current calls.
worker.RIL._processCalls(calls);
context.RIL._processCalls(calls);
let notificationInfo = {
notificationType: 1, // MT
@ -79,7 +80,7 @@ add_test(function test_notification() {
number: number
};
worker.RIL._processSuppSvcNotification(notificationInfo);
context.RIL._processSuppSvcNotification(notificationInfo);
let postedMessage = workerHelper.postedMessage;
do_check_eq(postedMessage.rilMessageType, 'suppSvcNotification');
@ -87,7 +88,7 @@ add_test(function test_notification() {
do_check_eq(postedMessage.callIndex, resultCallIndex);
// Clear all existed calls.
worker.RIL._processCalls(null);
context.RIL._processCalls(null);
}
testNotification(oneCall, SUPP_SVC_NOTIFICATION_CODE2_PUT_ON_HOLD, null,

Просмотреть файл

@ -14,16 +14,17 @@ function newUint8Worker() {
let worker = newWorker();
let index = 0; // index for read
let buf = [];
let context = worker.ContextPool._contexts[0];
worker.Buf.writeUint8 = function(value) {
context.Buf.writeUint8 = function(value) {
buf.push(value);
};
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
@ -36,22 +37,23 @@ function newUint8SupportOutgoingIndexWorker() {
let worker = newWorker();
let index = 4; // index for read
let buf = [0, 0, 0, 0]; // Preserved parcel size
let context = worker.ContextPool._contexts[0];
worker.Buf.writeUint8 = function(value) {
if (worker.Buf.outgoingIndex >= buf.length) {
context.Buf.writeUint8 = function(value) {
if (context.Buf.outgoingIndex >= buf.length) {
buf.push(value);
} else {
buf[worker.Buf.outgoingIndex] = value;
buf[context.Buf.outgoingIndex] = value;
}
worker.Buf.outgoingIndex++;
context.Buf.outgoingIndex++;
};
worker.Buf.readUint8 = function() {
context.Buf.readUint8 = function() {
return buf[index++];
};
worker.Buf.seekIncoming = function(offset) {
context.Buf.seekIncoming = function(offset) {
index += offset;
};
@ -66,8 +68,9 @@ function newUint8SupportOutgoingIndexWorker() {
*/
add_test(function test_if_send_stk_terminal_profile() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let profileSend = false;
worker.RIL.sendStkTerminalProfile = function(data) {
context.RIL.sendStkTerminalProfile = function(data) {
profileSend = true;
};
@ -80,7 +83,7 @@ add_test(function test_if_send_stk_terminal_profile() {
};
worker.RILQUIRKS_SEND_STK_PROFILE_DOWNLOAD = false;
worker.RIL._processICCStatus(iccStatus);
context.RIL._processICCStatus(iccStatus);
do_check_eq(profileSend, false);
@ -92,8 +95,9 @@ add_test(function test_if_send_stk_terminal_profile() {
*/
add_test(function test_send_stk_terminal_profile() {
let worker = newUint8Worker();
let ril = worker.RIL;
let buf = worker.Buf;
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let buf = context.Buf;
ril.sendStkTerminalProfile(STK_SUPPORTED_TERMINAL_PROFILE);
@ -112,8 +116,9 @@ add_test(function test_send_stk_terminal_profile() {
*/
add_test(function test_stk_terminal_response() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
buf.sendParcel = function() {
// Type
@ -171,7 +176,7 @@ add_test(function test_stk_terminal_response() {
input: "Mozilla",
resultCode: STK_RESULT_OK
};
worker.RIL.sendStkTerminalResponse(response);
context.RIL.sendStkTerminalResponse(response);
});
// Test ComprehensionTlvHelper
@ -181,8 +186,9 @@ add_test(function test_stk_terminal_response() {
*/
add_test(function test_write_location_info_tlv() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let tlvHelper = worker.ComprehensionTlvHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let tlvHelper = context.ComprehensionTlvHelper;
// Test with 2-digit mnc, and gsmCellId obtained from UMTS network.
let loc = {
@ -270,8 +276,9 @@ add_test(function test_write_location_info_tlv() {
*/
add_test(function test_write_disconnecting_cause() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let tlvHelper = worker.ComprehensionTlvHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let tlvHelper = context.ComprehensionTlvHelper;
tlvHelper.writeCauseTlv(RIL_ERROR_TO_GECKO_ERROR[ERROR_GENERIC_FAILURE]);
let tag = pduHelper.readHexOctet();
@ -291,7 +298,8 @@ add_test(function test_write_disconnecting_cause() {
*/
add_test(function test_get_size_of_length_octets() {
let worker = newUint8Worker();
let tlvHelper = worker.ComprehensionTlvHelper;
let context = worker.ContextPool._contexts[0];
let tlvHelper = context.ComprehensionTlvHelper;
let length = 0x70;
do_check_eq(tlvHelper.getSizeOfLengthOctets(length), 1);
@ -313,8 +321,9 @@ add_test(function test_get_size_of_length_octets() {
*/
add_test(function test_write_length() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let tlvHelper = worker.ComprehensionTlvHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let tlvHelper = context.ComprehensionTlvHelper;
let length = 0x70;
tlvHelper.writeLength(length);
@ -347,9 +356,10 @@ add_test(function test_write_length() {
*/
add_test(function test_stk_proactive_command_search_next_tag() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let tag_test = [
0xD0,
@ -389,9 +399,10 @@ add_test(function test_stk_proactive_command_search_next_tag() {
*/
add_test(function test_stk_proactive_command_refresh() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let refresh_1 = [
0xD0,
@ -422,9 +433,10 @@ add_test(function test_stk_proactive_command_refresh() {
*/
add_test(function test_stk_proactive_command_play_tone() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let tone_1 = [
0xD0,
@ -464,9 +476,10 @@ add_test(function test_stk_proactive_command_play_tone() {
*/
add_test(function test_stk_proactive_command_poll_interval() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let poll_1 = [
0xD0,
@ -498,9 +511,10 @@ add_test(function test_stk_proactive_command_poll_interval() {
*/
add_test(function test_read_septets_to_string() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let display_text_1 = [
0xd0,
@ -529,9 +543,10 @@ add_test(function test_read_septets_to_string() {
*/
add_test(function test_stk_proactive_command_event_list() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let event_1 = [
0xD0,
@ -565,10 +580,11 @@ add_test(function test_stk_proactive_command_event_list() {
*/
add_test(function test_stk_proactive_command_get_input() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let stkCmdHelper = worker.StkCommandParamsFactory;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let stkCmdHelper = context.StkCommandParamsFactory;
let get_input_1 = [
0xD0,
@ -633,9 +649,10 @@ add_test(function test_stk_proactive_command_get_input() {
*/
add_test(function test_stk_proactive_command_more_time() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let more_time_1 = [
0xD0,
@ -662,10 +679,11 @@ add_test(function test_stk_proactive_command_more_time() {
*/
add_test(function test_stk_proactive_command_select_item() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let stkFactory = worker.StkCommandParamsFactory;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let stkFactory = context.StkCommandParamsFactory;
let select_item_1 = [
0xD0,
@ -749,10 +767,11 @@ add_test(function test_stk_proactive_command_select_item() {
*/
add_test(function test_stk_proactive_command_set_up_menu() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let stkFactory = worker.StkCommandParamsFactory;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let stkFactory = context.StkCommandParamsFactory;
let set_up_menu_1 = [
0xD0,
@ -832,10 +851,11 @@ add_test(function test_stk_proactive_command_set_up_menu() {
*/
add_test(function test_stk_proactive_command_set_up_call() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let cmdFactory = worker.StkCommandParamsFactory;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
let cmdFactory = context.StkCommandParamsFactory;
let set_up_call_1 = [
0xD0,
@ -869,9 +889,10 @@ add_test(function test_stk_proactive_command_set_up_call() {
*/
add_test(function test_stk_proactive_command_timer_management() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
// Timer Management - Start
let timer_management_1 = [
@ -931,9 +952,10 @@ add_test(function test_stk_proactive_command_timer_management() {
*/
add_test(function test_stk_proactive_command_provide_local_information() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
// Verify IMEI
let local_info_1 = [
@ -979,9 +1001,10 @@ add_test(function test_stk_proactive_command_provide_local_information() {
*/
add_test(function test_stk_proactive_command_open_channel() {
let worker = newUint8Worker();
let pduHelper = worker.GsmPDUHelper;
let berHelper = worker.BerTlvHelper;
let stkHelper = worker.StkProactiveCmdHelper;
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let berHelper = context.BerTlvHelper;
let stkHelper = context.StkProactiveCmdHelper;
// Open Channel
let open_channel = [
@ -1083,8 +1106,9 @@ add_test(function test_stk_proactive_command_open_channel() {
*/
add_test(function test_stk_event_download_location_status() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
buf.sendParcel = function() {
// Type
@ -1153,7 +1177,7 @@ add_test(function test_stk_event_download_location_status() {
gsmCellId: 0
}
};
worker.RIL.sendStkEventDownload({
context.RIL.sendStkEventDownload({
event: event
});
});
@ -1165,9 +1189,10 @@ add_test(function test_stk_event_download_location_status() {
*/
add_test(function test_stk_event_download_language_selection() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let iccHelper = worker.ICCPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
let iccHelper = context.ICCPDUHelper;
buf.sendParcel = function() {
// Type
@ -1214,7 +1239,7 @@ add_test(function test_stk_event_download_language_selection() {
eventType: STK_EVENT_TYPE_LANGUAGE_SELECTION,
language: "zh"
};
worker.RIL.sendStkEventDownload({
context.RIL.sendStkEventDownload({
event: event
});
});
@ -1224,8 +1249,9 @@ add_test(function test_stk_event_download_language_selection() {
*/
add_test(function test_stk_event_download_user_activity() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
buf.sendParcel = function() {
// Type
@ -1262,7 +1288,7 @@ add_test(function test_stk_event_download_user_activity() {
let event = {
eventType: STK_EVENT_TYPE_USER_ACTIVITY
};
worker.RIL.sendStkEventDownload({
context.RIL.sendStkEventDownload({
event: event
});
});
@ -1272,8 +1298,9 @@ add_test(function test_stk_event_download_user_activity() {
*/
add_test(function test_stk_event_download_idle_screen_available() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
buf.sendParcel = function() {
// Type
@ -1310,7 +1337,7 @@ add_test(function test_stk_event_download_idle_screen_available() {
let event = {
eventType: STK_EVENT_TYPE_IDLE_SCREEN_AVAILABLE
};
worker.RIL.sendStkEventDownload({
context.RIL.sendStkEventDownload({
event: event
});
});
@ -1320,8 +1347,9 @@ add_test(function test_stk_event_download_idle_screen_available() {
*/
add_test(function test_stk_event_download_browser_termination() {
let worker = newUint8SupportOutgoingIndexWorker();
let buf = worker.Buf;
let pduHelper = worker.GsmPDUHelper;
let context = worker.ContextPool._contexts[0];
let buf = context.Buf;
let pduHelper = context.GsmPDUHelper;
buf.sendParcel = function() {
// Type
@ -1367,7 +1395,7 @@ add_test(function test_stk_event_download_browser_termination() {
eventType: STK_EVENT_TYPE_BROWSER_TERMINATION,
terminationCause: STK_BROWSER_TERMINATION_CAUSE_USER
};
worker.RIL.sendStkEventDownload({
context.RIL.sendStkEventDownload({
event: event
});
});

Просмотреть файл

@ -29,14 +29,15 @@ function _getWorker() {
add_test(function test_setVoicePrivacyMode_success() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
worker.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.setVoicePrivacyMode({
context.RIL.setVoicePrivacyMode({
enabled: true
});
@ -50,14 +51,15 @@ add_test(function test_setVoicePrivacyMode_success() {
add_test(function test_setVoicePrivacyMode_generic_failure() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
worker.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
rilRequestError: ERROR_GENERIC_FAILURE
});
};
worker.RIL.setVoicePrivacyMode({
context.RIL.setVoicePrivacyMode({
enabled: true
});
@ -71,18 +73,19 @@ add_test(function test_setVoicePrivacyMode_generic_failure() {
add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32List = function fakeReadUint32List() {
context.Buf.readInt32List = function fakeReadUint32List() {
return [1];
};
worker.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
worker.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryVoicePrivacyMode();
context.RIL.queryVoicePrivacyMode();
let postedMessage = workerHelper.postedMessage;
@ -94,18 +97,19 @@ add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
add_test(function test_queryVoicePrivacyMode_success_enabled_false() {
let workerHelper = _getWorker();
let worker = workerHelper.worker;
let context = worker.ContextPool._contexts[0];
worker.Buf.readInt32List = function fakeReadUint32List() {
context.Buf.readInt32List = function fakeReadUint32List() {
return [0];
};
worker.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
worker.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
context.RIL[REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE](1, {
rilRequestError: ERROR_SUCCESS
});
};
worker.RIL.queryVoicePrivacyMode();
context.RIL.queryVoicePrivacyMode();
let postedMessage = workerHelper.postedMessage;

Просмотреть файл

@ -543,6 +543,14 @@ gfxDWriteFontEntry::ReadCMAP(FontInfoData *aFontInfoData)
mHasCmapTable = NS_SUCCEEDED(rv);
if (mHasCmapTable) {
// Bug 969504: exclude U+25B6 from Segoe UI family, because it's used
// by sites to represent a "Play" icon, but the glyph in Segoe UI Light
// and Semibold on Windows 7 is too thin. (Ditto for leftward U+25C0.)
// Fallback to Segoe UI Symbol is preferred.
if (FamilyName().EqualsLiteral("Segoe UI")) {
charmap->clear(0x25b6);
charmap->clear(0x25c0);
}
gfxPlatformFontList *pfl = gfxPlatformFontList::PlatformFontList();
mCharacterMap = pfl->FindCharMap(charmap);
} else {

Просмотреть файл

@ -144,6 +144,22 @@ ConnectWorkerToRIL::RunTask(JSContext *aCx)
NS_ASSERTION(!JS_IsRunning(aCx), "Are we being called somehow?");
JS::Rooted<JSObject*> workerGlobal(aCx, JS::CurrentGlobalOrNull(aCx));
// Check whether |postRILMessage| has been defined. No one but this class
// should ever define |postRILMessage| in a RIL worker, so we call to
// |JS_LookupProperty| instead of |JS_GetProperty| here.
JS::Rooted<JS::Value> val(aCx);
if (!JS_LookupProperty(aCx, workerGlobal, "postRILMessage", &val)) {
JS_ReportPendingException(aCx);
return false;
}
// |JS_LookupProperty| could still return JS_TRUE with an "undefined"
// |postRILMessage|, so we have to make sure that with an additional call
// to |JS_TypeOfValue|.
if (JSTYPE_FUNCTION == JS_TypeOfValue(aCx, val)) {
return true;
}
return !!JS_DefineFunction(aCx, workerGlobal,
"postRILMessage", PostToRIL, 2, 0);
}
@ -151,13 +167,16 @@ ConnectWorkerToRIL::RunTask(JSContext *aCx)
class DispatchRILEvent : public WorkerTask
{
public:
DispatchRILEvent(UnixSocketRawData* aMessage)
: mMessage(aMessage)
DispatchRILEvent(unsigned long aClient,
UnixSocketRawData* aMessage)
: mClientId(aClient)
, mMessage(aMessage)
{ }
virtual bool RunTask(JSContext *aCx);
private:
unsigned long mClientId;
nsAutoPtr<UnixSocketRawData> mMessage;
};
@ -166,15 +185,18 @@ DispatchRILEvent::RunTask(JSContext *aCx)
{
JS::Rooted<JSObject*> obj(aCx, JS::CurrentGlobalOrNull(aCx));
JSObject *array = JS_NewUint8Array(aCx, mMessage->mSize);
JS::Rooted<JSObject*> array(aCx, JS_NewUint8Array(aCx, mMessage->mSize));
if (!array) {
return false;
}
JS::Rooted<JS::Value> arrayVal(aCx, JS::ObjectValue(*array));
memcpy(JS_GetArrayBufferViewData(array), mMessage->mData, mMessage->mSize);
JS::AutoValueArray<2> args(aCx);
args[0].setNumber((uint32_t)mClientId);
args[1].setObject(*array);
JS::Rooted<JS::Value> rval(aCx);
return JS_CallFunctionName(aCx, obj, "onRILMessage", arrayVal, &rval);
return JS_CallFunctionName(aCx, obj, "onRILMessage", args, &rval);
}
class RilConnector : public mozilla::ipc::UnixSocketConnector
@ -354,7 +376,7 @@ RilConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
{
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<DispatchRILEvent> dre(new DispatchRILEvent(aMessage.forget()));
nsRefPtr<DispatchRILEvent> dre(new DispatchRILEvent(mClientId, aMessage.forget()));
mDispatcher->PostTask(dre);
}

Просмотреть файл

@ -0,0 +1,26 @@
function ceil(x) {
return Math.ceil(x);
}
// Compiled as Ceil(double -> int32)
assertEq(ceil(1.1), 2);
assertEq(ceil(-1.1), -1);
assertEq(ceil(-3), -3);
// As we use the identity Math.ceil(x) == -Math.floor(-x) and Floor(-0) bails out,
// this should bail out.
assertEq(ceil(0), 0);
assertEq(ceil(0), 0);
// Reuses the Ceil(double -> int32) path
assertEq(ceil(1.1), 2);
assertEq(ceil(-1.1), -1);
assertEq(ceil(-3), -3);
// Bails out and then compiles as Ceil(double -> double)
assertEq(ceil(-0), -0);
assertEq(ceil(Math.pow(2, 32)), Math.pow(2, 32));
assertEq(ceil(-0), -0);
// Still works but not inlined as double -> int32 (it still uses double -> double)
assertEq(ceil(1.5), 2);

Просмотреть файл

@ -208,7 +208,7 @@ function setupFloorDouble() {
function testFloor() {
for (var i = 0; i < 4; ++i) {
var f = Math.floor(f32[i]);
assertFloat32(g, false); // f is an int32
assertFloat32(f, false); // f is an int32
var g = Math.floor(-0 + f32[i]);
assertFloat32(g, false);
@ -229,3 +229,41 @@ function testFloorDouble() {
}
test(setupFloor, testFloor);
test(setupFloorDouble, testFloorDouble);
function setupCeil() {
f32[0] = -5.5;
f32[1] = -1.5;
f32[2] = 0;
f32[3] = 1.5;
}
function setupCeilDouble() {
f32[4] = NaN;
f32[5] = -0;
f32[6] = Infinity;
f32[7] = -Infinity;
f32[8] = Math.pow(2,31); // too big to fit into a int
}
function testCeil() {
for(var i = 0; i < 2; ++i) {
var f = Math.ceil(f32[i]);
assertFloat32(f, false);
var g = Math.ceil(-0 + f32[i]);
assertFloat32(g, false);
assertEq(f, g);
}
}
function testCeilDouble() {
for(var i = 4; i < 9; ++i) {
var f = Math.fround(Math.ceil(f32[i]));
assertFloat32(f, true);
var g = Math.ceil(-0 + f32[i]);
assertFloat32(g, false);
assertEq(f, g);
}
}
test(setupCeil, testCeil);
test(setupCeilDouble, testCeilDouble);

Просмотреть файл

@ -4618,7 +4618,7 @@ ICGetElem_TypedArray::Compiler::generateStubCode(MacroAssembler &masm)
bool
ICGetElem_Arguments::Compiler::generateStubCode(MacroAssembler &masm)
{
// Variatns of GetElem_Arguments can enter stub frames if entered in CallProp
// Variants of GetElem_Arguments can enter stub frames if entered in CallProp
// context when noSuchMethod support is on.
#if JS_HAS_NO_SUCH_METHOD
#ifdef DEBUG

Просмотреть файл

@ -620,6 +620,21 @@ IonBuilder::inlineMathCeil(CallInfo &callInfo)
return InliningStatus_Inlined;
}
if (IsFloatingPointType(argType) && returnType == MIRType_Int32) {
// Math.ceil(x) == -Math.floor(-x)
callInfo.setImplicitlyUsedUnchecked();
MConstant *minusOne = MConstant::New(alloc(), DoubleValue(-1.0));
current->add(minusOne);
MMul *mul = MMul::New(alloc(), callInfo.getArg(0), minusOne, argType);
current->add(mul);
MFloor *floor = MFloor::New(alloc(), mul);
current->add(floor);
MMul *result = MMul::New(alloc(), floor, minusOne, MIRType_Int32);
current->add(result);
current->push(result);
return InliningStatus_Inlined;
}
if (IsFloatingPointType(argType) && returnType == MIRType_Double) {
callInfo.setImplicitlyUsedUnchecked();
MMathFunction *ins = MMathFunction::New(alloc(), callInfo.getArg(0), MMathFunction::Ceil, nullptr);

Просмотреть файл

@ -42,7 +42,6 @@ UNIFIED_SOURCES += [
'testIntern.cpp',
'testIntString.cpp',
'testIntTypesABI.cpp',
'testJitRValueAlloc.cpp',
'testJSEvaluateScript.cpp',
'testLookup.cpp',
'testLooselyEqual.cpp',
@ -73,6 +72,11 @@ UNIFIED_SOURCES += [
'testXDR.cpp',
]
if CONFIG['ENABLE_ION']:
UNIFIED_SOURCES += [
'testJitRValueAlloc.cpp',
]
DEFINES['EXPORT_JS_API'] = True
# Building against js_static requires that we declare mfbt sybols "exported"
# on its behalf.

Просмотреть файл

@ -1666,6 +1666,11 @@ ContainerState::FindFixedPosFrameForLayerData(const nsIFrame* aAnimatedGeometryR
nsIntRegion* aVisibleRegion,
bool* aIsSolidColorInVisibleRegion)
{
if (!mManager->IsWidgetLayerManager()) {
// Never attach any fixed-pos metadata to inactive layers, it's pointless!
return nullptr;
}
nsPresContext* presContext = mContainerFrame->PresContext();
nsIFrame* viewport = presContext->PresShell()->GetRootFrame();
const nsIFrame* result = nullptr;
@ -1685,6 +1690,10 @@ ContainerState::FindFixedPosFrameForLayerData(const nsIFrame* aAnimatedGeometryR
result = f;
break;
}
if (f == mContainerReferenceFrame) {
// The metadata will go on an ancestor layer if necessary.
return nullptr;
}
}
if (!result) {
return nullptr;

Просмотреть файл

@ -80,12 +80,12 @@ nsHttpConnection::nsHttpConnection()
, mResponseTimeoutEnabled(false)
, mTCPKeepaliveConfig(kTCPKeepaliveDisabled)
{
LOG(("Creating nsHttpConnection @%p\n", this));
LOG(("Creating nsHttpConnection @%x\n", this));
}
nsHttpConnection::~nsHttpConnection()
{
LOG(("Destroying nsHttpConnection @%p\n", this));
LOG(("Destroying nsHttpConnection @%x\n", this));
ReportDataUsage(false);
if (!mEverUsedSpdy) {
@ -313,7 +313,7 @@ nsHttpConnection::Activate(nsAHttpTransaction *trans, uint32_t caps, int32_t pri
nsresult rv;
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnection::Activate [this=%p trans=%p caps=%x]\n",
LOG(("nsHttpConnection::Activate [this=%p trans=%x caps=%x]\n",
this, trans, caps));
if (!trans->IsNullTransaction())
@ -1247,7 +1247,7 @@ nsHttpConnection::EndIdleMonitoring()
void
nsHttpConnection::CloseTransaction(nsAHttpTransaction *trans, nsresult reason)
{
LOG(("nsHttpConnection::CloseTransaction[this=%p trans=%p reason=%x]\n",
LOG(("nsHttpConnection::CloseTransaction[this=%p trans=%x reason=%x]\n",
this, trans, reason));
MOZ_ASSERT(trans == mTransaction, "wrong transaction");
@ -1809,7 +1809,6 @@ nsHttpConnection::OnInputStreamReady(nsIAsyncInputStream *in)
if (!CanReuse()) {
LOG(("Server initiated close of idle conn %p\n", this));
// CloseIdleConnection may delete "this" - return immediately
gHttpHandler->ConnMgr()->CloseIdleConnection(this);
return NS_OK;
}

Просмотреть файл

@ -27,7 +27,7 @@ nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &host, int32_t port,
, mUsingSSL(usingSSL)
, mUsingConnect(false)
{
LOG(("Creating nsHttpConnectionInfo @%p\n", this));
LOG(("Creating nsHttpConnectionInfo @%x\n", this));
mUsingHttpProxy = (proxyInfo && proxyInfo->IsHTTP());

Просмотреть файл

@ -41,6 +41,25 @@ namespace net {
NS_IMPL_ISUPPORTS1(nsHttpConnectionMgr, nsIObserver)
static void
InsertTransactionSorted(nsTArray<nsHttpTransaction*> &pendingQ, nsHttpTransaction *trans)
{
// insert into queue with smallest valued number first. search in reverse
// order under the assumption that many of the existing transactions will
// have the same priority (usually 0).
for (int32_t i=pendingQ.Length()-1; i>=0; --i) {
nsHttpTransaction *t = pendingQ[i];
if (trans->Priority() >= t->Priority()) {
pendingQ.InsertElementAt(i+1, trans);
return;
}
}
pendingQ.InsertElementAt(0, trans);
}
//-----------------------------------------------------------------------------
nsHttpConnectionMgr::nsHttpConnectionMgr()
: mReentrantMonitor("nsHttpConnectionMgr.mReentrantMonitor")
, mMaxConns(0)
@ -55,12 +74,12 @@ nsHttpConnectionMgr::nsHttpConnectionMgr()
, mTimeoutTickArmed(false)
, mTimeoutTickNext(1)
{
LOG(("Creating nsHttpConnectionMgr @%p\n", this));
LOG(("Creating nsHttpConnectionMgr @%x\n", this));
}
nsHttpConnectionMgr::~nsHttpConnectionMgr()
{
LOG(("Destroying nsHttpConnectionMgr @%p\n", this));
LOG(("Destroying nsHttpConnectionMgr @%x\n", this));
if (mTimeoutTick)
mTimeoutTick->Cancel();
}
@ -158,7 +177,8 @@ nsHttpConnectionMgr::PostEvent(nsConnEventHandler handler, int32_t iparam, void
if (!mSocketThreadTarget) {
NS_WARNING("cannot post event if not initialized");
rv = NS_ERROR_NOT_INITIALIZED;
} else {
}
else {
nsRefPtr<nsIRunnable> event = new nsConnEvent(this, handler, iparam, vparam);
rv = mSocketThreadTarget->Dispatch(event, NS_DISPATCH_NORMAL);
}
@ -234,9 +254,11 @@ nsHttpConnectionMgr::Observe(nsISupports *subject,
nsCOMPtr<nsITimer> timer = do_QueryInterface(subject);
if (timer == mTimer) {
PruneDeadConnections();
} else if (timer == mTimeoutTick) {
}
else if (timer == mTimeoutTick) {
TimeoutTick();
} else {
}
else {
MOZ_ASSERT(false, "unexpected timer-callback");
LOG(("Unexpected timer object\n"));
return NS_ERROR_UNEXPECTED;
@ -250,42 +272,39 @@ nsHttpConnectionMgr::Observe(nsISupports *subject,
//-----------------------------------------------------------------------------
nsresult
nsHttpConnectionMgr::AddTransaction(nsHttpTransaction *aTrans, int32_t priority)
nsHttpConnectionMgr::AddTransaction(nsHttpTransaction *trans, int32_t priority)
{
LOG(("nsHttpConnectionMgr::AddTransaction [trans=%p %d]\n", aTrans, priority));
LOG(("nsHttpConnectionMgr::AddTransaction [trans=%x %d]\n", trans, priority));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgNewTransaction, priority, trans);
if (NS_SUCCEEDED(rv)) {
trans.forget();
}
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
nsresult
nsHttpConnectionMgr::RescheduleTransaction(nsHttpTransaction *aTrans, int32_t priority)
nsHttpConnectionMgr::RescheduleTransaction(nsHttpTransaction *trans, int32_t priority)
{
LOG(("nsHttpConnectionMgr::RescheduleTransaction [trans=%p %d]\n", aTrans, priority));
LOG(("nsHttpConnectionMgr::RescheduleTransaction [trans=%x %d]\n", trans, priority));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgReschedTransaction, priority, trans);
if (NS_SUCCEEDED(rv)) {
trans.forget();
}
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
nsresult
nsHttpConnectionMgr::CancelTransaction(nsHttpTransaction *aTrans, nsresult reason)
nsHttpConnectionMgr::CancelTransaction(nsHttpTransaction *trans, nsresult reason)
{
LOG(("nsHttpConnectionMgr::CancelTransaction [trans=%p reason=%x]\n", aTrans, reason));
LOG(("nsHttpConnectionMgr::CancelTransaction [trans=%x reason=%x]\n", trans, reason));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgCancelTransaction,
static_cast<int32_t>(reason), trans);
if (NS_SUCCEEDED(rv)) {
trans.forget();
}
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
@ -302,9 +321,8 @@ nsHttpConnectionMgr::DoShiftReloadConnectionCleanup(nsHttpConnectionInfo *aCI)
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgDoShiftReloadConnectionCleanup,
0, connInfo);
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv))
connInfo.forget();
}
return rv;
}
@ -378,9 +396,8 @@ nsHttpConnectionMgr::SpeculativeConnect(nsHttpConnectionInfo *ci,
nsresult rv =
PostEvent(&nsHttpConnectionMgr::OnMsgSpeculativeConnect, 0, args);
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv))
args.forget();
}
return rv;
}
@ -395,15 +412,14 @@ nsHttpConnectionMgr::GetSocketThreadTarget(nsIEventTarget **target)
}
nsresult
nsHttpConnectionMgr::ReclaimConnection(nsHttpConnection *aConn)
nsHttpConnectionMgr::ReclaimConnection(nsHttpConnection *conn)
{
LOG(("nsHttpConnectionMgr::ReclaimConnection [conn=%p]\n", aConn));
LOG(("nsHttpConnectionMgr::ReclaimConnection [conn=%x]\n", conn));
nsRefPtr<nsHttpConnection> conn(aConn);
NS_ADDREF(conn);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgReclaimConnection, 0, conn);
if (NS_SUCCEEDED(rv)) {
conn.forget();
}
if (NS_FAILED(rv))
NS_RELEASE(conn);
return rv;
}
@ -428,9 +444,8 @@ nsHttpConnectionMgr::CompleteUpgrade(nsAHttpConnection *aConn,
new nsCompleteUpgradeData(aConn, aUpgradeListener);
nsresult rv;
rv = PostEvent(&nsHttpConnectionMgr::OnMsgCompleteUpgrade, 0, data);
if (NS_FAILED(rv)) {
if (NS_FAILED(rv))
delete data;
}
return rv;
}
@ -443,15 +458,14 @@ nsHttpConnectionMgr::UpdateParam(nsParamName name, uint16_t value)
}
nsresult
nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *aCI)
nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *ci)
{
LOG(("nsHttpConnectionMgr::ProcessPendingQ [ci=%s]\n", aCI->HashKey().get()));
LOG(("nsHttpConnectionMgr::ProcessPendingQ [ci=%s]\n", ci->HashKey().get()));
nsRefPtr<nsHttpConnectionInfo> ci(aCI);
NS_ADDREF(ci);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgProcessPendingQ, 0, ci);
if (NS_SUCCEEDED(rv)) {
ci.forget();
}
if (NS_FAILED(rv))
NS_RELEASE(ci);
return rv;
}
@ -479,9 +493,8 @@ nsHttpConnectionMgr::UpdateRequestTokenBucket(EventTokenBucket *aBucket)
// to post the new value to the socket thread.
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgUpdateRequestTokenBucket,
0, bucket.get());
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv))
bucket.forget();
}
return rv;
}
@ -535,7 +548,6 @@ nsHttpConnectionMgr::CloseIdleConnection(nsHttpConnection *conn)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnectionMgr::CloseIdleConnection %p conn=%p",
this, conn));
nsRefPtr<nsHttpConnection> deleteProtector(conn);
if (!conn->ConnectionInfo())
return NS_ERROR_UNEXPECTED;
@ -547,7 +559,7 @@ nsHttpConnectionMgr::CloseIdleConnection(nsHttpConnection *conn)
return NS_ERROR_UNEXPECTED;
conn->Close(NS_ERROR_ABORT);
conn = nullptr;
NS_RELEASE(conn);
mNumIdleConns--;
ConditionallyStopPruneDeadConnectionsTimer();
return NS_OK;
@ -841,10 +853,10 @@ nsHttpConnectionMgr::PurgeExcessIdleConnectionsCB(const nsACString &key,
// There are no idle conns left in this connection entry
return PL_DHASH_NEXT;
}
nsRefPtr<nsHttpConnection> conn(ent->mIdleConns[0]);
nsHttpConnection *conn = ent->mIdleConns[0];
ent->mIdleConns.RemoveElementAt(0);
conn->Close(NS_ERROR_ABORT);
conn = nullptr;
NS_RELEASE(conn);
self->mNumIdleConns--;
self->ConditionallyStopPruneDeadConnectionsTimer();
}
@ -890,15 +902,15 @@ nsHttpConnectionMgr::PruneDeadConnectionsCB(const nsACString &key,
uint32_t timeToNextExpire = UINT32_MAX;
int32_t count = ent->mIdleConns.Length();
if (count > 0) {
for (int32_t i = count - 1; i >= 0; --i) {
if (!ent->mIdleConns[i]->CanReuse()) {
nsRefPtr<nsHttpConnection> conn(ent->mIdleConns[i]);
for (int32_t i=count-1; i>=0; --i) {
nsHttpConnection *conn = ent->mIdleConns[i];
if (!conn->CanReuse()) {
ent->mIdleConns.RemoveElementAt(i);
conn->Close(NS_ERROR_ABORT);
NS_RELEASE(conn);
self->mNumIdleConns--;
} else {
timeToNextExpire = std::min(timeToNextExpire,
ent->mIdleConns[i]->TimeToLive());
timeToNextExpire = std::min(timeToNextExpire, conn->TimeToLive());
}
}
}
@ -911,7 +923,8 @@ nsHttpConnectionMgr::PruneDeadConnectionsCB(const nsACString &key,
// marking it dont reuse will create an active tear down if
// the spdy session is idle.
conn->DontReuse();
} else {
}
else {
timeToNextExpire = std::min(timeToNextExpire,
conn->TimeToLive());
}
@ -967,32 +980,42 @@ nsHttpConnectionMgr::ShutdownPassCB(const nsACString &key,
{
nsHttpConnectionMgr *self = (nsHttpConnectionMgr *) closure;
// close all active connections and release list references
nsHttpTransaction *trans;
nsHttpConnection *conn;
// close all active connections
while (ent->mActiveConns.Length()) {
nsRefPtr<nsHttpConnection> conn(ent->mActiveConns[0]);
conn = ent->mActiveConns[0];
ent->mActiveConns.RemoveElementAt(0);
self->DecrementActiveConnCount(conn);
conn->Close(NS_ERROR_ABORT);
NS_RELEASE(conn);
}
// close all idle connections and release list references
// close all idle connections
while (ent->mIdleConns.Length()) {
nsRefPtr<nsHttpConnection> conn(ent->mIdleConns[0]);
conn = ent->mIdleConns[0];
ent->mIdleConns.RemoveElementAt(0);
self->mNumIdleConns--;
conn->Close(NS_ERROR_ABORT);
NS_RELEASE(conn);
}
// If all idle connections are removed,
// we can stop pruning dead connections.
self->ConditionallyStopPruneDeadConnectionsTimer();
// close all pending transactions and release list references
// close all pending transactions
while (ent->mPendingQ.Length()) {
nsRefPtr<nsHttpTransaction> trans(ent->mPendingQ[0]);
trans = ent->mPendingQ[0];
ent->mPendingQ.RemoveElementAt(0);
trans->Close(NS_ERROR_ABORT);
NS_RELEASE(trans);
}
// close all half open tcp connections
@ -1047,6 +1070,7 @@ nsHttpConnectionMgr::ProcessPendingQForEntry(nsConnectionEntry *ent, bool consid
if (ent->mPendingQ.RemoveElement(trans)) {
dispatchedSuccessfully = true;
NS_RELEASE(trans);
continue; // dont ++i as we just made the array shorter
}
@ -1239,10 +1263,11 @@ nsHttpConnectionMgr::ClosePersistentConnections(nsConnectionEntry *ent)
LOG(("nsHttpConnectionMgr::ClosePersistentConnections [ci=%s]\n",
ent->mConnInfo->HashKey().get()));
while (ent->mIdleConns.Length()) {
nsRefPtr<nsHttpConnection> conn(ent->mIdleConns[0]);
nsHttpConnection *conn = ent->mIdleConns[0];
ent->mIdleConns.RemoveElementAt(0);
mNumIdleConns--;
conn->Close(NS_ERROR_ABORT);
NS_RELEASE(conn);
}
int32_t activeCount = ent->mActiveConns.Length();
@ -1455,9 +1480,8 @@ nsHttpConnectionMgr::AddToShortestPipeline(nsConnectionEntry *ent,
activeTrans = bestConn->Transaction();
nsresult rv = activeTrans->AddTransaction(trans);
if (NS_FAILED(rv)) {
if (NS_FAILED(rv))
return false;
}
LOG((" scheduling trans %p on pipeline at position %d\n",
trans, trans->PipelinePosition()));
@ -1563,7 +1587,7 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
nsRefPtr<nsHttpConnection> conn = GetSpdyPreferredConn(ent);
if (conn) {
if ((caps & NS_HTTP_ALLOW_KEEPALIVE) || !conn->IsExperienced()) {
LOG((" dispatch to spdy: [conn=%p]\n", conn.get()));
LOG((" dispatch to spdy: [conn=%x]\n", conn.get()));
trans->RemoveDispatchedAsBlocking(); /* just in case */
DispatchTransaction(ent, trans, conn);
return NS_OK;
@ -1589,7 +1613,8 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
}
}
}
} else {
}
else {
// Mark the transaction and its load group as blocking right now to prevent
// other transactions from being reordered in the queue due to slow syns.
trans->DispatchedAsBlocking();
@ -1631,15 +1656,18 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
conn = ent->mIdleConns[0];
ent->mIdleConns.RemoveElementAt(0);
mNumIdleConns--;
nsHttpConnection *temp = conn;
NS_RELEASE(temp);
// we check if the connection can be reused before even checking if
// it is a "matching" connection.
if (!conn->CanReuse()) {
LOG((" dropping stale connection: [conn=%p]\n", conn.get()));
LOG((" dropping stale connection: [conn=%x]\n", conn.get()));
conn->Close(NS_ERROR_ABORT);
conn = nullptr;
} else {
LOG((" reusing connection [conn=%p]\n", conn.get()));
}
else {
LOG((" reusing connection [conn=%x]\n", conn.get()));
conn->EndIdleMonitoring();
}
@ -1714,7 +1742,7 @@ nsHttpConnectionMgr::DispatchTransaction(nsConnectionEntry *ent,
nsresult rv;
LOG(("nsHttpConnectionMgr::DispatchTransaction "
"[ci=%s trans=%p caps=%x conn=%p priority=%d]\n",
"[ci=%s trans=%x caps=%x conn=%x priority=%d]\n",
ent->mConnInfo->HashKey().get(), trans, caps, conn, priority));
// It is possible for a rate-paced transaction to be dispatched independent
@ -1774,7 +1802,7 @@ nsHttpConnectionMgr::DispatchAbstractTransaction(nsConnectionEntry *ent,
MOZ_ASSERT(!conn->UsingSpdy(),
"Spdy Must Not Use DispatchAbstractTransaction");
LOG(("nsHttpConnectionMgr::DispatchAbstractTransaction "
"[ci=%s trans=%p caps=%x conn=%p]\n",
"[ci=%s trans=%x caps=%x conn=%x]\n",
ent->mConnInfo->HashKey().get(), aTrans, caps, conn));
/* Use pipeline datastructure even if connection does not currently qualify
@ -1792,7 +1820,8 @@ nsHttpConnectionMgr::DispatchAbstractTransaction(nsConnectionEntry *ent,
if (!NS_SUCCEEDED(rv))
return rv;
transaction = pipeline;
} else {
}
else {
LOG((" not using pipeline datastructure due to class solo.\n"));
transaction = aTrans;
}
@ -1805,7 +1834,6 @@ nsHttpConnectionMgr::DispatchAbstractTransaction(nsConnectionEntry *ent,
rv = conn->Activate(transaction, caps, priority);
if (NS_FAILED(rv)) {
LOG((" conn->Activate failed [rv=%x]\n", rv));
nsRefPtr<nsHttpConnection> deleteProtector(conn);
ent->mActiveConns.RemoveElement(conn);
if (conn == ent->mYellowConnection)
ent->OnYellowComplete();
@ -1815,7 +1843,9 @@ nsHttpConnectionMgr::DispatchAbstractTransaction(nsConnectionEntry *ent,
// sever back references to connection, and do so without triggering
// a call to ReclaimConnection ;-)
transaction->SetConnection(nullptr);
handle->Reset();
NS_RELEASE(handle->mConn);
// destroy the connection
NS_RELEASE(conn);
}
// As transaction goes out of scope it will drop the last refernece to the
@ -1841,7 +1871,7 @@ nsHttpConnectionMgr::BuildPipeline(nsConnectionEntry *ent,
nsRefPtr<nsHttpPipeline> pipeline = new nsHttpPipeline();
pipeline->AddTransaction(firstTrans);
pipeline.forget(result);
NS_ADDREF(*result = pipeline);
return NS_OK;
}
@ -1922,9 +1952,10 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
if (rv == NS_ERROR_NOT_AVAILABLE) {
LOG((" adding transaction to pending queue "
"[trans=%p pending-count=%u]\n",
trans, ent->mPendingQ.Length() + 1));
trans, ent->mPendingQ.Length()+1));
// put this transaction on the pending queue...
InsertTransactionSorted(ent->mPendingQ, trans);
NS_ADDREF(trans);
return NS_OK;
}
@ -1932,10 +1963,12 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
return rv;
}
void
nsHttpConnectionMgr::AddActiveConn(nsHttpConnection *conn,
nsConnectionEntry *ent)
{
NS_ADDREF(conn);
ent->mActiveConns.AppendElement(conn);
mNumActiveConns++;
ActivateTimeoutTick();
@ -1995,7 +2028,7 @@ nsHttpConnectionMgr::ProcessSpdyPendingQ(nsConnectionEntry *ent)
if (!conn || !conn->CanDirectlyActivate())
return;
nsTArray<nsRefPtr<nsHttpTransaction> > leftovers;
nsTArray<nsHttpTransaction*> leftovers;
uint32_t index;
// Dispatch all the transactions we can
@ -2016,15 +2049,17 @@ nsHttpConnectionMgr::ProcessSpdyPendingQ(nsConnectionEntry *ent)
// close the transaction
MOZ_ASSERT(false, "Dispatch SPDY Transaction");
LOG(("ProcessSpdyPendingQ Dispatch Transaction failed trans=%p\n",
trans));
trans));
trans->Close(rv);
}
NS_RELEASE(trans);
}
// Slurp up the rest of the pending queue into our leftovers bucket (we
// might have some left if conn->CanDirectlyActivate returned false)
for (; index < ent->mPendingQ.Length(); ++index) {
leftovers.AppendElement(ent->mPendingQ[index]);
nsHttpTransaction *trans = ent->mPendingQ[index];
leftovers.AppendElement(trans);
}
// Put the leftovers back in the pending queue and get rid of the
@ -2120,13 +2155,12 @@ nsHttpConnectionMgr::OnMsgNewTransaction(int32_t priority, void *param)
{
LOG(("nsHttpConnectionMgr::OnMsgNewTransaction [trans=%p]\n", param));
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
trans->SetPriority(priority);
nsresult rv = ProcessNewTransaction(trans);
if (NS_FAILED(rv)) {
if (NS_FAILED(rv))
trans->Close(rv); // for whatever its worth
}
NS_RELEASE(trans);
}
void
@ -2135,8 +2169,7 @@ nsHttpConnectionMgr::OnMsgReschedTransaction(int32_t priority, void *param)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnectionMgr::OnMsgReschedTransaction [trans=%p]\n", param));
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
trans->SetPriority(priority);
nsConnectionEntry *ent = LookupConnectionEntry(trans->ConnectionInfo(),
@ -2149,6 +2182,8 @@ nsHttpConnectionMgr::OnMsgReschedTransaction(int32_t priority, void *param)
InsertTransactionSorted(ent->mPendingQ, trans);
}
}
NS_RELEASE(trans);
}
void
@ -2158,8 +2193,7 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
LOG(("nsHttpConnectionMgr::OnMsgCancelTransaction [trans=%p]\n", param));
nsresult closeCode = static_cast<nsresult>(reason);
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
//
// if the transaction owns a connection and the transaction is not done,
// then ask the connection to close the transaction. otherwise, close the
@ -2176,8 +2210,10 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
int32_t index = ent->mPendingQ.IndexOf(trans);
if (index >= 0) {
LOG(("nsHttpConnectionMgr::OnMsgCancelTransaction [trans=%p]"
" found in pending queue\n", trans.get()));
" found in pending queue\n", trans));
ent->mPendingQ.RemoveElementAt(index);
nsHttpTransaction *temp = trans;
NS_RELEASE(temp); // b/c NS_RELEASE nulls its argument!
}
}
trans->Close(closeCode);
@ -2196,19 +2232,19 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
if (liveTransaction && liveTransaction->IsNullTransaction()) {
LOG(("nsHttpConnectionMgr::OnMsgCancelTransaction [trans=%p] "
"also canceling Null Transaction %p on conn %p\n",
trans.get(), liveTransaction, activeConn));
trans, liveTransaction, activeConn));
activeConn->CloseTransaction(liveTransaction, closeCode);
}
}
}
NS_RELEASE(trans);
}
void
nsHttpConnectionMgr::OnMsgProcessPendingQ(int32_t, void *param)
{
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
nsRefPtr<nsHttpConnectionInfo> ci =
dont_AddRef(static_cast<nsHttpConnectionInfo *>(param));
nsHttpConnectionInfo *ci = (nsHttpConnectionInfo *) param;
if (!ci) {
LOG(("nsHttpConnectionMgr::OnMsgProcessPendingQ [ci=nullptr]\n"));
@ -2227,6 +2263,8 @@ nsHttpConnectionMgr::OnMsgProcessPendingQ(int32_t, void *param)
// for the specified connection info. walk the connection table...
mCT.Enumerate(ProcessOneTransactionCB, this);
}
NS_RELEASE(ci);
}
void
@ -2264,8 +2302,7 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnectionMgr::OnMsgReclaimConnection [conn=%p]\n", param));
nsRefPtr<nsHttpConnection> conn =
dont_AddRef(static_cast<nsHttpConnection *>(param));
nsHttpConnection *conn = (nsHttpConnection *) param;
//
// 1) remove the connection from the active list
@ -2275,15 +2312,16 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
nsConnectionEntry *ent = LookupConnectionEntry(conn->ConnectionInfo(),
conn, nullptr);
nsRefPtr<nsHttpConnectionInfo> ci;
nsHttpConnectionInfo *ci = nullptr;
if (!ent) {
// this should never happen
LOG(("nsHttpConnectionMgr::OnMsgReclaimConnection ent == null\n"));
MOZ_ASSERT(false, "no connection entry");
ci = conn->ConnectionInfo();
} else {
ci = ent->mConnInfo;
NS_ADDREF(ci = conn->ConnectionInfo());
}
else {
NS_ADDREF(ci = ent->mConnInfo);
// If the connection is in the active list, remove that entry
// and the reference held by the mActiveConns list.
@ -2303,7 +2341,8 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
if (ent->mActiveConns.RemoveElement(conn)) {
if (conn == ent->mYellowConnection)
ent->OnYellowComplete();
nsHttpConnection *temp = conn;
NS_RELEASE(temp);
DecrementActiveConnCount(conn);
ConditionallyStopTimeoutTick();
}
@ -2324,6 +2363,7 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
break;
}
NS_ADDREF(conn);
ent->mIdleConns.InsertElementAt(idx, conn);
mNumIdleConns++;
conn->BeginIdleMonitoring();
@ -2334,13 +2374,15 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
uint32_t timeToLive = conn->TimeToLive();
if(!mTimer || NowInSeconds() + timeToLive < mTimeOfNextWakeUp)
PruneDeadConnectionsAfter(timeToLive);
} else {
}
else {
LOG((" connection cannot be reused; closing connection\n"));
conn->Close(NS_ERROR_ABORT);
}
}
OnMsgProcessPendingQ(0, ci.forget().get()); // releases |ci ref|
OnMsgProcessPendingQ(0, ci); // releases |ci|
NS_RELEASE(conn);
}
void
@ -2403,6 +2445,8 @@ nsHttpConnectionMgr::nsConnectionEntry::~nsConnectionEntry()
{
if (mSpdyPreferred)
gHttpHandler->ConnMgr()->RemoveSpdyPreferredEnt(mCoalescingKey);
NS_RELEASE(mConnInfo);
}
void
@ -2525,26 +2569,6 @@ nsHttpConnectionMgr::TimeoutTickCB(const nsACString &key,
return PL_DHASH_NEXT;
}
void
nsHttpConnectionMgr::
InsertTransactionSorted(nsTArray<nsRefPtr<nsHttpTransaction> > &pendingQ,
nsHttpTransaction *trans)
{
// Insert into queue with smallest valued number first. Search in reverse
// order under the assumption that many of the existing transactions will
// have the same priority (usually 0).
// List holds a reference on all members of mPendingQ
for (int32_t i = pendingQ.Length() - 1; i >= 0; --i) {
nsHttpTransaction *t = pendingQ[i];
if (trans->Priority() >= t->Priority()) {
pendingQ.InsertElementAt(i + 1, trans);
return;
}
}
pendingQ.InsertElementAt(0, trans);
}
//-----------------------------------------------------------------------------
// nsHttpConnectionMgr::nsConnectionHandle
@ -2552,6 +2576,7 @@ nsHttpConnectionMgr::nsConnectionHandle::~nsConnectionHandle()
{
if (mConn) {
gHttpHandler->ReclaimConnection(mConn);
NS_RELEASE(mConn);
}
}
@ -2632,7 +2657,8 @@ nsHttpConnectionMgr::OnMsgSpeculativeConnect(int32_t, void *param)
!RestrictConnections(ent, ignorePossibleSpdyConnections) &&
!AtActiveConnectionLimit(ent, args->mTrans->Caps())) {
CreateTransport(ent, args->mTrans, args->mTrans->Caps(), true);
} else {
}
else {
LOG((" Transport not created due to existing connection count\n"));
}
}
@ -2982,7 +3008,8 @@ nsHalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream *out)
mStreamOut = nullptr;
mStreamIn = nullptr;
mSocketTransport = nullptr;
} else {
}
else {
TimeDuration rtt = TimeStamp::Now() - mBackupSynStarted;
rv = conn->Init(mEnt->mConnInfo,
gHttpHandler->ConnMgr()->mMaxRequestDelay,
@ -3015,11 +3042,12 @@ nsHalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream *out)
if (index != -1) {
MOZ_ASSERT(!mSpeculative,
"Speculative Half Open found mTranscation");
nsRefPtr<nsHttpTransaction> temp(mEnt->mPendingQ[index]);
nsRefPtr<nsHttpTransaction> temp = dont_AddRef(mEnt->mPendingQ[index]);
mEnt->mPendingQ.RemoveElementAt(index);
gHttpHandler->ConnMgr()->AddActiveConn(conn, mEnt);
rv = gHttpHandler->ConnMgr()->DispatchTransaction(mEnt, temp, conn);
} else {
}
else {
// this transaction was dispatched off the pending q before all the
// sockets established themselves.
@ -3054,7 +3082,8 @@ nsHalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream *out)
conn->Classify(nsAHttpTransaction::CLASS_SOLO);
rv = gHttpHandler->ConnMgr()->
DispatchAbstractTransaction(mEnt, trans, mCaps, conn, 0);
} else {
}
else {
// otherwise just put this in the persistent connection pool
LOG(("nsHalfOpenSocket::OnOutputStreamReady no transaction match "
"returning conn %p to pool\n", conn.get()));
@ -3208,6 +3237,7 @@ nsConnectionEntry::nsConnectionEntry(nsHttpConnectionInfo *ci)
, mPreferIPv4(false)
, mPreferIPv6(false)
{
NS_ADDREF(mConnInfo);
if (gHttpHandler->GetPipelineAggressive()) {
mGreenDepth = kPipelineUnlimited;
mPipelineState = PS_GREEN;
@ -3333,7 +3363,8 @@ nsConnectionEntry::OnPipelineFeedbackInfo(
"Penalty now %d, throttle[%d] = %d\n", mConnInfo->Host(),
classification, info, mPipeliningPenalty, classification,
mPipeliningClassPenalty[classification]));
} else {
}
else {
// hand out credits for neutral and good events such as
// "headers look ok" events
@ -3368,7 +3399,8 @@ nsConnectionEntry::OnYellowComplete()
LOG(("transition %s to green\n", mConnInfo->Host()));
mPipelineState = PS_GREEN;
mGreenDepth = mInitialGreenDepth;
} else {
}
else {
// The purpose of the yellow state is to witness at least
// one successful pipelined transaction without seeing any
// kind of negative feedback before opening the flood gates.
@ -3412,7 +3444,8 @@ nsConnectionEntry::CreditPenalty()
// update last credit mark to reflect elapsed time
mLastCreditTime += TimeDuration::FromSeconds(creditsEarned << 4);
} else {
}
else {
failed = true; /* just assume this */
}

Просмотреть файл

@ -265,10 +265,10 @@ private:
nsConnectionEntry(nsHttpConnectionInfo *ci);
~nsConnectionEntry();
nsRefPtr<nsHttpConnectionInfo> mConnInfo;
nsTArray<nsRefPtr<nsHttpTransaction> > mPendingQ; // pending transaction queue
nsTArray<nsRefPtr<nsHttpConnection> > mActiveConns; // active connections
nsTArray<nsRefPtr<nsHttpConnection> > mIdleConns; // idle persistent connections
nsHttpConnectionInfo *mConnInfo;
nsTArray<nsHttpTransaction*> mPendingQ; // pending transaction queue
nsTArray<nsHttpConnection*> mActiveConns; // active connections
nsTArray<nsHttpConnection*> mIdleConns; // idle persistent connections
nsTArray<nsHalfOpenSocket*> mHalfOpens; // half open connections
// calculate the number of half open sockets that have not had at least 1
@ -379,18 +379,16 @@ private:
// need for consumer code to know when to give the connection back to the
// connection manager.
//
class nsConnectionHandle MOZ_FINAL : public nsAHttpConnection
class nsConnectionHandle : public nsAHttpConnection
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSAHTTPCONNECTION(mConn)
nsConnectionHandle(nsHttpConnection *conn) : mConn(conn) { }
nsConnectionHandle(nsHttpConnection *conn) { NS_ADDREF(mConn = conn); }
virtual ~nsConnectionHandle();
void Reset() { mConn = nullptr; }
private:
nsRefPtr<nsHttpConnection> mConn;
nsHttpConnection *mConn;
};
// nsHalfOpenSocket is used to hold the state of an opening TCP socket
@ -522,8 +520,6 @@ private:
void StartedConnect();
void RecvdConnect();
static void InsertTransactionSorted(nsTArray<nsRefPtr<nsHttpTransaction> > &,
nsHttpTransaction *);
nsConnectionEntry *GetOrCreateConnectionEntry(nsHttpConnectionInfo *);
nsresult MakeNewConnection(nsConnectionEntry *ent,

Просмотреть файл

@ -111,14 +111,19 @@ NewURI(const nsACString &aSpec,
int32_t aDefaultPort,
nsIURI **aURI)
{
nsRefPtr<nsStandardURL> url = new nsStandardURL();
nsStandardURL *url = new nsStandardURL();
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(url);
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
aDefaultPort, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) {
NS_RELEASE(url);
return rv;
}
url.forget(aURI);
*aURI = url; // no QI needed
return NS_OK;
}
@ -129,7 +134,8 @@ NewURI(const nsACString &aSpec,
nsHttpHandler *gHttpHandler = nullptr;
nsHttpHandler::nsHttpHandler()
: mHttpVersion(NS_HTTP_VERSION_1_1)
: mConnMgr(nullptr)
, mHttpVersion(NS_HTTP_VERSION_1_1)
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
, mReferrerLevel(0xff) // by default we always send a referrer
@ -225,7 +231,7 @@ nsHttpHandler::~nsHttpHandler()
// make sure the connection manager is shutdown
if (mConnMgr) {
mConnMgr->Shutdown();
mConnMgr = nullptr;
NS_RELEASE(mConnMgr);
}
// Note: don't call NeckoChild::DestroyNeckoChild() here, as it's too late
@ -383,6 +389,9 @@ nsHttpHandler::InitConnectionMgr()
if (!mConnMgr) {
mConnMgr = new nsHttpConnectionMgr();
if (!mConnMgr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mConnMgr);
}
rv = mConnMgr->Init(mMaxConnections,

Просмотреть файл

@ -345,7 +345,7 @@ private:
nsHttpAuthCache mPrivateAuthCache;
// the connection manager
nsRefPtr<nsHttpConnectionMgr> mConnMgr;
nsHttpConnectionMgr *mConnMgr;
//
// prefs

Просмотреть файл

@ -62,7 +62,8 @@ private:
//-----------------------------------------------------------------------------
nsHttpPipeline::nsHttpPipeline()
: mStatus(NS_OK)
: mConnection(nullptr)
, mStatus(NS_OK)
, mRequestIsPartial(false)
, mResponseIsPartial(false)
, mClosed(false)
@ -82,6 +83,8 @@ nsHttpPipeline::~nsHttpPipeline()
// make sure we aren't still holding onto any transactions!
Close(NS_ERROR_ABORT);
NS_IF_RELEASE(mConnection);
if (mPushBackBuf)
free(mPushBackBuf);
}
@ -94,7 +97,7 @@ nsHttpPipeline::AddTransaction(nsAHttpTransaction *trans)
if (mRequestQ.Length() || mResponseQ.Length())
mUtilizedPipeline = true;
trans->AddRef(); // ref held by mRequestQ
NS_ADDREF(trans);
mRequestQ.AppendElement(trans);
uint32_t qlen = PipelineDepth();
@ -202,11 +205,10 @@ nsHttpPipeline::OnHeadersAvailable(nsAHttpTransaction *trans,
}
void
nsHttpPipeline::CloseTransaction(nsAHttpTransaction *aTrans, nsresult reason)
nsHttpPipeline::CloseTransaction(nsAHttpTransaction *trans, nsresult reason)
{
nsRefPtr<nsAHttpTransaction> trans(dont_AddRef(aTrans));
LOG(("nsHttpPipeline::CloseTransaction [this=%p trans=%x reason=%x]\n",
this, trans.get(), reason));
this, trans, reason));
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
MOZ_ASSERT(NS_FAILED(reason), "expecting failure code");
@ -241,7 +243,7 @@ nsHttpPipeline::CloseTransaction(nsAHttpTransaction *aTrans, nsresult reason)
DontReuse();
trans->Close(reason);
trans = nullptr;
NS_RELEASE(trans);
if (killPipeline) {
// reschedule anything from this pipeline onto a different connection
@ -383,11 +385,12 @@ nsHttpPipeline::TakeSubTransactions(
int32_t i, count = mRequestQ.Length();
for (i = 0; i < count; ++i) {
nsRefPtr<nsAHttpTransaction> trans(dont_AddRef(Request(i)));
nsAHttpTransaction *trans = Request(i);
// set the transaction conneciton object back to the underlying
// nsHttpConnectionHandle
trans->SetConnection(mConnection);
outTransactions.AppendElement(trans);
NS_RELEASE(trans);
}
mRequestQ.Clear();
@ -406,13 +409,14 @@ nsHttpPipeline::SetConnection(nsAHttpConnection *conn)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
MOZ_ASSERT(!mConnection, "already have a connection");
mConnection = conn;
NS_IF_ADDREF(mConnection = conn);
}
nsAHttpConnection *
nsHttpPipeline::Connection()
{
LOG(("nsHttpPipeline::Connection [this=%p conn=%x]\n", this, mConnection.get()));
LOG(("nsHttpPipeline::Connection [this=%p conn=%x]\n", this, mConnection));
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
return mConnection;
@ -684,7 +688,7 @@ nsHttpPipeline::WriteSegments(nsAHttpSegmentWriter *writer,
// Release the transaction if it is not IsProxyConnectInProgress()
if (trans == Response(0)) {
nsRefPtr<nsAHttpTransaction> listReference(dont_AddRef(trans));
NS_RELEASE(trans);
mResponseQ.RemoveElementAt(0);
mResponseIsPartial = false;
++mHttp1xTransactionCount;
@ -727,6 +731,7 @@ uint32_t
nsHttpPipeline::CancelPipeline(nsresult originalReason)
{
uint32_t i, reqLen, respLen, total;
nsAHttpTransaction *trans;
reqLen = mRequestQ.Length();
respLen = mResponseQ.Length();
@ -742,12 +747,12 @@ nsHttpPipeline::CancelPipeline(nsresult originalReason)
// any pending requests can ignore this error and be restarted
// unless it is during a CONNECT tunnel request
for (i = 0; i < reqLen; ++i) {
// Each element on the list has a reference held by the list
nsRefPtr<nsAHttpTransaction> trans(dont_AddRef(Request(i)));
trans = Request(i);
if (mConnection && mConnection->IsProxyConnectInProgress())
trans->Close(originalReason);
else
trans->Close(NS_ERROR_NET_RESET);
NS_RELEASE(trans);
}
mRequestQ.Clear();
@ -756,8 +761,9 @@ nsHttpPipeline::CancelPipeline(nsresult originalReason)
// Higher levels of callers ensure that we don't process non-idempotent
// tranasction with the NS_HTTP_ALLOW_PIPELINING bit set
for (i = 1; i < respLen; ++i) {
nsRefPtr<nsAHttpTransaction> trans(dont_AddRef(Response(i)));
trans = Response(i);
trans->Close(NS_ERROR_NET_RESET);
NS_RELEASE(trans);
}
if (respLen > 1)
@ -795,10 +801,9 @@ nsHttpPipeline::Close(nsresult reason)
gHttpHandler->ConnMgr()->PipelineFeedbackInfo(
ci, nsHttpConnectionMgr::RedCanceledPipeline, nullptr, 0);
if (!Response(0)) {
nsAHttpTransaction *trans = Response(0);
if (!trans)
return;
}
nsRefPtr<nsAHttpTransaction> trans(dont_AddRef(Response(0)));
// The current transaction can be restarted via reset
// if the response has not started to arrive and the reason
@ -814,7 +819,7 @@ nsHttpPipeline::Close(nsresult reason)
trans->Close(reason);
}
trans = nullptr;
NS_RELEASE(trans);
mResponseQ.Clear();
}

Просмотреть файл

@ -58,7 +58,7 @@ private:
// overload of nsAHttpTransaction::QueryPipeline()
nsHttpPipeline *QueryPipeline();
nsRefPtr<nsAHttpConnection> mConnection;
nsAHttpConnection *mConnection;
nsTArray<nsAHttpTransaction*> mRequestQ; // array of transactions
nsTArray<nsAHttpTransaction*> mResponseQ; // array of transactions
nsresult mStatus;

Просмотреть файл

@ -89,6 +89,8 @@ LogHeaders(const char *lineStart)
nsHttpTransaction::nsHttpTransaction()
: mCallbacksLock("transaction mCallbacks lock")
, mRequestSize(0)
, mConnection(nullptr)
, mConnInfo(nullptr)
, mRequestHead(nullptr)
, mResponseHead(nullptr)
, mContentLength(-1)
@ -147,6 +149,9 @@ nsHttpTransaction::~nsHttpTransaction()
// Force the callbacks to be released right now
mCallbacks = nullptr;
NS_IF_RELEASE(mConnection);
NS_IF_RELEASE(mConnInfo);
delete mResponseHead;
delete mForTakeResponseHead;
delete mChunkedDecoder;
@ -264,7 +269,7 @@ nsHttpTransaction::Init(uint32_t caps,
!activityDistributorActive);
if (NS_FAILED(rv)) return rv;
mConnInfo = cinfo;
NS_ADDREF(mConnInfo = cinfo);
mCallbacks = callbacks;
mConsumerTarget = target;
mCaps = caps;
@ -440,7 +445,8 @@ nsHttpTransaction::TakeSubTransactions(
void
nsHttpTransaction::SetConnection(nsAHttpConnection *conn)
{
mConnection = conn;
NS_IF_RELEASE(mConnection);
NS_IF_ADDREF(mConnection = conn);
if (conn) {
MOZ_EVENT_TRACER_EXEC(static_cast<nsAHttpTransaction*>(this),
@ -955,9 +961,8 @@ nsHttpTransaction::Close(nsresult reason)
mTimings.responseEnd.IsNull() && !mTimings.responseStart.IsNull())
mTimings.responseEnd = TimeStamp::Now();
if (relConn) {
mConnection = nullptr;
}
if (relConn && mConnection)
NS_RELEASE(mConnection);
// save network statistics in the end of transaction
SaveNetworkStats(true);
@ -1111,7 +1116,7 @@ nsHttpTransaction::Restart()
// clear old connection state...
mSecurityInfo = 0;
mConnection = nullptr;
NS_IF_RELEASE(mConnection);
// disable pipelining for the next attempt in case pipelining caused the
// reset. this is being overly cautious since we don't know if pipelining

Просмотреть файл

@ -185,11 +185,10 @@ private:
nsCOMPtr<nsIInputStream> mRequestStream;
uint64_t mRequestSize;
nsRefPtr<nsHttpConnectionInfo> mConnInfo;
nsRefPtr<nsAHttpConnection> mConnection;
nsAHttpConnection *mConnection; // hard ref
nsHttpConnectionInfo *mConnInfo; // hard ref
nsHttpRequestHead *mRequestHead; // weak ref
nsHttpResponseHead *mResponseHead; // owning ref
nsHttpResponseHead *mResponseHead; // hard ref
nsAHttpSegmentReader *mReader;
nsAHttpSegmentWriter *mWriter;

Просмотреть файл

@ -4014,6 +4014,11 @@
"extended_statistics_ok": true,
"description": "Number of sites blocked from the new tab page."
},
"NEWTAB_PAGE_SHOWN": {
"expires_in_version": "35",
"kind": "boolean",
"description": "Number of times about:newtab was shown from opening a new tab or window."
},
"PANORAMA_INITIALIZATION_TIME_MS": {
"expires_in_version": "never",
"kind": "exponential",

Просмотреть файл

@ -78,10 +78,6 @@ DELAYLOAD_DLLS += [
]
if CONFIG['MOZ_METRO']:
if CONFIG['MOZ_DEBUG']:
DELAYLOAD_DLLS += ['VCCORLIB' + CONFIG['CRTDLLVERSION'] + 'D.DLL']
else:
DELAYLOAD_DLLS += ['VCCORLIB' + CONFIG['CRTDLLVERSION'] + '.DLL']
DELAYLOAD_DLLS += [
'API-MS-WIN-CORE-WINRT-L' + CONFIG['CRTEXPDLLVERSION'] + '.DLL',
'API-MS-WIN-CORE-WINRT-STRING-L' + CONFIG['CRTEXPDLLVERSION'] + '.DLL',

Просмотреть файл

@ -5,213 +5,213 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GonkMemoryPressureMonitoring.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/FileUtils.h"
#include "mozilla/Monitor.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsMemoryPressure.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "base/message_loop.h"
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <android/log.h>
#define LOG(args...) \
__android_log_print(ANDROID_LOG_INFO, "GonkMemoryPressure" , ## args)
#ifdef MOZ_NUWA_PROCESS
#include "ipc/Nuwa.h"
#endif
using namespace mozilla;
namespace {
/**
* MemoryPressureWatcher watches sysfs from its own thread to notice when the
* system is under memory pressure. When we observe memory pressure, we use
* MemoryPressureRunnable to notify observers that they should release memory.
*
* When the system is under memory pressure, we don't want to constantly fire
* memory-pressure events. So instead, we try to detect when sysfs indicates
* that we're no longer under memory pressure, and only then start firing events
* again.
*
* (This is a bit problematic because we can't poll() to detect when we're no
* longer under memory pressure; instead we have to periodically read the sysfs
* node. If we remain under memory pressure for a long time, this means we'll
* continue waking up to read from the node for a long time, potentially wasting
* battery life. Hopefully we don't hit this case in practice! We write to
* logcat each time we go around this loop so it's at least noticable.)
*
* Shutting down safely is a bit of a chore. XPCOM won't shut down until all
* threads exit, so we need to exit the Run() method below on shutdown. But our
* thread might be blocked in one of two situations: We might be poll()'ing the
* sysfs node waiting for memory pressure to occur, or we might be asleep
* waiting to read() the sysfs node to see if we're no longer under memory
* pressure.
*
* To let us wake up from the poll(), we poll() not just the sysfs node but also
* a pipe, which we write to on shutdown. To let us wake up from sleeping
* between read()s, we sleep by Wait()'ing on a monitor, which we notify on
* shutdown.
*/
class MemoryPressureWatcher
: public nsIRunnable
, public nsIObserver
//
// MemoryPressureWatcher watches on the I/O thread for changes to the
// lowmemkiller's sysfs interface. If the system runs low on memory,
// MemoryPressureWatcher sends a MemoryPressureEvent, removes itself
// from the I/O loop, and schedules a PollTask to re-start polling
// after a timeout has been reached.
//
// The PollTask is allocated by MemoryPressureWatcher and handed over
// to the I/O loop, which then owns the object and deletes it after it
// ran. We cannot allocate the object dynamically, because the system
// is already low on memory. Instead we overload the new and delete
// operators for PollTask to hand-out statically allocated memory.
// There can only be at most one instance of PollTask at a time, so
// we can re-use the same memory on each allocation.
//
// There is a separate observer for shutdown events. When the system
// shuts down, it sends a task to the I/O thread for removing the
// watcher. If a PollTask is pending, it gets canceled. We cannot
// delete it at this point, because it's owned by the I/O loop.
//
class MemoryPressureWatcher : public MessageLoopForIO::Watcher
{
public:
MemoryPressureWatcher()
: mMonitor("MemoryPressureWatcher")
, mShuttingDown(false)
class PollTask : public CancelableTask
{
}
NS_DECL_THREADSAFE_ISUPPORTS
nsresult Init()
{
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
NS_ENSURE_STATE(os);
// The observer service holds us alive.
os->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, /* holdsWeak */ false);
// While we're under memory pressure, we periodically read()
// notify_trigger_active to try and see when we're no longer under memory
// pressure. mPollMS indicates how many milliseconds we wait between those
// read()s.
mPollMS = Preferences::GetUint("gonk.systemMemoryPressureRecoveryPollMS",
/* default */ 5000);
int pipes[2];
NS_ENSURE_STATE(!pipe(pipes));
mShutdownPipeRead = pipes[0];
mShutdownPipeWrite = pipes[1];
return NS_OK;
}
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
LOG("Observed XPCOM shutdown.");
MonitorAutoLock lock(mMonitor);
mShuttingDown = true;
mMonitor.Notify();
int rv;
do {
// Write something to the pipe; doesn't matter what.
uint32_t dummy = 0;
rv = write(mShutdownPipeWrite, &dummy, sizeof(dummy));
} while(rv == -1 && errno == EINTR);
return NS_OK;
}
NS_IMETHOD Run()
{
MOZ_ASSERT(!NS_IsMainThread());
#ifdef MOZ_NUWA_PROCESS
if (IsNuwaProcess()) {
NS_ASSERTION(NuwaMarkCurrentThread != nullptr,
"NuwaMarkCurrentThread is undefined!");
NuwaMarkCurrentThread(nullptr, nullptr);
public:
PollTask(MemoryPressureWatcher* aWatcher)
: mWatcher(aWatcher)
{
MOZ_ASSERT(mWatcher);
}
#endif
int lowMemFd = open("/sys/kernel/mm/lowmemkiller/notify_trigger_active",
O_RDONLY | O_CLOEXEC);
NS_ENSURE_STATE(lowMemFd != -1);
ScopedClose autoClose(lowMemFd);
static void* operator new(size_t aSize);
static void operator delete(void* aMem, size_t aSize);
nsresult rv = CheckForMemoryPressure(lowMemFd, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
void Run() MOZ_OVERRIDE
{
MOZ_ASSERT(MessageLoopForIO::current());
while (true) {
// Wait for a notification on lowMemFd or for data to be written to
// mShutdownPipeWrite. (poll(lowMemFd, POLLPRI) blocks until we're under
// memory pressure.)
struct pollfd pollfds[2];
pollfds[0].fd = lowMemFd;
pollfds[0].events = POLLPRI;
pollfds[1].fd = mShutdownPipeRead;
pollfds[1].events = POLLIN;
if (mWatcher) {
MOZ_ASSERT(MessageLoopForIO::current() == mWatcher->GetIOLoop());
mWatcher->StartWatching();
}
}
int pollRv;
do {
pollRv = poll(pollfds, ArrayLength(pollfds), /* timeout */ -1);
} while (pollRv == -1 && errno == EINTR);
void Cancel() MOZ_OVERRIDE
{
mWatcher = nullptr;
}
if (pollfds[1].revents) {
// Something was written to our shutdown pipe; we're outta here.
LOG("shutting down (1)");
return NS_OK;
private:
MemoryPressureWatcher* mWatcher;
};
template <size_t Size> class PollTaskAllocator
{
public:
void* Alloc()
{
MOZ_ASSERT(!sAllocated);
sAllocated = true;
return mMem;
}
void Release(void* aMem)
{
MOZ_ASSERT(mMem == aMem);
MOZ_ASSERT(sAllocated);
sAllocated = false;
}
private:
static bool sAllocated;
unsigned char mMem[Size];
};
MemoryPressureWatcher(MessageLoop* aIOLoop, uint32_t aPollMS)
: mFd(-1)
, mIOLoop(aIOLoop)
, mPollTask(nullptr)
, mPollMS(aPollMS)
, mMemoryPressure(false)
{
MOZ_ASSERT(mIOLoop);
}
virtual ~MemoryPressureWatcher()
{
MOZ_ASSERT(MessageLoopForIO::current() == mIOLoop);
MOZ_ASSERT(mFd == -1);
}
MessageLoop* GetIOLoop () const
{
return mIOLoop;
}
nsresult Open()
{
MOZ_ASSERT(MessageLoopForIO::current() == mIOLoop);
int fd;
do {
fd = open("/sys/kernel/mm/lowmemkiller/notify_trigger_active",
O_RDONLY | O_CLOEXEC);
} while (fd == -1 && errno == EINTR);
if (NS_WARN_IF(fd == -1)) {
return NS_ERROR_NOT_AVAILABLE;
}
mFd = fd;
return NS_OK;
}
void Close()
{
MOZ_ASSERT(MessageLoopForIO::current() == mIOLoop);
if (NS_WARN_IF(mFd == -1)) {
return;
}
int res;
do {
res = close(mFd);
} while (res == -1 && errno == EINTR);
NS_WARN_IF(res == -1);
mFd = -1;
}
void StartWatching()
{
MessageLoopForIO* ioLoop = MessageLoopForIO::current();
MOZ_ASSERT(ioLoop == mIOLoop);
ioLoop->WatchFileDescriptor(mFd, true, MessageLoopForIO::WATCH_READ,
&mReadWatcher, this);
mPollTask = nullptr;
}
void StopWatching()
{
if (mPollTask) {
mPollTask->Cancel();
}
mReadWatcher.StopWatchingFileDescriptor();
}
virtual void OnFileCanWriteWithoutBlocking(int aFd) MOZ_OVERRIDE
{
MOZ_ASSERT(MessageLoopForIO::current() == mIOLoop);
NS_WARNING("Must not write to memory monitor");
}
virtual void OnFileCanReadWithoutBlocking(int aFd) MOZ_OVERRIDE
{
MOZ_ASSERT(MessageLoopForIO::current() == mIOLoop);
bool memoryPressure;
nsresult rv = CheckForMemoryPressure(memoryPressure);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
if (memoryPressure) {
LOG("Memory pressure detected.");
StopWatching();
if (mMemoryPressure) {
rv = NS_DispatchMemoryPressure(MemPressure_Ongoing);
} else {
rv = NS_DispatchMemoryPressure(MemPressure_New);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// If pollfds[1] isn't happening, pollfds[0] ought to be!
if (!(pollfds[0].revents & POLLPRI)) {
LOG("Unexpected revents value after poll(): %d. "
"Shutting down GonkMemoryPressureMonitoring.", pollfds[0].revents);
return NS_ERROR_FAILURE;
}
// POLLPRI on lowMemFd indicates that we're in a low-memory situation. We
// could read lowMemFd to double-check, but we've observed that the read
// sometimes completes after the memory-pressure event is over, so let's
// just believe the result of poll().
// We use low-memory-no-forward because each process has its own watcher
// and thus there is no need for the main process to forward this event.
rv = NS_DispatchMemoryPressure(MemPressure_New);
NS_ENSURE_SUCCESS(rv, rv);
// Manually check lowMemFd until we observe that memory pressure is over.
// We won't fire any more low-memory events until we observe that
// we're no longer under pressure. Instead, we fire low-memory-ongoing
// events, which cause processes to keep flushing caches but will not
// trigger expensive GCs and other attempts to save memory that are
// likely futile at this point.
bool memoryPressure;
do {
{
MonitorAutoLock lock(mMonitor);
// We need to check mShuttingDown before we wait here, in order to
// catch a shutdown signal sent after we poll()'ed mShutdownPipeRead
// above but before we started waiting on the monitor. But we don't
// need to check after we wait, because we'll either do another
// iteration of this inner loop, in which case we'll check
// mShuttingDown, or we'll exit this loop and do another iteration
// of the outer loop, in which case we'll check the shutdown pipe.
if (mShuttingDown) {
LOG("shutting down (2)");
return NS_OK;
}
mMonitor.Wait(PR_MillisecondsToInterval(mPollMS));
}
LOG("Checking to see if memory pressure is over.");
rv = CheckForMemoryPressure(lowMemFd, &memoryPressure);
NS_ENSURE_SUCCESS(rv, rv);
if (memoryPressure) {
rv = NS_DispatchMemoryPressure(MemPressure_Ongoing);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
} while (false);
// While we're under memory pressure, we periodically read()
// notify_trigger_active to try and see when we're no longer under
// memory pressure. mPollMS indicates how many milliseconds we wait
// between those read()s.
mPollTask = new PollTask(this);
mIOLoop->PostDelayedTask(FROM_HERE, mPollTask, mPollMS);
} else if (mMemoryPressure) {
LOG("Memory pressure is over.");
}
return NS_OK;
mMemoryPressure = memoryPressure;
}
private:
@ -222,38 +222,138 @@ private:
*
* We don't expect this method to block.
*/
nsresult CheckForMemoryPressure(int aLowMemFd, bool* aOut)
nsresult CheckForMemoryPressure(bool& aOut)
{
if (aOut) {
*aOut = false;
}
aOut = false;
lseek(aLowMemFd, 0, SEEK_SET);
off_t off = lseek(mFd, 0, SEEK_SET);
if (NS_WARN_IF(off)) {
return NS_ERROR_UNEXPECTED;
}
char buf[2];
int nread;
do {
nread = read(aLowMemFd, buf, sizeof(buf));
nread = read(mFd, buf, sizeof(buf));
} while(nread == -1 && errno == EINTR);
NS_ENSURE_STATE(nread == 2);
if (NS_WARN_IF(nread != 2)) {
return NS_ERROR_UNEXPECTED;
}
// The notify_trigger_active sysfs node should contain either "0\n" or
// "1\n". The latter indicates memory pressure.
if (aOut) {
*aOut = buf[0] == '1' && buf[1] == '\n';
}
aOut = buf[0] == '1' && buf[1] == '\n';
return NS_OK;
}
Monitor mMonitor;
int mFd;
MessageLoop* mIOLoop;
MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
PollTask* mPollTask;
uint32_t mPollMS;
bool mShuttingDown;
ScopedClose mShutdownPipeRead;
ScopedClose mShutdownPipeWrite;
bool mMemoryPressure;
};
NS_IMPL_ISUPPORTS2(MemoryPressureWatcher, nsIRunnable, nsIObserver);
static
MemoryPressureWatcher::PollTaskAllocator<sizeof(MemoryPressureWatcher::PollTask)>
sPollTaskAllocator;
template<>
bool
MemoryPressureWatcher::PollTaskAllocator<sizeof(MemoryPressureWatcher::PollTask)>::sAllocated(false);
void*
MemoryPressureWatcher::PollTask::operator new(size_t aSize)
{
return sPollTaskAllocator.Alloc();
}
void
MemoryPressureWatcher::PollTask::operator delete(void* aMem, size_t aSize)
{
sPollTaskAllocator.Release(aMem);
}
// Initializes MemoryPressureWatcher on I/O thread
//
class InitMemoryPressureWatcherTask : public Task
{
public:
InitMemoryPressureWatcherTask(MemoryPressureWatcher* aWatcher)
: mWatcher(aWatcher)
{
MOZ_ASSERT(mWatcher);
}
void Run() MOZ_OVERRIDE
{
MOZ_ASSERT(MessageLoopForIO::current() == mWatcher->GetIOLoop());
nsresult rv = mWatcher->Open();
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
mWatcher->StartWatching();
}
private:
MemoryPressureWatcher* mWatcher;
};
// Releases MemoryPressureWatcher on I/O thread
//
class ShutdownMemoryPressureWatcherTask : public Task
{
public:
ShutdownMemoryPressureWatcherTask(MemoryPressureWatcher* aWatcher)
: mWatcher(aWatcher)
{
MOZ_ASSERT(mWatcher);
}
void Run() MOZ_OVERRIDE
{
MOZ_ASSERT(MessageLoopForIO::current() == mWatcher->GetIOLoop());
mWatcher->StopWatching();
mWatcher->Close();
}
private:
nsAutoPtr<MemoryPressureWatcher> mWatcher;
};
// Closes MemoryPressureWatcher on shutdown
//
class ShutdownObserver : public nsIObserver
{
public:
ShutdownObserver(MemoryPressureWatcher* aWatcher)
: mWatcher(aWatcher)
{
MOZ_ASSERT(mWatcher);
}
NS_DECL_THREADSAFE_ISUPPORTS
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
MOZ_ASSERT(!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID));
LOG("Observed XPCOM shutdown.");
Task* task = new ShutdownMemoryPressureWatcherTask(mWatcher);
mWatcher->GetIOLoop()->PostTask(FROM_HERE, task);
return NS_OK;
}
private:
MemoryPressureWatcher* mWatcher;
};
NS_IMPL_ISUPPORTS1(ShutdownObserver, nsIObserver);
} // anonymous namespace
@ -262,13 +362,22 @@ namespace mozilla {
void
InitGonkMemoryPressureMonitoring()
{
// memoryPressureWatcher is held alive by the observer service.
nsRefPtr<MemoryPressureWatcher> memoryPressureWatcher =
new MemoryPressureWatcher();
NS_ENSURE_SUCCESS_VOID(memoryPressureWatcher->Init());
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
uint32_t pollMS =
Preferences::GetUint("gonk.systemMemoryPressureRecoveryPollMS", 5000);
MemoryPressureWatcher* watcher = new MemoryPressureWatcher(ioLoop, pollMS);
nsCOMPtr<nsIThread> thread;
NS_NewThread(getter_AddRefs(thread), memoryPressureWatcher);
// Start watcher on I/O thread
Task* task = new InitMemoryPressureWatcherTask(watcher);
watcher->GetIOLoop()->PostTask(FROM_HERE, task);
// Install shutdown observer
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (NS_WARN_IF(!os)) {
return;
}
nsRefPtr<ShutdownObserver> observer = new ShutdownObserver(watcher);
os->AddObserver(observer, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
}
} // namespace mozilla