Commit 07aae009 authored by Richard Stotz's avatar Richard Stotz Committed by Chromium LUCI CQ

NativeIO: Improving some web platform tests without functional changes.

This CL fixes some minor issues with NativeIO's web platform tests.
- The concurrent_io tests obtain a more unified structure to reduce the
chance of missing an await.
- createFile() is removed from close_async as the exact same function is
provided by resources/support.js.

Bug: 1157915
Change-Id: I3e33cc8d93e08c31dddc4d844310c92eeba31a7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587058
Commit-Queue: Richard Stotz <rstz@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836214}
parent 5012d348
// META: title=NativeIO API: close(). // META: title=NativeIO API: close().
// META: global=window,worker // META: global=window,worker
// META: script=resources/support.js
'use strict'; '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.
async function createFile(testCase, fileName) {
const file = await nativeIO.open(fileName);
testCase.add_cleanup(async () => {
await file.close();
await nativeIO.delete(fileName);
});
const writeSharedArrayBuffer = new SharedArrayBuffer(4);
const writtenBytes = new Uint8Array(writeSharedArrayBuffer);
writtenBytes.set([64, 65, 66, 67]);
const writeCount = await file.write(writtenBytes, 0);
assert_equals(writeCount, 4);
return file;
}
promise_test(async testCase => { promise_test(async testCase => {
const file = await createFile(testCase, 'file_name'); const file = await createFile(testCase, 'file_name');
assert_equals(await file.close(), undefined); assert_equals(await file.close(), undefined);
......
...@@ -15,7 +15,7 @@ for (let op of kOperations) { ...@@ -15,7 +15,7 @@ for (let op of kOperations) {
const res = op.prepare(); const res = op.prepare();
const flushPromise = file.flush(); const flushPromise = file.flush();
op.assertRejection(testCase, file, res); await op.assertRejection(testCase, file, res);
await flushPromise; await flushPromise;
......
...@@ -14,7 +14,7 @@ for (let op of kOperations) { ...@@ -14,7 +14,7 @@ for (let op of kOperations) {
const res = op.prepare(); const res = op.prepare();
const setLengthPromise = file.setLength(5); const setLengthPromise = file.setLength(5);
op.assertRejection(testCase, file, res); await op.assertRejection(testCase, file, res);
await setLengthPromise; await setLengthPromise;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// and assertUnchanged. May be empty. // and assertUnchanged. May be empty.
// assertRejection: A promise_rejects_dom(...) statement that calls // assertRejection: A promise_rejects_dom(...) statement that calls
// operation B. Takes the object returned by prepare as // operation B. Takes the object returned by prepare as
// third parameter. // third parameter. Returns a promise.
// assertUnchanged: An assertion that rejecting the promise did not change // assertUnchanged: An assertion that rejecting the promise did not change
// the buffers in unexpected ways. The assertion does not // the buffers in unexpected ways. The assertion does not
// check if the file itself was not changed. This will be // check if the file itself was not changed. This will be
...@@ -30,8 +30,8 @@ const kOperations = []; ...@@ -30,8 +30,8 @@ const kOperations = [];
const readBytes = new Uint8Array(readSharedArrayBuffer); const readBytes = new Uint8Array(readSharedArrayBuffer);
return readBytes; return readBytes;
}, },
assertRejection: (testCase, file, readBytes) => { assertRejection: async (testCase, file, readBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError', await promise_rejects_dom(testCase, 'InvalidStateError',
file.read(readBytes, 4)); file.read(readBytes, 4));
}, },
assertUnchanged: (readBytes) => { assertUnchanged: (readBytes) => {
...@@ -48,8 +48,8 @@ const kOperations = []; ...@@ -48,8 +48,8 @@ const kOperations = [];
writtenBytes.set([96, 97, 98, 99]); writtenBytes.set([96, 97, 98, 99]);
return writtenBytes; return writtenBytes;
}, },
assertRejection: (testCase, file, writtenBytes) => { assertRejection: async (testCase, file, writtenBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError', await promise_rejects_dom(testCase, 'InvalidStateError',
file.write(writtenBytes, 4)); file.write(writtenBytes, 4));
}, },
assertUnchanged: () => {}, assertUnchanged: () => {},
...@@ -59,8 +59,8 @@ const kOperations = []; ...@@ -59,8 +59,8 @@ const kOperations = [];
const kOpGetLength = { const kOpGetLength = {
name: 'getLength', name: 'getLength',
prepare: () => {}, prepare: () => {},
assertRejection: (testCase, file) => { assertRejection: async (testCase, file) => {
return promise_rejects_dom(testCase, 'InvalidStateError', await promise_rejects_dom(testCase, 'InvalidStateError',
file.getLength()); file.getLength());
}, },
assertUnchanged: () => {}, assertUnchanged: () => {},
...@@ -82,7 +82,7 @@ const kOperations = []; ...@@ -82,7 +82,7 @@ const kOperations = [];
name: 'setLength', name: 'setLength',
prepare: () => {}, prepare: () => {},
assertRejection: async (testCase, file, readBytes) => { assertRejection: async (testCase, file, readBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError', await promise_rejects_dom(testCase, 'InvalidStateError',
file.setLength(2)); file.setLength(2));
}, },
assertUnchanged: () => {}, assertUnchanged: () => {},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment