tor-browser

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

test_file_url_with_host.js (941B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 function setupChannel(uri) {
      6  var chan = NetUtil.newChannel({
      7    uri,
      8    loadUsingSystemPrincipal: true,
      9  });
     10  chan.QueryInterface(Ci.nsIFileChannel);
     11  return chan;
     12 }
     13 
     14 add_task(async function test() {
     15  setupChannel("file:///path");
     16  Assert.ok(
     17    true,
     18    "Should be able to create channel from file URL without hostname"
     19  );
     20 
     21  setupChannel("file://example.com/path");
     22  Assert.ok(
     23    true,
     24    "Should be able to create channel from file URL with hostname"
     25  );
     26 
     27  await Assert.rejects(
     28    fetch("file:///path"),
     29    /TypeError: NetworkError when attempting to fetch resource./
     30  );
     31 
     32  await Assert.rejects(
     33    fetch("file://example.com/path"),
     34    /TypeError: NetworkError when attempting to fetch resource./
     35  );
     36 });