tor-browser

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

test_generateQI.js (999B)


      1 "use strict";
      2 
      3 add_task(async function test_generateQI() {
      4  function checkQI(interfaces, iface) {
      5    let obj = {
      6      QueryInterface: ChromeUtils.generateQI(interfaces),
      7    };
      8    equal(obj.QueryInterface(iface), obj,
      9         `Correct return value for query to ${iface}`);
     10  }
     11 
     12  // Test success scenarios.
     13  checkQI([], Ci.nsISupports);
     14 
     15  checkQI([Ci.nsIPropertyBag, "nsIPropertyBag2"], Ci.nsIPropertyBag);
     16  checkQI([Ci.nsIPropertyBag, "nsIPropertyBag2"], Ci.nsIPropertyBag2);
     17 
     18  checkQI([Ci.nsIPropertyBag, "nsIPropertyBag2", "nsINotARealInterface"], Ci.nsIPropertyBag2);
     19 
     20  // Non-IID values get stringified, and don't cause any errors as long
     21  // as there isn't a non-IID property with the same name on Ci.
     22  checkQI([Ci.nsIPropertyBag, "nsIPropertyBag2", null, Object], Ci.nsIPropertyBag2);
     23 
     24  ChromeUtils.generateQI([])(Ci.nsISupports);
     25 
     26  // Test failure scenarios.
     27  Assert.throws(() => checkQI([], Ci.nsIPropertyBag),
     28                e => e.result == Cr.NS_ERROR_NO_INTERFACE);
     29 });