Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | let Cc = Components.classes; |
michael@0 | 7 | let Ci = Components.interfaces; |
michael@0 | 8 | let Cu = Components.utils; |
michael@0 | 9 | |
michael@0 | 10 | Components.utils.import("resource://gre/modules/SharedPreferences.jsm"); |
michael@0 | 11 | Components.utils.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageListenerManager); |
michael@0 | 14 | let deferred = 0; |
michael@0 | 15 | let shouldPass = true; |
michael@0 | 16 | let reqId = 0; |
michael@0 | 17 | function getRequestId(increment) { |
michael@0 | 18 | reqId += increment; |
michael@0 | 19 | return "Request" + reqId; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | let paymentSuccess = { |
michael@0 | 23 | receiveMessage: function(aMsg) { |
michael@0 | 24 | let msg = aMsg.json; |
michael@0 | 25 | if (shouldPass) { |
michael@0 | 26 | do_check_eq(msg.requestId, getRequestId(0)); |
michael@0 | 27 | } else { |
michael@0 | 28 | do_throw("Test should not have passed"); |
michael@0 | 29 | } |
michael@0 | 30 | deferred.resolve(); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | let paymentFailed = { |
michael@0 | 35 | receiveMessage: function(aMsg) { |
michael@0 | 36 | let msg = aMsg.json; |
michael@0 | 37 | if (shouldPass) { |
michael@0 | 38 | do_throw("Test should not have failed: " + msg.errorMsg); |
michael@0 | 39 | } else { |
michael@0 | 40 | do_check_eq(msg.requestId, getRequestId(0)); |
michael@0 | 41 | do_check_eq(msg.errorMsg, "FAILED CORRECTLY"); |
michael@0 | 42 | } |
michael@0 | 43 | deferred.resolve(); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | add_task(function test_get_set() { |
michael@0 | 48 | let ui = Cc["@mozilla.org/payment/ui-glue;1"].getService(Ci.nsIPaymentUIGlue); |
michael@0 | 49 | deferred = Promise.defer(); |
michael@0 | 50 | let id = getRequestId(1); |
michael@0 | 51 | ui.confirmPaymentRequest(id, |
michael@0 | 52 | [{ wrappedJSObject: { type: "Fake Provider" } }], |
michael@0 | 53 | function(aRequestId, type) { |
michael@0 | 54 | do_check_eq(type, "Fake Provider"); |
michael@0 | 55 | deferred.resolve(); |
michael@0 | 56 | }, |
michael@0 | 57 | function(id, msg) { |
michael@0 | 58 | do_throw("confirmPaymentRequest should not have failed"); |
michael@0 | 59 | deferred.resolve(); |
michael@0 | 60 | }); |
michael@0 | 61 | yield deferred.promise; |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | add_task(function test_default() { |
michael@0 | 65 | ppmm.addMessageListener("Payment:Success", paymentSuccess); |
michael@0 | 66 | ppmm.addMessageListener("Payment:Failed", paymentFailed); |
michael@0 | 67 | |
michael@0 | 68 | let ui = Cc["@mozilla.org/payment/ui-glue;1"].getService(Ci.nsIPaymentUIGlue); |
michael@0 | 69 | deferred = Promise.defer(); |
michael@0 | 70 | let id = getRequestId(1); |
michael@0 | 71 | shouldPass = true; |
michael@0 | 72 | ui.showPaymentFlow(id, |
michael@0 | 73 | { |
michael@0 | 74 | uri: "chrome://roboextender/content/paymentsUI.html", |
michael@0 | 75 | jwt: "#pass" |
michael@0 | 76 | }, |
michael@0 | 77 | function(id, msg) { |
michael@0 | 78 | do_throw("confirmPaymentRequest should not have failed"); |
michael@0 | 79 | deferred.resolve(); |
michael@0 | 80 | }); |
michael@0 | 81 | yield deferred.promise; |
michael@0 | 82 | |
michael@0 | 83 | deferred = Promise.defer(); |
michael@0 | 84 | let id = getRequestId(1); |
michael@0 | 85 | shouldPass = false; |
michael@0 | 86 | ui.showPaymentFlow(id, |
michael@0 | 87 | { |
michael@0 | 88 | uri: "chrome://roboextender/content/paymentsUI.html", |
michael@0 | 89 | jwt: "#fail" |
michael@0 | 90 | }, |
michael@0 | 91 | function(id, msg) { |
michael@0 | 92 | do_throw("confirmPaymentRequest should not have failed"); |
michael@0 | 93 | deferred.resolve(); |
michael@0 | 94 | }); |
michael@0 | 95 | |
michael@0 | 96 | yield deferred.promise; |
michael@0 | 97 | |
michael@0 | 98 | ppmm.removeMessageListener("Payment:Success", paymentSuccess); |
michael@0 | 99 | ppmm.removeMessageListener("Payment:Failed", paymentFailed); |
michael@0 | 100 | }); |
michael@0 | 101 | |
michael@0 | 102 | run_next_test(); |