• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<meta charset=utf-8>
3<script src=/resources/testharness.js></script>
4<script src=/resources/testharnessreport.js></script>
5<div id=log></div>
6<script>
7function bURL(url, base) {
8  return new URL(url, base || "about:blank")
9}
10
11function runURLTests(urltests) {
12  for(var i = 0, l = urltests.length; i < l; i++) {
13    var expected = urltests[i]
14    if (typeof expected === "string") continue // skip comments
15
16    test(function() {
17      if (expected.failure) {
18        assert_throws(new TypeError(), function() {
19          bURL(expected.input, expected.base)
20        })
21        return
22      }
23
24      var url = bURL(expected.input, expected.base)
25      assert_equals(url.href, expected.href, "href")
26      assert_equals(url.protocol, expected.protocol, "protocol")
27      assert_equals(url.username, expected.username, "username")
28      assert_equals(url.password, expected.password, "password")
29      assert_equals(url.host, expected.host, "host")
30      assert_equals(url.hostname, expected.hostname, "hostname")
31      assert_equals(url.port, expected.port, "port")
32      assert_equals(url.pathname, expected.pathname, "pathname")
33      assert_equals(url.search, expected.search, "search")
34      if ("searchParams" in expected) {
35        assert_true("searchParams" in url)
36        assert_equals(url.searchParams.toString(), expected.searchParams, "searchParams")
37      }
38      assert_equals(url.hash, expected.hash, "hash")
39    }, "Parsing: <" + expected.input + "> against <" + expected.base + ">")
40  }
41}
42
43promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
44</script>
45