summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/url/resources/utilities.js
blob: 6392198c4fb8114efd0e339610c8f052068b7ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Start the bidding at 42 for no particular reason.
var lastID = 42;

function canonicalize(url)
{
  // It would be more elegant to use the DOM here, but we use document.write()
  // so the tests run correctly in Firefox.
  var id = ++lastID;
  document.write("<a id='" + id + "' href='" + url + "'></a>");
  return document.getElementById(id).href;
}

function setBaseURL(url)
{
  // According to the HTML5 spec, we're only supposed to honor <base> elements
  // in the <head>, but we use document.write() here to make the test run in
  // Firefox.
  document.write('<base href="' + url + '">');
}

function segments(url)
{
  // It would be more elegant to use the DOM here, but we use document.write()
  // so the tests run correctly in Firefox.
  var id = ++lastID;
  document.write("<a id='" + id + "' href='" + url + "'></a>");
  var elmt = document.getElementById(id);
  return JSON.stringify([
    elmt.protocol,
    elmt.hostname,
    elmt.port,
    elmt.pathname,
    elmt.search,
    elmt.hash
  ]);
}