head_helpers.js (1772B)
1 /* import-globals-from ../../../common/tests/unit/head_helpers.js */ 2 3 var { XPCOMUtils } = ChromeUtils.importESModule( 4 "resource://gre/modules/XPCOMUtils.sys.mjs" 5 ); 6 7 try { 8 // In the context of xpcshell tests, there won't be a default AppInfo 9 // eslint-disable-next-line mozilla/use-services 10 Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); 11 } catch (ex) { 12 // Make sure to provide the right OS so crypto loads the right binaries 13 var OS = "XPCShell"; 14 if (mozinfo.os == "win") { 15 OS = "WINNT"; 16 } else if (mozinfo.os == "mac") { 17 OS = "Darwin"; 18 } else { 19 OS = "Linux"; 20 } 21 22 const { updateAppInfo } = ChromeUtils.importESModule( 23 "resource://testing-common/AppInfo.sys.mjs" 24 ); 25 updateAppInfo({ 26 name: "XPCShell", 27 ID: "{3e3ba16c-1675-4e88-b9c8-afef81b3d2ef}", 28 version: "1", 29 platformVersion: "", 30 OS, 31 }); 32 } 33 34 function base64UrlDecode(s) { 35 s = s.replace(/-/g, "+"); 36 s = s.replace(/_/g, "/"); 37 38 // Replace padding if it was stripped by the sender. 39 // See http://tools.ietf.org/html/rfc4648#section-4 40 switch (s.length % 4) { 41 case 0: 42 break; // No pad chars in this case 43 case 2: 44 s += "=="; 45 break; // Two pad chars 46 case 3: 47 s += "="; 48 break; // One pad char 49 default: 50 throw new Error("Illegal base64url string!"); 51 } 52 53 // With correct padding restored, apply the standard base64 decoder 54 return atob(s); 55 } 56 57 /** 58 * Print some debug message to the console. All arguments will be printed, 59 * separated by spaces. 60 * 61 * @param [arg0, arg1, arg2, ...] 62 * Any number of arguments to print out 63 * Usage: _("Hello World") -> prints "Hello World" 64 * Usage: _(1, 2, 3) -> prints "1 2 3" 65 */ 66 var _ = function () { 67 print(Array.from(arguments).join(" ")); 68 };