tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js (3953B)


      1 importScripts('/resources/testharness.js');
      2 importScripts('resources/test-helpers.js');
      3 importScripts('resources/sandboxed-fs-test-helpers.js');
      4 importScripts('resources/test-helpers.js');
      5 
      6 'use strict';
      7 
      8 directory_test(async (t, root_dir) =>  {
      9  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
     10 
     11  const syncHandle1 = await fileHandle.createSyncAccessHandle();
     12  t.add_cleanup(() => syncHandle1.close());
     13  await promise_rejects_dom(
     14      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
     15 
     16  syncHandle1.close();
     17  const syncHandle2 = await fileHandle.createSyncAccessHandle();
     18  syncHandle2.close();
     19 }, 'There can only be one open access handle at any given time');
     20 
     21 directory_test(async (t, root_dir) =>  {
     22  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
     23  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
     24 
     25  const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
     26  t.add_cleanup(() => fooSyncHandle.close());
     27 
     28  const barSyncHandle1 = await barFileHandle.createSyncAccessHandle();
     29  t.add_cleanup(() => barSyncHandle1.close());
     30  await promise_rejects_dom(
     31      t, 'NoModificationAllowedError', barFileHandle.createSyncAccessHandle());
     32 
     33  barSyncHandle1.close();
     34  const barSyncHandle2 = await barFileHandle.createSyncAccessHandle();
     35  barSyncHandle2.close();
     36 }, 'An access handle from one file does not interfere with the creation of an' +
     37     ' access handle on another file');
     38 
     39 directory_test(async (t, root_dir) =>  {
     40  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
     41  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
     42 
     43  const fooWritable = await cleanup_writable(t, await fooFileHandle.createWritable());
     44  t.add_cleanup(() => fooWritable.close());
     45 
     46  const barSyncHandle = await barFileHandle.createSyncAccessHandle();
     47  t.add_cleanup(() => barSyncHandle.close());
     48 }, 'A writable stream from one file does not interfere with the creation of an' +
     49     ' access handle on another file');
     50 
     51 directory_test(async (t, root_dir) =>  {
     52  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
     53  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
     54 
     55  const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
     56  t.add_cleanup(() => fooSyncHandle.close());
     57 
     58  const barWritable = await cleanup_writable(t, await barFileHandle.createWritable());
     59  t.add_cleanup(() => barWritable.close());
     60 }, 'An access handle from one file does not interfere with the creation of a' +
     61     ' writable stream on another file');
     62 
     63 directory_test(async (t, root_dir) =>  {
     64  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
     65 
     66  const syncHandle = await fileHandle.createSyncAccessHandle();
     67  t.add_cleanup(() => { syncHandle.close(); });
     68  await promise_rejects_dom(
     69    t, 'NoModificationAllowedError', cleanup_writable(t, fileHandle.createWritable()));
     70 
     71  syncHandle.close();
     72  const writable = await cleanup_writable(t, await fileHandle.createWritable());
     73  await writable.close();
     74 }, 'Writable streams cannot be created if there is an open access handle');
     75 
     76 directory_test(async (t, root_dir) =>  {
     77  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
     78 
     79  const writable1 = await cleanup_writable(t, await fileHandle.createWritable());
     80  const writable2 = await cleanup_writable(t, await fileHandle.createWritable());
     81  await promise_rejects_dom(
     82      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
     83 
     84  await writable1.close();
     85  await promise_rejects_dom(
     86      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
     87 
     88  await writable2.close();
     89  const syncHandle = await fileHandle.createSyncAccessHandle();
     90  syncHandle.close();
     91 }, 'Access handles cannot be created if there are open Writable streams');
     92 
     93 done();