tor-browser

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

test_substituting_protocol_handler.js (1819B)


      1 "use strict";
      2 
      3 add_task(async function test_case_insensitive_substitutions() {
      4  let resProto = Services.io
      5    .getProtocolHandler("resource")
      6    .QueryInterface(Ci.nsISubstitutingProtocolHandler);
      7 
      8  let uri = Services.io.newFileURI(do_get_file("data"));
      9 
     10  resProto.setSubstitution("FooBar", uri);
     11  resProto.setSubstitutionWithFlags("BarBaz", uri, 0);
     12 
     13  equal(
     14    resProto.resolveURI(Services.io.newURI("resource://foobar/")),
     15    uri.spec,
     16    "Got correct resolved URI for setSubstitution"
     17  );
     18 
     19  equal(
     20    resProto.resolveURI(Services.io.newURI("resource://foobar/")),
     21    uri.spec,
     22    "Got correct resolved URI for setSubstitutionWithFlags"
     23  );
     24 
     25  ok(
     26    resProto.hasSubstitution("foobar"),
     27    "hasSubstitution works with all-lower-case root"
     28  );
     29  ok(
     30    resProto.hasSubstitution("FooBar"),
     31    "hasSubstitution works with mixed-case root"
     32  );
     33 
     34  equal(
     35    resProto.getSubstitution("foobar").spec,
     36    uri.spec,
     37    "getSubstitution works with all-lower-case root"
     38  );
     39  equal(
     40    resProto.getSubstitution("FooBar").spec,
     41    uri.spec,
     42    "getSubstitution works with mixed-case root"
     43  );
     44 
     45  resProto.setSubstitution("foobar", null);
     46  resProto.setSubstitution("barbaz", null);
     47 
     48  Assert.throws(
     49    () => resProto.resolveURI(Services.io.newURI("resource://foobar/")),
     50    e => e.result == Cr.NS_ERROR_NOT_AVAILABLE,
     51    "Correctly unregistered case-insensitive substitution in setSubstitution"
     52  );
     53  Assert.throws(
     54    () => resProto.resolveURI(Services.io.newURI("resource://barbaz/")),
     55    e => e.result == Cr.NS_ERROR_NOT_AVAILABLE,
     56    "Correctly unregistered case-insensitive substitution in setSubstitutionWithFlags"
     57  );
     58 
     59  Assert.throws(
     60    () => resProto.getSubstitution("foobar"),
     61    e => e.result == Cr.NS_ERROR_NOT_AVAILABLE,
     62    "foobar substitution has been removed"
     63  );
     64 });