diff options
author | Maximilian Krambach <[email protected]> | 2019-06-19 10:57:20 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2019-06-19 10:58:44 +0000 |
commit | f5e27a12d3fd22b95e83c03a5650659bfa2299b9 (patch) | |
tree | 7ddac98f4f0a20ffc6d6a2aaf2ec25ddd5a7efd3 /lang/js/unittests.js | |
parent | Post release updates (diff) | |
download | gpgme-f5e27a12d3fd22b95e83c03a5650659bfa2299b9.tar.gz gpgme-f5e27a12d3fd22b95e83c03a5650659bfa2299b9.zip |
js: Error handling for browser errors
--
* Connection.js
- Add some meaningful nativeMessaging feedback for failing
communication due to misconfiguration or other browser-originated
fails
- add an "isDisconnected" property
- "isNativeHostUnknown" tries to match browser's feedback string if
the browser does not find gpgme-json
* init.js
- initialization will now reject with a more meaningful error if the
configuration is not set up or other browser-based errors
(chrome.runtime.lastError) are present. This should speed up
the normal initialization (not having to waiting for a timeout
any more in case of improper setup)
* errors.js
- CONN_NATIVEMESSAGE: New error that passes the browser's
nativeMessaging error
- CONN_NO_CONFIG: native messaging error indicating that the
nativeMessaging host was not set up properly
* unittests.js:
- added the "isDisconnected" property to the startup tests
- added tests for proper behavior of connection checks
Diffstat (limited to 'lang/js/unittests.js')
-rw-r--r-- | lang/js/unittests.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lang/js/unittests.js b/lang/js/unittests.js index 414d18d1..45e2b93c 100644 --- a/lang/js/unittests.js +++ b/lang/js/unittests.js @@ -49,11 +49,42 @@ function unittests (){ expect(answer.info).to.be.an('Array'); expect(conn0.disconnect).to.be.a('function'); expect(conn0.post).to.be.a('function'); + expect(conn0.isDisconnected).to.be.false; done(); }); }); + it('Simple connection check', function (done) { + let conn0 = new Connection; + conn0.checkConnection(false, connectionTimeout).then( + function (answer) { + expect(answer).to.be.true; + expect(conn0.isDisconnected).to.be.false; + done(); + }); + }); + + it('Connection check with backend information', function (done) { + let conn0 = new Connection; + conn0.checkConnection(true, connectionTimeout).then( + function (answer) { + expect(answer).to.be.an('Object'); + expect(answer.gpgme).to.be.a('String'); + expect(answer.info).to.be.an('Array'); + expect(answer.info.length).to.be.above(0); + for (const item of answer.info) { + expect(item).to.have.property('protocol'); + expect(item).to.have.property('fname'); + expect(item).to.have.property('version'); + expect(item).to.have.property('req_version'); + expect(item).to.have.property('homedir'); + } + expect(conn0.isDisconnected).to.be.false; + done(); + }); + }); + it('Disconnecting', function (done) { let conn0 = new Connection; conn0.checkConnection(false, connectionTimeout).then( @@ -63,6 +94,7 @@ function unittests (){ conn0.checkConnection(false, connectionTimeout).then( function (result) { expect(result).to.be.false; + expect(conn0.isDisconnected).to.be.true; done(); }); }); |