diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /toolkit/components/places/tests/head_common.js | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/head_common.js')
-rw-r--r-- | toolkit/components/places/tests/head_common.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index d7a465786e..22d89db139 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -169,7 +169,6 @@ function readFileData(aFile) { } return bytes; } - /** * Reads the data from the named file, verifying the expected file length. * @@ -187,6 +186,42 @@ function readFileOfLength(aFileName, aExpectedLength) { } /** + * Reads the data from the specified nsIFile, then returns it as data URL. + * + * @param file + * The nsIFile to read from. + * @param mimeType + * The mime type of the file content. + * @return Promise that retunes data URL. + */ +async function readFileDataAsDataURL(file, mimeType) { + const data = readFileData(file); + return fileDataToDataURL(data, mimeType); +} + +/** + * Converts the given data to the data URL. + * + * @param data + * The file data. + * @param mimeType + * The mime type of the file content. + * @return Promise that retunes data URL. + */ +async function fileDataToDataURL(data, mimeType) { + const dataURL = await new Promise(resolve => { + const buffer = new Uint8ClampedArray(data); + const blob = new Blob([buffer], { type: mimeType }); + const reader = new FileReader(); + reader.onload = e => { + resolve(e.target.result); + }; + reader.readAsDataURL(blob); + }); + return dataURL; +} + +/** * Returns the base64-encoded version of the given string. This function is * similar to window.btoa, but is available to xpcshell tests also. * |