chromium/third_party/blink/web_tests/http/tests/websocket/url-parsing.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("Test WebSocket URL parsing.");

// Not enough arguments.
shouldThrow('new WebSocket()');

// Invalid url will fail to be parsed.
shouldThrow('new WebSocket("ws://javascript:a")');

// Relative URLs behave like HTTP(S) URLs

let url = new URL("null", location);
url.protocol = "ws";
shouldBe('(new WebSocket(null)).url', 'url.href');
url.pathname = "/applet"
shouldBe('(new WebSocket("/applet")).url', 'url.href');

// Non ws URL is not allowed.
shouldThrow('new WebSocket("javascript:a")');

// Resolve the url string using the resolve a Web address algorithm.
// Use 127.0.0.1:8880 and existing ws handler to make sure we don't receive unexpected response (so no console message appears)
shouldBe('(new WebSocket("ws://127.0.0.1:8880/a/../simple")).url', '"ws://127.0.0.1:8880/simple"');
shouldBe('(new WebSocket("ws://127.0.0.1:8880/simple?")).url', '"ws://127.0.0.1:8880/simple?"');
shouldBe('(new WebSocket("ws://127.0.0.1:8880/simple?k=v")).url', '"ws://127.0.0.1:8880/simple?k=v"');
shouldBe('(new WebSocket("http://127.0.0.1:8880/simple?")).url', '"ws://127.0.0.1:8880/simple?"');
shouldBe('(new WebSocket("https://127.0.0.1:8880/simple?")).url', '"wss://127.0.0.1:8880/simple?"');

// The WebSocket API specification says If /url/ has a <fragment>
// component, then fail the parsing WebSocket URLs, so throw a SYNTAX_ERR
// exception.
shouldThrow('new WebSocket("ws://127.0.0.1/path#")');
shouldThrow('new WebSocket("ws://127.0.0.1/path#fragment")');

shouldThrow('new WebSocket("ws:://127.0.0.1/")');

</script>
</body>
</html>