Bug 926358 - Fix the potential issue in MMI request handler. r=allstars.chh
authorEdgar Chen <echen@mozilla.com>
Mon, 14 Oct 2013 18:47:55 +0800
changeset 164590 44a0355a4ead7966b6fa1dcd49e39427030e143c
parent 164589 f613b9c6f07dd1998b2943545ab823046acc5ccb
child 164591 c338eea00f79cbfbb2e87989f61b73ba061edd64
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars
bugs926358
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 926358 - Fix the potential issue in MMI request handler. r=allstars.chh
dom/network/tests/marionette/test_mobile_mmi.js
dom/system/gonk/RILContentHelper.js
--- a/dom/network/tests/marionette/test_mobile_mmi.js
+++ b/dom/network/tests/marionette/test_mobile_mmi.js
@@ -71,18 +71,37 @@ tasks.push(function testGettingIMEI() {
     ok(event.target.result instanceof Object, "result instanceof Object");
     is(event.target.result.statusMessage, "000000000000000", "Emulator IMEI");
     is(event.target.result.serviceCode, "scImei", "Service code IMEI");
     is(event.target.result.additionalInformation, undefined,
        "No additional information");
     tasks.next();
   }
   request.onerror = function onerror() {
-    ok(false, "request success");
+    ok(false, "request should not error");
     tasks.abort();
   };
 });
 
+tasks.push(function testInvalidMMICode(){
+  log("Test invalid MMI code ...");
+
+  let request = mobileConnection.sendMMI("InvalidMMICode");
+  ok(request instanceof DOMRequest,
+     "request is instanceof " + request.constructor);
+
+  request.onsuccess = function onsuccess(event) {
+    ok(false, "request should not success");
+    tasks.abort();
+  };
+
+  request.onerror = function onerror() {
+    ok(true, "request error");
+    is(request.error.name, "emMmiError", "MMI error name");
+    tasks.next();
+  };
+});
+
 // WARNING: All tasks should be pushed before this!!!
 tasks.push(function cleanUp() {
   SpecialPowers.removePermission("mobileconnection", document);
   finish();
 });
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -847,27 +847,27 @@ RILContentHelper.prototype = {
         lockType: lockType,
         requestId: requestId
       }
     });
     return request;
   },
 
   sendMMI: function sendMMI(window, mmi) {
-    // We need to save the global window to get the proper MMIError
-    // constructor once we get the reply from the parent process.
-    this._window = window;
-
     debug("Sending MMI " + mmi);
     if (!window) {
       throw Components.Exception("Can't get window object",
                                  Cr.NS_ERROR_UNEXPECTED);
     }
     let request = Services.DOMRequest.createRequest(window);
     let requestId = this.getRequestId(request);
+    // We need to save the global window to get the proper MMIError
+    // constructor once we get the reply from the parent process.
+    this._windowsMap[requestId] = window;
+
     cpmm.sendAsyncMessage("RIL:SendMMI", {
       clientId: 0,
       data: {
         mmi: mmi,
         requestId: requestId
       }
     });
     return request;
@@ -1829,16 +1829,18 @@ RILContentHelper.prototype = {
       return;
     }
     Services.DOMRequest.fireSuccess(request, null);
   },
 
   handleSendCancelMMI: function handleSendCancelMMI(message) {
     debug("handleSendCancelMMI " + JSON.stringify(message));
     let request = this.takeRequest(message.requestId);
+    let requestWindow = this._windowsMap[message.requestId];
+    delete this._windowsMap[message.requestId];
     if (!request) {
       return;
     }
 
     let success = message.success;
 
     // We expect to have an IMEI at this point if the request was supposed
     // to query for the IMEI, so getting a successful reply from the RIL
@@ -1863,20 +1865,20 @@ RILContentHelper.prototype = {
       additionalInformation: message.additionalInformation
     };
 
     if (success) {
       result.statusMessage = message.statusMessage;
       let mmiResult = new DOMMMIResult(result);
       Services.DOMRequest.fireSuccess(request, mmiResult);
     } else {
-      let mmiError = new this._window.DOMMMIError(result.serviceCode,
-                                                  message.errorMsg,
-                                                  null,
-                                                  result.additionalInformation);
+      let mmiError = new requestWindow.DOMMMIError(result.serviceCode,
+                                                   message.errorMsg,
+                                                   null,
+                                                   result.additionalInformation);
       Services.DOMRequest.fireDetailedError(request, mmiError);
     }
   },
 
   _deliverEvent: function _deliverEvent(listenerType, name, args) {
     let thisListeners = this[listenerType];
     if (!thisListeners) {
       return;