tor-browser

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

test_uri_mutator.js (1334B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 "use strict";
      7 
      8 function standardMutator() {
      9  return Cc["@mozilla.org/network/standard-url-mutator;1"].createInstance(
     10    Ci.nsIURIMutator
     11  );
     12 }
     13 
     14 add_task(async function test_simple_setter_chaining() {
     15  let uri = standardMutator()
     16    .setSpec("http://example.com/")
     17    .setQuery("hello")
     18    .setRef("bla")
     19    .setScheme("ftp")
     20    .finalize();
     21  equal(uri.spec, "ftp://example.com/?hello#bla");
     22 });
     23 
     24 add_task(async function test_qi_behaviour() {
     25  let uri = standardMutator()
     26    .setSpec("http://example.com/")
     27    .QueryInterface(Ci.nsIURI);
     28  equal(uri.spec, "http://example.com/");
     29 
     30  Assert.throws(
     31    () => {
     32      uri = standardMutator().QueryInterface(Ci.nsIURI);
     33    },
     34    /NS_NOINTERFACE/,
     35    "mutator doesn't QI if it holds no URI"
     36  );
     37 
     38  let mutator = standardMutator().setSpec("http://example.com/path");
     39  uri = mutator.QueryInterface(Ci.nsIURI);
     40  equal(uri.spec, "http://example.com/path");
     41  Assert.throws(
     42    () => {
     43      uri = mutator.QueryInterface(Ci.nsIURI);
     44    },
     45    /NS_NOINTERFACE/,
     46    "Second QueryInterface should fail"
     47  );
     48 });