summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js
blob: 169364cb444542a53b907d68c6f332e5cd3b3ae9 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
importScripts('/resources/testharness.js');
importScripts('resources/test-helpers.js');
importScripts('resources/sandboxed-fs-test-helpers.js');
importScripts('resources/test-helpers.js');

'use strict';

directory_test(async (t, root_dir) =>  {
  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});

  const syncHandle1 = await fileHandle.createSyncAccessHandle();
  t.add_cleanup(() => syncHandle1.close());
  await promise_rejects_dom(
      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());

  syncHandle1.close();
  const syncHandle2 = await fileHandle.createSyncAccessHandle();
  syncHandle2.close();
}, 'There can only be one open access handle at any given time');

directory_test(async (t, root_dir) =>  {
  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});

  const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
  t.add_cleanup(() => fooSyncHandle.close());

  const barSyncHandle1 = await barFileHandle.createSyncAccessHandle();
  t.add_cleanup(() => barSyncHandle1.close());
  await promise_rejects_dom(
      t, 'NoModificationAllowedError', barFileHandle.createSyncAccessHandle());

  barSyncHandle1.close();
  const barSyncHandle2 = await barFileHandle.createSyncAccessHandle();
  barSyncHandle2.close();
}, 'An access handle from one file does not interfere with the creation of an' +
     ' access handle on another file');

directory_test(async (t, root_dir) =>  {
  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});

  const fooWritable = await cleanup_writable(t, await fooFileHandle.createWritable());
  t.add_cleanup(() => fooWritable.close());

  const barSyncHandle = await barFileHandle.createSyncAccessHandle();
  t.add_cleanup(() => barSyncHandle.close());
}, 'A writable stream from one file does not interfere with the creation of an' +
     ' access handle on another file');

directory_test(async (t, root_dir) =>  {
  const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
  const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});

  const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
  t.add_cleanup(() => fooSyncHandle.close());

  const barWritable = await cleanup_writable(t, await barFileHandle.createWritable());
  t.add_cleanup(() => barWritable.close());
}, 'An access handle from one file does not interfere with the creation of a' +
     ' writable stream on another file');

directory_test(async (t, root_dir) =>  {
  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});

  const syncHandle = await fileHandle.createSyncAccessHandle();
  t.add_cleanup(() => { syncHandle.close(); });
  await promise_rejects_dom(
    t, 'NoModificationAllowedError', cleanup_writable(t, fileHandle.createWritable()));

  syncHandle.close();
  const writable = await cleanup_writable(t, await fileHandle.createWritable());
  await writable.close();
}, 'Writable streams cannot be created if there is an open access handle');

directory_test(async (t, root_dir) =>  {
  const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});

  const writable1 = await cleanup_writable(t, await fileHandle.createWritable());
  const writable2 = await cleanup_writable(t, await fileHandle.createWritable());
  await promise_rejects_dom(
      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());

  await writable1.close();
  await promise_rejects_dom(
      t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());

  await writable2.close();
  const syncHandle = await fileHandle.createSyncAccessHandle();
  syncHandle.close();
}, 'Access handles cannot be created if there are open Writable streams');

done();