FileSystemSyncAccessHandle-flush.https.worker.js (869B)
1 importScripts('/resources/testharness.js'); 2 importScripts('resources/sync-access-handle-test.js'); 3 4 'use strict'; 5 6 sync_access_handle_test((t, handle) => { 7 handle.flush(); 8 }, 'Test flush on an empty file.'); 9 10 sync_access_handle_test((t, handle) => { 11 if (!('TextEncoder' in self)) { 12 return; 13 } 14 const encoder = new TextEncoder(); 15 const decoder = new TextDecoder(); 16 17 const text = 'Hello Storage Foundation'; 18 const writeBuffer = new TextEncoder().encode(text); 19 handle.write(writeBuffer, {at: 0}); 20 handle.flush(); 21 let readBuffer = new Uint8Array(text.length); 22 handle.read(readBuffer, {at: 0}); 23 assert_equals( 24 text, new TextDecoder().decode(readBuffer), 25 'Check that the written bytes and the read bytes match'); 26 }, 'SyncAccessHandle.read returns bytes written by SyncAccessHandle.write' + 27 ' after SyncAccessHandle.flush'); 28 29 done();