diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js index 1ee0e39..214d16a 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js @@ -106,11 +106,12 @@ const oldMods = kitchenState(modsKey); if (oldMods) { + // No migration! return oldMods; } - // In case of migration or first install. - const [err, mods, ...warns] = createPacModifiers( kitchenState(modsKey) ); + // In case of first install. + const [err, mods, ...warns] = createPacModifiers(); if (err) { throw err; } @@ -154,7 +155,6 @@ }); - console.log('Input mods:', mods); const self = {}; Object.assign(self, getDefaults(), mods); self.ifNoMods = ifNoMods; diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/test/pac-kitchen.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/test/pac-kitchen.js index 5d286a5..1cb7c0b 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/test/pac-kitchen.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/test/pac-kitchen.js @@ -1,6 +1,5 @@ 'use strict'; -const Chrome = require('sinon-chrome'); const Storage = require('_project-root/tools/sinon-storage'); const Chai = require('chai'); const Mocha = require('mocha'); @@ -9,25 +8,67 @@ const CachelessRequire = require('_project-root/tools/cacheless-require')(module Mocha.describe('window.apis.pacKitchen', function () { - Mocha.beforeEach(function() { - global.chrome = Chrome; + global.chrome = CachelessRequire('sinon-chrome/extensions'); global.window = { - chrome: Chrome, + chrome: global.chrome, localStorage: new Storage(), }; CachelessRequire('../00-init-apis.js'); }); - Mocha.it('is evaluated and defined', function () { + Mocha.it('is exported with correct default values', function () { CachelessRequire('../35-pac-kitchen-api.js'); Chai.expect(window.apis.pacKitchen, 'to be exported as global').to.exist; const mods = window.apis.pacKitchen.getPacMods(); - Chai.expect(mods, 'expose default configs on first run').to.exist; + Chai.expect( + mods, 'to expose default configs on first run' + ).to.exist; + Chai.expect(mods.ifNoMods, 'to impose modifications by default (prohibits DIRECT)').to.be.false; + + const orderedMods = window.apis.pacKitchen.getOrderedConfigs(); + Chai.expect(orderedMods, 'to have method for getting ordered configs').to.exist; + { + const several = 9; + Chai.expect(orderedMods.length, 'to have several ordered configs').to.be.above(several); + } + + Chai.expect( + Object.keys(mods).length, + 'pacModifiers to inherit default configs keys as props and add extra props' + ).to.be.above(orderedMods.length); + + Chai.expect( + orderedMods.every((mod) => mods[mod.key] === mod.dflt), + 'all configs to be default on first run' + ).to.be.ok; + + const excMods = window.apis.pacKitchen.getOrderedConfigs('exceptions'); + Chai.expect(excMods.length, 'to have several ordered mods under category "exceptions"').to.be.above(0); + + const proxyMods = window.apis.pacKitchen.getOrderedConfigs('ownProxies'); + Chai.expect(proxyMods.length, 'to have several ordered mods under category "ownProxies"').to.be.above(0); + + const generalMods = window.apis.pacKitchen.getOrderedConfigs('general'); + Chai.expect(generalMods.length, 'to have several ordered mods without category').to.be.above(0); + + Chai.expect( + orderedMods.length, 'to be a sum of categorized (and ordered) mods' + ).to.be.equal( + proxyMods.length + excMods.length + generalMods.length + ); + + }); + + Mocha.it('is installed (by modifying `chrome.proxy.settings.set`)', function () { + + CachelessRequire('../35-pac-kitchen-api.js'); + Chai.expect(originalSet.notCalled, 'original set not to be called during install').to.be.true; + //Chai.expect(originalSet, 'settings.set to be modified').not.to.be.equal(window.chrome.proxy.settings.set); }); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/test/utils.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/test/utils.js index ab37402..afb7341 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/test/utils.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/test/utils.js @@ -15,7 +15,7 @@ Mocha.describe('window.utils', function () { }); - Mocha.it('exports as global', function () { + Mocha.it('is exported as global', function () { CachelessRequire(initApis); Chai.expect(window.utils, 'to be exported as global').to.exist;