Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / native-io / write_capacity_allocation_async.tentative.https.any.js
blob91544fe7cf37ba747e29de10f79220a9496d7385
1 // META: title=NativeIO API: Write respects the allocated capacities.
2 // META: global=window,worker
4 promise_test(async testCase => {
5   const file = await storageFoundation.open('test_file');
6   testCase.add_cleanup(async () => {
7     await file.close();
8     await storageFoundation.delete('test_file');
9   });
10   const writeBuffer = new Uint8Array(4);
11   writeBuffer.set([64, 65, 66, 67]);
12   await promise_rejects_dom(
13     testCase, 'QuotaExceededError', file.write(writeBuffer, 0));
14 }, 'NativeIOFile.write() fails without any capacity request.');
16 promise_test(async testCase => {
17   const file = await storageFoundation.open('test_file');
19   const granted_capacity = await storageFoundation.requestCapacity(4);
20   assert_greater_than_equal(granted_capacity, 2);
21   testCase.add_cleanup(async () => {
22     await file.close();
23     await storageFoundation.delete('test_file');
24     await storageFoundation.releaseCapacity(granted_capacity);
25   });
26   const writeBuffer = new Uint8Array(granted_capacity - 1);
27   writeBuffer.set(Array(granted_capacity - 1).fill(64));
29   const {writtenBytes} = await file.write(writeBuffer, 0);
30   assert_equals(writtenBytes, granted_capacity - 1);
31 }, 'NativeIOFile.write() succeeds when given a buffer of length ' +
32      'granted capacity - 1');
34 promise_test(async testCase => {
35   const file = await storageFoundation.open('test_file');
37   const granted_capacity = await storageFoundation.requestCapacity(4);
38   assert_greater_than_equal(granted_capacity, 2);
39   testCase.add_cleanup(async () => {
40     await file.close();
41     await storageFoundation.delete('test_file');
42   });
43   const writeBuffer = new Uint8Array(granted_capacity);
44   writeBuffer.set(Array(granted_capacity).fill(64));
46   const {writtenBytes} = await file.write(writeBuffer, 0);
47   assert_equals(writtenBytes, granted_capacity);
48 }, 'NativeIOFile.write() succeeds when given the granted capacity');
50 promise_test(async testCase => {
51   const file = await storageFoundation.open('test_file');
53   const granted_capacity = await storageFoundation.requestCapacity(4);
54   assert_greater_than_equal(granted_capacity, 2);
55   testCase.add_cleanup(async () => {
56     await file.close();
57     await storageFoundation.delete('test_file');
58     await storageFoundation.releaseCapacity(granted_capacity);
59   });
60   const writeBuffer = new Uint8Array(granted_capacity + 1);
61   writeBuffer.set(Array(granted_capacity + 1).fill(64));
63   await promise_rejects_dom(testCase,
64     'QuotaExceededError', file.write(writeBuffer, 0));
65 }, 'NativeIOFile.write() fails when given the granted capacity + 1');