Bug 973024 - 1.b/3: share newInterceptWorker. r=yoshi, a=test-only
authorVicamo Yang <vyang@mozilla.com>
Mon, 23 Jun 2014 20:56:03 +0800
changeset 207258 5201bb92000bd753d04b452dcf165ec7be242e2c
parent 207257 defd74bd5e9d97dfdb81be9bc06e234387a487cf
child 207259 1299f18f51afaf496cb22ba826f78060e5495f38
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoshi, test-only
bugs973024
milestone32.0a2
Bug 973024 - 1.b/3: share newInterceptWorker. r=yoshi, a=test-only
dom/system/gonk/tests/header_helpers.js
dom/system/gonk/tests/test_ril_worker_cf.js
dom/system/gonk/tests/test_ril_worker_clip.js
dom/system/gonk/tests/test_ril_worker_clir.js
dom/system/gonk/tests/test_ril_worker_cw.js
dom/system/gonk/tests/test_ril_worker_ecm.js
dom/system/gonk/tests/test_ril_worker_mmi.js
dom/system/gonk/tests/test_ril_worker_sms_cdma.js
dom/system/gonk/tests/test_ril_worker_ssn.js
dom/system/gonk/tests/test_ril_worker_voiceprivacy.js
--- a/dom/system/gonk/tests/header_helpers.js
+++ b/dom/system/gonk/tests/header_helpers.js
@@ -106,16 +106,38 @@ function newUint8Worker() {
   };
 
   worker.debug = do_print;
 
   return worker;
 }
 
 /**
+ * Create a worker that keeps posted chrome message.
+ */
+function newInterceptWorker() {
+  let postedMessage;
+  let worker = newWorker({
+    postRILMessage: function(data) {
+    },
+    postMessage: function(message) {
+      postedMessage = message;
+    }
+  });
+  return {
+    get postedMessage() {
+      return postedMessage;
+    },
+    get worker() {
+      return worker;
+    }
+  };
+}
+
+/**
  * Create a parcel suitable for postRILMessage().
  *
  * @param fakeParcelSize
  *        Value to be written to parcel size field for testing
  *        incorrect/incomplete parcel reading. Replaced with correct
  *        one determined length of data if negative.
  * @param response
  *        Response code of the incoming parcel.
--- a/dom/system/gonk/tests/test_ril_worker_cf.js
+++ b/dom/system/gonk/tests/test_ril_worker_cf.js
@@ -47,37 +47,18 @@ add_test(function test_toaFromString_unk
 add_test(function test_toaFromString_international() {
   let retval = toaFromString("+34666222333");
 
   do_check_eq(retval, TOA_INTERNATIONAL);
 
   run_next_test();
 });
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_setCallForward_unconditional() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallForward = function fakeSetCallForward(options) {
     context.RIL[REQUEST_SET_CALL_FORWARD](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -94,17 +75,17 @@ add_test(function test_setCallForward_un
 
   do_check_eq(postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_queryCallForwardStatus_unconditional() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallForward = function fakeSetCallForward(options) {
     context.RIL[REQUEST_SET_CALL_FORWARD](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
--- a/dom/system/gonk/tests/test_ril_worker_clip.js
+++ b/dom/system/gonk/tests/test_ril_worker_clip.js
@@ -2,37 +2,18 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_queryCLIP_provisioned() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.queryCLIP = function fakeQueryCLIP(options) {
@@ -51,17 +32,17 @@ add_test(function test_queryCLIP_provisi
 
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.success);
   do_check_eq(postedMessage.provisioned, 1);
   run_next_test();
 });
 
 add_test(function test_getCLIP_error_generic_failure_invalid_length() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.queryCLIP = function fakeQueryCLIP(options) {
--- a/dom/system/gonk/tests/test_ril_worker_clir.js
+++ b/dom/system/gonk/tests/test_ril_worker_clir.js
@@ -11,37 +11,18 @@ const CLIR_DEFAULT     = 0;
 const CLIR_INVOCATION  = 1;
 // Allows CLI presentation.
 const CLIR_SUPPRESSION = 2;
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_setCLIR_success() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCLIR = function fakeSetCLIR(options) {
     context.RIL[REQUEST_SET_CLIR](0, {
       rilMessageType: "setCLIR",
       rilRequestError: ERROR_SUCCESS
     });
@@ -55,17 +36,17 @@ add_test(function test_setCLIR_success()
 
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_setCLIR_generic_failure() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCLIR = function fakeSetCLIR(options) {
     context.RIL[REQUEST_SET_CLIR](0, {
       rilMessageType: "setCLIR",
       rilRequestError: ERROR_GENERIC_FAILURE
     });
@@ -79,17 +60,17 @@ add_test(function test_setCLIR_generic_f
 
   do_check_eq(postedMessage.errorMsg, "GenericFailure");
   do_check_false(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_getCLIR_n0_m1() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.getCLIR = function fakeGetCLIR(options) {
@@ -112,17 +93,17 @@ add_test(function test_getCLIR_n0_m1() {
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.success);
   do_check_eq(postedMessage.n, 0);
   do_check_eq(postedMessage.m, 1);
   run_next_test();
 });
 
 add_test(function test_getCLIR_error_generic_failure_invalid_length() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.getCLIR = function fakeGetCLIR(options) {
--- a/dom/system/gonk/tests/test_ril_worker_cw.js
+++ b/dom/system/gonk/tests/test_ril_worker_cw.js
@@ -2,37 +2,18 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_setCallWaiting_success() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
     context.RIL[REQUEST_SET_CALL_WAITING](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -45,17 +26,17 @@ add_test(function test_setCallWaiting_su
 
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_setCallWaiting_generic_failure() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
     context.RIL[REQUEST_SET_CALL_WAITING](0, {
       rilRequestError: ERROR_GENERIC_FAILURE
     });
   };
@@ -68,17 +49,17 @@ add_test(function test_setCallWaiting_ge
 
   do_check_eq(postedMessage.errorMsg, "GenericFailure");
   do_check_false(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_queryCallWaiting_success_enabled_true() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
@@ -99,17 +80,17 @@ add_test(function test_queryCallWaiting_
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.success);
   do_check_eq(postedMessage.length, 1);
   do_check_true(postedMessage.enabled);
   run_next_test();
 });
 
 add_test(function test_queryCallWaiting_success_enabled_false() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
--- a/dom/system/gonk/tests/test_ril_worker_ecm.js
+++ b/dom/system/gonk/tests/test_ril_worker_ecm.js
@@ -2,35 +2,16 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 var timeoutCallback = null;
 var timeoutDelayMs = 0;
 const TIMER_ID = 1234;
 const TIMEOUT_VALUE = 300000;  // 5 mins.
 
 // No window in xpcshell-test. Create our own timer mechanism.
 
 function setTimeout(callback, timeoutMs) {
@@ -49,17 +30,17 @@ function fireTimeout() {
   do_check_neq(timeoutCallback, null);
   if (timeoutCallback) {
     timeoutCallback();
     timeoutCallback = null;
   }
 }
 
 add_test(function test_enter_emergencyCbMode() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   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) {
     context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
     let postedMessage = workerHelper.postedMessage;
 
@@ -74,17 +55,17 @@ add_test(function test_enter_emergencyCb
     // Should start timer.
     do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
   }
 
   run_next_test();
 });
 
 add_test(function test_exit_emergencyCbMode() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
   context.RIL[UNSOLICITED_EXIT_EMERGENCY_CALLBACK_MODE]();
   let postedMessage = workerHelper.postedMessage;
 
   // Should store the mode.
@@ -96,17 +77,17 @@ add_test(function test_exit_emergencyCbM
 
   // Should clear timer.
   do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, null);
 
   run_next_test();
 });
 
 add_test(function test_request_exit_emergencyCbMode_when_timeout() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
   do_check_eq(context.RIL._isInEmergencyCbMode, true);
   do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
 
   let parcelTypes = [];
@@ -122,17 +103,17 @@ add_test(function test_request_exit_emer
 
   // Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE.
   do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1);
 
   run_next_test();
 });
 
 add_test(function test_request_exit_emergencyCbMode_when_dial() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
   do_check_eq(context.RIL._isInEmergencyCbMode, true);
   do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
 
   let parcelTypes = [];
@@ -149,17 +130,17 @@ add_test(function test_request_exit_emer
 
   // Check indeed sent out REQUEST_EXIT_EMERGENCY_CALLBACK_MODE.
   do_check_neq(parcelTypes.indexOf(REQUEST_EXIT_EMERGENCY_CALLBACK_MODE), -1);
 
   run_next_test();
 });
 
 add_test(function test_request_exit_emergencyCbMode_explicitly() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL[UNSOLICITED_ENTER_EMERGENCY_CALLBACK_MODE]();
   do_check_eq(context.RIL._isInEmergencyCbMode, true);
   do_check_eq(context.RIL._exitEmergencyCbModeTimeoutID, TIMER_ID);
 
   let parcelTypes = [];
--- a/dom/system/gonk/tests/test_ril_worker_mmi.js
+++ b/dom/system/gonk/tests/test_ril_worker_mmi.js
@@ -15,38 +15,18 @@ function parseMMI(mmi) {
     postMessage: function(message) {
       // Do nothing
     }
   });
   let context = worker.ContextPool._contexts[0];
   return context.RIL._parseMMI(mmi);
 }
 
-function getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    },
-  });
-
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 function testSendMMI(mmi, error) {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   do_print("worker.postMessage " + worker.postMessage);
 
   context.RIL.radioState = GECKO_RADIOSTATE_READY;
   context.RIL.sendMMI({rilMessageType: "sendMMI", mmi: mmi});
 
@@ -366,17 +346,17 @@ add_test(function test_sendMMI_undefined
 
 add_test(function test_sendMMI_invalid() {
   testSendMMI("11", MMI_ERROR_KS_ERROR);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_short_code() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   let ussdOptions;
 
   context.RIL.sendUSSD = function fakeSendUSSD(options){
     ussdOptions = options;
     context.RIL[REQUEST_SEND_USSD](0, {
@@ -399,17 +379,17 @@ add_test(function test_sendMMI_short_cod
 
 add_test(function test_sendMMI_dial_string() {
   testSendMMI("123", MMI_ERROR_KS_ERROR);
 
   run_next_test();
 });
 
 function setCallForwardSuccess(mmi) {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallForward = function fakeSetCallForward(options) {
     context.RIL[REQUEST_SET_CALL_FORWARD](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -431,17 +411,17 @@ add_test(function test_sendMMI_call_forw
 
 add_test(function test_sendMMI_call_forwarding_deactivation() {
   setCallForwardSuccess("#21*12345*99*10#");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_forwarding_interrogation() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.Buf.readString = function fakeReadString() {
@@ -473,17 +453,17 @@ add_test(function test_sendMMI_call_forw
   do_check_eq(postedMessage.rules.length, 1);
   do_check_true(postedMessage.rules[0].active);
   do_check_eq(postedMessage.rules[0].reason, CALL_FORWARD_REASON_UNCONDITIONAL);
   do_check_eq(postedMessage.rules[0].number, "+34666222333");
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_forwarding_interrogation_no_rules() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return 0;
   };
 
   context.RIL.queryCallForwardStatus = function fakeQueryCallForward(options) {
@@ -542,17 +522,17 @@ add_test(function test_sendMMI_call_forw
 
 add_test(function test_sendMMI_call_forwarding_CFAllConditional() {
   setCallForwardSuccess("*002*12345*99*10#");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.changeICCPIN = function fakeChangeICCPIN(options) {
     context.RIL[REQUEST_ENTER_SIM_PIN](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -588,17 +568,17 @@ add_test(function test_sendMMI_change_PI
 
 add_test(function test_sendMMI_change_PIN_new_PIN_mismatch() {
   testSendMMI("**04*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_change_PIN2() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.changeICCPIN2 = function fakeChangeICCPIN2(options){
     context.RIL[REQUEST_ENTER_SIM_PIN2](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -634,17 +614,17 @@ add_test(function test_sendMMI_change_PI
 
 add_test(function test_sendMMI_change_PIN2_new_PIN2_mismatch() {
   testSendMMI("**042*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.enterICCPUK = function fakeEnterICCPUK(options){
     context.RIL[REQUEST_ENTER_SIM_PUK](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -680,17 +660,17 @@ add_test(function test_sendMMI_unblock_P
 
 add_test(function test_sendMMI_unblock_PIN_new_PIN_mismatch() {
   testSendMMI("**05*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_unblock_PIN2() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.enterICCPUK2 = function fakeEnterICCPUK2(options){
     context.RIL[REQUEST_ENTER_SIM_PUK2](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -726,17 +706,17 @@ add_test(function test_sendMMI_unblock_P
 
 add_test(function test_sendMMI_unblock_PIN2_new_PIN_mismatch() {
   testSendMMI("**052*4567*1234*4567#", MMI_ERROR_KS_MISMATCH_PIN);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_get_IMEI() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let mmiOptions;
 
   context.RIL.getIMEI = function getIMEI(options){
     mmiOptions = options;
     context.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_SUCCESS,
@@ -750,17 +730,17 @@ add_test(function test_sendMMI_get_IMEI(
   do_check_neq(mmiOptions.mmi, null);
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_get_IMEI_error() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let mmiOptions;
 
   context.RIL.getIMEI = function getIMEI(options){
     mmiOptions = options;
     context.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_RADIO_NOT_AVAILABLE,
@@ -774,17 +754,17 @@ add_test(function test_sendMMI_get_IMEI_
   do_check_neq(mmiOptions.mmi, null);
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_RADIO_NOT_AVAILABLE);
   do_check_false(postedMessage.success);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_barring_BAIC_interrogation_voice() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32List = function fakeReadUint32List() {
     return [1];
   };
 
   context.RIL.queryICCFacilityLock =
@@ -805,17 +785,17 @@ add_test(function test_sendMMI_call_barr
   do_check_eq(postedMessage.statusMessage,  MMI_SM_KS_SERVICE_ENABLED_FOR);
   do_check_true(Array.isArray(postedMessage.additionalInformation));
   do_check_eq(postedMessage.additionalInformation[0], "serviceClassVoice");
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_barring_BAIC_activation() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let mmiOptions;
 
   context.RIL.setICCFacilityLock =
     function fakeSetICCFacilityLock(options){
       mmiOptions = options;
       context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
@@ -833,17 +813,17 @@ add_test(function test_sendMMI_call_barr
   do_check_eq(mmiOptions.procedure, MMI_PROCEDURE_ACTIVATION);
   do_check_true(postedMessage.success);
   do_check_eq(postedMessage.statusMessage,  MMI_SM_KS_SERVICE_ENABLED);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_barring_BAIC_deactivation() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let mmiOptions;
 
   context.RIL.setICCFacilityLock =
     function fakeSetICCFacilityLock(options){
       mmiOptions = options;
       context.RIL[REQUEST_SET_FACILITY_LOCK](0, {
@@ -867,17 +847,17 @@ add_test(function test_sendMMI_call_barr
 
 add_test(function test_sendMMI_call_barring_BAIC_procedure_not_supported() {
   testSendMMI("**33*0000#", MMI_ERROR_KS_NOT_SUPPORTED);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_USSD() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let ussdOptions;
 
   context.RIL.sendUSSD = function fakeSendUSSD(options){
     ussdOptions = options;
     context.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_SUCCESS
@@ -893,17 +873,17 @@ add_test(function test_sendMMI_USSD() {
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_SUCCESS);
   do_check_true(postedMessage.success);
   do_check_true(context.RIL._ussdSession);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_USSD_error() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
   let ussdOptions;
 
   context.RIL.sendUSSD = function fakeSendUSSD(options){
     ussdOptions = options;
     context.RIL[REQUEST_SEND_USSD](0, {
       rilRequestError: ERROR_GENERIC_FAILURE
@@ -919,17 +899,17 @@ add_test(function test_sendMMI_USSD_erro
   do_check_eq (postedMessage.errorMsg, GECKO_ERROR_GENERIC_FAILURE);
   do_check_false(postedMessage.success);
   do_check_false(context.RIL._ussdSession);
 
   run_next_test();
 });
 
 function setCallWaitingSuccess(mmi) {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setCallWaiting = function fakeSetCallWaiting(options) {
     context.RIL[REQUEST_SET_CALL_WAITING](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -963,17 +943,17 @@ add_test(function test_sendMMI_call_wait
 
 add_test(function test_sendMMI_call_waiting_erasure() {
   testSendMMI("##43#", MMI_ERROR_KS_NOT_SUPPORTED);
 
   run_next_test();
 });
 
 add_test(function test_sendMMI_call_waiting_interrogation() {
-  let workerhelper = getWorker();
+  let workerhelper = newInterceptWorker();
   let worker = workerhelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32 = function fakeReadUint32() {
     return context.Buf.int32Array.pop();
   };
 
   context.RIL.queryCallWaiting = function fakeQueryCallWaiting(options) {
--- a/dom/system/gonk/tests/test_ril_worker_sms_cdma.js
+++ b/dom/system/gonk/tests/test_ril_worker_sms_cdma.js
@@ -2,35 +2,16 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 /*
  * Helper function to covert a HEX string to a byte array.
  *
  * @param hexString
  *        A hexadecimal string of which the length is even.
  */
 function hexStringToBytes(hexString) {
   let bytes = [];
@@ -183,17 +164,17 @@ function pduToParcelData(cdmaPduHelper, 
 
   return data;
 }
 
 /**
  * Verify CDMA SMS Delivery ACK Message.
  */
 add_test(function test_processCdmaSmsStatusReport() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   function test_StatusReport(errorClass, msgStatus) {
     let msgId = 0;
     let sentSmsMap = context.RIL._pendingSentSmsMap;
 
     sentSmsMap[msgId] = {};
@@ -257,17 +238,17 @@ add_test(function test_processCdmaSmsSta
 
   run_next_test();
 });
 
 /**
  * Verify WAP Push over CDMA SMS Message.
  */
 add_test(function test_processCdmaSmsWapPush() {
-  let workerHelper = _getWorker(),
+  let workerHelper = newInterceptWorker(),
       worker = workerHelper.worker,
       context = worker.ContextPool._contexts[0],
       bitBufferHelper = context.BitBufferHelper,
       cdmaPduHelper = context.CdmaPDUHelper;
 
   function test_CdmaSmsWapPdu(wdpData, reversed) {
     let orig_address = "0987654321",
         hexString,
--- a/dom/system/gonk/tests/test_ril_worker_ssn.js
+++ b/dom/system/gonk/tests/test_ril_worker_ssn.js
@@ -2,37 +2,18 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_notification() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   function Call(callIndex, number) {
     this.callIndex = callIndex;
     this.number = number;
   }
 
--- a/dom/system/gonk/tests/test_ril_worker_voiceprivacy.js
+++ b/dom/system/gonk/tests/test_ril_worker_voiceprivacy.js
@@ -2,37 +2,18 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
-function _getWorker() {
-  let _postedMessage;
-  let _worker = newWorker({
-    postRILMessage: function(data) {
-    },
-    postMessage: function(message) {
-      _postedMessage = message;
-    }
-  });
-  return {
-    get postedMessage() {
-      return _postedMessage;
-    },
-    get worker() {
-      return _worker;
-    }
-  };
-}
-
 add_test(function test_setVoicePrivacyMode_success() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
     context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
       rilRequestError: ERROR_SUCCESS
     });
   };
@@ -44,17 +25,17 @@ add_test(function test_setVoicePrivacyMo
   let postedMessage = workerHelper.postedMessage;
 
   do_check_eq(postedMessage.errorMsg, undefined);
 
   run_next_test();
 });
 
 add_test(function test_setVoicePrivacyMode_generic_failure() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.RIL.setVoicePrivacyMode = function fakeSetVoicePrivacyMode(options) {
     context.RIL[REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE](0, {
       rilRequestError: ERROR_GENERIC_FAILURE
     });
   };
@@ -66,17 +47,17 @@ add_test(function test_setVoicePrivacyMo
   let postedMessage = workerHelper.postedMessage;
 
   do_check_eq(postedMessage.errorMsg, "GenericFailure");
 
   run_next_test();
 });
 
 add_test(function test_queryVoicePrivacyMode_success_enabled_true() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32List = function fakeReadUint32List() {
     return [1];
   };
 
   context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {
@@ -90,17 +71,17 @@ add_test(function test_queryVoicePrivacy
   let postedMessage = workerHelper.postedMessage;
 
   do_check_eq(postedMessage.errorMsg, undefined);
   do_check_true(postedMessage.enabled);
   run_next_test();
 });
 
 add_test(function test_queryVoicePrivacyMode_success_enabled_false() {
-  let workerHelper = _getWorker();
+  let workerHelper = newInterceptWorker();
   let worker = workerHelper.worker;
   let context = worker.ContextPool._contexts[0];
 
   context.Buf.readInt32List = function fakeReadUint32List() {
     return [0];
   };
 
   context.RIL.queryVoicePrivacyMode = function fakeQueryVoicePrivacyMode(options) {