1430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Blockdescription("Canonicalization of file URLs when the base URL is an http URL");
2430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
3430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Blockcases = [
4430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Windows-style paths
5430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:c:\\\\foo\\\\bar.html", "file:///C:/foo/bar.html"],
6430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["  File:c|////foo\\\\bar.html", "file:///C:////foo/bar.html"],
7430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:", "file:///"],
8430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:UNChost/path", "file://unchost/path"],
9430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // CanonicalizeFileURL supports absolute Windows style paths for IE
10430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // compatability. Note that the caller must decide that this is a file
11430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // URL itself so it can call the file canonicalizer. This is usually
12430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // done automatically as part of relative URL resolving.
13430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["c:\\\\foo\\\\bar", "file:///C:/foo/bar"],
14430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["C|/foo/bar", "file:///C:/foo/bar"],
15430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["/C|\\\\foo\\\\bar", "file:///C:/foo/bar"],
16430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["//C|/foo/bar", "file:///C:/foo/bar"],
17430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["//server/file", "file://server/file"],
18430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["\\\\\\\\server\\\\file", "file://server/file"],
19430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["/\\\\server/file", "file://server/file"],
20430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // We should preserve the number of slashes after the colon for IE
21430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // compatability, except when there is none, in which case we should
22430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // add one.
23430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:c:foo/bar.html", "file:///C:/foo/bar.html"],
24430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:/\\\\/\\\\C:\\\\\\\\//foo\\\\bar.html", "file:///C:////foo/bar.html"],
25430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Three slashes should be non-UNC, even if there is no drive spec (IE
26430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // does this, which makes the resulting request invalid).
27430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:///foo/bar.txt", "file:///foo/bar.txt"],
28430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // TODO(brettw) we should probably fail for invalid host names, which
29430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // would change the expected result on this test. We also currently allow
30430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // colon even though it's probably invalid, because its currently the
31430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // "natural" result of the way the canonicalizer is written. There doesn't
32430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // seem to be a strong argument for why allowing it here would be bad, so
33430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // we just tolerate it and the load will fail later.
34430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["FILE:/\\\\/\\\\7:\\\\\\\\//foo\\\\bar.html", "file://7:////foo/bar.html"],
35430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:filer/home\\\\me", "file://filer/home/me"],
36430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Make sure relative paths can't go above the "C:"
37430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:///C:/foo/../../../bar.html", "file:///C:/bar.html"],
38430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Busted refs shouldn't make the whole thing fail.
39430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:///C:/asdf#\\xc2", "file:///C:/asdf#\\xef\\xbf\\xbd"],
40430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
41430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Unix-style paths
42430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:///home/me", "file:///home/me"],
43430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // Windowsy ones should get still treated as Unix-style.
44430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:c:\\\\foo\\\\bar.html", "file:///c:/foo/bar.html"],
45430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file:c|//foo\\\\bar.html", "file:///c%7C//foo/bar.html"],
46430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    // file: tests from WebKit (LayoutTests/fast/loader/url-parse-1.html)
47430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["//", "file:///"],
48430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["///", "file:///"],
49430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["///test", "file:///test"],
50430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file://test", "file://test/"],
51430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file://localhost",  "file://localhost/"],
52430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file://localhost/", "file://localhost/"],
53430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block    ["file://localhost/test", "file://localhost/test"],
54430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block];
55430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
56430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Blockvar originalBaseURL = canonicalize(".");
57430b6b672341c7e8b5e4cfafaaae20315e68701bSteve BlocksetBaseURL("http://example.com/mock/path");
58430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
59430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Blockfor (var i = 0; i < cases.length; ++i) {
60430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block  test_vector = cases[i][0];
61430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block  expected_result = cases[i][1];
62430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block  shouldBe("canonicalize('" + test_vector + "')",
63430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block           "'" + expected_result + "'");
64430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block}
65430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
66430b6b672341c7e8b5e4cfafaaae20315e68701bSteve BlocksetBaseURL(originalBaseURL);
67430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Block
68430b6b672341c7e8b5e4cfafaaae20315e68701bSteve Blockvar successfullyParsed = true;
69