summaryrefslogtreecommitdiffstats
path: root/remote/webdriver-bidi/test/browser/head.js
blob: e9a125a1937e615801f28265da3c9590702f1d4a (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
/**
 * Load a given URL in the currently selected tab
 */
async function loadURL(url, expectedURL = undefined) {
  expectedURL = expectedURL || url;

  const browser = gBrowser.selectedTab.linkedBrowser;
  const loaded = BrowserTestUtils.browserLoaded(browser, true, expectedURL);

  BrowserTestUtils.startLoadingURIString(browser, url);
  await loaded;
}

/** Creates an inline URL for the given source document. */
function inline(src, doctype = "html") {
  let doc;
  switch (doctype) {
    case "html":
      doc = `<!doctype html>\n<meta charset=utf-8>\n${src}`;
      break;
    default:
      throw new Error("Unexpected doctype: " + doctype);
  }

  return `https://example.com/document-builder.sjs?html=${encodeURIComponent(
    doc
  )}`;
}