1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/TestURLManipulation.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 1.5 +<html> 1.6 +<head> 1.7 + <title>URL manipulation</title> 1.8 + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 1.9 + 1.10 + <script type="text/javascript"> 1.11 + var gIOService = null; 1.12 + function getIOService() 1.13 + { 1.14 + if (gIOService) 1.15 + return gIOService; 1.16 + 1.17 + try { 1.18 + gIOService = Components.classes["@mozilla.org/network/io-service;1"] 1.19 + .getService(Components.interfaces.nsIIOService); 1.20 + } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); } 1.21 + 1.22 + return gIOService; 1.23 + } 1.24 + 1.25 + function getnsIURL(inURLString) 1.26 + { 1.27 + var URL = null; 1.28 + var ioserv = getIOService(); 1.29 + try { 1.30 + var URI = ioserv.newURI(inURLString, "", null); 1.31 + URL = URI.QueryInterface(Components.interfaces.nsIURL); 1.32 + } catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); } 1.33 + return URL; 1.34 + } 1.35 + 1.36 + function getCommonSpec() 1.37 + { 1.38 + var URL1 = getnsIURL(document.foo.baseEdit.value); 1.39 + var URL2 = getnsIURL(document.foo.compareEdit.value); 1.40 + var result = ""; 1.41 + try { 1.42 + result = URL1.getCommonBaseSpec(URL2); 1.43 + } catch(e) { dump("problem with getCommonSpec ("+e+")\n"); } 1.44 + document.foo.resultEdit.value = result; 1.45 + } 1.46 + 1.47 + function getRelativeSpec() 1.48 + { 1.49 + var URL1 = getnsIURL(document.foo.baseEdit.value); 1.50 + var URL2 = getnsIURL(document.foo.compareEdit.value); 1.51 + var result = ""; 1.52 + try { 1.53 + result = URL1.getRelativeSpec(URL2); 1.54 + } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); } 1.55 + document.foo.resultEdit.value = result; 1.56 + } 1.57 + 1.58 + function doResolve() 1.59 + { 1.60 + var URL = getnsIURL(document.foo.baseEdit.value); 1.61 + var result = ""; 1.62 + try { 1.63 + result = URL.resolve(document.foo.resultEdit.value); 1.64 + } catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); } 1.65 + document.foo.compareEdit.value = result; 1.66 + } 1.67 + </script> 1.68 +</head> 1.69 +<body> 1.70 +<h1>testing of URL manipulation:</h1> 1.71 +<p> 1.72 + <form name="foo"> 1.73 + <p> 1.74 + <label for="baseEdit">base url (absolute)</label><br> 1.75 + <input type="input" name="baseEdit" size="80" value="http://www.mozilla.org/"> 1.76 + 1.77 + <p> 1.78 + <label for="compareEdit">comparison uri (absolute)</label><br> 1.79 + <input type="input" name="compareEdit" size="80"> 1.80 + 1.81 + <p> 1.82 + <label for="resultEdit">resolved url</label><br> 1.83 + <input type="input" name="resultEdit" size="80"> 1.84 + 1.85 + <p> 1.86 + <input type="button" onclick="getCommonSpec();" value="Get Common Spec"> 1.87 + <input type="button" onclick="getRelativeSpec();" value="Get Relative Spec"> 1.88 + <input type="button" onclick="doResolve();" value="Resolve"> 1.89 + <h5> note: results from "resolve" are placed in "comparison uri" edit field</h5> 1.90 + </form> 1.91 +<p> 1.92 +<br> 1.93 + 1.94 +<h3>notes for testing</h3> 1.95 +different types of uris:<br> 1.96 +<ul> 1.97 + <li>about:</li> 1.98 + <li>about:blank</li> 1.99 + <li>mailbox://nsmail-2.mcom.com/xxx</li> 1.100 + <li>mailto:brade@netscape.com)</li> 1.101 + <li>junk</li> 1.102 + <li>http://foo/</li> 1.103 + <li>http://foo.com/</li> 1.104 + <li>https://foo.com/</li> 1.105 + <li>ftp://ftp.mozilla.org/</li> 1.106 + <li>http://foo.com:8080/</li> 1.107 + <li>http://brade@foo.com/</li> 1.108 + <li>http://brade:password@foo.com/</li> 1.109 + <li>http://brade:@foo.com:8080/</li> 1.110 + <li>file:///</li> 1.111 + <li>file:///Quest/Desktop%20Folder/test.html</li> 1.112 +</ul> 1.113 +other variations:<br> 1.114 +<ul> 1.115 + <li>sub-directories on above list</li> 1.116 + <li>files on above list</li> 1.117 + <li>sub-directories and files on above list<br> 1.118 + </li> 1.119 + <li>directories which don't end in a '/'</li> 1.120 + <li>files with queries</li> 1.121 + <li>files with no extension</li> 1.122 + <li>files with references</li> 1.123 + <li>files with params</li> 1.124 + <li>other schemes (chrome, ldap, news, finger, etc.)<br> 1.125 + </li> 1.126 +</ul> 1.127 +<br> 1.128 +This should be true:<br> 1.129 + resultString = baseURL.getRelativeSpec(URL);<br> 1.130 +<==><br> 1.131 + baseURL.resolve(resultString) == URL.spec;<br> 1.132 +</body> 1.133 +</html>