tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_chromeutils_getXPCOMErrorName.js (1337B)


      1 "use strict";
      2 
      3 // Test ChromeUtils.getXPCOMErrorName
      4 
      5 add_task(function test_getXPCOMErrorName() {
      6  info("Force the initialization of NSS to get the error names right");
      7  Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
      8 
      9  Assert.equal(
     10    ChromeUtils.getXPCOMErrorName(Cr.NS_OK),
     11    "NS_OK",
     12    "getXPCOMErrorName works for NS_OK"
     13  );
     14 
     15  Assert.equal(
     16    ChromeUtils.getXPCOMErrorName(Cr.NS_ERROR_FAILURE),
     17    "NS_ERROR_FAILURE",
     18    "getXPCOMErrorName works for NS_ERROR_FAILURE"
     19  );
     20 
     21  const nssErrors = Cc["@mozilla.org/nss_errors_service;1"].getService(
     22    Ci.nsINSSErrorsService
     23  );
     24  Assert.equal(
     25    ChromeUtils.getXPCOMErrorName(
     26      nssErrors.getXPCOMFromNSSError(Ci.nsINSSErrorsService.NSS_SEC_ERROR_BASE)
     27    ),
     28    "NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_SECURITY, SEC_ERROR_IO)",
     29    "getXPCOMErrorName works for NSS_SEC_ERROR_BASE"
     30  );
     31  // See https://searchfox.org/mozilla-central/rev/a48e21143960b383004afa9ff9411c5cf6d5a958/security/nss/lib/util/secerr.h#20
     32  const SEC_ERROR_BAD_DATA = Ci.nsINSSErrorsService.NSS_SEC_ERROR_BASE + 2;
     33  Assert.equal(
     34    ChromeUtils.getXPCOMErrorName(
     35      nssErrors.getXPCOMFromNSSError(SEC_ERROR_BAD_DATA)
     36    ),
     37    "NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_SECURITY, SEC_ERROR_BAD_DATA)",
     38    "getXPCOMErrorName works for NSS's SEC_ERROR_BAD_DATA"
     39  );
     40 });