netwerk/test/unit/test_bug553970.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug553970.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +function makeURL(spec) {
     1.5 +  return Cc["@mozilla.org/network/io-service;1"].
     1.6 +           getService(Components.interfaces.nsIIOService).
     1.7 +           newURI(spec, null, null).
     1.8 +           QueryInterface(Components.interfaces.nsIURL);
     1.9 +}
    1.10 +
    1.11 +// Checks that nsIURL::GetRelativeSpec does what it claims to do.
    1.12 +function run_test() {
    1.13 +
    1.14 +  // Elements of tests have the form [this.spec, aURIToCompare.spec, expectedResult].
    1.15 +  let tests = [
    1.16 +    ["http://mozilla.org/",  "http://www.mozilla.org/", "http://www.mozilla.org/"],
    1.17 +    ["http://mozilla.org/",  "http://www.mozilla.org",  "http://www.mozilla.org/"],
    1.18 +    ["http://foo.com/bar/",  "http://foo.com:80/bar/",  ""                       ],
    1.19 +    ["http://foo.com/",      "http://foo.com/a.htm#b",  "a.htm#b"                ],
    1.20 +    ["http://foo.com/a/b/",  "http://foo.com/c",        "../../c"                ],
    1.21 +    ["http://foo.com/a?b/c/", "http://foo.com/c" ,      "c"                      ],
    1.22 +    ["http://foo.com/a#b/c/", "http://foo.com/c" ,      "c"                      ],
    1.23 +    ["http://foo.com/a;p?b/c/", "http://foo.com/c" ,    "c"                      ],
    1.24 +    ["http://foo.com/a/b?c/d/", "http://foo.com/c",     "../c"                   ],
    1.25 +    ["http://foo.com/a/b#c/d/", "http://foo.com/c",     "../c"                   ],
    1.26 +    ["http://foo.com/a/b;p?c/d/", "http://foo.com/c",   "../c"                   ],
    1.27 +    ["http://foo.com/a/b/c?d/e/", "http://foo.com/f",   "../../f"                ],
    1.28 +    ["http://foo.com/a/b/c#d/e/", "http://foo.com/f",   "../../f"                ],
    1.29 +    ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f", "../../f"                ],
    1.30 +    ["http://foo.com/a?b/c/", "http://foo.com/c/d" ,    "c/d"                    ],
    1.31 +    ["http://foo.com/a#b/c/", "http://foo.com/c/d" ,    "c/d"                    ],
    1.32 +    ["http://foo.com/a;p?b/c/", "http://foo.com/c/d" ,  "c/d"                    ],
    1.33 +    ["http://foo.com/a/b?c/d/", "http://foo.com/c/d",   "../c/d"                 ],
    1.34 +    ["http://foo.com/a/b#c/d/", "http://foo.com/c/d",   "../c/d"                 ],
    1.35 +    ["http://foo.com/a/b;p?c/d/", "http://foo.com/c/d", "../c/d"                 ],
    1.36 +    ["http://foo.com/a/b/c?d/e/", "http://foo.com/f/g/", "../../f/g/"            ],
    1.37 +    ["http://foo.com/a/b/c#d/e/", "http://foo.com/f/g/", "../../f/g/"            ],
    1.38 +    ["http://foo.com/a/b/c;p?d/e/", "http://foo.com/f/g/", "../../f/g/"          ],
    1.39 +  ];
    1.40 +
    1.41 +  for (var i = 0; i < tests.length; i++) {
    1.42 +    let url1 = makeURL(tests[i][0]);
    1.43 +    let url2 = makeURL(tests[i][1]);
    1.44 +    let expected = tests[i][2];
    1.45 +    do_check_eq(expected, url1.getRelativeSpec(url2));
    1.46 +  }
    1.47 +}

mercurial