Fetch sender certificates on-demand
This commit is contained in:
parent
6ff55914f0
commit
a82fa86176
19 changed files with 752 additions and 298 deletions
51
ts/test-electron/util/waitForOnline_test.ts
Normal file
51
ts/test-electron/util/waitForOnline_test.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { waitForOnline } from '../../util/waitForOnline';
|
||||
|
||||
describe('waitForOnline', () => {
|
||||
function getFakeWindow(): EventTarget {
|
||||
const result = new EventTarget();
|
||||
sinon.stub(result, 'addEventListener');
|
||||
sinon.stub(result, 'removeEventListener');
|
||||
return result;
|
||||
}
|
||||
|
||||
it("resolves immediately if you're online", async () => {
|
||||
const fakeNavigator = { onLine: true };
|
||||
const fakeWindow = getFakeWindow();
|
||||
|
||||
await waitForOnline(fakeNavigator, fakeWindow);
|
||||
|
||||
sinon.assert.notCalled(fakeWindow.addEventListener as sinon.SinonStub);
|
||||
sinon.assert.notCalled(fakeWindow.removeEventListener as sinon.SinonStub);
|
||||
});
|
||||
|
||||
it("if you're offline, resolves as soon as you're online", async () => {
|
||||
const fakeNavigator = { onLine: false };
|
||||
const fakeWindow = getFakeWindow();
|
||||
|
||||
(fakeWindow.addEventListener as sinon.SinonStub)
|
||||
.withArgs('online')
|
||||
.callsFake((_eventName: string, callback: () => void) => {
|
||||
setTimeout(callback, 0);
|
||||
});
|
||||
|
||||
let done = false;
|
||||
const promise = (async () => {
|
||||
await waitForOnline(fakeNavigator, fakeWindow);
|
||||
done = true;
|
||||
})();
|
||||
|
||||
assert.isFalse(done);
|
||||
|
||||
await promise;
|
||||
|
||||
assert.isTrue(done);
|
||||
sinon.assert.calledOnce(fakeWindow.addEventListener as sinon.SinonStub);
|
||||
sinon.assert.calledOnce(fakeWindow.removeEventListener as sinon.SinonStub);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue