tor-browser

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

test_sourcetree_utils_getRelativePath.js (1942B)


      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 "use strict";
      6 
      7 const { require } = ChromeUtils.importESModule(
      8  "resource://devtools/shared/loader/Loader.sys.mjs"
      9 );
     10 const {
     11  getRelativePath,
     12 } = require("devtools/client/debugger/src/utils/sources-tree/utils");
     13 
     14 function run_test() {
     15  info("Test a url without any path");
     16  equal(
     17    getRelativePath("http://example.com/"),
     18    "(index)",
     19    "Returns a string representing the index file"
     20  );
     21 
     22  info("Test a url with directory path");
     23  equal(
     24    getRelativePath("http://example.com/path/"),
     25    "path/",
     26    "Returns the directory path"
     27  );
     28 
     29  info("Test a http url a simple file path with no extension");
     30  equal(
     31    getRelativePath("http://example.com/file"),
     32    "file",
     33    "Returns the simple path"
     34  );
     35 
     36  info("Test a file url with a multi directory file path with no extension");
     37  equal(
     38    getRelativePath("file:///path/to/file"),
     39    "path/to/file",
     40    "Returns the full file path"
     41  );
     42 
     43  info("Test a http url which is multi directory with html file path");
     44  equal(
     45    getRelativePath("http://example.com/path/to/file.html"),
     46    "path/to/file.html",
     47    "Returns the full html file path"
     48  );
     49 
     50  info("Test a http url which is multi directory with js file path");
     51  equal(
     52    getRelativePath("http://example.com/path/to/file.js"),
     53    "path/to/file.js",
     54    "Returns the full js file path"
     55  );
     56 
     57  info("Test a file url with path and query parameters");
     58  equal(
     59    getRelativePath("file:///path/to/file.js?bla=bla"),
     60    "path/to/file.js",
     61    "Returns the full path without the query params"
     62  );
     63 
     64  info("Test a webpack url with path and fragment");
     65  equal(
     66    getRelativePath("webpack:///path/to/file.js#bla"),
     67    "path/to/file.js",
     68    "Returns the full path without the query params"
     69  );
     70 }