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: global=window,worker
// META: script=resources/support.js
'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 => {
const file = await createFile(testCase, 'file_name');
assert_equals(await file.close(), undefined);
......
......@@ -15,7 +15,7 @@ for (let op of kOperations) {
const res = op.prepare();
const flushPromise = file.flush();
op.assertRejection(testCase, file, res);
await op.assertRejection(testCase, file, res);
await flushPromise;
......
......@@ -14,7 +14,7 @@ for (let op of kOperations) {
const res = op.prepare();
const setLengthPromise = file.setLength(5);
op.assertRejection(testCase, file, res);
await op.assertRejection(testCase, file, res);
await setLengthPromise;
......
......@@ -11,7 +11,7 @@
// and assertUnchanged. May be empty.
// assertRejection: A promise_rejects_dom(...) statement that calls
// 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
// the buffers in unexpected ways. The assertion does not
// check if the file itself was not changed. This will be
......@@ -30,8 +30,8 @@ const kOperations = [];
const readBytes = new Uint8Array(readSharedArrayBuffer);
return readBytes;
},
assertRejection: (testCase, file, readBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError',
assertRejection: async (testCase, file, readBytes) => {
await promise_rejects_dom(testCase, 'InvalidStateError',
file.read(readBytes, 4));
},
assertUnchanged: (readBytes) => {
......@@ -48,8 +48,8 @@ const kOperations = [];
writtenBytes.set([96, 97, 98, 99]);
return writtenBytes;
},
assertRejection: (testCase, file, writtenBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError',
assertRejection: async (testCase, file, writtenBytes) => {
await promise_rejects_dom(testCase, 'InvalidStateError',
file.write(writtenBytes, 4));
},
assertUnchanged: () => {},
......@@ -59,8 +59,8 @@ const kOperations = [];
const kOpGetLength = {
name: 'getLength',
prepare: () => {},
assertRejection: (testCase, file) => {
return promise_rejects_dom(testCase, 'InvalidStateError',
assertRejection: async (testCase, file) => {
await promise_rejects_dom(testCase, 'InvalidStateError',
file.getLength());
},
assertUnchanged: () => {},
......@@ -82,7 +82,7 @@ const kOperations = [];
name: 'setLength',
prepare: () => {},
assertRejection: async (testCase, file, readBytes) => {
return promise_rejects_dom(testCase, 'InvalidStateError',
await promise_rejects_dom(testCase, 'InvalidStateError',
file.setLength(2));
},
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