2010-04-22 Maciej Stachowiak <mjs@apple.com>
[WebKit.git] / LayoutTests / fast / url / script-tests / file-http-base.js
1 description("Canonicalization of file URLs when the base URL is an http URL");
2
3 cases = [ 
4     // Windows-style paths
5     ["file:c:\\\\foo\\\\bar.html", "file:///C:/foo/bar.html"],
6     ["  File:c|////foo\\\\bar.html", "file:///C:////foo/bar.html"],
7     ["file:", "file:///"],
8     ["file:UNChost/path", "file://unchost/path"],
9     // CanonicalizeFileURL supports absolute Windows style paths for IE
10     // compatability. Note that the caller must decide that this is a file
11     // URL itself so it can call the file canonicalizer. This is usually
12     // done automatically as part of relative URL resolving.
13     ["c:\\\\foo\\\\bar", "file:///C:/foo/bar"],
14     ["C|/foo/bar", "file:///C:/foo/bar"],
15     ["/C|\\\\foo\\\\bar", "file:///C:/foo/bar"],
16     ["//C|/foo/bar", "file:///C:/foo/bar"],
17     ["//server/file", "file://server/file"],
18     ["\\\\\\\\server\\\\file", "file://server/file"],
19     ["/\\\\server/file", "file://server/file"],
20     // We should preserve the number of slashes after the colon for IE
21     // compatability, except when there is none, in which case we should
22     // add one.
23     ["file:c:foo/bar.html", "file:///C:/foo/bar.html"],
24     ["file:/\\\\/\\\\C:\\\\\\\\//foo\\\\bar.html", "file:///C:////foo/bar.html"],
25     // Three slashes should be non-UNC, even if there is no drive spec (IE
26     // does this, which makes the resulting request invalid).
27     ["file:///foo/bar.txt", "file:///foo/bar.txt"],
28     // TODO(brettw) we should probably fail for invalid host names, which
29     // would change the expected result on this test. We also currently allow
30     // colon even though it's probably invalid, because its currently the
31     // "natural" result of the way the canonicalizer is written. There doesn't
32     // seem to be a strong argument for why allowing it here would be bad, so
33     // we just tolerate it and the load will fail later.
34     ["FILE:/\\\\/\\\\7:\\\\\\\\//foo\\\\bar.html", "file://7:////foo/bar.html"],
35     ["file:filer/home\\\\me", "file://filer/home/me"],
36     // Make sure relative paths can't go above the "C:"
37     ["file:///C:/foo/../../../bar.html", "file:///C:/bar.html"],
38     // Busted refs shouldn't make the whole thing fail.
39     ["file:///C:/asdf#\\xc2", "file:///C:/asdf#\\xef\\xbf\\xbd"],
40
41     // Unix-style paths
42     ["file:///home/me", "file:///home/me"],
43     // Windowsy ones should get still treated as Unix-style.
44     ["file:c:\\\\foo\\\\bar.html", "file:///c:/foo/bar.html"],
45     ["file:c|//foo\\\\bar.html", "file:///c%7C//foo/bar.html"],
46     // file: tests from WebKit (LayoutTests/fast/loader/url-parse-1.html)
47     ["//", "file:///"],
48     ["///", "file:///"],
49     ["///test", "file:///test"],
50     ["file://test", "file://test/"],
51     ["file://localhost",  "file://localhost/"],
52     ["file://localhost/", "file://localhost/"],
53     ["file://localhost/test", "file://localhost/test"],
54 ];
55
56 var originalBaseURL = canonicalize(".");
57 setBaseURL("http://example.com/mock/path");
58
59 for (var i = 0; i < cases.length; ++i) {
60   test_vector = cases[i][0];
61   expected_result = cases[i][1];
62   shouldBe("canonicalize('" + test_vector + "')",
63            "'" + expected_result + "'");
64 }
65
66 setBaseURL(originalBaseURL);
67
68 var successfullyParsed = true;