mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 21:00:42 +02:00
Automatic update from web-platform-tests *.any.js: explicitly list defaults, part 3 *.any.js's META global no longer supports negation or the default feature making everything a bit easier as a result. See https://github.com/web-platform-tests/rfcs/pull/52, #23117, and #23121. Closes #23111. -- wpt-commits: 96c7f0b57b704c94a7535d58009500ea94c02995 wpt-pr: 23133
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
// META: title=Synchronous NativeIO API: close().
|
|
// META: global=dedicatedworker
|
|
|
|
'use strict';
|
|
|
|
// Returns a handle to a newly created file that holds some data.
|
|
//
|
|
// The file will be closed and deleted when the test ends.
|
|
function createFileSync(testCase, fileName) {
|
|
const file = nativeIO.openSync(fileName);
|
|
testCase.add_cleanup(() => {
|
|
file.close();
|
|
nativeIO.deleteSync('test_file');
|
|
});
|
|
|
|
const writtenBytes = Uint8Array.from([64, 65, 66, 67]);
|
|
const writeCount = file.write(writtenBytes, 0);
|
|
assert_equals(writeCount, 4);
|
|
|
|
return file;
|
|
}
|
|
|
|
test(testCase => {
|
|
const file = createFileSync(testCase, 'file_name');
|
|
assert_equals(undefined, file.close());
|
|
|
|
assert_equals(undefined, file.close());
|
|
}, 'nativeIO.close is idempotent');
|
|
|
|
test(testCase => {
|
|
const file = createFileSync(testCase, 'file_name');
|
|
assert_equals(undefined, file.close());
|
|
|
|
const readBytes = new Uint8Array(4);
|
|
assert_throws_dom('InvalidStateError', () => file.read(readBytes, 4));
|
|
}, 'nativeIO.read fails after nativeIO.close settles');
|
|
|
|
test(testCase => {
|
|
const file = createFileSync(testCase, 'file_name');
|
|
assert_equals(undefined, file.close());
|
|
|
|
const writtenBytes = Uint8Array.from([96, 97, 98, 99]);
|
|
assert_throws_dom('InvalidStateError', () => file.write(writtenBytes, 4));
|
|
}, 'NativeIOFile.write fails after NativeIOFile.close');
|