Home | History | Annotate | Download | only in script-tests
      1 description("Test resolution of relative Windows-like URLs.");
      2 
      3 cases = [ 
      4   // Format: [baseURL, relativeURL, expectedURL],
      5   // Resolving against Windows file base URLs.
      6   ["file:///C:/foo", "http://host/", "http://host/"],
      7   ["file:///C:/foo", "bar", "file:///C:/bar"],
      8   ["file:///C:/foo", "../../../bar.html", "file:///C:/bar.html"],
      9   ["file:///C:/foo", "/../bar.html", "file:///C:/bar.html"],
     10   // But two backslashes on Windows should be UNC so should be treated
     11   // as absolute.
     12   ["http://host/a", "\\\\\\\\another\\\\path", ""],
     13   // IE doesn't support drive specs starting with two slashes. It fails
     14   // immediately and doesn't even try to load. We fix it up to either
     15   // an absolute path or UNC depending on what it looks like.
     16   ["file:///C:/something", "//c:/foo", "file:///C:/foo"],
     17   ["file:///C:/something", "//localhost/c:/foo", "file:///C:/foo"],
     18   // Windows drive specs should be allowed and treated as absolute.
     19   ["file:///C:/foo", "c:", ""],
     20   ["file:///C:/foo", "c:/foo", ""],
     21   ["http://host/a", "c:\\\\foo", ""],
     22   // Relative paths with drive letters should be allowed when the base is
     23   // also a file.
     24   ["file:///C:/foo", "/z:/bar", "file:///Z:/bar"],
     25   // Treat absolute paths as being off of the drive.
     26   ["file:///C:/foo", "/bar", "file:///C:/bar"],
     27   ["file://localhost/C:/foo", "/bar", "file://localhost/C:/bar"],
     28   ["file:///C:/foo/com/", "/bar", "file:///C:/bar"],
     29   // On Windows, two slashes without a drive letter when the base is a file
     30   // means that the path is UNC.
     31   ["file:///C:/something", "//somehost/path", "file://somehost/path"],
     32   ["file:///C:/something", "/\\\\//somehost/path", "file://somehost/path"],
     33 ];
     34 
     35 var originalBaseURL = canonicalize(".");
     36 
     37 for (var i = 0; i < cases.length; ++i) {
     38   baseURL = cases[i][0];
     39   relativeURL = cases[i][1];
     40   expectedURL = cases[i][2];
     41   setBaseURL(baseURL);
     42   shouldBe("canonicalize('" + relativeURL + "')",
     43            "'" + expectedURL + "'");
     44 }
     45 
     46 setBaseURL(originalBaseURL);
     47 
     48 var successfullyParsed = true;
     49