3 function makeURL(spec) {
4 return Services.io.newURI(spec).QueryInterface(Ci.nsIURL);
7 // Checks that nsIURL::GetRelativeSpec does what it claims to do.
9 // Elements of tests have the form [this.spec, aURIToCompare.spec, expectedResult].
12 "http://mozilla.org/",
13 "http://www.mozilla.org/",
14 "http://www.mozilla.org/",
17 "http://mozilla.org/",
18 "http://www.mozilla.org",
19 "http://www.mozilla.org/",
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/"],
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));