tor-browser

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

test_scriptable_nsIClassInfo.js (1219B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 add_task(function () {
      5  class TestClass {
      6    QueryInterface = ChromeUtils.generateQI([
      7      "nsIXPCTestInterfaceA",
      8      "nsIClassInfo",
      9    ]);
     10 
     11    interfaces = [Ci.nsIXPCTestInterfaceA, Ci.nsIClassInfo, Ci.nsISupports];
     12    contractID = "@mozilla.org/test/class;1";
     13    classDescription = "description";
     14    classID = Components.ID("{4da556d4-00fa-451a-a280-d2aec7c5f265}");
     15    flags = 0;
     16 
     17    name = "this is a test";
     18  }
     19 
     20  let instance = new TestClass();
     21  Assert.ok(instance, "can create an instance");
     22  Assert.ok(instance.QueryInterface(Ci.nsIClassInfo), "can QI to nsIClassInfo");
     23 
     24  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
     25  registrar.registerFactory(
     26    instance.classID,
     27    instance.classDescription,
     28    instance.contractID,
     29    {
     30      createInstance(iid) {
     31        return instance.QueryInterface(iid);
     32      },
     33    }
     34  );
     35  Assert.ok(true, "successfully registered the factory");
     36 
     37  let otherInstance = Cc["@mozilla.org/test/class;1"].createInstance(
     38    Ci.nsIXPCTestInterfaceA
     39  );
     40  Assert.ok(otherInstance, "can create an instance via xpcom");
     41 });