Uint8Array migration

This commit is contained in:
Fedor Indutny 2021-09-23 17:49:05 -07:00 committed by GitHub
parent daf75190b8
commit 4ef0bf96cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
137 changed files with 2202 additions and 3170 deletions

View file

@ -11,10 +11,7 @@ module.exports = {
globals: {
assert: true,
assertEqualArrayBuffers: true,
getString: true,
hexToArrayBuffer: true,
stringToArrayBuffer: true,
},
parserOptions: {

View file

@ -51,18 +51,6 @@ Whisper.Database.id = 'test';
/*
* global helpers for tests
*/
window.assertEqualArrayBuffers = (ab1, ab2) => {
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
};
window.hexToArrayBuffer = str => {
const ret = new ArrayBuffer(str.length / 2);
const array = new Uint8Array(ret);
for (let i = 0; i < str.length / 2; i += 1) {
array[i] = parseInt(str.substr(i * 2, 2), 16);
}
return ret;
};
function deleteIndexedDB() {
return new Promise((resolve, reject) => {

View file

@ -9,7 +9,7 @@ const { assert } = require('chai');
const { app } = require('electron');
const Attachments = require('../../app/attachments');
const { stringToArrayBuffer } = require('../../ts/util/stringToArrayBuffer');
const Bytes = require('../../ts/Bytes');
const PREFIX_LENGTH = 2;
const NUM_SEPARATORS = 1;
@ -28,7 +28,7 @@ describe('Attachments', () => {
});
it('should write file to disk and return path', async () => {
const input = stringToArrayBuffer('test string');
const input = Bytes.fromString('test string');
const tempDirectory = path.join(
tempRootDirectory,
'Attachments_createWriterForNew'
@ -57,7 +57,7 @@ describe('Attachments', () => {
});
it('should write file to disk on given path and return path', async () => {
const input = stringToArrayBuffer('test string');
const input = Bytes.fromString('test string');
const tempDirectory = path.join(
tempRootDirectory,
'Attachments_createWriterForExisting'
@ -82,7 +82,7 @@ describe('Attachments', () => {
});
it('throws if relative path goes higher than root', async () => {
const input = stringToArrayBuffer('test string');
const input = Bytes.fromString('test string');
const tempDirectory = path.join(
tempRootDirectory,
'Attachments_createWriterForExisting'
@ -124,7 +124,7 @@ describe('Attachments', () => {
Attachments.createName()
);
const fullPath = path.join(tempDirectory, relativePath);
const input = stringToArrayBuffer('test string');
const input = Bytes.fromString('test string');
const inputBuffer = Buffer.from(input);
await fse.ensureFile(fullPath);
@ -260,7 +260,7 @@ describe('Attachments', () => {
Attachments.createName()
);
const fullPath = path.join(tempDirectory, relativePath);
const input = stringToArrayBuffer('test string');
const input = Bytes.fromString('test string');
const inputBuffer = Buffer.from(input);
await fse.ensureFile(fullPath);

View file

@ -6,7 +6,7 @@ const sinon = require('sinon');
const Message = require('../../../js/modules/types/message');
const { SignalService } = require('../../../ts/protobuf');
const { stringToArrayBuffer } = require('../../../ts/util/stringToArrayBuffer');
const Bytes = require('../../../ts/Bytes');
describe('Message', () => {
const logger = {
@ -60,7 +60,7 @@ describe('Message', () => {
attachments: [
{
path: 'ab/abcdefghi',
data: stringToArrayBuffer('Its easy if you try'),
data: Bytes.fromString('Its easy if you try'),
},
],
};
@ -78,9 +78,9 @@ describe('Message', () => {
const writeExistingAttachmentData = attachment => {
assert.equal(attachment.path, 'ab/abcdefghi');
assert.deepEqual(
attachment.data,
stringToArrayBuffer('Its easy if you try')
assert.strictEqual(
Bytes.toString(attachment.data),
'Its easy if you try'
);
};
@ -101,7 +101,7 @@ describe('Message', () => {
{
thumbnail: {
path: 'ab/abcdefghi',
data: stringToArrayBuffer('Its easy if you try'),
data: Bytes.fromString('Its easy if you try'),
},
},
],
@ -126,9 +126,9 @@ describe('Message', () => {
const writeExistingAttachmentData = attachment => {
assert.equal(attachment.path, 'ab/abcdefghi');
assert.deepEqual(
attachment.data,
stringToArrayBuffer('Its easy if you try')
assert.strictEqual(
Bytes.toString(attachment.data),
'Its easy if you try'
);
};
@ -151,7 +151,7 @@ describe('Message', () => {
isProfile: false,
avatar: {
path: 'ab/abcdefghi',
data: stringToArrayBuffer('Its easy if you try'),
data: Bytes.fromString('Its easy if you try'),
},
},
},
@ -177,9 +177,9 @@ describe('Message', () => {
const writeExistingAttachmentData = attachment => {
assert.equal(attachment.path, 'ab/abcdefghi');
assert.deepEqual(
attachment.data,
stringToArrayBuffer('Its easy if you try')
assert.strictEqual(
Bytes.toString(attachment.data),
'Its easy if you try'
);
};
@ -268,7 +268,7 @@ describe('Message', () => {
{
contentType: 'audio/aac',
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
data: stringToArrayBuffer('Its easy if you try'),
data: Bytes.fromString('Its easy if you try'),
fileName: 'test\u202Dfig.exe',
size: 1111,
},
@ -292,12 +292,13 @@ describe('Message', () => {
contact: [],
};
const expectedAttachmentData = stringToArrayBuffer(
'Its easy if you try'
);
const expectedAttachmentData = 'Its easy if you try';
const context = {
writeNewAttachmentData: async attachmentData => {
assert.deepEqual(attachmentData, expectedAttachmentData);
assert.strictEqual(
Bytes.toString(attachmentData),
expectedAttachmentData
);
return 'abc/abcdefg';
},
getRegionCode: () => 'US',

View file

@ -1,23 +0,0 @@
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
require('mocha-testcheck').install();
const { assert } = require('chai');
const SchemaVersion = require('../../../js/modules/types/schema_version');
describe('SchemaVersion', () => {
describe('isValid', () => {
check.it('should return true for positive integers', gen.posInt, input => {
assert.isTrue(SchemaVersion.isValid(input));
});
check.it(
'should return false for any other value',
gen.primitive.suchThat(value => typeof value !== 'number' || value < 0),
input => {
assert.isFalse(SchemaVersion.isValid(input));
}
);
});
});