-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1652418 [wpt PR 24575] - [nativeio] NativeIO: Add setLength, a=te…
…stonly Automatic update from web-platform-tests [nativeio] NativeIO: Add setLength The MacOS sandbox does not allow calling base::File::SetLength() from the renderer directly, see crbug.com/1084565. The call to setLength is therefore routed through the browser process, which likely decreases performance and increases complexity. Another option would be to create a SeatbeltExtensionToken that allows to pierce the sandbox on MacOS for a single file. As this would likely lead to more complex code, we decided that going through the browser process is the better option for now. Bug: 914488 Change-Id: Idc58d804e19751a2e37cfeb5c645f778edf4639c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2257855 Commit-Queue: Richard Stotz <rstz@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Reviewed-by: Mike West <mkwst@chromium.org> Cr-Commit-Position: refs/heads/master@{#799005} -- wpt-commits: c9e08236b532473b460dca5daa717dcb8824d7dc wpt-pr: 24575
- Loading branch information
1 parent
9874603
commit c7490ac
Showing
8 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...atform/tests/native-io/concurrent_io/concurrent_io_setLength_async.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// META: title=NativeIO API: Concurrent io while setLength is resolving. | ||
// META: global=window,worker | ||
// META: script=operation_helpers.js | ||
// META: script=../resources/support.js | ||
|
||
'use strict'; | ||
|
||
// See documentation in operation_helpers.js | ||
|
||
for (let op of kOperations) { | ||
promise_test(async testCase => { | ||
const file = await createFile(testCase, 'setlength_file'); | ||
|
||
const res = op.prepare(); | ||
|
||
const setLengthPromise = file.setLength(5); | ||
op.assertRejection(testCase, file, res); | ||
|
||
await setLengthPromise; | ||
|
||
const readSharedArrayBuffer = new SharedArrayBuffer(5); | ||
const readBytes = new Uint8Array(readSharedArrayBuffer); | ||
assert_equals(await file.read(readBytes, 0), 5, | ||
`NativeIOFile.read() should not fail after a rejected ` + | ||
`${op.name}() during setLength().`); | ||
assert_array_equals(readBytes, [64, 65, 66, 67, 0], | ||
`Rejecting ${op.name}() during setLength()` + | ||
` should not change the file.`); | ||
op.assertUnchanged(res); | ||
}, `${op.name}() rejects while setLength() is resolving.`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
testing/web-platform/tests/native-io/getLength_setLength_async_basic.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// META: title=NativeIO API: Assigned length is observed back. | ||
// META: global=window,worker | ||
// META: script=resources/support.js | ||
|
||
'use strict'; | ||
|
||
promise_test(async testCase => { | ||
const file = await nativeIO.open('test_file'); | ||
testCase.add_cleanup(async () => { | ||
await file.close(); | ||
await nativeIO.delete('test_file'); | ||
}); | ||
|
||
const writeSharedArrayBuffer = new SharedArrayBuffer(4); | ||
const writtenBytes = new Uint8Array(writeSharedArrayBuffer); | ||
writtenBytes.set([97, 98, 99, 100]); | ||
await file.write(writtenBytes, 0); | ||
|
||
await file.setLength(3); | ||
const readBytes = await readIoFile(file); | ||
|
||
const remainingBytes = Uint8Array.from([97, 98, 99]); | ||
|
||
assert_array_equals( | ||
readBytes, remainingBytes, | ||
'NativeIOFile.setLength() should remove bytes from the end of ' + | ||
'a file when decreasing its length'); | ||
}, 'NativeIOFile.setLength shrinks a file, NativeIOFile.getLength reports ' + | ||
'new length'); | ||
|
||
promise_test(async testCase => { | ||
const file = await nativeIO.open('test_file'); | ||
testCase.add_cleanup(async () => { | ||
await file.close(); | ||
await nativeIO.delete('test_file'); | ||
}); | ||
|
||
const writeSharedArrayBuffer = new SharedArrayBuffer(4); | ||
const writtenBytes = new Uint8Array(writeSharedArrayBuffer); | ||
writtenBytes.set([97, 98, 99, 100]); | ||
await file.write(writtenBytes, 0); | ||
|
||
await file.setLength(5); | ||
const readBytes = await readIoFile(file); | ||
|
||
const expectedBytes = Uint8Array.from([97, 98, 99, 100, 0]); | ||
|
||
assert_array_equals( | ||
readBytes, expectedBytes, | ||
'NativeIOFile.setLength() should append zeros when increasing' + | ||
' the file size'); | ||
}, 'NativeIOFile.setLength appends zeros to a file, NativeIOFile.getLength ' + | ||
'reports new length'); |
48 changes: 48 additions & 0 deletions
48
testing/web-platform/tests/native-io/getLength_setLength_sync_basic.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// META: title=Synchronous NativeIO API: Assigned length is observed back. | ||
// META: global=dedicatedworker | ||
// META: script=resources/support.js | ||
|
||
'use strict'; | ||
|
||
test(testCase => { | ||
const file = nativeIO.openSync('test_file'); | ||
testCase.add_cleanup(() => { | ||
file.close(); | ||
nativeIO.deleteSync('test_file'); | ||
}); | ||
|
||
const writtenBytes = Uint8Array.from([97, 98, 99, 100]); | ||
file.write(writtenBytes, 0); | ||
|
||
file.setLength(3); | ||
const readBytes = readIoFileSync(file); | ||
|
||
const remainingBytes = Uint8Array.from([97, 98, 99]); | ||
assert_array_equals( | ||
readBytes, remainingBytes, | ||
'NativeIOFileSync.setLength() should remove bytes from the end of ' + | ||
'a file when decreasing its length.'); | ||
}, 'NativeIOFileSync.setLength shrinks a file and' + | ||
' NativeIOFileSync.getLength reports its new length.'); | ||
|
||
test(testCase => { | ||
const file = nativeIO.openSync('test_file'); | ||
testCase.add_cleanup(() => { | ||
file.close(); | ||
nativeIO.deleteSync('test_file'); | ||
}); | ||
|
||
const writtenBytes = Uint8Array.from([97, 98, 99, 100]); | ||
file.write(writtenBytes, 0); | ||
|
||
file.setLength(5); | ||
const readBytes = readIoFileSync(file); | ||
|
||
const expectedBytes = Uint8Array.from([97, 98, 99, 100, 0]); | ||
|
||
assert_array_equals( | ||
readBytes, expectedBytes, | ||
'NativeIOFileSync.setLength() should append zeros when increasing' + | ||
' the file size.'); | ||
}, 'NativeIOFileSync.setLength appends zeros to a file and ' + | ||
'NativeIOFileSync.getLength reports its new length.'); |
20 changes: 20 additions & 0 deletions
20
testing/web-platform/tests/native-io/setLength_bounds_async.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: title=NativeIO API: Out-of-bounds errors for setLength. | ||
// META: global=window,worker | ||
// META: script=resources/support.js | ||
|
||
'use strict'; | ||
|
||
promise_test(async testCase => { | ||
const file = await createFile(testCase, "file_length_zero"); | ||
await file.setLength(0); | ||
const lengthDecreased = await file.getLength(); | ||
assert_equals(lengthDecreased, 0, | ||
"NativeIOFile.setLength() should set the file length to 0."); | ||
}, 'NativeIOFile.setLength does not throw an error when descreasing the ' + | ||
'file length to 0.'); | ||
|
||
promise_test(async testCase => { | ||
const file = await createFile(testCase, "file_length_negative"); | ||
await promise_rejects_js(testCase, TypeError, | ||
file.setLength(-1)); | ||
}, 'NativeIOFile.setLength() throws when setting negative lengths.'); |
24 changes: 24 additions & 0 deletions
24
testing/web-platform/tests/native-io/setLength_bounds_sync.tentative.https.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// META: title=Synchronous NativeIO API: Out-of-bounds errors for setLength. | ||
// META: global=dedicatedworker | ||
// META: script=resources/support.js | ||
|
||
'use strict'; | ||
|
||
test(testCase => { | ||
const file = createFileSync(testCase, "file_length_zero"); | ||
file.setLength(0); | ||
const lengthDecreased = file.getLength(); | ||
assert_equals(lengthDecreased, 0, | ||
"NativeIOFileSync.setLength() should set the file length to 0."); | ||
}, 'NativeIOFileSync.setLength() does not throw an error when descreasing ' + | ||
'the file length to 0.'); | ||
|
||
test(testCase => { | ||
const file = createFileSync(testCase, "file_length_negative"); | ||
|
||
// Without this assertion, the test passes even if setLength is not defined. | ||
assert_implements(file.setLength, | ||
"NativeIOFileSync.setLength is not implemented."); | ||
|
||
assert_throws_js(TypeError, () => file.setLength(-1)); | ||
}, 'NativeIOFileSync.setLength() throws when setting negative lengths.'); |