Bug 1600058 - [remote] Implement IO.close. r=remote-protocol-reviewers,ato,maja_zf

Differential Revision: https://phabricator.services.mozilla.com/D55969

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2019-12-16 16:19:02 +00:00
Родитель 5a966347fc
Коммит ce07f3fba4
4 изменённых файлов: 75 добавлений и 0 удалений

Просмотреть файл

@ -29,6 +29,23 @@ const streamRegistry = new StreamRegistry();
class IO extends Domain {
// commands
/**
* Close the stream, discard any temporary backing storage.
*
* @param {Object} options
* @param {string} options.handle
* Handle of the stream to close.
*/
async close(options) {
const { handle } = options;
if (typeof handle != "string") {
throw new TypeError(`handle: string value expected`);
}
await streamRegistry.remove(handle);
}
/**
* Read a chunk of the stream.
*

Просмотреть файл

@ -7,4 +7,5 @@ support-files =
!/remote/test/browser/chrome-remote-interface.js
!/remote/test/browser/head.js
[browser_close.js]
[browser_read.js]

Просмотреть файл

@ -0,0 +1,40 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function fileRemovedAfterClose({ IO }) {
const contents = "Lorem ipsum";
const { handle, path } = await registerFileStream(contents);
await IO.close({ handle });
ok(!(await OS.File.exists(path)), "Discarded the temporary backing storage");
});
add_task(async function unknownHandle({ IO }) {
const handle = "1000000";
try {
await IO.close({ handle });
ok(false, "Close shouldn't pass");
} catch (e) {
ok(
e.message.startsWith(`Invalid stream handle`),
"Error contains expected message"
);
}
});
add_task(async function invalidHandleTypes({ IO }) {
for (const handle of [null, true, 1, [], {}]) {
try {
await IO.close({ handle });
ok(false, "Close shouldn't pass");
} catch (e) {
ok(
e.message.startsWith(`handle: string value expected`),
"Error contains expected message"
);
}
}
});

Просмотреть файл

@ -67,6 +67,23 @@ add_task(async function readBySize({ IO }) {
}
});
add_task(async function readAfterClose({ IO }) {
const contents = "Lorem ipsum";
const { handle } = await registerFileStream(contents);
await IO.close({ handle });
try {
await IO.read({ handle });
ok(false, "Read shouldn't pass");
} catch (e) {
ok(
e.message.startsWith(`Invalid stream handle`),
"Error contains expected message"
);
}
});
add_task(async function unknownHandle({ IO }) {
const handle = "1000000";