summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base-javascript.html
blob: 65d9c84fcf70f4f51c71179fd85dd4a298a88da1 (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
<!-- Please update base-data.html together with this -->
<!DOCTYPE html>
<meta charset="utf-8">
<title>&lt;base> and javascript: URLs</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<base href="javascript:/,test">
<base href="https://example.com/">
<div id=log></div>
<script>
test(() => {
  const link = document.createElement("a");
  link.href = "blah";
  assert_equals(link.href, new URL("blah", document.URL).href);
}, "First <base> has a javascript: URL so fallback is used");

test(() => {
  document.querySelector("base").remove();
  const link = document.createElement("a");
  link.href = "blah";
  assert_equals(link.href, new URL("blah", "https://example.com/").href);
}, "First <base> is removed so second is used");

test(() => {
  const base = document.createElement("base");
  base.href = "javascript:/,more-test";
  document.head.prepend(base);
  const link = document.createElement("a");
  link.href = "blah";
  assert_equals(link.href, new URL("blah", document.URL).href);
}, "Dynamically inserted first <base> has a javascript: URL so fallback is used");
</script>