diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 5a03b3e7..5588aa7f 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -1,4 +1,4 @@ -/* globals tryWorker: true */ +/* globals tryTests: true */ 'use strict'; @@ -403,7 +403,7 @@ describe('OpenPGP.js public api tests', function() { }); describe('encrypt, decrypt, sign, verify - integration tests', function() { - var privateKey, publicKey, zeroCopyVal, useNativeVal; + var privateKey, publicKey, zeroCopyVal, useNativeVal, aead_protectVal; beforeEach(function() { publicKey = openpgp.key.readArmored(pub_key); @@ -414,11 +414,13 @@ describe('OpenPGP.js public api tests', function() { expect(privateKey.err).to.not.exist; zeroCopyVal = openpgp.config.zeroCopy; useNativeVal = openpgp.config.useNative; + aead_protectVal = openpgp.config.aead_protect; }); afterEach(function() { openpgp.config.zeroCopy = zeroCopyVal; openpgp.config.useNative = useNativeVal; + openpgp.config.aead_protect = aead_protectVal; }); it('Decrypting key with wrong passphrase returns false', function () { @@ -429,13 +431,42 @@ describe('OpenPGP.js public api tests', function() { expect(privateKey.keys[0].decrypt(passphrase)).to.be.true; }); - describe('without Worker', tests); + tryTests('CFB mode (asm.js)', tests, { + if: true, + beforeEach: function() { + openpgp.config.useNative = false; + openpgp.config.aead_protect = false; + } + }); - tryWorker('with Worker', tests, function() { - openpgp.config.useNative = false; - openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); - }, function() { - openpgp.destroyWorker(); // cleanup worker in case of failure + tryTests('CFB mode (asm.js, worker)', tests, { + if: typeof window !== 'undefined' && window.Worker, + before: function() { + openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); + }, + beforeEach: function() { + openpgp.config.useNative = false; + openpgp.config.aead_protect = false; + }, + after: function() { + openpgp.destroyWorker(); + } + }); + + tryTests('GCM mode (asm.js)', tests, { + if: true, + beforeEach: function() { + openpgp.config.useNative = false; + openpgp.config.aead_protect = true; + } + }); + + tryTests('GCM mode (native)', tests, { + if: openpgp.util.getWebCrypto(), + beforeEach: function() { + openpgp.config.useNative = true; + openpgp.config.aead_protect = true; + } }); function tests() { diff --git a/test/unittests.js b/test/unittests.js index 9ed7383a..6af30273 100644 --- a/test/unittests.js +++ b/test/unittests.js @@ -6,17 +6,19 @@ return new Promise(function(res, rej) { rej(val); }); }; -(typeof window !== 'undefined' ? window : global).tryWorker = function(name, tests, beforeFn, afterFn) { - if (typeof window !== 'undefined' && window.Worker) { +(typeof window !== 'undefined' ? window : global).tryTests = function(name, tests, options) { + if (options.if) { describe(name, function() { - before(beforeFn); + if (options.before) { before(options.before); } + if (options.beforeEach) { beforeEach(options.beforeEach); } tests(); - after(afterFn); + if (options.afterEach) { afterEach(options.afterEach); } + if (options.after) { after(options.after); } }); } else { - describe.skip(name + ' (No Web Worker support --> skipping tests)', tests); + describe.skip(name + ' (no support --> skipping tests)', tests); } }; diff --git a/test/worker/async_proxy.js b/test/worker/async_proxy.js index 66170871..c90bd71b 100644 --- a/test/worker/async_proxy.js +++ b/test/worker/async_proxy.js @@ -1,4 +1,4 @@ -/* globals tryWorker: true */ +/* globals tryTests: true */ 'use strict'; @@ -35,11 +35,15 @@ var pub_key = var plaintext = 'short message\nnext line\n한국어/조선말'; var pubKey; -tryWorker('Async Proxy', tests, function() { - openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); - pubKey = openpgp.key.readArmored(pub_key).keys[0]; -}, function() { - openpgp.destroyWorker(); +tryTests('Async Proxy', tests, { + if: typeof window !== 'undefined' && window.Worker, + before: function() { + openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); + pubKey = openpgp.key.readArmored(pub_key).keys[0]; + }, + after: function() { + openpgp.destroyWorker(); + } }); function tests() {