webapprt/test/chrome/browser_mozpay.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 Cu.import("resource://gre/modules/Services.jsm");
michael@0 2 let { PaymentManager } = Cu.import("resource://gre/modules/Payment.jsm", {});
michael@0 3 Cu.import("resource://webapprt/modules/WebappRT.jsm");
michael@0 4
michael@0 5 function test() {
michael@0 6 waitForExplicitFinish();
michael@0 7
michael@0 8 let curTest = 0;
michael@0 9
michael@0 10 let tests = [];
michael@0 11 tests.push({
michael@0 12 providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=",
michael@0 13 message: "Success."
michael@0 14 });
michael@0 15 tests.push({
michael@0 16 providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-failure.html?req=",
michael@0 17 message: "Chocolate rejected."
michael@0 18 });
michael@0 19
michael@0 20 let jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhdWQiOiAibW9j" +
michael@0 21 "a3BheXByb3ZpZGVyLnBocGZvZ2FwcC5jb20iLCAiaXNzIjogIkVudGVyI" +
michael@0 22 "HlvdSBhcHAga2V5IGhlcmUhIiwgInJlcXVlc3QiOiB7Im5hbWUiOiAiUG" +
michael@0 23 "llY2Ugb2YgQ2FrZSIsICJwcmljZSI6ICIxMC41MCIsICJwcmljZVRpZXI" +
michael@0 24 "iOiAxLCAicHJvZHVjdGRhdGEiOiAidHJhbnNhY3Rpb25faWQ9ODYiLCAi" +
michael@0 25 "Y3VycmVuY3lDb2RlIjogIlVTRCIsICJkZXNjcmlwdGlvbiI6ICJWaXJ0d" +
michael@0 26 "WFsIGNob2NvbGF0ZSBjYWtlIHRvIGZpbGwgeW91ciB2aXJ0dWFsIHR1bW" +
michael@0 27 "15In0sICJleHAiOiAxMzUyMjMyNzkyLCAiaWF0IjogMTM1MjIyOTE5Miw" +
michael@0 28 "gInR5cCI6ICJtb2NrL3BheW1lbnRzL2luYXBwL3YxIn0.QZxc62USCy4U" +
michael@0 29 "IyKIC1TKelVhNklvk-Ou1l_daKntaFI";
michael@0 30
michael@0 31 PaymentManager.registeredProviders = {};
michael@0 32 PaymentManager.registeredProviders["mock/payments/inapp/v1"] = {
michael@0 33 name: "mockprovider",
michael@0 34 description: "Mock Payment Provider",
michael@0 35 uri: tests[curTest].providerUri,
michael@0 36 requestMethod: "GET"
michael@0 37 };
michael@0 38
michael@0 39 let providerWindow;
michael@0 40
michael@0 41 let winObserver = function(win, topic) {
michael@0 42 if (topic == "domwindowopened") {
michael@0 43 win.addEventListener("load", function onLoadWindow() {
michael@0 44 win.removeEventListener("load", onLoadWindow, false);
michael@0 45
michael@0 46 if (win.document.getElementById("content").getAttribute("src") ==
michael@0 47 (tests[curTest].providerUri + jwt)) {
michael@0 48 ok(true, "Payment provider window shown.");
michael@0 49 providerWindow = win;
michael@0 50 }
michael@0 51 }, false);
michael@0 52 }
michael@0 53 }
michael@0 54
michael@0 55 Services.ww.registerNotification(winObserver);
michael@0 56
michael@0 57 let mutObserver = null;
michael@0 58
michael@0 59 function onLoad() {
michael@0 60 let msg = gAppBrowser.contentDocument.getElementById("msg");
michael@0 61 mutObserver = new MutationObserver(function(mutations) {
michael@0 62 is(msg.textContent, tests[curTest].message, "Got: " + tests[curTest].message);
michael@0 63
michael@0 64 if (!providerWindow) {
michael@0 65 ok(false, "Payment provider window shown.");
michael@0 66 } else {
michael@0 67 providerWindow.close();
michael@0 68 providerWindow = null;
michael@0 69 }
michael@0 70
michael@0 71 runNextTest();
michael@0 72 });
michael@0 73 mutObserver.observe(msg, { childList: true });
michael@0 74 }
michael@0 75
michael@0 76 loadWebapp("mozpay.webapp", undefined, onLoad);
michael@0 77
michael@0 78 function runNextTest() {
michael@0 79 providerWindow = null;
michael@0 80 if (mutObserver) {
michael@0 81 mutObserver.disconnect();
michael@0 82 }
michael@0 83
michael@0 84 curTest++;
michael@0 85
michael@0 86 if (curTest < tests.length) {
michael@0 87 PaymentManager.registeredProviders["mock/payments/inapp/v1"].uri = tests[curTest].providerUri;
michael@0 88
michael@0 89 gAppBrowser.addEventListener("load", function onLoadH() {
michael@0 90 gAppBrowser.removeEventListener("load", onLoadH, true);
michael@0 91 onLoad();
michael@0 92 }, true);
michael@0 93 gAppBrowser.reload();
michael@0 94 } else {
michael@0 95 finish();
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 registerCleanupFunction(function() {
michael@0 100 Services.ww.unregisterNotification(winObserver);
michael@0 101 mutObserver.disconnect();
michael@0 102 });
michael@0 103 }

mercurial