Bug 938304 - navigator.mozPay(): callbacks do not pass through result (desktop fix). r=ferjm
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Mon, 17 Mar 2014 10:42:15 -0400
changeset 192132 9a2844261651c5d9e82234f5627a00dec3d7fa46
parent 192131 447791883dd4949bda1ea5b8d47ef1acfe3a95ba
child 192133 ec77797d0a47d48d85a11d90ebbb750e989ba860
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersferjm
bugs938304
milestone30.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 938304 - navigator.mozPay(): callbacks do not pass through result (desktop fix). r=ferjm
webapprt/PaymentUIGlue.js
webapprt/test/chrome/browser_mozpay.js
webapprt/test/chrome/mozpay-failure.html
webapprt/test/chrome/mozpay.html
webapprt/test/chrome/webapprt.ini
--- a/webapprt/PaymentUIGlue.js
+++ b/webapprt/PaymentUIGlue.js
@@ -9,30 +9,31 @@ const { interfaces: Ci, utils: Cu } = Co
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                   "@mozilla.org/childprocessmessagemanager;1",
                                   "nsIMessageSender");
 
 function paymentSuccess(aRequestId) {
-  return paymentCallback(aRequestId, "Payment:Success");
+  return function(aResult) {
+    closePaymentWindow(aRequestId, function() {
+      cpmm.sendAsyncMessage("Payment:Success", { requestId: aRequestId,
+                                                 result: aResult });
+    });
+  };
 }
 
 function paymentFailed(aRequestId) {
-  return paymentCallback(aRequestId, "Payment:Failed");
-}
-
-function paymentCallback(aRequestId, aMsg) {
-  return function(aResult) {
-          closePaymentWindow(aRequestId, function() {
-            cpmm.sendAsyncMessage(aMsg, { result: aResult,
-                                          requestId: aRequestId });
-          });
-        };
+  return function(aErrorMsg) {
+    closePaymentWindow(aRequestId, function() {
+      cpmm.sendAsyncMessage("Payment:Failed", { requestId: aRequestId,
+                                                errorMsg: aErrorMsg });
+    });
+  };
 }
 
 let payments = {};
 
 function closePaymentWindow(aId, aCallback) {
   if (payments[aId]) {
     payments[aId].handled = true;
     payments[aId].win.close();
--- a/webapprt/test/chrome/browser_mozpay.js
+++ b/webapprt/test/chrome/browser_mozpay.js
@@ -1,70 +1,103 @@
 Cu.import("resource://gre/modules/Services.jsm");
 let { PaymentManager } = Cu.import("resource://gre/modules/Payment.jsm", {});
+Cu.import("resource://webapprt/modules/WebappRT.jsm");
 
 function test() {
   waitForExplicitFinish();
 
-  let providerWindow = null;
-  let providerUri = "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=";
+  let curTest = 0;
+
+  let tests = [];
+  tests.push({
+    providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=",
+    message: "Success."
+  });
+  tests.push({
+    providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-failure.html?req=",
+    message: "Chocolate rejected."
+  });
+
   let jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhdWQiOiAibW9j" +
             "a3BheXByb3ZpZGVyLnBocGZvZ2FwcC5jb20iLCAiaXNzIjogIkVudGVyI" +
             "HlvdSBhcHAga2V5IGhlcmUhIiwgInJlcXVlc3QiOiB7Im5hbWUiOiAiUG" +
             "llY2Ugb2YgQ2FrZSIsICJwcmljZSI6ICIxMC41MCIsICJwcmljZVRpZXI" +
             "iOiAxLCAicHJvZHVjdGRhdGEiOiAidHJhbnNhY3Rpb25faWQ9ODYiLCAi" +
             "Y3VycmVuY3lDb2RlIjogIlVTRCIsICJkZXNjcmlwdGlvbiI6ICJWaXJ0d" +
             "WFsIGNob2NvbGF0ZSBjYWtlIHRvIGZpbGwgeW91ciB2aXJ0dWFsIHR1bW" +
             "15In0sICJleHAiOiAxMzUyMjMyNzkyLCAiaWF0IjogMTM1MjIyOTE5Miw" +
             "gInR5cCI6ICJtb2NrL3BheW1lbnRzL2luYXBwL3YxIn0.QZxc62USCy4U" +
             "IyKIC1TKelVhNklvk-Ou1l_daKntaFI";
 
   PaymentManager.registeredProviders = {};
   PaymentManager.registeredProviders["mock/payments/inapp/v1"] = {
     name: "mockprovider",
     description: "Mock Payment Provider",
-    uri: providerUri,
+    uri: tests[curTest].providerUri,
     requestMethod: "GET"
   };
 
+  let providerWindow;
+
   let winObserver = function(win, topic) {
     if (topic == "domwindowopened") {
       win.addEventListener("load", function onLoadWindow() {
         win.removeEventListener("load", onLoadWindow, false);
 
         if (win.document.getElementById("content").getAttribute("src") ==
-            (providerUri + jwt)) {
+            (tests[curTest].providerUri + jwt)) {
           ok(true, "Payment provider window shown.");
           providerWindow = win;
         }
       }, false);
     }
   }
 
   Services.ww.registerNotification(winObserver);
 
   let mutObserver = null;
 
-  loadWebapp("mozpay.webapp", undefined, function onLoad() {
+  function onLoad() {
     let msg = gAppBrowser.contentDocument.getElementById("msg");
     mutObserver = new MutationObserver(function(mutations) {
-      if (msg.textContent == "Success.") {
-        ok(true, "Payment success.");
-      } else {
-        ok(false, "Payment success.");
-      }
+      is(msg.textContent, tests[curTest].message, "Got: " + tests[curTest].message);
 
-      if (providerWindow == null) {
+      if (!providerWindow) {
         ok(false, "Payment provider window shown.");
       } else {
         providerWindow.close();
+        providerWindow = null;
       }
 
-      finish();
+      runNextTest();
     });
     mutObserver.observe(msg, { childList: true });
-  });
+  }
+
+  loadWebapp("mozpay.webapp", undefined, onLoad);
+
+  function runNextTest() {
+    providerWindow = null;
+    if (mutObserver) {
+      mutObserver.disconnect();
+    }
+
+    curTest++;
+
+    if (curTest < tests.length) {
+      PaymentManager.registeredProviders["mock/payments/inapp/v1"].uri = tests[curTest].providerUri;
+
+      gAppBrowser.addEventListener("load", function onLoadH() {
+        gAppBrowser.removeEventListener("load", onLoadH, true);
+        onLoad();
+      }, true);
+      gAppBrowser.reload();
+    } else {
+      finish();
+    }
+  }
 
   registerCleanupFunction(function() {
     Services.ww.unregisterNotification(winObserver);
     mutObserver.disconnect();
   });
 }
copy from webapprt/test/chrome/mozpay-success.html
copy to webapprt/test/chrome/mozpay-failure.html
--- a/webapprt/test/chrome/mozpay-success.html
+++ b/webapprt/test/chrome/mozpay-failure.html
@@ -1,12 +1,12 @@
 <!DOCTYPE HTML>
 <html>
   <head>
     <meta charset="utf-8">
   </head>
   <body>
     <script>
-    mozPaymentProvider.paymentSuccess();
+    mozPaymentProvider.paymentFailed('Chocolate rejected.');
     </script>
     <p id="msg">Webapp waiting to pay...</p>
   </body>
 </html>
--- a/webapprt/test/chrome/mozpay.html
+++ b/webapprt/test/chrome/mozpay.html
@@ -32,14 +32,14 @@
               "gInR5cCI6ICJtb2NrL3BheW1lbnRzL2luYXBwL3YxIn0.QZxc62USCy4U" +
               "IyKIC1TKelVhNklvk-Ou1l_daKntaFI";
 
     var request = navigator.mozPay(jwt);
     request.onsuccess = function onsuccess() {
       document.getElementById("msg").textContent = "Success.";
     };
     request.onerror = function onerror() {
-      document.getElementById("msg").textContent = "Failure.";
+      document.getElementById("msg").textContent = request.error.name;
     };
     </script>
     <p id="msg">Webapp waiting to be paid...</p>
   </body>
 </html>
--- a/webapprt/test/chrome/webapprt.ini
+++ b/webapprt/test/chrome/webapprt.ini
@@ -21,16 +21,17 @@ support-files =
   geolocation-prompt-noperm.html
   debugger.webapp
   debugger.webapp^headers^
   debugger.html
   mozpay.webapp
   mozpay.webapp^headers^
   mozpay.html
   mozpay-success.html
+  mozpay-failure.html
   getUserMedia.webapp
   getUserMedia.webapp^headers^
   getUserMedia.html
   window-open-self.webapp
   window-open-self.webapp^headers^
   window-open-self.html
   window-open.webapp
   window-open.webapp^headers^