~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/netwerk/test/TestURLManipulation.html

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
2
<html>
 
3
<head>
 
4
  <title>URL manipulation</title>
 
5
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
 
6
 
 
7
  <script type="text/javascript">
 
8
    var gIOService = null;
 
9
    function getIOService()
 
10
    {
 
11
      if (gIOService)
 
12
        return gIOService;
 
13
 
 
14
      try {
 
15
        gIOService = Components.classes["@mozilla.org/network/io-service;1"]
 
16
                            .getService(Components.interfaces.nsIIOService);
 
17
      } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
 
18
 
 
19
      return gIOService;
 
20
   }
 
21
 
 
22
    function getnsIURL(inURLString)
 
23
    {
 
24
      var URL = null;
 
25
      var ioserv = getIOService();
 
26
      try {
 
27
        var URI = ioserv.newURI(inURLString, "", null);
 
28
        URL = URI.QueryInterface(Components.interfaces.nsIURL);
 
29
      } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
 
30
      return URL;
 
31
    }
 
32
 
 
33
    function getCommonSpec()
 
34
    {
 
35
      var URL1 = getnsIURL(document.foo.baseEdit.value);
 
36
      var URL2 = getnsIURL(document.foo.compareEdit.value);
 
37
      var result = "";
 
38
      try {
 
39
        result = URL1.getCommonBaseSpec(URL2);
 
40
      } catch(e) { dump("problem with getCommonSpec ("+e+")\n"); }
 
41
      document.foo.resultEdit.value = result;
 
42
    }
 
43
 
 
44
    function getRelativeSpec()
 
45
    {
 
46
      var URL1 = getnsIURL(document.foo.baseEdit.value);
 
47
      var URL2 = getnsIURL(document.foo.compareEdit.value);
 
48
      var result = "";
 
49
      try {
 
50
        result = URL1.getRelativeSpec(URL2);
 
51
      } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
 
52
      document.foo.resultEdit.value = result;
 
53
    }
 
54
 
 
55
    function doResolve()
 
56
    {
 
57
      var URL = getnsIURL(document.foo.baseEdit.value);
 
58
      var result = "";
 
59
      try {
 
60
        result = URL.resolve(document.foo.resultEdit.value);
 
61
      } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
 
62
      document.foo.compareEdit.value = result;
 
63
    }
 
64
  </script>
 
65
</head>
 
66
<body>
 
67
<h1>testing of URL manipulation:</h1>
 
68
<p>
 
69
  <form name="foo"> 
 
70
    <p>
 
71
    <label for="baseEdit">base url (absolute)</label><br>
 
72
    <input type="input" name="baseEdit" size="80" value="http://www.mozilla.org/">
 
73
 
 
74
    <p>
 
75
    <label for="compareEdit">comparison uri (absolute)</label><br>
 
76
    <input type="input" name="compareEdit" size="80">
 
77
 
 
78
    <p>
 
79
    <label for="resultEdit">resolved url</label><br>
 
80
    <input type="input" name="resultEdit" size="80">
 
81
 
 
82
    <p>
 
83
    <input type="button" onclick="getCommonSpec();" value="Get Common Spec">
 
84
    <input type="button" onclick="getRelativeSpec();" value="Get Relative Spec">
 
85
    <input type="button" onclick="doResolve();" value="Resolve">
 
86
    <h5> note: results from "resolve" are placed in "comparison uri" edit field</h5>
 
87
  </form>
 
88
<p>
 
89
<br>
 
90
 
 
91
<h3>notes for testing</h3>
 
92
different types of uris:<br>
 
93
<ul>
 
94
  <li>about:</li>
 
95
  <li>about:blank</li>
 
96
  <li>mailbox://nsmail-2.mcom.com/xxx</li>
 
97
  <li>mailto:brade@netscape.com)</li>
 
98
  <li>junk</li>
 
99
  <li>http://foo/</li>
 
100
  <li>http://foo.com/</li>
 
101
  <li>https://foo.com/</li>
 
102
  <li>ftp://ftp.mozilla.org/</li>
 
103
  <li>http://foo.com:8080/</li>
 
104
  <li>http://brade@foo.com/</li>
 
105
  <li>http://brade:password@foo.com/</li>
 
106
  <li>http://brade:@foo.com:8080/</li>
 
107
  <li>file:///</li>
 
108
  <li>file:///Quest/Desktop%20Folder/test.html</li>
 
109
</ul>
 
110
other variations:<br>
 
111
<ul>
 
112
  <li>sub-directories on above list</li>
 
113
  <li>files on above list</li>
 
114
  <li>sub-directories and files on above list<br>
 
115
  </li>
 
116
  <li>directories which don't end in a '/'</li>
 
117
  <li>files with queries</li>
 
118
  <li>files with no extension</li>
 
119
  <li>files with references</li>
 
120
  <li>files with params</li>
 
121
  <li>other schemes (chrome, ldap, news, finger, etc.)<br>
 
122
  </li>
 
123
</ul>
 
124
<br>
 
125
This should be true:<br>
 
126
&nbsp; resultString = baseURL.getRelativeSpec(URL);<br>
 
127
&lt;==&gt;<br>
 
128
&nbsp; baseURL.resolve(resultString) == URL.spec;<br>
 
129
</body>
 
130
</html>