TestURLManipulation.html 3.8 KB

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