Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_bug553970.js
blobadb45a2ee9cd8c52a1a389f610f9dda3e4c5bb26
1 "use strict";
3 function makeURL(spec) {
4   return Services.io.newURI(spec).QueryInterface(Ci.nsIURL);
7 // Checks that nsIURL::GetRelativeSpec does what it claims to do.
8 function run_test() {
9   // Elements of tests have the form [this.spec, aURIToCompare.spec, expectedResult].
10   let tests = [
11     [
12       "http://mozilla.org/",
13       "http://www.mozilla.org/",
14       "http://www.mozilla.org/",
15     ],
16     [
17       "http://mozilla.org/",
18       "http://www.mozilla.org",
19       "http://www.mozilla.org/",
20     ],
21     ["http://foo.com/bar/", "http://foo.com:80/bar/", ""],
22     ["http://foo.com/", "http://foo.com/a.htm#b", "a.htm#b"],
23     ["http://foo.com/a/b/", "http://foo.com/c", "../../c"],
24     ["http://foo.com/a?b/c/", "http://foo.com/c", "c"],
25     ["http://foo.com/a#b/c/", "http://foo.com/c", "c"],
26     ["http://foo.com/a;p?b/c/", "http://foo.com/c", "c"],
27     ["http://foo.com/a/b?c/d/", "http://foo.com/c", "../c"],
28     ["http://foo.com/a/b#c/d/", "http://foo.com/c", "../c"],
29     ["http://foo.com/a/b;p?c/d/", "http://foo.com/c", "../c"],
30     ["http://foo.com/a/b/c?d/e/", "http://foo.com/f", "../../f"],
31     ["http://foo.com/a/b/c#d/e/", "http://foo.com/f", "../../f"],
32     ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f", "../../f"],
33     ["http://foo.com/a?b/c/", "http://foo.com/c/d", "c/d"],
34     ["http://foo.com/a#b/c/", "http://foo.com/c/d", "c/d"],
35     ["http://foo.com/a;p?b/c/", "http://foo.com/c/d", "c/d"],
36     ["http://foo.com/a/b?c/d/", "http://foo.com/c/d", "../c/d"],
37     ["http://foo.com/a/b#c/d/", "http://foo.com/c/d", "../c/d"],
38     ["http://foo.com/a/b;p?c/d/", "http://foo.com/c/d", "../c/d"],
39     ["http://foo.com/a/b/c?d/e/", "http://foo.com/f/g/", "../../f/g/"],
40     ["http://foo.com/a/b/c#d/e/", "http://foo.com/f/g/", "../../f/g/"],
41     ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f/g/", "../../f/g/"],
42   ];
44   for (var i = 0; i < tests.length; i++) {
45     let url1 = makeURL(tests[i][0]);
46     let url2 = makeURL(tests[i][1]);
47     let expected = tests[i][2];
48     Assert.equal(expected, url1.getRelativeSpec(url2));
49   }