michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: let { PaymentManager } = Cu.import("resource://gre/modules/Payment.jsm", {}); michael@0: Cu.import("resource://webapprt/modules/WebappRT.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let curTest = 0; michael@0: michael@0: let tests = []; michael@0: tests.push({ michael@0: providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=", michael@0: message: "Success." michael@0: }); michael@0: tests.push({ michael@0: providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-failure.html?req=", michael@0: message: "Chocolate rejected." michael@0: }); michael@0: michael@0: let jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhdWQiOiAibW9j" + michael@0: "a3BheXByb3ZpZGVyLnBocGZvZ2FwcC5jb20iLCAiaXNzIjogIkVudGVyI" + michael@0: "HlvdSBhcHAga2V5IGhlcmUhIiwgInJlcXVlc3QiOiB7Im5hbWUiOiAiUG" + michael@0: "llY2Ugb2YgQ2FrZSIsICJwcmljZSI6ICIxMC41MCIsICJwcmljZVRpZXI" + michael@0: "iOiAxLCAicHJvZHVjdGRhdGEiOiAidHJhbnNhY3Rpb25faWQ9ODYiLCAi" + michael@0: "Y3VycmVuY3lDb2RlIjogIlVTRCIsICJkZXNjcmlwdGlvbiI6ICJWaXJ0d" + michael@0: "WFsIGNob2NvbGF0ZSBjYWtlIHRvIGZpbGwgeW91ciB2aXJ0dWFsIHR1bW" + michael@0: "15In0sICJleHAiOiAxMzUyMjMyNzkyLCAiaWF0IjogMTM1MjIyOTE5Miw" + michael@0: "gInR5cCI6ICJtb2NrL3BheW1lbnRzL2luYXBwL3YxIn0.QZxc62USCy4U" + michael@0: "IyKIC1TKelVhNklvk-Ou1l_daKntaFI"; michael@0: michael@0: PaymentManager.registeredProviders = {}; michael@0: PaymentManager.registeredProviders["mock/payments/inapp/v1"] = { michael@0: name: "mockprovider", michael@0: description: "Mock Payment Provider", michael@0: uri: tests[curTest].providerUri, michael@0: requestMethod: "GET" michael@0: }; michael@0: michael@0: let providerWindow; michael@0: michael@0: let winObserver = function(win, topic) { michael@0: if (topic == "domwindowopened") { michael@0: win.addEventListener("load", function onLoadWindow() { michael@0: win.removeEventListener("load", onLoadWindow, false); michael@0: michael@0: if (win.document.getElementById("content").getAttribute("src") == michael@0: (tests[curTest].providerUri + jwt)) { michael@0: ok(true, "Payment provider window shown."); michael@0: providerWindow = win; michael@0: } michael@0: }, false); michael@0: } michael@0: } michael@0: michael@0: Services.ww.registerNotification(winObserver); michael@0: michael@0: let mutObserver = null; michael@0: michael@0: function onLoad() { michael@0: let msg = gAppBrowser.contentDocument.getElementById("msg"); michael@0: mutObserver = new MutationObserver(function(mutations) { michael@0: is(msg.textContent, tests[curTest].message, "Got: " + tests[curTest].message); michael@0: michael@0: if (!providerWindow) { michael@0: ok(false, "Payment provider window shown."); michael@0: } else { michael@0: providerWindow.close(); michael@0: providerWindow = null; michael@0: } michael@0: michael@0: runNextTest(); michael@0: }); michael@0: mutObserver.observe(msg, { childList: true }); michael@0: } michael@0: michael@0: loadWebapp("mozpay.webapp", undefined, onLoad); michael@0: michael@0: function runNextTest() { michael@0: providerWindow = null; michael@0: if (mutObserver) { michael@0: mutObserver.disconnect(); michael@0: } michael@0: michael@0: curTest++; michael@0: michael@0: if (curTest < tests.length) { michael@0: PaymentManager.registeredProviders["mock/payments/inapp/v1"].uri = tests[curTest].providerUri; michael@0: michael@0: gAppBrowser.addEventListener("load", function onLoadH() { michael@0: gAppBrowser.removeEventListener("load", onLoadH, true); michael@0: onLoad(); michael@0: }, true); michael@0: gAppBrowser.reload(); michael@0: } else { michael@0: finish(); michael@0: } michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.ww.unregisterNotification(winObserver); michael@0: mutObserver.disconnect(); michael@0: }); michael@0: }