2019-03-28 08:34:31 -05:00
|
|
|
import { setChromeFlags } from '../src/app/chrome-flags';
|
|
|
|
import { config } from '../src/app/config-handler';
|
2019-08-20 04:00:13 -05:00
|
|
|
import { isDevEnv, isLinux, isMac, isWindowsOS } from '../src/common/env';
|
2019-03-28 08:34:31 -05:00
|
|
|
import { app } from './__mocks__/electron';
|
|
|
|
|
2020-03-04 06:19:43 -06:00
|
|
|
jest.mock('../src/app/config-handler', () => {
|
2019-03-28 08:34:31 -05:00
|
|
|
return {
|
2020-03-18 09:20:27 -05:00
|
|
|
CloudConfigDataTypes: {
|
|
|
|
NOT_SET: 'NOT_SET',
|
|
|
|
ENABLED: 'ENABLED',
|
|
|
|
DISABLED: 'DISABLED',
|
|
|
|
},
|
2019-03-28 08:34:31 -05:00
|
|
|
config: {
|
2020-03-04 06:19:43 -06:00
|
|
|
getConfigFields: jest.fn(() => {
|
2019-03-28 08:34:31 -05:00
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
2020-03-18 09:20:27 -05:00
|
|
|
disableThrottling: 'DISABLED',
|
2019-03-28 08:34:31 -05:00
|
|
|
},
|
2020-03-04 06:19:43 -06:00
|
|
|
disableGpu: true,
|
2019-03-28 08:34:31 -05:00
|
|
|
};
|
|
|
|
}),
|
2020-03-18 09:20:27 -05:00
|
|
|
getCloudConfigFields: jest.fn(() => {
|
|
|
|
return {
|
|
|
|
disableThrottling: 'DISABLED',
|
|
|
|
};
|
|
|
|
}),
|
2019-03-28 08:34:31 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../src/common/utils', () => {
|
|
|
|
return {
|
2019-07-04 01:41:29 -05:00
|
|
|
getCommandLineArgs: jest.fn(),
|
2019-03-28 08:34:31 -05:00
|
|
|
compareVersions: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('electron-log');
|
|
|
|
|
|
|
|
describe('chrome flags', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
(isDevEnv as any) = false;
|
|
|
|
(isMac as any) = true;
|
|
|
|
(isWindowsOS as any) = false;
|
2019-08-20 04:00:13 -05:00
|
|
|
(isLinux as any) = false;
|
2020-03-02 23:45:27 -06:00
|
|
|
config.getConfigFields = jest.fn(() => {
|
2019-03-28 08:34:31 -05:00
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
|
|
|
},
|
2020-03-04 06:19:43 -06:00
|
|
|
disableGpu: true,
|
2019-03-28 08:34:31 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call `setChromeFlags` correctly', () => {
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(1, 'auth-negotiate-delegate-whitelist', 'url');
|
|
|
|
expect(spy).nthCalledWith(2, 'auth-server-whitelist', 'whitelist');
|
|
|
|
expect(spy).nthCalledWith(3, 'disable-background-timer-throttling', 'true');
|
|
|
|
expect(spy).nthCalledWith(4, 'disable-d3d11', true);
|
|
|
|
expect(spy).nthCalledWith(5, 'disable-gpu', true);
|
|
|
|
expect(spy).nthCalledWith(6, 'disable-gpu-compositing', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call `setChromeFlags` correctly when `disableGpu` is false', () => {
|
2020-03-02 23:45:27 -06:00
|
|
|
config.getConfigFields = jest.fn(() => {
|
2019-03-28 08:34:31 -05:00
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(1, 'auth-negotiate-delegate-whitelist', 'url');
|
|
|
|
expect(spy).nthCalledWith(2, 'auth-server-whitelist', 'whitelist');
|
|
|
|
expect(spy).nthCalledWith(3, 'disable-background-timer-throttling', 'true');
|
|
|
|
expect(spy).not.nthCalledWith(4);
|
|
|
|
});
|
|
|
|
|
2020-03-18 09:20:27 -05:00
|
|
|
it('should set `disable-renderer-backgrounding` chrome flag correctly when cloud config is ENABLED', () => {
|
|
|
|
config.getConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
|
|
|
disableGpu: false,
|
|
|
|
disableThrottling: 'ENABLED',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
|
|
|
|
expect(spy).not.nthCalledWith(5);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set `disable-renderer-backgrounding` chrome flag correctly when cloud config PMP setting is ENABLED', () => {
|
|
|
|
config.getCloudConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
disableThrottling: 'ENABLED',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(7, 'disable-renderer-backgrounding', 'true');
|
|
|
|
expect(spy).not.nthCalledWith(8);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set `disable-renderer-backgrounding` chrome flag when any one is ENABLED ', () => {
|
|
|
|
config.getConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
|
|
|
disableGpu: false,
|
|
|
|
disableThrottling: 'DISABLED',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
config.getCloudConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
disableThrottling: 'ENABLED',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
|
|
|
|
expect(spy).not.nthCalledWith(5);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set `disable-renderer-backgrounding` chrome flag when PMP is ENABLED', () => {
|
|
|
|
config.getConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
customFlags: {
|
|
|
|
authServerWhitelist: 'url',
|
|
|
|
authNegotiateDelegateWhitelist: 'whitelist',
|
|
|
|
disableGpu: false,
|
|
|
|
disableThrottling: 'ENABLED',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
config.getCloudConfigFields = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
disableThrottling: 'DISABLED',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(4, 'disable-renderer-backgrounding', 'true');
|
|
|
|
expect(spy).not.nthCalledWith(5);
|
|
|
|
});
|
|
|
|
|
2019-03-28 08:34:31 -05:00
|
|
|
describe('`isDevEnv`', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
(isDevEnv as any) = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call `setChromeFlags` correctly', () => {
|
|
|
|
const spy = jest.spyOn(app.commandLine, 'appendSwitch');
|
|
|
|
setChromeFlags();
|
|
|
|
expect(spy).nthCalledWith(1, 'auth-negotiate-delegate-whitelist', 'url');
|
|
|
|
expect(spy).nthCalledWith(2, 'auth-server-whitelist', 'whitelist');
|
|
|
|
expect(spy).nthCalledWith(3, 'disable-background-timer-throttling', 'true');
|
|
|
|
expect(spy).nthCalledWith(4, 'disable-d3d11', true);
|
|
|
|
expect(spy).nthCalledWith(5, 'disable-gpu', true);
|
|
|
|
expect(spy).nthCalledWith(6, 'disable-gpu-compositing', true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|