Bug 973024 - 1.a/3: share newUint8Worker. r=yoshi, a=test-only
authorVicamo Yang <vyang@mozilla.com>
Mon, 23 Jun 2014 20:56:02 +0800
changeset 208341 defd74bd5e9d97dfdb81be9bc06e234387a487cf
parent 208340 4e6018ad263903b6d931ec4c8ff6b2417a1a1548
child 208342 5201bb92000bd753d04b452dcf165ec7be242e2c
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoshi, test-only
bugs973024
milestone32.0a2
Bug 973024 - 1.a/3: share newUint8Worker. r=yoshi, a=test-only
dom/system/gonk/tests/header_helpers.js
dom/system/gonk/tests/test_ril_worker_barring_password.js
dom/system/gonk/tests/test_ril_worker_icc.js
dom/system/gonk/tests/test_ril_worker_ruim.js
dom/system/gonk/tests/test_ril_worker_stk.js
--- a/dom/system/gonk/tests/header_helpers.js
+++ b/dom/system/gonk/tests/header_helpers.js
@@ -74,16 +74,48 @@ function newWorker(custom_ns) {
 
   // Register at least one client.
   worker_ns.ContextPool.registerClient({ clientId: 0 });
 
   return worker_ns;
 }
 
 /**
+ * Create a buffered RIL worker.
+ *
+ * @return A worker object that stores sending octets in a internal buffer.
+ */
+function newUint8Worker() {
+  let worker = newWorker();
+  let index = 0; // index for read
+  let buf = [];
+
+  let context = worker.ContextPool._contexts[0];
+  context.Buf.writeUint8 = function(value) {
+    buf.push(value);
+  };
+
+  context.Buf.readUint8 = function() {
+    return buf[index++];
+  };
+
+  context.Buf.seekIncoming = function(offset) {
+    index += offset;
+  };
+
+  context.Buf.getReadAvailable = function() {
+    return buf.length - index;
+  };
+
+  worker.debug = do_print;
+
+  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_barring_password.js
+++ b/dom/system/gonk/tests/test_ril_worker_barring_password.js
@@ -5,42 +5,16 @@ subscriptLoader.loadSubScript("resource:
 
 function run_test() {
   run_next_test();
 }
 
 const PIN = "0000";
 const NEW_PIN = "1234";
 
-/**
- * Helper function.
- */
-function newUint8Worker() {
-  let worker = newWorker();
-  let context = worker.ContextPool._contexts[0];
-  let index = 0; // index for read
-  let buf = [];
-
-  context.Buf.writeUint8 = function(value) {
-    buf.push(value);
-  };
-
-  context.Buf.readUint8 = function() {
-    return buf[index++];
-  };
-
-  context.Buf.seekIncoming = function(offset) {
-    index += offset;
-  };
-
-  worker.debug = do_print;
-
-  return worker;
-}
-
 add_test(function test_change_call_barring_password() {
   let worker = newUint8Worker();
   let context = worker.ContextPool._contexts[0];
   let buf = context.Buf;
 
   function do_test(facility, pin, newPin) {
     buf.sendParcel = function fakeSendParcel () {
       // Request Type.
--- a/dom/system/gonk/tests/test_ril_worker_icc.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc.js
@@ -3,46 +3,16 @@
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
 /**
- * Helper function.
- */
-function newUint8Worker() {
-  let worker = newWorker();
-  let index = 0; // index for read
-  let buf = [];
-
-  let context = worker.ContextPool._contexts[0];
-  context.Buf.writeUint8 = function(value) {
-    buf.push(value);
-  };
-
-  context.Buf.readUint8 = function() {
-    return buf[index++];
-  };
-
-  context.Buf.seekIncoming = function(offset) {
-    index += offset;
-  };
-
-  context.Buf.getReadAvailable = function() {
-    return buf.length - index;
-  };
-
-  worker.debug = do_print;
-
-  return worker;
-}
-
-/**
  * Verify ICCPDUHelper#readICCUCS2String()
  */
 add_test(function test_read_icc_ucs2_string() {
   let worker = newUint8Worker();
   let context = worker.ContextPool._contexts[0];
   let helper = context.GsmPDUHelper;
   let iccHelper = context.ICCPDUHelper;
 
--- a/dom/system/gonk/tests/test_ril_worker_ruim.js
+++ b/dom/system/gonk/tests/test_ril_worker_ruim.js
@@ -3,42 +3,16 @@
 
 subscriptLoader.loadSubScript("resource://gre/modules/ril_consts.js", this);
 
 function run_test() {
   run_next_test();
 }
 
 /**
- * Helper function.
- */
-function newUint8Worker() {
-  let worker = newWorker();
-  let context = worker.ContextPool._contexts[0];
-  let index = 0; // index for read
-  let buf = [];
-
-  context.Buf.writeUint8 = function(value) {
-    buf.push(value);
-  };
-
-  context.Buf.readUint8 = function() {
-    return buf[index++];
-  };
-
-  context.Buf.seekIncoming = function(offset) {
-    index += offset;
-  };
-
-  worker.debug = do_print;
-
-  return worker;
-}
-
-/**
  * Verify RUIM Service.
  */
 add_test(function test_is_ruim_service_available() {
   let worker = newWorker();
   let context = worker.ContextPool._contexts[0];
   context.RIL._isCdma = true;
   context.RIL.appType = CARD_APPTYPE_RUIM;
 
--- a/dom/system/gonk/tests/test_ril_worker_stk.js
+++ b/dom/system/gonk/tests/test_ril_worker_stk.js
@@ -5,39 +5,16 @@ subscriptLoader.loadSubScript("resource:
 
 function run_test() {
   run_next_test();
 }
 
 /**
  * Helper function.
  */
-function newUint8Worker() {
-  let worker = newWorker();
-  let index = 0; // index for read
-  let buf = [];
-  let context = worker.ContextPool._contexts[0];
-
-  context.Buf.writeUint8 = function(value) {
-    buf.push(value);
-  };
-
-  context.Buf.readUint8 = function() {
-    return buf[index++];
-  };
-
-  context.Buf.seekIncoming = function(offset) {
-    index += offset;
-  };
-
-  worker.debug = do_print;
-
-  return worker;
-}
-
 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];
 
   context.Buf.writeUint8 = function(value) {
     if (context.Buf.outgoingIndex >= buf.length) {