summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/FileSystemSyncAccessHandle-flush.https.tentative.worker.js
blob: 96953a88f2eaa7383bf80a1fe49bd7204cb46863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
importScripts('/resources/testharness.js');
importScripts('resources/sync-access-handle-test.js');

'use strict';

sync_access_handle_test((t, handle) => {
  handle.flush();
}, 'Test flush on an empty file.');

sync_access_handle_test((t, handle) => {
  if (!('TextEncoder' in self)) {
    return;
  }
  const encoder = new TextEncoder();
  const decoder = new TextDecoder();

  const text = 'Hello Storage Foundation';
  const writeBuffer = new TextEncoder().encode(text);
  handle.write(writeBuffer, {at: 0});
  handle.flush();
  let readBuffer = new Uint8Array(text.length);
  handle.read(readBuffer, {at: 0});
  assert_equals(
      text, new TextDecoder().decode(readBuffer),
      'Check that the written bytes and the read bytes match');
}, 'SyncAccessHandle.read returns bytes written by SyncAccessHandle.write' +
    ' after SyncAccessHandle.flush');

done();