Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / native-io / write_capacity_allocation_sync.tentative.https.any.js
blobb72b1f645da0146ef1a9804a64a009f853239eed
1 // META: title=NativeIO API: Write respects the allocated capacities.
2 // META: global=dedicatedworker
4 test(testCase => {
5   const file =  storageFoundation.openSync('test_file');
6   testCase.add_cleanup(() => {
7     file.close();
8     storageFoundation.deleteSync('test_file');
9   });
10   const writeBuffer = Uint8Array.from([64, 65, 66, 67]);
11   assert_throws_dom('QuotaExceededError', () => {file.write(writeBuffer, 0)});
12 }, 'NativeIOFileSync.write() fails without any capacity request.');
14 test(testCase => {
15   const file =  storageFoundation.openSync('test_file');
17   const granted_capacity =  storageFoundation.requestCapacitySync(4);
18   assert_greater_than_equal(granted_capacity, 2);
20   testCase.add_cleanup(() => {
21     file.close();
22     storageFoundation.deleteSync('test_file');
23     storageFoundation.releaseCapacitySync(granted_capacity);
24   });
26   const writeBuffer = new Uint8Array(granted_capacity - 1).fill(64);
27   file.write(writeBuffer, 0);
28 }, 'NativeIOFileSync.write() succeeds when given a buffer of length ' +
29      'granted capacity - 1');
31 test(testCase => {
32   const file =  storageFoundation.openSync('test_file');
34   const granted_capacity =  storageFoundation.requestCapacitySync(4);
35   assert_greater_than_equal(granted_capacity, 2);
36   testCase.add_cleanup(() => {
37     file.close();
38     storageFoundation.deleteSync('test_file');
39     storageFoundation.releaseCapacitySync(granted_capacity);
40   });
41   const writeBuffer = new Uint8Array(granted_capacity).fill(64);
43   file.write(writeBuffer, 0);
44 }, 'NativeIOFileSync.write() succeeds when given the granted capacity');
46 test(testCase => {
47   const file =  storageFoundation.openSync('test_file');
49   const granted_capacity =  storageFoundation.requestCapacitySync(4);
50   assert_greater_than_equal(granted_capacity, 2);
51   testCase.add_cleanup(() => {
52     file.close();
53     storageFoundation.deleteSync('test_file');
54     storageFoundation.releaseCapacitySync(granted_capacity);
55   });
56   const writeBuffer = new Uint8Array(granted_capacity + 1).fill(64);
58   assert_throws_dom('QuotaExceededError', () => {file.write(writeBuffer, 0)});
59 }, 'NativeIOFileSync.write() fails when given the granted capacity + 1');