<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.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/../websocket/tests/hybi/simple")).url', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple"');
shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?")).url', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple?"');
shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v")).url', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple?k=v"');
shouldBe('(new WebSocket("http://127.0.0.1:8880/websocket/tests/hybi/simple?")).url', '"ws://127.0.0.1:8880/websocket/tests/hybi/simple?"');
shouldBe('(new WebSocket("https://127.0.0.1:8880/websocket/tests/hybi/simple?")).url', '"wss://127.0.0.1:8880/websocket/tests/hybi/simple?"');

// draft-hixie-thewebsocketprotocol-60 says If /url/ has a <fragment>
// component, then fail the parsing Web Socket 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")');

</script>
<script src="../../../../js-test-resources/js-test-post.js"></script>
</body>
</html>
