netwerk/test/unit/test_bug553970.js

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:9d7765bae74b
1 function makeURL(spec) {
2 return Cc["@mozilla.org/network/io-service;1"].
3 getService(Components.interfaces.nsIIOService).
4 newURI(spec, null, null).
5 QueryInterface(Components.interfaces.nsIURL);
6 }
7
8 // Checks that nsIURL::GetRelativeSpec does what it claims to do.
9 function run_test() {
10
11 // Elements of tests have the form [this.spec, aURIToCompare.spec, expectedResult].
12 let tests = [
13 ["http://mozilla.org/", "http://www.mozilla.org/", "http://www.mozilla.org/"],
14 ["http://mozilla.org/", "http://www.mozilla.org", "http://www.mozilla.org/"],
15 ["http://foo.com/bar/", "http://foo.com:80/bar/", "" ],
16 ["http://foo.com/", "http://foo.com/a.htm#b", "a.htm#b" ],
17 ["http://foo.com/a/b/", "http://foo.com/c", "../../c" ],
18 ["http://foo.com/a?b/c/", "http://foo.com/c" , "c" ],
19 ["http://foo.com/a#b/c/", "http://foo.com/c" , "c" ],
20 ["http://foo.com/a;p?b/c/", "http://foo.com/c" , "c" ],
21 ["http://foo.com/a/b?c/d/", "http://foo.com/c", "../c" ],
22 ["http://foo.com/a/b#c/d/", "http://foo.com/c", "../c" ],
23 ["http://foo.com/a/b;p?c/d/", "http://foo.com/c", "../c" ],
24 ["http://foo.com/a/b/c?d/e/", "http://foo.com/f", "../../f" ],
25 ["http://foo.com/a/b/c#d/e/", "http://foo.com/f", "../../f" ],
26 ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f", "../../f" ],
27 ["http://foo.com/a?b/c/", "http://foo.com/c/d" , "c/d" ],
28 ["http://foo.com/a#b/c/", "http://foo.com/c/d" , "c/d" ],
29 ["http://foo.com/a;p?b/c/", "http://foo.com/c/d" , "c/d" ],
30 ["http://foo.com/a/b?c/d/", "http://foo.com/c/d", "../c/d" ],
31 ["http://foo.com/a/b#c/d/", "http://foo.com/c/d", "../c/d" ],
32 ["http://foo.com/a/b;p?c/d/", "http://foo.com/c/d", "../c/d" ],
33 ["http://foo.com/a/b/c?d/e/", "http://foo.com/f/g/", "../../f/g/" ],
34 ["http://foo.com/a/b/c#d/e/", "http://foo.com/f/g/", "../../f/g/" ],
35 ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f/g/", "../../f/g/" ],
36 ];
37
38 for (var i = 0; i < tests.length; i++) {
39 let url1 = makeURL(tests[i][0]);
40 let url2 = makeURL(tests[i][1]);
41 let expected = tests[i][2];
42 do_check_eq(expected, url1.getRelativeSpec(url2));
43 }
44 }

mercurial