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