summaryrefslogtreecommitdiffstats
path: root/netwerk/test/TestURLManipulation.html
blob: fd58652b7be8b9cae6e45db3eca52a66a73d164a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>URL manipulation</title>
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

  <script type="text/javascript">
    var gIOService = null;
    function getIOService()
    {
      if (gIOService)
        return gIOService;

      try {
        gIOService = Components.classes["@mozilla.org/network/io-service;1"]
                            .getService(Components.interfaces.nsIIOService);
      } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }

      return gIOService;
   }

    function getnsIURL(inURLString)
    {
      var URL = null;
      var ioserv = getIOService();
      try {
        var URI = ioserv.newURI(inURLString, "", null);
        URL = URI.QueryInterface(Components.interfaces.nsIURL);
      } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
      return URL;
    }

    function getCommonSpec()
    {
      var URL1 = getnsIURL(document.foo.baseEdit.value);
      var URL2 = getnsIURL(document.foo.compareEdit.value);
      var result = "";
      try {
        result = URL1.getCommonBaseSpec(URL2);
      } catch(e) { dump("problem with getCommonSpec ("+e+")\n"); }
      document.foo.resultEdit.value = result;
    }

    function getRelativeSpec()
    {
      var URL1 = getnsIURL(document.foo.baseEdit.value);
      var URL2 = getnsIURL(document.foo.compareEdit.value);
      var result = "";
      try {
        result = URL1.getRelativeSpec(URL2);
      } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
      document.foo.resultEdit.value = result;
    }

    function doResolve()
    {
      var URL = getnsIURL(document.foo.baseEdit.value);
      var result = "";
      try {
        result = URL.resolve(document.foo.resultEdit.value);
      } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
      document.foo.compareEdit.value = result;
    }
  </script>
</head>
<body>
<h1>testing of URL manipulation:</h1>
<p>
  <form name="foo"> 
    <p>
    <label for="baseEdit">base url (absolute)</label><br>
    <input type="input" name="baseEdit" size="80" value="http://www.mozilla.org/">

    <p>
    <label for="compareEdit">comparison uri (absolute)</label><br>
    <input type="input" name="compareEdit" size="80">

    <p>
    <label for="resultEdit">resolved url</label><br>
    <input type="input" name="resultEdit" size="80">

    <p>
    <input type="button" onclick="getCommonSpec();" value="Get Common Spec">
    <input type="button" onclick="getRelativeSpec();" value="Get Relative Spec">
    <input type="button" onclick="doResolve();" value="Resolve">
    <h5> note: results from "resolve" are placed in "comparison uri" edit field</h5>
  </form>
<p>
<br>

<h3>notes for testing</h3>
different types of uris:<br>
<ul>
  <li>about:</li>
  <li>about:blank</li>
  <li>mailbox://nsmail-2.mcom.com/xxx</li>
  <li>mailto:brade@netscape.com)</li>
  <li>junk</li>
  <li>http://foo/</li>
  <li>http://foo.com/</li>
  <li>https://foo.com/</li>
  <li>ftp://ftp.mozilla.org/</li>
  <li>http://foo.com:8080/</li>
  <li>http://brade@foo.com/</li>
  <li>http://brade:password@foo.com/</li>
  <li>http://brade:@foo.com:8080/</li>
  <li>file:///</li>
  <li>file:///Quest/Desktop%20Folder/test.html</li>
</ul>
other variations:<br>
<ul>
  <li>sub-directories on above list</li>
  <li>files on above list</li>
  <li>sub-directories and files on above list<br>
  </li>
  <li>directories which don't end in a '/'</li>
  <li>files with queries</li>
  <li>files with no extension</li>
  <li>files with references</li>
  <li>files with params</li>
  <li>other schemes (chrome, ldap, news, finger, etc.)<br>
  </li>
</ul>
<br>
This should be true:<br>
&nbsp; resultString = baseURL.getRelativeSpec(URL);<br>
&lt;==&gt;<br>
&nbsp; baseURL.resolve(resultString) == URL.spec;<br>
</body>
</html>