| <!DOCTYPE html> |
| <script src="../../../resources/js-test.js"></script> |
| <script> |
| |
| function breakDownURL(string) |
| { |
| var a = new URL(string); |
| |
| var result = ""; |
| |
| var propertyNames = [ |
| "protocol", |
| "username", |
| "password", |
| "hostname", |
| "host", |
| "port", |
| "pathname", |
| "search", |
| "hash", |
| "origin" |
| ]; |
| for (var i = 0; i < propertyNames.length; ++i) { |
| var name = propertyNames[i]; |
| var value = a[name]; |
| if (value == "") |
| continue; |
| if (name == "hostname" && value == a.host) |
| continue; |
| if (typeof value != "string") |
| value = "non-string"; |
| if (result != "") |
| result += ", "; |
| result += name + "=" + value; |
| } |
| |
| if (string != a.toString()) |
| result += ", toString=" + a.toString(); |
| |
| return result; |
| } |
| |
| shouldBe("breakDownURL('about:blank')", "'protocol=about:, pathname=blank, origin=null'"); |
| shouldBe("breakDownURL('http://example.com/')", "'protocol=http:, host=example.com, pathname=/, origin=http://example.com'"); |
| shouldBe("breakDownURL('http://@example.com/')", "'protocol=http:, host=example.com, pathname=/, origin=http://example.com, toString=http://example.com/'"); |
| shouldBe("breakDownURL('http://a@example.com/')", "'protocol=http:, username=a, host=example.com, pathname=/, origin=http://example.com'"); |
| shouldBe("breakDownURL('http://a:@example.com/')", "'protocol=http:, username=a, host=example.com, pathname=/, origin=http://example.com, toString=http://a@example.com/'"); |
| shouldBe("breakDownURL('http://joebob1:abc123@example.com/')", "'protocol=http:, username=joebob1, password=abc123, host=example.com, pathname=/, origin=http://example.com'"); |
| shouldBe("breakDownURL('http://:def456@example.com/')", "'protocol=http:, password=def456, host=example.com, pathname=/, origin=http://example.com'"); |
| shouldBe("breakDownURL('http://example.com/foo/bar')", "'protocol=http:, host=example.com, pathname=/foo/bar, origin=http://example.com'"); |
| shouldBe("breakDownURL('HTTP://example.com/foo/bar')", "'protocol=http:, host=example.com, pathname=/foo/bar, origin=http://example.com, toString=http://example.com/foo/bar'"); |
| shouldBe("breakDownURL('https://example.com/ttt?ggg')", "'protocol=https:, host=example.com, pathname=/ttt, search=?ggg, origin=https://example.com'"); |
| shouldBe("breakDownURL('ftp://example.com/ttt?ggg')", "'protocol=ftp:, host=example.com, pathname=/ttt, search=?ggg, origin=ftp://example.com'"); |
| shouldBe("breakDownURL('file:///Users/darin')", "'protocol=file:, pathname=/Users/darin, origin=file://'"); |
| shouldBe("breakDownURL('data:text/html,<b>foo</b>')", "'protocol=data:, pathname=text/html,<b>foo</b>, origin=null'"); |
| shouldBe("breakDownURL('http://a:b@c:1/e/f?g%h')", "'protocol=http:, username=a, password=b, hostname=c, host=c:1, port=1, pathname=/e/f, search=?g%h, origin=http://c:1'"); |
| shouldBe("breakDownURL('http://ex%61mple.com/')", "'protocol=http:, host=example.com, pathname=/, origin=http://example.com, toString=http://example.com/'"); |
| shouldThrow("breakDownURL('http://ex%2fmple.com/')"); |
| |
| </script> |