From 35f5ed906a96b6d812655494bfc29e5f4b032a90 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Mon, 2 Feb 2015 17:20:57 +0800 Subject: [PATCH] Bug 1123624 - Part 2-3: Add tests for stk system message. r=bevis --- dom/icc/tests/marionette/head.js | 30 +++++++++++++++++++ .../tests/marionette/test_stk_bip_command.js | 6 ++++ .../tests/marionette/test_stk_display_text.js | 6 ++++ .../tests/marionette/test_stk_get_inkey.js | 6 ++++ .../tests/marionette/test_stk_get_input.js | 6 ++++ .../marionette/test_stk_launch_browser.js | 6 ++++ .../tests/marionette/test_stk_local_info.js | 6 ++++ dom/icc/tests/marionette/test_stk_poll_off.js | 6 ++++ dom/icc/tests/marionette/test_stk_refresh.js | 6 ++++ .../tests/marionette/test_stk_select_item.js | 6 ++++ .../tests/marionette/test_stk_send_dtmf.js | 6 ++++ dom/icc/tests/marionette/test_stk_send_sms.js | 6 ++++ dom/icc/tests/marionette/test_stk_send_ss.js | 6 ++++ .../tests/marionette/test_stk_send_ussd.js | 6 ++++ .../tests/marionette/test_stk_setup_call.js | 6 ++++ .../marionette/test_stk_setup_event_list.js | 6 ++++ .../test_stk_setup_idle_mode_text.js | 6 ++++ .../tests/marionette/test_stk_setup_menu.js | 6 ++++ .../marionette/test_stk_timer_management.js | 6 ++++ 19 files changed, 138 insertions(+) diff --git a/dom/icc/tests/marionette/head.js b/dom/icc/tests/marionette/head.js index 1ce0ae009030..a28127f67467 100644 --- a/dom/icc/tests/marionette/head.js +++ b/dom/icc/tests/marionette/head.js @@ -287,6 +287,36 @@ function waitForTargetEvent(aEventTarget, aEventName, aMatchFun) { }); } +/** + * Wait for one named system message. + * + * Resolve if that named message is received. Never reject. + * + * Fulfill params: the message passed. + * + * @param aEventName + * A string message name. + * @param aMatchFun [optional] + * A matching function returns true or false to filter the message. If no + * matching function passed the promise is resolved after receiving the + * first message. + * + * @return A deferred promise. + */ +function waitForSystemMessage(aMessageName, aMatchFun) { + let target = workingFrame.contentWindow.navigator; + + return new Promise(function(aResolve, aReject) { + target.mozSetMessageHandler(aMessageName, function(aMessage) { + if (!aMatchFun || aMatchFun(aMessage)) { + target.mozSetMessageHandler(aMessageName, null); + ok(true, "System message '" + aMessageName + "' got."); + aResolve(aMessage); + } + }); + }); +} + /** * Set radio enabling state and wait for "radiostatechange" event. * diff --git a/dom/icc/tests/marionette/test_stk_bip_command.js b/dom/icc/tests/marionette/test_stk_bip_command.js index 91096943976f..6431936e8871 100644 --- a/dom/icc/tests/marionette/test_stk_bip_command.js +++ b/dom/icc/tests/marionette/test_stk_bip_command.js @@ -121,6 +121,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testBipCommand(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testBipCommand(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_display_text.js b/dom/icc/tests/marionette/test_stk_display_text.js index fd04702448ae..a65b300aa49a 100644 --- a/dom/icc/tests/marionette/test_stk_display_text.js +++ b/dom/icc/tests/marionette/test_stk_display_text.js @@ -230,6 +230,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testDisplayText(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testDisplayText(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_get_inkey.js b/dom/icc/tests/marionette/test_stk_get_inkey.js index 7c2008cf1542..881622106a18 100644 --- a/dom/icc/tests/marionette/test_stk_get_inkey.js +++ b/dom/icc/tests/marionette/test_stk_get_inkey.js @@ -145,6 +145,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testGetInKey(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testGetInKey(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_get_input.js b/dom/icc/tests/marionette/test_stk_get_input.js index 807f8232dd23..e0e23e22da60 100644 --- a/dom/icc/tests/marionette/test_stk_get_input.js +++ b/dom/icc/tests/marionette/test_stk_get_input.js @@ -186,6 +186,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testGetInput(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testGetInput(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_launch_browser.js b/dom/icc/tests/marionette/test_stk_launch_browser.js index a52b875a86ed..c47277a1a2f4 100644 --- a/dom/icc/tests/marionette/test_stk_launch_browser.js +++ b/dom/icc/tests/marionette/test_stk_launch_browser.js @@ -135,6 +135,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testLaunchBrowser(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testLaunchBrowser(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_local_info.js b/dom/icc/tests/marionette/test_stk_local_info.js index 89faf5974ffe..8c2a064b6bbc 100644 --- a/dom/icc/tests/marionette/test_stk_local_info.js +++ b/dom/icc/tests/marionette/test_stk_local_info.js @@ -53,6 +53,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testLocalInfo(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testLocalInfo(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_poll_off.js b/dom/icc/tests/marionette/test_stk_poll_off.js index b58a22eac201..83fab4b7a673 100644 --- a/dom/icc/tests/marionette/test_stk_poll_off.js +++ b/dom/icc/tests/marionette/test_stk_poll_off.js @@ -30,6 +30,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testPollOff(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testPollOff(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_refresh.js b/dom/icc/tests/marionette/test_stk_refresh.js index 37ba0692c91b..ed4ad42143fa 100644 --- a/dom/icc/tests/marionette/test_stk_refresh.js +++ b/dom/icc/tests/marionette/test_stk_refresh.js @@ -35,6 +35,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testRefresh(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testRefresh(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_select_item.js b/dom/icc/tests/marionette/test_stk_select_item.js index 6d348bc86547..c3236a54b459 100644 --- a/dom/icc/tests/marionette/test_stk_select_item.js +++ b/dom/icc/tests/marionette/test_stk_select_item.js @@ -331,6 +331,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSelectItem(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSelectItem(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_send_dtmf.js b/dom/icc/tests/marionette/test_stk_send_dtmf.js index 35fb99778a31..2cec5514223d 100644 --- a/dom/icc/tests/marionette/test_stk_send_dtmf.js +++ b/dom/icc/tests/marionette/test_stk_send_dtmf.js @@ -97,6 +97,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSendDTMF(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSendDTMF(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_send_sms.js b/dom/icc/tests/marionette/test_stk_send_sms.js index c684a76d7c10..25f069b3d645 100644 --- a/dom/icc/tests/marionette/test_stk_send_sms.js +++ b/dom/icc/tests/marionette/test_stk_send_sms.js @@ -191,6 +191,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSendSMS(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSendSMS(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_send_ss.js b/dom/icc/tests/marionette/test_stk_send_ss.js index 930ff11d5dd6..30c50cbbfc0b 100644 --- a/dom/icc/tests/marionette/test_stk_send_ss.js +++ b/dom/icc/tests/marionette/test_stk_send_ss.js @@ -119,6 +119,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSendSS(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSendSS(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_send_ussd.js b/dom/icc/tests/marionette/test_stk_send_ussd.js index 096e37611d16..a6934f137921 100644 --- a/dom/icc/tests/marionette/test_stk_send_ussd.js +++ b/dom/icc/tests/marionette/test_stk_send_ussd.js @@ -157,6 +157,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSendUSSD(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSendUSSD(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_setup_call.js b/dom/icc/tests/marionette/test_stk_setup_call.js index 555d8793985d..f43a5426cd6b 100644 --- a/dom/icc/tests/marionette/test_stk_setup_call.js +++ b/dom/icc/tests/marionette/test_stk_setup_call.js @@ -220,6 +220,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSetupCall(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSetupCall(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_setup_event_list.js b/dom/icc/tests/marionette/test_stk_setup_event_list.js index e3d90b94d06d..f3b6e83cb58f 100644 --- a/dom/icc/tests/marionette/test_stk_setup_event_list.js +++ b/dom/icc/tests/marionette/test_stk_setup_event_list.js @@ -68,6 +68,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSetupEventList(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSetupEventList(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_setup_idle_mode_text.js b/dom/icc/tests/marionette/test_stk_setup_idle_mode_text.js index cb2d131ac60a..51a4940e9152 100644 --- a/dom/icc/tests/marionette/test_stk_setup_idle_mode_text.js +++ b/dom/icc/tests/marionette/test_stk_setup_idle_mode_text.js @@ -99,6 +99,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSetupIdleModeText(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSetupIdleModeText(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_setup_menu.js b/dom/icc/tests/marionette/test_stk_setup_menu.js index 47b835c24f63..cb5dd9b6a579 100644 --- a/dom/icc/tests/marionette/test_stk_setup_menu.js +++ b/dom/icc/tests/marionette/test_stk_setup_menu.js @@ -296,6 +296,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testSetupMenu(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testSetupMenu(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command)); diff --git a/dom/icc/tests/marionette/test_stk_timer_management.js b/dom/icc/tests/marionette/test_stk_timer_management.js index 7d29a6c0e0a7..b5003e21cbe3 100644 --- a/dom/icc/tests/marionette/test_stk_timer_management.js +++ b/dom/icc/tests/marionette/test_stk_timer_management.js @@ -60,6 +60,12 @@ startTestCommon(function() { // Wait onstkcommand event. promises.push(waitForTargetEvent(icc, "stkcommand") .then((aEvent) => testTimerManagement(aEvent.command, data.expect))); + // Wait icc-stkcommand system message. + promises.push(waitForSystemMessage("icc-stkcommand") + .then((aMessage) => { + is(aMessage.iccId, icc.iccInfo.iccid, "iccId"); + testTimerManagement(aMessage.command, data.expect); + })); // Send emulator command to generate stk unsolicited event. promises.push(sendEmulatorStkPdu(data.command));