1 // Start the bidding at 42 for no particular reason. 2 var lastID = 42; 3 4 function canonicalize(url) 5 { 6 // It would be more elegant to use the DOM here, but we use document.write() 7 // so the tests run correctly in Firefox. 8 var id = ++lastID; 9 document.write("<a id='" + id + "' href='" + url + "'></a>"); 10 return document.getElementById(id).href; 11 } 12 13 function setBaseURL(url) 14 { 15 // It would be more elegant to use the DOM here, but we chose document.write() 16 // so the tests ran correctly in Firefox at the time we originally wrote them. 17 18 // Remove any existing base elements. 19 var existingBase = document.getElementsByTagName('base'); 20 while (existingBase.length) { 21 var element = existingBase[0]; 22 element.parentNode.removeChild(element); 23 } 24 25 // Add a new base element. 26 document.write('<base href="' + url + '">'); 27 } 28 29 function segments(url) 30 { 31 // It would be more elegant to use the DOM here, but we use document.write() 32 // so the tests run correctly in Firefox. 33 var id = ++lastID; 34 document.write("<a id='" + id + "' href='" + url + "'></a>"); 35 var elmt = document.getElementById(id); 36 return JSON.stringify([ 37 elmt.protocol, 38 elmt.hostname, 39 elmt.port, 40 elmt.pathname, 41 elmt.search, 42 elmt.hash 43 ]); 44 } 45