Skip to content

Commit 9d415b8

Browse files
authored
Test base URL with multiple globals for WebSocket
See whatwg/websockets#45
1 parent 446398a commit 9d415b8

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!DOCTYPE html>
2+
<title>Current page used as a test helper</title>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<title>Incumbent page used as a test helper</title>
3+
4+
<iframe src="../current/current.html" id="current"></iframe>
5+
6+
<script>
7+
const current = document.querySelector("#current").contentWindow;
8+
9+
window.hello = () => {
10+
window.ws = new current.WebSocket('foo');
11+
ws.close();
12+
};
13+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<title>Multiple globals for base URL in WebSocket constructor</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
6+
<!-- This is the entry global -->
7+
8+
<iframe src="incumbent/incumbent.html"></iframe>
9+
10+
<script>
11+
async_test((t) => {
12+
onload = t.step_func_done(() => {
13+
frames[0].hello();
14+
// Inside constructors, "this's relevant settings object" === "current settings object",
15+
// because of how "this" is constructed.
16+
// https://github.com/whatwg/websockets/issues/46
17+
const expectedUrl = new URL('current/foo', location.href);
18+
expectedUrl.protocol = 'ws:';
19+
assert_equals(frames[0].ws.url, expectedUrl.href);
20+
});
21+
});
22+
</script>

0 commit comments

Comments
 (0)