gecko-dev/testing/web-platform/tests/websockets/bufferedAmount-unchanged-by-sync-xhr.any.js
Adam Rice 4ef0dc6d52 Bug 1479471 [wpt PR 12198] - Update buffered amount when async callbacks are called, a=testonly
Automatic update from web-platform-testsUpdate buffered amount when async callbacks are called

If an asynchronous callback is called, it means we must have returned to
the start of the event loop. Ensure that any consumed bufferedAmount is
reflected in that case. Do not reflect bufferedAmount if the EventQueue
is paused, as that means that we may be in a nested event loop.

Add a unit test for this case. Also add a unit test for normal
bufferedAmount behaviour, as there wasn't one.

Add a web platform test for what happens if a sync XHR is performed
between calling send() and looking at bufferedAmount.

BUG=856651

Change-Id: Iafa2d619a1eb5284b64500ac03d336fb6380193b
Reviewed-on: https://chromium-review.googlesource.com/1151086
Commit-Queue: Adam Rice <ricea@chromium.org>
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580078}

--

wpt-commits: 80f89c9af6cda0d80faf7f9b1c487eaff7205059
wpt-pr: 12198
2018-08-04 05:39:01 +00:00

23 lines
746 B
JavaScript

// META: script=websocket.sub.js
// META: global=sharedworker
async_test(t => {
const url = 'wss://' + __SERVER__NAME + ':' + __SECURE__PORT + '/echo';
const ws = new WebSocket(url);
ws.onopen = t.step_func(() => {
ws.onclose = ws.onerror = null;
assert_equals(ws.bufferedAmount, 0);
ws.send('hello');
assert_equals(ws.bufferedAmount, 5);
// Stop execution for 1s with a sync XHR.
const xhr = new XMLHttpRequest();
xhr.open('GET', '/common/blank.html?pipe=trickle(d1)', false);
xhr.send();
assert_equals(ws.bufferedAmount, 5);
ws.close();
t.done();
});
ws.onerror = ws.onclose = t.unreached_func('open should succeed');
}, 'bufferedAmount should not be updated during a sync XHR');
done();