Bug 889737 - Part 10: Fix xpcshell tests. r=vicamo

This commit is contained in:
Szu-Yu Chen [:aknow] 2014-09-22 01:36:00 -04:00
parent 0488a241d4
commit ee1aaae1fe
10 changed files with 439 additions and 400 deletions

View File

@ -7,6 +7,19 @@ function run_test() {
run_next_test();
}
function createMMIOptions(procedure, serviceCode, sia, sib, sic) {
let mmi = {
fullMMI: Array.slice(arguments).join("*") + "#",
procedure: procedure,
serviceCode: serviceCode,
sia: sia,
sib: sib,
sic: sic
};
return mmi;
}
function testSendMMI(mmi, error) {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
@ -27,20 +40,8 @@ function testSendMMI(mmi, error) {
* sendMMI tests.
*/
add_test(function test_sendMMI_empty() {
testSendMMI("", MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_undefined() {
testSendMMI({}, MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_invalid() {
testSendMMI("11", MMI_ERROR_KS_ERROR);
add_test(function test_sendMMI_null() {
testSendMMI(null, MMI_ERROR_KS_ERROR);
run_next_test();
});
@ -61,7 +62,7 @@ add_test(function test_sendMMI_short_code() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "**"});
context.RIL.sendMMI({mmi: {fullMMI: "**"}});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "**");
@ -72,12 +73,6 @@ add_test(function test_sendMMI_short_code() {
run_next_test();
});
add_test(function test_sendMMI_dial_string() {
testSendMMI("123", MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_change_PIN() {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
@ -90,7 +85,8 @@ add_test(function test_sendMMI_change_PIN() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "**04*1234*4567*4567#"});
context.RIL.sendMMI({mmi: createMMIOptions("**", "04", "1234", "4567",
"4567")});
let postedMessage = workerhelper.postedMessage;
@ -101,25 +97,29 @@ add_test(function test_sendMMI_change_PIN() {
});
add_test(function test_sendMMI_change_PIN_no_new_PIN() {
testSendMMI("**04*1234**4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "04", "1234", "", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_change_PIN_no_old_PIN() {
testSendMMI("**04**1234*4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "04", "", "1234", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_change_PIN_wrong_procedure() {
testSendMMI("*04*1234*4567*4567#", MMI_ERROR_KS_INVALID_ACTION);
testSendMMI(createMMIOptions("*", "04", "1234", "4567", "4567"),
MMI_ERROR_KS_INVALID_ACTION);
run_next_test();
});
add_test(function test_sendMMI_change_PIN_new_PIN_mismatch() {
testSendMMI("**04*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
testSendMMI(createMMIOptions("**", "04", "4567", "1234", "4567"),
MMI_ERROR_KS_MISMATCH_PIN);
run_next_test();
});
@ -136,7 +136,8 @@ add_test(function test_sendMMI_change_PIN2() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "**042*1234*4567*4567#"});
context.RIL.sendMMI({mmi: createMMIOptions("**", "042", "1234", "4567",
"4567")});
let postedMessage = workerhelper.postedMessage;
@ -147,25 +148,29 @@ add_test(function test_sendMMI_change_PIN2() {
});
add_test(function test_sendMMI_change_PIN2_no_new_PIN2() {
testSendMMI("**042*1234**4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "042", "1234", "", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_change_PIN2_no_old_PIN2() {
testSendMMI("**042**1234*4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "042", "", "1234", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_change_PIN2_wrong_procedure() {
testSendMMI("*042*1234*4567*4567#", MMI_ERROR_KS_INVALID_ACTION);
testSendMMI(createMMIOptions("*", "042", "1234", "4567", "4567"),
MMI_ERROR_KS_INVALID_ACTION);
run_next_test();
});
add_test(function test_sendMMI_change_PIN2_new_PIN2_mismatch() {
testSendMMI("**042*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
testSendMMI(createMMIOptions("**", "042", "4567", "1234", "4567"),
MMI_ERROR_KS_MISMATCH_PIN);
run_next_test();
});
@ -182,7 +187,8 @@ add_test(function test_sendMMI_unblock_PIN() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "**05*1234*4567*4567#"});
context.RIL.sendMMI({mmi: createMMIOptions("**", "05", "1234", "4567",
"4567")});
let postedMessage = workerhelper.postedMessage;
@ -193,25 +199,29 @@ add_test(function test_sendMMI_unblock_PIN() {
});
add_test(function test_sendMMI_unblock_PIN_no_new_PIN() {
testSendMMI("**05*1234**4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "05", "1234", "", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN_no_PUK() {
testSendMMI("**05**1234*4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "05", "", "1234", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN_wrong_procedure() {
testSendMMI("*05*1234*4567*4567#", MMI_ERROR_KS_INVALID_ACTION);
testSendMMI(createMMIOptions("*", "05", "1234", "4567", "4567"),
MMI_ERROR_KS_INVALID_ACTION);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN_new_PIN_mismatch() {
testSendMMI("**05*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
testSendMMI(createMMIOptions("**", "05", "4567", "1234", "4567"),
MMI_ERROR_KS_MISMATCH_PIN);
run_next_test();
});
@ -228,7 +238,8 @@ add_test(function test_sendMMI_unblock_PIN2() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "**052*1234*4567*4567#"});
context.RIL.sendMMI({mmi: createMMIOptions("**", "052", "1234", "4567",
"4567")});
let postedMessage = workerhelper.postedMessage;
@ -239,25 +250,29 @@ add_test(function test_sendMMI_unblock_PIN2() {
});
add_test(function test_sendMMI_unblock_PIN2_no_new_PIN2() {
testSendMMI("**052*1234**4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "052", "1234", "", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN2_no_PUK2() {
testSendMMI("**052**1234*4567#", MMI_ERROR_KS_ERROR);
testSendMMI(createMMIOptions("**", "052", "", "1234", "4567"),
MMI_ERROR_KS_ERROR);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN2_wrong_procedure() {
testSendMMI("*052*1234*4567*4567#", MMI_ERROR_KS_INVALID_ACTION);
testSendMMI(createMMIOptions("*", "052", "1234", "4567", "4567"),
MMI_ERROR_KS_INVALID_ACTION);
run_next_test();
});
add_test(function test_sendMMI_unblock_PIN2_new_PIN_mismatch() {
testSendMMI("**052*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
testSendMMI(createMMIOptions("**", "052", "4567", "1234", "4567"),
MMI_ERROR_KS_MISMATCH_PIN);
run_next_test();
});
@ -275,7 +290,7 @@ add_test(function test_sendMMI_get_IMEI() {
});
};
context.RIL.sendMMI({mmi: "*#06#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "06")});
let postedMessage = workerhelper.postedMessage;
@ -299,7 +314,7 @@ add_test(function test_sendMMI_get_IMEI_error() {
});
};
context.RIL.sendMMI({mmi: "*#06#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "06")});
let postedMessage = workerhelper.postedMessage;
@ -328,7 +343,7 @@ add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*#33#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "33")});
let postedMessage = workerhelper.postedMessage;
@ -358,7 +373,7 @@ add_test(function test_sendMMI_call_barring_BAIC_activation() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*33#"});
context.RIL.sendMMI({mmi: createMMIOptions("*", "33")});
let postedMessage = workerhelper.postedMessage;
@ -386,7 +401,7 @@ add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "#33#"});
context.RIL.sendMMI({mmi: createMMIOptions("#", "33")});
let postedMessage = workerhelper.postedMessage;
@ -398,7 +413,7 @@ add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
});
add_test(function test_sendMMI_call_barring_BAIC_procedure_not_supported() {
testSendMMI("**33*0000#", MMI_ERROR_KS_NOT_SUPPORTED);
testSendMMI(createMMIOptions("**", "33", "0000"), MMI_ERROR_KS_NOT_SUPPORTED);
run_next_test();
});
@ -417,11 +432,11 @@ add_test(function test_sendMMI_USSD() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*123#"});
context.RIL.sendMMI({mmi: createMMIOptions("*", "123")});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "*123#");
do_check_eq(ussdOptions.ussd, "**123#");
do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_true(postedMessage.success);
do_check_true(context.RIL._ussdSession);
@ -443,11 +458,11 @@ add_test(function test_sendMMI_USSD_error() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*123#"});
context.RIL.sendMMI({mmi: createMMIOptions("*", "123")});
let postedMessage = workerhelper.postedMessage;
do_check_eq(ussdOptions.ussd, "*123#");
do_check_eq(ussdOptions.ussd, "**123#");
do_check_eq (postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
do_check_false(postedMessage.success);
do_check_false(context.RIL._ussdSession);
@ -476,25 +491,25 @@ function setCallWaitingSuccess(mmi) {
}
add_test(function test_sendMMI_call_waiting_activation() {
setCallWaitingSuccess("*43*10#");
setCallWaitingSuccess(createMMIOptions("*", "43", "10"));
run_next_test();
});
add_test(function test_sendMMI_call_waiting_deactivation() {
setCallWaitingSuccess("#43#");
setCallWaitingSuccess(createMMIOptions("#", "43"));
run_next_test();
});
add_test(function test_sendMMI_call_waiting_registration() {
testSendMMI("**43#", MMI_ERROR_KS_NOT_SUPPORTED);
testSendMMI(createMMIOptions("**", "43"), MMI_ERROR_KS_NOT_SUPPORTED);
run_next_test();
});
add_test(function test_sendMMI_call_waiting_erasure() {
testSendMMI("##43#", MMI_ERROR_KS_NOT_SUPPORTED);
testSendMMI(createMMIOptions("##", "43"), MMI_ERROR_KS_NOT_SUPPORTED);
run_next_test();
});
@ -520,7 +535,7 @@ add_test(function test_sendMMI_call_waiting_interrogation() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*#43#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "43")});
let postedMessage = workerhelper.postedMessage;

View File

@ -7,7 +7,20 @@ function run_test() {
run_next_test();
}
function setCallForwardSuccess(mmi) {
function createMMIOptions(procedure, serviceCode, sia, sib, sic) {
let mmi = {
fullMMI: Array.slice(arguments).join("*") + "#",
procedure: procedure,
serviceCode: serviceCode,
sia: sia,
sib: sib,
sic: sic
};
return mmi;
}
function setCallForwardSuccess(procedure, serviceCode, sia, sib, sic) {
let workerhelper = newInterceptWorker();
let worker = workerhelper.worker;
let context = worker.ContextPool._contexts[0];
@ -19,22 +32,23 @@ function setCallForwardSuccess(mmi) {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: mmi});
context.RIL.sendMMI({mmi: createMMIOptions(procedure, serviceCode, sia, sib,
sic)});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_eq(postedMessage.errorMsg, undefined);
do_check_true(postedMessage.success);
}
add_test(function test_sendMMI_call_forwarding_activation() {
setCallForwardSuccess("*21*12345*99*10#");
setCallForwardSuccess("*", "21", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_deactivation() {
setCallForwardSuccess("#21*12345*99*10#");
setCallForwardSuccess("#", "21", "12345", "99", "10");
run_next_test();
});
@ -67,11 +81,11 @@ add_test(function test_sendMMI_call_forwarding_interrogation() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*#21#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "21")});
let postedMessage = workerhelper.postedMessage;
do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
do_check_eq(postedMessage.errorMsg, undefined);
do_check_true(postedMessage.success);
do_check_true(Array.isArray(postedMessage.rules));
do_check_eq(postedMessage.rules.length, 1);
@ -97,7 +111,7 @@ add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
};
context.RIL.radioState = GECKO_RADIOSTATE_ENABLED;
context.RIL.sendMMI({mmi: "*#21#"});
context.RIL.sendMMI({mmi: createMMIOptions("*#", "21")});
let postedMessage = workerhelper.postedMessage;
@ -109,43 +123,43 @@ add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
add_test(function test_sendMMI_call_forwarding_registration() {
setCallForwardSuccess("**21*12345*99*10#");
setCallForwardSuccess("**", "21", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_erasure() {
setCallForwardSuccess("##21*12345*99#");
setCallForwardSuccess("##", "21", "12345", "99");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFB() {
setCallForwardSuccess("*67*12345*99*10#");
setCallForwardSuccess("*", "67", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRy() {
setCallForwardSuccess("*61*12345*99*10#");
setCallForwardSuccess("*", "61", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFNRc() {
setCallForwardSuccess("*62*12345*99*10#");
setCallForwardSuccess("*", "62", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAll() {
setCallForwardSuccess("*004*12345*99*10#");
setCallForwardSuccess("*", "004", "12345", "99", "10");
run_next_test();
});
add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
setCallForwardSuccess("*002*12345*99*10#");
setCallForwardSuccess("*", "002", "12345", "99", "10");
run_next_test();
});

View File

@ -1,317 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
function run_test() {
run_next_test();
}
let worker;
function parseMMI(mmi) {
if (!worker) {
worker = newWorker({
postRILMessage: function(data) {
// Do nothing
},
postMessage: function(message) {
// Do nothing
}
});
}
let context = worker.ContextPool._contexts[0];
return context.RIL._parseMMI(mmi);
}
add_test(function test_parseMMI_empty() {
let mmi = parseMMI("");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_undefined() {
let mmi = parseMMI();
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_one_digit_short_code() {
let mmi = parseMMI("1");
do_check_eq(mmi.fullMMI, "1");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_invalid_short_code() {
let mmi = parseMMI("11");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_short_code() {
let mmi = parseMMI("21");
do_check_eq(mmi.fullMMI, "21");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_dial_string() {
let mmi = parseMMI("12345");
do_check_null(mmi);
run_next_test();
});
add_test(function test_parseMMI_USSD_without_asterisk_prefix() {
let mmi = parseMMI("123#");
do_check_eq(mmi.fullMMI, "123#");
do_check_eq(mmi.procedure, undefined);
do_check_eq(mmi.serviceCode, undefined);
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_USSD() {
let mmi = parseMMI("*123#");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia() {
let mmi = parseMMI("*123*1#");
do_check_eq(mmi.fullMMI, "*123*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib() {
let mmi = parseMMI("*123**1#");
do_check_eq(mmi.fullMMI, "*123**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sic() {
let mmi = parseMMI("*123***1#");
do_check_eq(mmi.fullMMI, "*123***1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sib() {
let mmi = parseMMI("*123*1*1#");
do_check_eq(mmi.fullMMI, "*123*1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sic() {
let mmi = parseMMI("*123*1**1#");
do_check_eq(mmi.fullMMI, "*123*1**1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "1");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib_sic() {
let mmi = parseMMI("*123**1*1#");
do_check_eq(mmi.fullMMI, "*123**1*1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "1");
do_check_eq(mmi.sic, "1");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_pwd() {
let mmi = parseMMI("*123****1#");
do_check_eq(mmi.fullMMI, "*123****1#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, "");
do_check_eq(mmi.sib, "");
do_check_eq(mmi.sic, "");
do_check_eq(mmi.pwd, "1");
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_dial_number() {
let mmi = parseMMI("*123#345");
do_check_eq(mmi.fullMMI, "*123#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "123");
do_check_eq(mmi.sia, undefined);
do_check_eq(mmi.sib, undefined);
do_check_eq(mmi.sic, undefined);
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "345");
run_next_test();
});
/**
* MMI procedures tests
*/
add_test(function test_parseMMI_activation() {
let mmi = parseMMI("*00*12*34*56#");
do_check_eq(mmi.fullMMI, "*00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_deactivation() {
let mmi = parseMMI("#00*12*34*56#");
do_check_eq(mmi.fullMMI, "#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_DEACTIVATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_interrogation() {
let mmi = parseMMI("*#00*12*34*56#");
do_check_eq(mmi.fullMMI, "*#00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_INTERROGATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_registration() {
let mmi = parseMMI("**00*12*34*56#");
do_check_eq(mmi.fullMMI, "**00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_REGISTRATION);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_erasure() {
let mmi = parseMMI("##00*12*34*56#");
do_check_eq(mmi.fullMMI, "##00*12*34*56#");
do_check_eq(mmi.procedure, MMI_PROCEDURE_ERASURE);
do_check_eq(mmi.serviceCode, "00");
do_check_eq(mmi.sia, "12");
do_check_eq(mmi.sib, "34");
do_check_eq(mmi.sic, "56");
do_check_eq(mmi.pwd, undefined);
do_check_eq(mmi.dialNumber, "");
run_next_test();
});

View File

@ -24,7 +24,6 @@ skip-if = true
[test_ril_worker_sms_segment_info.js]
[test_ril_worker_mmi.js]
[test_ril_worker_mmi_cf.js]
[test_ril_worker_mmi_parseMMI.js]
[test_ril_worker_cf.js]
[test_ril_worker_cellbroadcast_config.js]
[test_ril_worker_cellbroadcast.js]

View File

@ -481,12 +481,13 @@ TelephonyService.prototype = {
aListener.enumerateCallStateComplete();
},
_hasCalls: function(aClientId) {
return Object.keys(this._currentCalls[aClientId]).length !== 0;
},
_hasCallsOnOtherClient: function(aClientId) {
for (let cid = 0; cid < this._numClients; ++cid) {
if (cid === aClientId) {
continue;
}
if (Object.keys(this._currentCalls[cid]).length !== 0) {
if (cid !== aClientId && this._hasCalls(cid)) {
return true;
}
}
@ -567,7 +568,7 @@ TelephonyService.prototype = {
return;
}
let mmi = this._parseMMI(aClientId, aNumber);
let mmi = this._parseMMI(aNumber, this._hasCalls(aClientId));
if (!mmi) {
this._dialCall(aClientId,
{ number: aNumber,
@ -812,13 +813,12 @@ TelephonyService.prototype = {
/**
* Helper to parse short string. TS.22.030 Figure 3.5.3.2.
*/
_isShortString: function(aClientId, aMmiString) {
_isShortString: function(aMmiString, hasCalls) {
if (aMmiString.length > 2) {
return false;
}
// In a call case.
if (Object.getOwnPropertyNames(this._currentCalls[aClientId]).length > 0) {
if (hasCalls) {
return true;
}
@ -836,7 +836,11 @@ TelephonyService.prototype = {
/**
* Helper to parse MMI/USSD string. TS.22.030 Figure 3.5.3.2.
*/
_parseMMI: function(aClientId, aMmiString) {
_parseMMI: function(aMmiString, hasCalls) {
if (!aMmiString) {
return null;
}
let matches = this._getMMIRegExp().exec(aMmiString);
if (matches) {
return {
@ -852,7 +856,7 @@ TelephonyService.prototype = {
}
if (this._isPoundString(aMmiString) ||
this._isShortString(aClientId, aMmiString)) {
this._isShortString(aMmiString, hasCalls)) {
return {
fullMMI: aMmiString
};
@ -1263,7 +1267,7 @@ TelephonyService.prototype = {
},
dialMMI: function(aClientId, aMmiString, aCallback) {
let mmi = this._parseMMI(aClientId, aMmiString);
let mmi = this._parseMMI(aMmiString, this._hasCalls(aClientId));
this._dialMMI(aClientId, mmi, aCallback);
},

View File

@ -44,6 +44,7 @@ IPDL_SOURCES += [
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini']
XPIDL_SOURCES += [
'nsIGonkTelephonyService.idl',
]

View File

@ -0,0 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
let subscriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);

View File

@ -0,0 +1,308 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
let NS = {};
subscriptLoader.loadSubScript("resource://gre/components/TelephonyService.js",
NS);
function run_test() {
run_next_test();
}
function parseMMI(mmiString) {
return NS.TelephonyService.prototype._parseMMI(mmiString, false);
}
add_test(function test_parseMMI_empty() {
let mmi = parseMMI("");
equal(mmi, null);
run_next_test();
});
add_test(function test_parseMMI_undefined() {
let mmi = parseMMI();
equal(mmi, null);
run_next_test();
});
add_test(function test_parseMMI_one_digit_short_code() {
let mmi = parseMMI("1");
equal(mmi.fullMMI, "1");
equal(mmi.procedure, undefined);
equal(mmi.serviceCode, undefined);
equal(mmi.sia, undefined);
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_invalid_short_code() {
let mmi = parseMMI("11");
equal(mmi, null);
run_next_test();
});
add_test(function test_parseMMI_short_code() {
let mmi = parseMMI("21");
equal(mmi.fullMMI, "21");
equal(mmi.procedure, undefined);
equal(mmi.serviceCode, undefined);
equal(mmi.sia, undefined);
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_dial_string() {
let mmi = parseMMI("12345");
equal(mmi, null);
run_next_test();
});
add_test(function test_parseMMI_USSD_without_asterisk_prefix() {
let mmi = parseMMI("123#");
equal(mmi.fullMMI, "123#");
equal(mmi.procedure, undefined);
equal(mmi.serviceCode, undefined);
equal(mmi.sia, undefined);
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, undefined);
run_next_test();
});
add_test(function test_parseMMI_USSD() {
let mmi = parseMMI("*123#");
equal(mmi.fullMMI, "*123#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, undefined);
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia() {
let mmi = parseMMI("*123*1#");
equal(mmi.fullMMI, "*123*1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "1");
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib() {
let mmi = parseMMI("*123**1#");
equal(mmi.fullMMI, "*123**1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "");
equal(mmi.sib, "1");
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sic() {
let mmi = parseMMI("*123***1#");
equal(mmi.fullMMI, "*123***1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "");
equal(mmi.sib, "");
equal(mmi.sic, "1");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sib() {
let mmi = parseMMI("*123*1*1#");
equal(mmi.fullMMI, "*123*1*1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "1");
equal(mmi.sib, "1");
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sia_sic() {
let mmi = parseMMI("*123*1**1#");
equal(mmi.fullMMI, "*123*1**1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "1");
equal(mmi.sib, "");
equal(mmi.sic, "1");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_sib_sic() {
let mmi = parseMMI("*123**1*1#");
equal(mmi.fullMMI, "*123**1*1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "");
equal(mmi.sib, "1");
equal(mmi.sic, "1");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_pwd() {
let mmi = parseMMI("*123****1#");
equal(mmi.fullMMI, "*123****1#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, "");
equal(mmi.sib, "");
equal(mmi.sic, "");
equal(mmi.pwd, "1");
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_dial_number() {
let mmi = parseMMI("*123#345");
equal(mmi.fullMMI, "*123#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "123");
equal(mmi.sia, undefined);
equal(mmi.sib, undefined);
equal(mmi.sic, undefined);
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "345");
run_next_test();
});
/**
* MMI procedures tests
*/
add_test(function test_parseMMI_activation() {
let mmi = parseMMI("*00*12*34*56#");
equal(mmi.fullMMI, "*00*12*34*56#");
equal(mmi.procedure, MMI_PROCEDURE_ACTIVATION);
equal(mmi.serviceCode, "00");
equal(mmi.sia, "12");
equal(mmi.sib, "34");
equal(mmi.sic, "56");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_deactivation() {
let mmi = parseMMI("#00*12*34*56#");
equal(mmi.fullMMI, "#00*12*34*56#");
equal(mmi.procedure, MMI_PROCEDURE_DEACTIVATION);
equal(mmi.serviceCode, "00");
equal(mmi.sia, "12");
equal(mmi.sib, "34");
equal(mmi.sic, "56");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_interrogation() {
let mmi = parseMMI("*#00*12*34*56#");
equal(mmi.fullMMI, "*#00*12*34*56#");
equal(mmi.procedure, MMI_PROCEDURE_INTERROGATION);
equal(mmi.serviceCode, "00");
equal(mmi.sia, "12");
equal(mmi.sib, "34");
equal(mmi.sic, "56");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_registration() {
let mmi = parseMMI("**00*12*34*56#");
equal(mmi.fullMMI, "**00*12*34*56#");
equal(mmi.procedure, MMI_PROCEDURE_REGISTRATION);
equal(mmi.serviceCode, "00");
equal(mmi.sia, "12");
equal(mmi.sib, "34");
equal(mmi.sic, "56");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});
add_test(function test_parseMMI_erasure() {
let mmi = parseMMI("##00*12*34*56#");
equal(mmi.fullMMI, "##00*12*34*56#");
equal(mmi.procedure, MMI_PROCEDURE_ERASURE);
equal(mmi.serviceCode, "00");
equal(mmi.sia, "12");
equal(mmi.sib, "34");
equal(mmi.sic, "56");
equal(mmi.pwd, undefined);
equal(mmi.dialNumber, "");
run_next_test();
});

View File

@ -0,0 +1,5 @@
[DEFAULT]
head = header_helpers.js
tail =
[test_parseMMI.js]

View File

@ -13,6 +13,7 @@ requesttimeoutfactor = 2
[include:dom/network/tests/unit_stats/xpcshell.ini]
[include:dom/resourcestats/tests/xpcshell/xpcshell.ini]
[include:dom/system/gonk/tests/xpcshell.ini]
[include:dom/telephony/test/xpcshell/xpcshell.ini]
[include:dom/wappush/tests/xpcshell.ini]
[include:toolkit/components/osfile/tests/xpcshell/xpcshell.ini]
[include:toolkit/components/captivedetect/test/unit/xpcshell.ini]