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