webapprt/test/chrome/browser_mozpay.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial