mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* chore: bump chromium in DEPS to 91.0.4472.5 * chore: rebuild chromium/dcheck.patch with import-patches -3 Mechanical only; no code changes (cherry picked from commit68e369c945) * chore: remove content_browser_main_loop.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153 The function being patched (BrowserMainLoop::MainMessageLoopRun()) no longer exists. NB: if removing this introduces regressions the likely fix will be to add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop() which has similar code and was added at the same time this was removed. (cherry picked from commit5220829748) * chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3 Mechanical only; no code changes (cherry picked from commit7613ca268e) * chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3 Mechanical only; no code changes (cherry picked from commitc0c5f45195) * chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch Mechanical only; no code changes (cherry picked from commitea6f3e096e) * chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3 Mechanical only; no code changes (cherry picked from commit8d9aa4f1f2) * chore: rebuild chromium/ui_gtk_public_header.patch manually no code changes (cherry picked from commit79e84fb72b) * chore: rebuild chromium/web_contents.patch with import-patches -3 Mechanical only; no code changes (cherry picked from commit543fb6dae7) * chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874 This patch has been merged upstream (cherry picked from commitd36de6e2d6) * chore: export patches (cherry picked from commit7c148e9102) * chore: update add_trustedauthclient_to_urlloaderfactory.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969 Sync with removal of render_frame_id_ (cherry picked from commitfd954aefd4) * chore: sync chromium/put_back_deleted_colors_for_autofill.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841 SkColorFromColorId() no longer takes theme, scheme args (cherry picked from commitf676453fb8) * chore: sync chromium/put_back_deleted_colors_for_autofill.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143 Change new calls to GetDarkSchemeColor to fit our patched call signature (cherry picked from commit27c5d9da5e) * chore: update add_trustedauthclient_to_urlloaderfactory.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969 Sync with removal of render_frame_id_ in our mojom (cherry picked from commit285db29015) * chore: update chromium/frame_host_manager.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008 UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool (cherry picked from commit06ac6c5d6a) * chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314 Upstream has removed `history_list_length_` which we were comparing to 0 to calculate our `is_initial_navigation` bool when calling ShouldFork(). ShouldFork() is ours and none of the code paths actually use that param, so this commit removes it altogether. (cherry picked from commit2b0cb2ca2a) * chore: update permissions_to_register Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074 Replace all uses of APIPermission::ID enum with Mojo type (cherry picked from commitbfe55a9c68) * refactor: update return type of PreMainMessageLoopRun() Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153 Used to return void; now returns an int errorcode. Note: 2725153 also has some nice doc updates about Browser's "stages" (cherry picked from commit2622e91c44) * refactor: sync ElectronBrowserMainParts to MainParts changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153 RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop so `BrowserMainLoop::result_code_` is no longer available to us for our exit_code_ pointer. This variable held a dual role: (1) of course, hold the exit code, but also (2) was a nullptr before the message loop was ready, indicating to anyone calling SetExitCode() that we were still in startup and could just exit() without any extra steps. exit_code_ still fulfills these two roles but is now a base::Optional. (cherry picked from commit0497272fab) * chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153 BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been removed; move that work to the new WillRunMainMessageLoop(). (cherry picked from commit77eacd8073) * refactor: stop using CallbackList; it has been removed. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973 (cherry picked from commit4bcf9d58b0) * refactor: update use of threadpools. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408 The upstream code is still in flux (e.g. reverts and re-lands) but the tl;dr for this commit is (1) include thread_pool.h if you're using it and (2) don't instantiate pools directly. (cherry picked from commit4e33ee0ad3) * refactor: remove routing_id from CreateLoaderAndStart Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858 NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart calls std::make_unique<InProgressRequest>, which needs a routing_id. This PR uses the member field `routing_id_` since there's no longer one being passed into CreateLoaderAndStart. (cherry picked from commit70759ad342) * refactor: sync to upstream ParittionOptions churn Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318 PartitionOptions' enums have changed. (cherry picked from commit48f437b478) * refactor: update Manifest::Location usage Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320 tldr: s/Manifest::FOO/ManifestLocation::kFoo/ (cherry picked from commit866e02999a) * update patches (cherry picked from commit4444596af5) * refactor: update extensions::Manifest to upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320 - extensions::Manifest::COMPONENT + extensions::mojom::ManifestLocation::kExternalComponent (cherry picked from commitc97cef7059) * refactor: sync with upstream UrlInfo ctor changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008 UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool (cherry picked from commit7effb909b6) * chore: update invocation of convert_protocol_to_json.py Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623 python3 is being used in parts of the upstream build, but the copy of convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol is not python3-friendly. Node has a py2+3-friendly version of it in its tools directory, so call it instead. (cherry picked from commita237fc9aff) * chore: use extensions::mojom::APIPermissionID Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122 tldr: - extensions::APIPermission::kFoo + extensions::mojom::APIPermissionID::kFoo (cherry picked from commitbf9ef3b636) * chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737 Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function. This is the same change made upstream at https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc (cherry picked from commitc4558b031d) * fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun (cherry picked from commitf509f1b8cc) * chore: Use IDType for permission change subscriptions. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431 tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to be an int; now it's the new SubscriptionId type (which is an IdType64). (cherry picked from commit11608d2745) * chore: sync PowerMonitor code to upstream refactor Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635 tldr: PowerMonitor has been split into PowerStateObserver, PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks posted to consumers who only need notifications for one of those things instead of all of them. (cherry picked from commit2d4c79413b) * chore: use PartitionOptions's new Cookies field Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318 (cherry picked from commitf69e95824f) * Revert "refactor: remove routing_id from CreateLoaderAndStart" This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245. 8c9773b was only a partial fix; reverting to start & try again. (cherry picked from commit96195f845b) * update patches (cherry picked from commit5d64fa28d5) * chore: update chromium/accelerator.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472 tldr: sync patch with upstream renamed variable & macro names. (cherry picked from commitce541697e5) * chore: update chromium/gtk_visibility.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200 tldr: no code changes; just updating the diff to apply cleanly. note: ooh upstream Wayland hacking! (cherry picked from commit6ec5c72878) * chore: update chromium/picture-in-picture.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023 tldr: no code changes; just updating the diff to apply cleanly. (cherry picked from commit8ae0b0d740) * chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573 tldr: no code changes; just updating the diff to apply cleanly. (cherry picked from commitd5b017208b) * chore: export_all_patches (cherry picked from commit218952ec9d) * chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511 tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated, so update the invocation in our patch. (cherry picked from commit6fe734f5ca) * chore: update ElectronBrowserClient w/upstream API Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454 tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer. Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>. (cherry picked from commitb760f7162b) * chore: handle new content::PermissionType::FILE_HANDLING in toV8() Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201 `file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc (cherry picked from commitd9cdb18eb7) * refactor: remove routing_id from CreateLoaderAndStart pt 1 Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858 Part 1: the easiest ones (cherry picked from commit6ee282b27a) * 2796724: Support Python3 https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724 (cherry picked from commitfbf5c04716) * 2668974: WebShare: Implement SharingServicePicker https://chromium-review.googlesource.com/c/chromium/src/+/2668974 (cherry picked from commit74577f2156) * 2802766: Apply modernize-make-unique to media/ https://chromium-review.googlesource.com/c/chromium/src/+/2802766 (cherry picked from commit409328fc38) * 2802823: Apply modernize-make-unique to gpu/ https://chromium-review.googlesource.com/c/chromium/src/+/2802823 (cherry picked from commit43658b0ed3) * 2803041: Apply modernize-make-unique to remaining files https://chromium-review.googlesource.com/c/chromium/src/+/2803041 (cherry picked from commit01f514f537) * 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks https://chromium-review.googlesource.com/c/chromium/src/+/2798873 (cherry picked from commit5384398823) * 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed https://chromium-review.googlesource.com/c/chromium/src/+/2733595 (cherry picked from commitf6cf612ee3) * chore: update patch indices (cherry picked from commitf078eddc2b) * 2795107: Remove unused PermissionRequest IDs. https://chromium-review.googlesource.com/c/chromium/src/+/2795107 (cherry picked from commit93077afbfb) * chore: fixup patch indices (cherry picked from commit8f2abcee38) * PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window https://chromium-review.googlesource.com/c/chromium/src/+/2710023 (cherry picked from commit4a4da7ad6a) * fixup! refactor: remove routing_id from CreateLoaderAndStart (cherry picked from commita1f0bbb0b5) * refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader (cherry picked from commit186528aab9) * fixup! chore: fixup patch indices (cherry picked from commit3129ea403d) * 2724817: Expand scope of wasm-eval to all URLs https://chromium-review.googlesource.com/c/chromium/src/+/2724817 (cherry picked from commitdacbf3d60d) * 2797341: [ozone/x11] Enabled the global shortcut listener. https://chromium-review.googlesource.com/c/chromium/src/+/2797341 (cherry picked from commit945890fcf9) * 2805553: Reland Add GTK ColorMixers to ColorPipeline P1 https://chromium-review.googlesource.com/c/chromium/src/+/2805553 (cherry picked from commitdb74b380fd) *2804366: PiP 1.5: Label back to tab button with origin and center it https://chromium-review.googlesource.com/c/chromium/src/+/2804366 (cherry picked from commitdeca961382) * 2784730: Fix crash on AX mode change in NativeViewHost without a Widget https://chromium-review.googlesource.com/c/chromium/src/+/2784730 (cherry picked from commit0fac051a0c) * chore: update patch indices (cherry picked from commit01235ba336) * 2810174: Add PdfAnnotationsEnabled policy. https://chromium-review.googlesource.com/c/chromium/src/+/2810174 (cherry picked from commitc8a7225cac) * 2807829: Allow capturers to indicate if they want a WakeLock or not. https://chromium-review.googlesource.com/c/chromium/src/+/2807829 (cherry picked from commit39f0c263d7) * update patches after cherry picks * chore: icon_util_x11 is now icon_util_linux Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362 (cherry picked from commitfa0d3a0f75) * build: fix missing symbols on linux build * use_ozone and use_x11 are not exclusive * new button view to build for pip Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341 Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366 (cherry picked from commit28253c6ccc) * chore: remove patch conflict (cherry picked from commit19c9e94014) * chore: build bttlb on all platforms for pip (cherry picked from commitae70252e09) * build: update linux manifests (cherry picked from commit88baf8835c) * chore: update windows zip manifests (cherry picked from commit01a1c37999) * chore: update mac zip manifests (cherry picked from commita203347075) * chore: update is_media_key patch to handle new ozone impl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341 (cherry picked from commit9d31092db8) * build: update sysroots Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496 (cherry picked from commit4985c57685) * build: add missing base include on windows (cherry picked from commitec782c1bde) * fix: update frame host manager patch for new state transitions Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464 (cherry picked from commit2772241a2c) * refactor: implement missing URLLoaderNetworkServiceObserver methods It is against The Mojo Rules to leave hanging callbacks. These always have to be called. Refs:186528aab9(cherry picked from commit2ce2f73a0c) * spec: fix locale test on local linux (cherry picked from commit898f8448f8) * fix: pass the exit code correctly in new PreMainMessageLoopRun Refs:2622e91c44(cherry picked from commitf8f388573c) * fix: ensure we early-exit when request_handler_ is not provided Refs:93077afbfb(cherry picked from commit20cd4cb875) * fix: strongly set result_code in the BrowserMainLoop (cherry picked from commita1d19bc212) * fix: invalid usage of non-targetted PostTask You must always either use a host threadpool or specify a target thread. In this case we did neither after this refactor. Refs:4e33ee0ad3(cherry picked from commit3632067c10) * build: ensure CI is truthy in arm test env (cherry picked from commite455f68b64) * chore: add mojo error code to url loader failure (cherry picked from commit60cc150a17) * fix: handle windowCaptureMacV2 being enabled when fetching media source id Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931 (cherry picked from commitf835dd1c2a) * chore: fix broken gtk_util color patch (cherry picked from commite0720df6d4) * chore: fix gn check (cherry picked from commit72ca89b311) * chore: add node patches for V8 changes (cherry picked from commit96027e0186) * chore: add thread_pool include for views delegate win (cherry picked from commit62faa304df) * chore: remove stray .rej files in patch (cherry picked from commit52562150ca) * chore: bump chromium in DEPS to 91.0.4472.10 * update patches * Merge branch '13-x-y' into roller/chromium/13-x-y * update patches * try to track down WOA failures * see if this helps websql failure * chore: debug websql error on WOA * Revert "chore: debug websql error on WOA" This reverts commit572987a15f. * Revert "see if this helps websql failure" This reverts commitf771dfe0ab. * Revert "try to track down WOA failures" This reverts commitd4eb5efdb3. * chore: no long disable CalculateNativeWinOcclusion on WOA This was resolved in https://chromium-review.googlesource.com/c/chromium/src/+/2478082 * run specs separately on WOA * Update comment * escape % * specify files properly * revert WOA testing changes * chore: bump chromium in DEPS to 91.0.4472.33 * chore: update patches * Trigger CI Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Samuel Attard <sattard@slack-corp.com>
1832 lines
63 KiB
TypeScript
1832 lines
63 KiB
TypeScript
import { expect } from 'chai';
|
|
import * as cp from 'child_process';
|
|
import * as https from 'https';
|
|
import * as http from 'http';
|
|
import * as net from 'net';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { promisify } from 'util';
|
|
import { app, BrowserWindow, Menu, session } from 'electron/main';
|
|
import { emittedOnce } from './events-helpers';
|
|
import { closeWindow, closeAllWindows } from './window-helpers';
|
|
import { ifdescribe, ifit } from './spec-helpers';
|
|
import split = require('split')
|
|
|
|
const features = process._linkedBinding('electron_common_features');
|
|
|
|
const fixturesPath = path.resolve(__dirname, '../spec/fixtures');
|
|
|
|
describe('electron module', () => {
|
|
it('does not expose internal modules to require', () => {
|
|
expect(() => {
|
|
require('clipboard');
|
|
}).to.throw(/Cannot find module 'clipboard'/);
|
|
});
|
|
|
|
describe('require("electron")', () => {
|
|
it('always returns the internal electron module', () => {
|
|
require('electron');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('app module', () => {
|
|
let server: https.Server;
|
|
let secureUrl: string;
|
|
const certPath = path.join(fixturesPath, 'certificates');
|
|
|
|
before((done) => {
|
|
const options = {
|
|
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
|
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
|
ca: [
|
|
fs.readFileSync(path.join(certPath, 'rootCA.pem')),
|
|
fs.readFileSync(path.join(certPath, 'intermediateCA.pem'))
|
|
],
|
|
requestCert: true,
|
|
rejectUnauthorized: false
|
|
};
|
|
|
|
server = https.createServer(options, (req, res) => {
|
|
if ((req as any).client.authorized) {
|
|
res.writeHead(200);
|
|
res.end('<title>authorized</title>');
|
|
} else {
|
|
res.writeHead(401);
|
|
res.end('<title>denied</title>');
|
|
}
|
|
});
|
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
const port = (server.address() as net.AddressInfo).port;
|
|
secureUrl = `https://127.0.0.1:${port}`;
|
|
done();
|
|
});
|
|
});
|
|
|
|
after(done => {
|
|
server.close(() => done());
|
|
});
|
|
|
|
describe('app.getVersion()', () => {
|
|
it('returns the version field of package.json', () => {
|
|
expect(app.getVersion()).to.equal('0.1.0');
|
|
});
|
|
});
|
|
|
|
describe('app.setVersion(version)', () => {
|
|
it('overrides the version', () => {
|
|
expect(app.getVersion()).to.equal('0.1.0');
|
|
app.setVersion('test-version');
|
|
|
|
expect(app.getVersion()).to.equal('test-version');
|
|
app.setVersion('0.1.0');
|
|
});
|
|
});
|
|
|
|
describe('app name APIs', () => {
|
|
it('with properties', () => {
|
|
it('returns the name field of package.json', () => {
|
|
expect(app.name).to.equal('Electron Test Main');
|
|
});
|
|
|
|
it('overrides the name', () => {
|
|
expect(app.name).to.equal('Electron Test Main');
|
|
app.name = 'test-name';
|
|
|
|
expect(app.name).to.equal('test-name');
|
|
app.name = 'Electron Test Main';
|
|
});
|
|
});
|
|
|
|
it('with functions', () => {
|
|
it('returns the name field of package.json', () => {
|
|
expect(app.getName()).to.equal('Electron Test Main');
|
|
});
|
|
|
|
it('overrides the name', () => {
|
|
expect(app.getName()).to.equal('Electron Test Main');
|
|
app.setName('test-name');
|
|
|
|
expect(app.getName()).to.equal('test-name');
|
|
app.setName('Electron Test Main');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('app.getLocale()', () => {
|
|
it('should not be empty', () => {
|
|
expect(app.getLocale()).to.not.equal('');
|
|
});
|
|
});
|
|
|
|
describe('app.getLocaleCountryCode()', () => {
|
|
it('should be empty or have length of two', () => {
|
|
let expectedLength = 2;
|
|
if (process.platform === 'linux' && process.env.CI) {
|
|
// Linux CI machines have no locale.
|
|
expectedLength = 0;
|
|
}
|
|
expect(app.getLocaleCountryCode()).to.be.a('string').and.have.lengthOf(expectedLength);
|
|
});
|
|
});
|
|
|
|
describe('app.isPackaged', () => {
|
|
it('should be false durings tests', () => {
|
|
expect(app.isPackaged).to.equal(false);
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform === 'darwin')('app.isInApplicationsFolder()', () => {
|
|
it('should be false during tests', () => {
|
|
expect(app.isInApplicationsFolder()).to.equal(false);
|
|
});
|
|
});
|
|
|
|
describe('app.exit(exitCode)', () => {
|
|
let appProcess: cp.ChildProcess | null = null;
|
|
|
|
afterEach(() => {
|
|
if (appProcess) appProcess.kill();
|
|
});
|
|
|
|
it('emits a process exit event with the code', async () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'quit-app');
|
|
const electronPath = process.execPath;
|
|
let output = '';
|
|
|
|
appProcess = cp.spawn(electronPath, [appPath]);
|
|
if (appProcess && appProcess.stdout) {
|
|
appProcess.stdout.on('data', data => { output += data; });
|
|
}
|
|
const [code] = await emittedOnce(appProcess, 'exit');
|
|
|
|
if (process.platform !== 'win32') {
|
|
expect(output).to.include('Exit event with code: 123');
|
|
}
|
|
expect(code).to.equal(123);
|
|
});
|
|
|
|
it('closes all windows', async function () {
|
|
const appPath = path.join(fixturesPath, 'api', 'exit-closes-all-windows-app');
|
|
const electronPath = process.execPath;
|
|
|
|
appProcess = cp.spawn(electronPath, [appPath]);
|
|
const [code, signal] = await emittedOnce(appProcess, 'exit');
|
|
|
|
expect(signal).to.equal(null, 'exit signal should be null, if you see this please tag @MarshallOfSound');
|
|
expect(code).to.equal(123, 'exit code should be 123, if you see this please tag @MarshallOfSound');
|
|
});
|
|
|
|
it('exits gracefully', async function () {
|
|
if (!['darwin', 'linux'].includes(process.platform)) {
|
|
this.skip();
|
|
return;
|
|
}
|
|
|
|
const electronPath = process.execPath;
|
|
const appPath = path.join(fixturesPath, 'api', 'singleton');
|
|
appProcess = cp.spawn(electronPath, [appPath]);
|
|
|
|
// Singleton will send us greeting data to let us know it's running.
|
|
// After that, ask it to exit gracefully and confirm that it does.
|
|
if (appProcess && appProcess.stdout) {
|
|
appProcess.stdout.on('data', () => appProcess!.kill());
|
|
}
|
|
const [code, signal] = await emittedOnce(appProcess, 'exit');
|
|
|
|
const message = `code:\n${code}\nsignal:\n${signal}`;
|
|
expect(code).to.equal(0, message);
|
|
expect(signal).to.equal(null, message);
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform === 'darwin')('app.setActivationPolicy', () => {
|
|
it('throws an error on invalid application policies', () => {
|
|
expect(() => {
|
|
app.setActivationPolicy('terrible' as any);
|
|
}).to.throw(/Invalid activation policy: must be one of 'regular', 'accessory', or 'prohibited'/);
|
|
});
|
|
});
|
|
|
|
describe('app.requestSingleInstanceLock', () => {
|
|
it('prevents the second launch of app', async function () {
|
|
this.timeout(120000);
|
|
const appPath = path.join(fixturesPath, 'api', 'singleton');
|
|
const first = cp.spawn(process.execPath, [appPath]);
|
|
await emittedOnce(first.stdout, 'data');
|
|
// Start second app when received output.
|
|
const second = cp.spawn(process.execPath, [appPath]);
|
|
const [code2] = await emittedOnce(second, 'exit');
|
|
expect(code2).to.equal(1);
|
|
const [code1] = await emittedOnce(first, 'exit');
|
|
expect(code1).to.equal(0);
|
|
});
|
|
|
|
it('passes arguments to the second-instance event', async () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'singleton');
|
|
const first = cp.spawn(process.execPath, [appPath]);
|
|
const firstExited = emittedOnce(first, 'exit');
|
|
|
|
// Wait for the first app to boot.
|
|
const firstStdoutLines = first.stdout.pipe(split());
|
|
while ((await emittedOnce(firstStdoutLines, 'data')).toString() !== 'started') {
|
|
// wait.
|
|
}
|
|
const data2Promise = emittedOnce(firstStdoutLines, 'data');
|
|
|
|
const secondInstanceArgs = [process.execPath, appPath, '--some-switch', 'some-arg'];
|
|
const second = cp.spawn(secondInstanceArgs[0], secondInstanceArgs.slice(1));
|
|
const [code2] = await emittedOnce(second, 'exit');
|
|
expect(code2).to.equal(1);
|
|
const [code1] = await firstExited;
|
|
expect(code1).to.equal(0);
|
|
const data2 = (await data2Promise)[0].toString('ascii');
|
|
const secondInstanceArgsReceived: string[] = JSON.parse(data2.toString('ascii'));
|
|
const expected = process.platform === 'win32'
|
|
? [process.execPath, '--some-switch', '--allow-file-access-from-files', appPath, 'some-arg']
|
|
: secondInstanceArgs;
|
|
expect(secondInstanceArgsReceived).to.eql(expected,
|
|
`expected ${JSON.stringify(expected)} but got ${data2.toString('ascii')}`);
|
|
});
|
|
});
|
|
|
|
describe('app.relaunch', () => {
|
|
let server: net.Server | null = null;
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch';
|
|
|
|
beforeEach(done => {
|
|
fs.unlink(socketPath, () => {
|
|
server = net.createServer();
|
|
server.listen(socketPath);
|
|
done();
|
|
});
|
|
});
|
|
|
|
afterEach((done) => {
|
|
server!.close(() => {
|
|
if (process.platform === 'win32') {
|
|
done();
|
|
} else {
|
|
fs.unlink(socketPath, () => done());
|
|
}
|
|
});
|
|
});
|
|
|
|
it('relaunches the app', function (done) {
|
|
this.timeout(120000);
|
|
|
|
let state = 'none';
|
|
server!.once('error', error => done(error));
|
|
server!.on('connection', client => {
|
|
client.once('data', data => {
|
|
if (String(data) === 'false' && state === 'none') {
|
|
state = 'first-launch';
|
|
} else if (String(data) === 'true' && state === 'first-launch') {
|
|
done();
|
|
} else {
|
|
done(`Unexpected state: "${state}", data: "${data}"`);
|
|
}
|
|
});
|
|
});
|
|
|
|
const appPath = path.join(fixturesPath, 'api', 'relaunch');
|
|
const child = cp.spawn(process.execPath, [appPath]);
|
|
child.stdout.on('data', (c) => console.log(c.toString()));
|
|
child.stderr.on('data', (c) => console.log(c.toString()));
|
|
child.on('exit', (code, signal) => {
|
|
if (code !== 0) {
|
|
console.log(`Process exited with code "${code}" signal "${signal}"`);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('app.setUserActivity(type, userInfo)', () => {
|
|
before(function () {
|
|
if (process.platform !== 'darwin') {
|
|
this.skip();
|
|
}
|
|
});
|
|
|
|
it('sets the current activity', () => {
|
|
app.setUserActivity('com.electron.testActivity', { testData: '123' });
|
|
expect(app.getCurrentActivityType()).to.equal('com.electron.testActivity');
|
|
});
|
|
});
|
|
|
|
describe('certificate-error event', () => {
|
|
afterEach(closeAllWindows);
|
|
it('is emitted when visiting a server with a self-signed cert', async () => {
|
|
const w = new BrowserWindow({ show: false });
|
|
w.loadURL(secureUrl);
|
|
await emittedOnce(app, 'certificate-error');
|
|
});
|
|
});
|
|
|
|
// xdescribe('app.importCertificate', () => {
|
|
// let w = null
|
|
|
|
// before(function () {
|
|
// if (process.platform !== 'linux') {
|
|
// this.skip()
|
|
// }
|
|
// })
|
|
|
|
// afterEach(() => closeWindow(w).then(() => { w = null }))
|
|
|
|
// it('can import certificate into platform cert store', done => {
|
|
// const options = {
|
|
// certificate: path.join(certPath, 'client.p12'),
|
|
// password: 'electron'
|
|
// }
|
|
|
|
// w = new BrowserWindow({
|
|
// show: false,
|
|
// webPreferences: {
|
|
// nodeIntegration: true
|
|
// }
|
|
// })
|
|
|
|
// w.webContents.on('did-finish-load', () => {
|
|
// expect(w.webContents.getTitle()).to.equal('authorized')
|
|
// done()
|
|
// })
|
|
|
|
// ipcRenderer.once('select-client-certificate', (event, webContentsId, list) => {
|
|
// expect(webContentsId).to.equal(w.webContents.id)
|
|
// expect(list).to.have.lengthOf(1)
|
|
|
|
// expect(list[0]).to.deep.equal({
|
|
// issuerName: 'Intermediate CA',
|
|
// subjectName: 'Client Cert',
|
|
// issuer: { commonName: 'Intermediate CA' },
|
|
// subject: { commonName: 'Client Cert' }
|
|
// })
|
|
|
|
// event.sender.send('client-certificate-response', list[0])
|
|
// })
|
|
|
|
// app.importCertificate(options, result => {
|
|
// expect(result).toNotExist()
|
|
// ipcRenderer.sendSync('set-client-certificate-option', false)
|
|
// w.loadURL(secureUrl)
|
|
// })
|
|
// })
|
|
// })
|
|
|
|
describe('BrowserWindow events', () => {
|
|
let w: BrowserWindow = null as any;
|
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null as any; }));
|
|
|
|
it('should emit browser-window-focus event when window is focused', async () => {
|
|
const emitted = emittedOnce(app, 'browser-window-focus');
|
|
w = new BrowserWindow({ show: false });
|
|
w.emit('focus');
|
|
const [, window] = await emitted;
|
|
expect(window.id).to.equal(w.id);
|
|
});
|
|
|
|
it('should emit browser-window-blur event when window is blured', async () => {
|
|
const emitted = emittedOnce(app, 'browser-window-blur');
|
|
w = new BrowserWindow({ show: false });
|
|
w.emit('blur');
|
|
const [, window] = await emitted;
|
|
expect(window.id).to.equal(w.id);
|
|
});
|
|
|
|
it('should emit browser-window-created event when window is created', async () => {
|
|
const emitted = emittedOnce(app, 'browser-window-created');
|
|
w = new BrowserWindow({ show: false });
|
|
const [, window] = await emitted;
|
|
expect(window.id).to.equal(w.id);
|
|
});
|
|
|
|
it('should emit web-contents-created event when a webContents is created', async () => {
|
|
const emitted = emittedOnce(app, 'web-contents-created');
|
|
w = new BrowserWindow({ show: false });
|
|
const [, webContents] = await emitted;
|
|
expect(webContents.id).to.equal(w.webContents.id);
|
|
});
|
|
|
|
// FIXME: re-enable this test on win32.
|
|
ifit(process.platform !== 'win32')('should emit renderer-process-crashed event when renderer crashes', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const emitted = emittedOnce(app, 'renderer-process-crashed');
|
|
w.webContents.executeJavaScript('process.crash()');
|
|
|
|
const [, webContents] = await emitted;
|
|
expect(webContents).to.equal(w.webContents);
|
|
});
|
|
|
|
// FIXME: re-enable this test on win32.
|
|
ifit(process.platform !== 'win32')('should emit render-process-gone event when renderer crashes', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const emitted = emittedOnce(app, 'render-process-gone');
|
|
w.webContents.executeJavaScript('process.crash()');
|
|
|
|
const [, webContents, details] = await emitted;
|
|
expect(webContents).to.equal(w.webContents);
|
|
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
|
|
});
|
|
|
|
ifdescribe(features.isDesktopCapturerEnabled())('desktopCapturer module filtering', () => {
|
|
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'desktop-capturer-get-sources');
|
|
w.webContents.executeJavaScript('require(\'electron\').desktopCapturer.getSources({ types: [\'screen\'] })');
|
|
|
|
const [, webContents] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
});
|
|
});
|
|
|
|
ifdescribe(features.isRemoteModuleEnabled())('remote module filtering', () => {
|
|
it('should emit remote-require event when remote.require() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
enableRemoteModule: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'remote-require');
|
|
w.webContents.executeJavaScript('require(\'electron\').remote.require(\'test\')');
|
|
|
|
const [, webContents, moduleName] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
expect(moduleName).to.equal('test');
|
|
});
|
|
|
|
it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
enableRemoteModule: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'remote-get-global');
|
|
w.webContents.executeJavaScript('require(\'electron\').remote.getGlobal(\'test\')');
|
|
|
|
const [, webContents, globalName] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
expect(globalName).to.equal('test');
|
|
});
|
|
|
|
it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
enableRemoteModule: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'remote-get-builtin');
|
|
w.webContents.executeJavaScript('require(\'electron\').remote.app');
|
|
|
|
const [, webContents, moduleName] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
expect(moduleName).to.equal('app');
|
|
});
|
|
|
|
it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
enableRemoteModule: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'remote-get-current-window');
|
|
w.webContents.executeJavaScript('{ require(\'electron\').remote.getCurrentWindow() }');
|
|
|
|
const [, webContents] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
});
|
|
|
|
it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
enableRemoteModule: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
|
|
const promise = emittedOnce(app, 'remote-get-current-web-contents');
|
|
w.webContents.executeJavaScript('{ require(\'electron\').remote.getCurrentWebContents() }');
|
|
|
|
const [, webContents] = await promise;
|
|
expect(webContents).to.equal(w.webContents);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('app.badgeCount', () => {
|
|
const platformIsNotSupported =
|
|
(process.platform === 'win32') ||
|
|
(process.platform === 'linux' && !app.isUnityRunning());
|
|
|
|
const expectedBadgeCount = 42;
|
|
|
|
after(() => { app.badgeCount = 0; });
|
|
|
|
ifdescribe(!platformIsNotSupported)('on supported platform', () => {
|
|
describe('with properties', () => {
|
|
it('sets a badge count', function () {
|
|
app.badgeCount = expectedBadgeCount;
|
|
expect(app.badgeCount).to.equal(expectedBadgeCount);
|
|
});
|
|
});
|
|
|
|
describe('with functions', () => {
|
|
it('sets a numerical badge count', function () {
|
|
app.setBadgeCount(expectedBadgeCount);
|
|
expect(app.getBadgeCount()).to.equal(expectedBadgeCount);
|
|
});
|
|
it('sets an non numeric (dot) badge count', function () {
|
|
app.setBadgeCount();
|
|
// Badge count should be zero when non numeric (dot) is requested
|
|
expect(app.getBadgeCount()).to.equal(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform !== 'win32' && platformIsNotSupported)('on unsupported platform', () => {
|
|
describe('with properties', () => {
|
|
it('does not set a badge count', function () {
|
|
app.badgeCount = 9999;
|
|
expect(app.badgeCount).to.equal(0);
|
|
});
|
|
});
|
|
|
|
describe('with functions', () => {
|
|
it('does not set a badge count)', function () {
|
|
app.setBadgeCount(9999);
|
|
expect(app.getBadgeCount()).to.equal(0);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform !== 'linux' && !process.mas)('app.get/setLoginItemSettings API', function () {
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
|
|
const processStartArgs = [
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
'--process-start-args', '"--hidden"'
|
|
];
|
|
const regAddArgs = [
|
|
'ADD',
|
|
'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run',
|
|
'/v',
|
|
'additionalEntry',
|
|
'/t',
|
|
'REG_BINARY',
|
|
'/f',
|
|
'/d'
|
|
];
|
|
|
|
beforeEach(() => {
|
|
app.setLoginItemSettings({ openAtLogin: false });
|
|
app.setLoginItemSettings({ openAtLogin: false, path: updateExe, args: processStartArgs });
|
|
app.setLoginItemSettings({ name: 'additionalEntry', openAtLogin: false });
|
|
});
|
|
|
|
afterEach(() => {
|
|
app.setLoginItemSettings({ openAtLogin: false });
|
|
app.setLoginItemSettings({ openAtLogin: false, path: updateExe, args: processStartArgs });
|
|
app.setLoginItemSettings({ name: 'additionalEntry', openAtLogin: false });
|
|
});
|
|
|
|
ifit(process.platform !== 'win32')('sets and returns the app as a login item', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('sets and returns the app as a login item (windows)', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, enabled: true });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
});
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false });
|
|
app.setLoginItemSettings({ openAtLogin: true, enabled: false });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: false,
|
|
launchItems: [{
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: false
|
|
}]
|
|
});
|
|
});
|
|
|
|
ifit(process.platform !== 'win32')('adds a login item that loads in hidden mode', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: process.platform === 'darwin' && !process.mas, // Only available on macOS
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('adds a login item that loads in hidden mode (windows)', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
});
|
|
});
|
|
|
|
it('correctly sets and unsets the LoginItem', function () {
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true });
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(true);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false });
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
|
|
});
|
|
|
|
it('correctly sets and unsets the LoginItem as hidden', function () {
|
|
if (process.platform !== 'darwin') this.skip();
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
|
|
expect(app.getLoginItemSettings().openAsHidden).to.equal(false);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true });
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(true);
|
|
expect(app.getLoginItemSettings().openAsHidden).to.equal(true);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: false });
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(true);
|
|
expect(app.getLoginItemSettings().openAsHidden).to.equal(false);
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('allows you to pass a custom executable and arguments', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, path: updateExe, args: processStartArgs, enabled: true });
|
|
expect(app.getLoginItemSettings().openAtLogin).to.equal(false);
|
|
const openAtLoginTrueEnabledTrue = app.getLoginItemSettings({
|
|
path: updateExe,
|
|
args: processStartArgs
|
|
});
|
|
|
|
expect(openAtLoginTrueEnabledTrue.openAtLogin).to.equal(true);
|
|
expect(openAtLoginTrueEnabledTrue.executableWillLaunchAtLogin).to.equal(true);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, path: updateExe, args: processStartArgs, enabled: false });
|
|
const openAtLoginTrueEnabledFalse = app.getLoginItemSettings({
|
|
path: updateExe,
|
|
args: processStartArgs
|
|
});
|
|
|
|
expect(openAtLoginTrueEnabledFalse.openAtLogin).to.equal(true);
|
|
expect(openAtLoginTrueEnabledFalse.executableWillLaunchAtLogin).to.equal(false);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false, path: updateExe, args: processStartArgs, enabled: false });
|
|
const openAtLoginFalseEnabledFalse = app.getLoginItemSettings({
|
|
path: updateExe,
|
|
args: processStartArgs
|
|
});
|
|
|
|
expect(openAtLoginFalseEnabledFalse.openAtLogin).to.equal(false);
|
|
expect(openAtLoginFalseEnabledFalse.executableWillLaunchAtLogin).to.equal(false);
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('allows you to pass a custom name', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true });
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'additionalEntry',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: false
|
|
}, {
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
});
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false, name: 'additionalEntry' });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: true,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: [],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('finds launch items independent of args', function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, args: ['arg1'] });
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false, args: ['arg2'] });
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: false,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'additionalEntry',
|
|
path: process.execPath,
|
|
args: ['arg2'],
|
|
scope: 'user',
|
|
enabled: false
|
|
}, {
|
|
name: 'electron.app.Electron',
|
|
path: process.execPath,
|
|
args: ['arg1'],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('finds launch items independent of path quotation or casing', function () {
|
|
const expectation = {
|
|
openAtLogin: false,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'additionalEntry',
|
|
path: 'C:\\electron\\myapp.exe',
|
|
args: ['arg1'],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
};
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: true, path: 'C:\\electron\\myapp.exe', args: ['arg1'] });
|
|
expect(app.getLoginItemSettings({ path: '"C:\\electron\\MYAPP.exe"' })).to.deep.equal(expectation);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false, name: 'additionalEntry' });
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: true, path: '"C:\\electron\\MYAPP.exe"', args: ['arg1'] });
|
|
expect(app.getLoginItemSettings({ path: 'C:\\electron\\myapp.exe' })).to.deep.equal({
|
|
...expectation,
|
|
launchItems: [
|
|
{
|
|
name: 'additionalEntry',
|
|
path: 'C:\\electron\\MYAPP.exe',
|
|
args: ['arg1'],
|
|
scope: 'user',
|
|
enabled: true
|
|
}
|
|
]
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('detects disabled by TaskManager', async function () {
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: true, args: ['arg1'] });
|
|
const appProcess = cp.spawn('reg', [...regAddArgs, '030000000000000000000000']);
|
|
await emittedOnce(appProcess, 'exit');
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
openAtLogin: false,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: false,
|
|
launchItems: [{
|
|
name: 'additionalEntry',
|
|
path: process.execPath,
|
|
args: ['arg1'],
|
|
scope: 'user',
|
|
enabled: false
|
|
}]
|
|
});
|
|
});
|
|
|
|
ifit(process.platform === 'win32')('detects enabled by TaskManager', async function () {
|
|
const expectation = {
|
|
openAtLogin: false,
|
|
openAsHidden: false,
|
|
wasOpenedAtLogin: false,
|
|
wasOpenedAsHidden: false,
|
|
restoreState: false,
|
|
executableWillLaunchAtLogin: true,
|
|
launchItems: [{
|
|
name: 'additionalEntry',
|
|
path: process.execPath,
|
|
args: ['arg1'],
|
|
scope: 'user',
|
|
enabled: true
|
|
}]
|
|
};
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false, args: ['arg1'] });
|
|
let appProcess = cp.spawn('reg', [...regAddArgs, '020000000000000000000000']);
|
|
await emittedOnce(appProcess, 'exit');
|
|
expect(app.getLoginItemSettings()).to.deep.equal(expectation);
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false, args: ['arg1'] });
|
|
appProcess = cp.spawn('reg', [...regAddArgs, '000000000000000000000000']);
|
|
await emittedOnce(appProcess, 'exit');
|
|
expect(app.getLoginItemSettings()).to.deep.equal(expectation);
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform !== 'linux')('accessibilitySupportEnabled property', () => {
|
|
it('with properties', () => {
|
|
it('can set accessibility support enabled', () => {
|
|
expect(app.accessibilitySupportEnabled).to.eql(false);
|
|
|
|
app.accessibilitySupportEnabled = true;
|
|
expect(app.accessibilitySupportEnabled).to.eql(true);
|
|
});
|
|
});
|
|
|
|
it('with functions', () => {
|
|
it('can set accessibility support enabled', () => {
|
|
expect(app.isAccessibilitySupportEnabled()).to.eql(false);
|
|
|
|
app.setAccessibilitySupportEnabled(true);
|
|
expect(app.isAccessibilitySupportEnabled()).to.eql(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getAppPath', () => {
|
|
it('works for directories with package.json', async () => {
|
|
const { appPath } = await runTestApp('app-path');
|
|
expect(appPath).to.equal(path.resolve(fixturesPath, 'api/app-path'));
|
|
});
|
|
|
|
it('works for directories with index.js', async () => {
|
|
const { appPath } = await runTestApp('app-path/lib');
|
|
expect(appPath).to.equal(path.resolve(fixturesPath, 'api/app-path/lib'));
|
|
});
|
|
|
|
it('works for files without extension', async () => {
|
|
const { appPath } = await runTestApp('app-path/lib/index');
|
|
expect(appPath).to.equal(path.resolve(fixturesPath, 'api/app-path/lib'));
|
|
});
|
|
|
|
it('works for files', async () => {
|
|
const { appPath } = await runTestApp('app-path/lib/index.js');
|
|
expect(appPath).to.equal(path.resolve(fixturesPath, 'api/app-path/lib'));
|
|
});
|
|
});
|
|
|
|
describe('getPath(name)', () => {
|
|
it('returns paths that exist', () => {
|
|
const paths = [
|
|
fs.existsSync(app.getPath('exe')),
|
|
fs.existsSync(app.getPath('home')),
|
|
fs.existsSync(app.getPath('temp'))
|
|
];
|
|
expect(paths).to.deep.equal([true, true, true]);
|
|
});
|
|
|
|
it('throws an error when the name is invalid', () => {
|
|
expect(() => {
|
|
app.getPath('does-not-exist' as any);
|
|
}).to.throw(/Failed to get 'does-not-exist' path/);
|
|
});
|
|
|
|
it('returns the overridden path', () => {
|
|
app.setPath('music', __dirname);
|
|
expect(app.getPath('music')).to.equal(__dirname);
|
|
});
|
|
|
|
if (process.platform === 'win32') {
|
|
it('gets the folder for recent files', () => {
|
|
const recent = app.getPath('recent');
|
|
|
|
// We expect that one of our test machines have overriden this
|
|
// to be something crazy, it'll always include the word "Recent"
|
|
// unless people have been registry-hacking like crazy
|
|
expect(recent).to.include('Recent');
|
|
});
|
|
|
|
it('can override the recent files path', () => {
|
|
app.setPath('recent', 'C:\\fake-path');
|
|
expect(app.getPath('recent')).to.equal('C:\\fake-path');
|
|
});
|
|
}
|
|
});
|
|
|
|
describe('setPath(name, path)', () => {
|
|
it('throws when a relative path is passed', () => {
|
|
const badPath = 'hey/hi/hello';
|
|
|
|
expect(() => {
|
|
app.setPath('music', badPath);
|
|
}).to.throw(/Path must be absolute/);
|
|
});
|
|
|
|
it('does not create a new directory by default', () => {
|
|
const badPath = path.join(__dirname, 'music');
|
|
|
|
expect(fs.existsSync(badPath)).to.be.false();
|
|
app.setPath('music', badPath);
|
|
expect(fs.existsSync(badPath)).to.be.false();
|
|
|
|
expect(() => { app.getPath(badPath as any); }).to.throw();
|
|
});
|
|
});
|
|
|
|
describe('setAppLogsPath(path)', () => {
|
|
it('throws when a relative path is passed', () => {
|
|
const badPath = 'hey/hi/hello';
|
|
|
|
expect(() => {
|
|
app.setAppLogsPath(badPath);
|
|
}).to.throw(/Path must be absolute/);
|
|
});
|
|
});
|
|
|
|
describe('select-client-certificate event', () => {
|
|
let w: BrowserWindow;
|
|
|
|
before(function () {
|
|
if (process.platform === 'linux') {
|
|
this.skip();
|
|
}
|
|
session.fromPartition('empty-certificate').setCertificateVerifyProc((req, cb) => { cb(0); });
|
|
});
|
|
|
|
beforeEach(() => {
|
|
w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
partition: 'empty-certificate'
|
|
}
|
|
});
|
|
});
|
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null as any; }));
|
|
|
|
after(() => session.fromPartition('empty-certificate').setCertificateVerifyProc(null));
|
|
|
|
it('can respond with empty certificate list', async () => {
|
|
app.once('select-client-certificate', function (event, webContents, url, list, callback) {
|
|
console.log('select-client-certificate emitted');
|
|
event.preventDefault();
|
|
callback();
|
|
});
|
|
await w.webContents.loadURL(secureUrl);
|
|
expect(w.webContents.getTitle()).to.equal('denied');
|
|
});
|
|
});
|
|
|
|
describe('setAsDefaultProtocolClient(protocol, path, args)', () => {
|
|
const protocol = 'electron-test';
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
|
|
const processStartArgs = [
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
'--process-start-args', '"--hidden"'
|
|
];
|
|
|
|
let Winreg: any;
|
|
let classesKey: any;
|
|
|
|
before(function () {
|
|
if (process.platform !== 'win32') {
|
|
this.skip();
|
|
} else {
|
|
Winreg = require('winreg');
|
|
|
|
classesKey = new Winreg({
|
|
hive: Winreg.HKCU,
|
|
key: '\\Software\\Classes\\'
|
|
});
|
|
}
|
|
});
|
|
|
|
after(function (done) {
|
|
if (process.platform !== 'win32') {
|
|
done();
|
|
} else {
|
|
const protocolKey = new Winreg({
|
|
hive: Winreg.HKCU,
|
|
key: `\\Software\\Classes\\${protocol}`
|
|
});
|
|
|
|
// The last test leaves the registry dirty,
|
|
// delete the protocol key for those of us who test at home
|
|
protocolKey.destroy(() => done());
|
|
}
|
|
});
|
|
|
|
beforeEach(() => {
|
|
app.removeAsDefaultProtocolClient(protocol);
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs);
|
|
});
|
|
|
|
afterEach(() => {
|
|
app.removeAsDefaultProtocolClient(protocol);
|
|
expect(app.isDefaultProtocolClient(protocol)).to.equal(false);
|
|
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs);
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.equal(false);
|
|
});
|
|
|
|
it('sets the app as the default protocol client', () => {
|
|
expect(app.isDefaultProtocolClient(protocol)).to.equal(false);
|
|
app.setAsDefaultProtocolClient(protocol);
|
|
expect(app.isDefaultProtocolClient(protocol)).to.equal(true);
|
|
});
|
|
|
|
it('allows a custom path and args to be specified', () => {
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.equal(false);
|
|
app.setAsDefaultProtocolClient(protocol, updateExe, processStartArgs);
|
|
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.equal(true);
|
|
expect(app.isDefaultProtocolClient(protocol)).to.equal(false);
|
|
});
|
|
|
|
it('creates a registry entry for the protocol class', async () => {
|
|
app.setAsDefaultProtocolClient(protocol);
|
|
|
|
const keys = await promisify(classesKey.keys).call(classesKey) as any[];
|
|
const exists = !!keys.find(key => key.key.includes(protocol));
|
|
expect(exists).to.equal(true);
|
|
});
|
|
|
|
it('completely removes a registry entry for the protocol class', async () => {
|
|
app.setAsDefaultProtocolClient(protocol);
|
|
app.removeAsDefaultProtocolClient(protocol);
|
|
|
|
const keys = await promisify(classesKey.keys).call(classesKey) as any[];
|
|
const exists = !!keys.find(key => key.key.includes(protocol));
|
|
expect(exists).to.equal(false);
|
|
});
|
|
|
|
it('only unsets a class registry key if it contains other data', async () => {
|
|
app.setAsDefaultProtocolClient(protocol);
|
|
|
|
const protocolKey = new Winreg({
|
|
hive: Winreg.HKCU,
|
|
key: `\\Software\\Classes\\${protocol}`
|
|
});
|
|
|
|
await promisify(protocolKey.set).call(protocolKey, 'test-value', 'REG_BINARY', '123');
|
|
app.removeAsDefaultProtocolClient(protocol);
|
|
|
|
const keys = await promisify(classesKey.keys).call(classesKey) as any[];
|
|
const exists = !!keys.find(key => key.key.includes(protocol));
|
|
expect(exists).to.equal(true);
|
|
});
|
|
|
|
it('sets the default client such that getApplicationNameForProtocol returns Electron', () => {
|
|
app.setAsDefaultProtocolClient(protocol);
|
|
expect(app.getApplicationNameForProtocol(`${protocol}://`)).to.equal('Electron');
|
|
});
|
|
});
|
|
|
|
describe('getApplicationNameForProtocol()', () => {
|
|
it('returns application names for common protocols', function () {
|
|
// We can't expect particular app names here, but these protocols should
|
|
// at least have _something_ registered. Except on our Linux CI
|
|
// environment apparently.
|
|
if (process.platform === 'linux') {
|
|
this.skip();
|
|
}
|
|
|
|
const protocols = [
|
|
'http://',
|
|
'https://'
|
|
];
|
|
protocols.forEach((protocol) => {
|
|
expect(app.getApplicationNameForProtocol(protocol)).to.not.equal('');
|
|
});
|
|
});
|
|
|
|
it('returns an empty string for a bogus protocol', () => {
|
|
expect(app.getApplicationNameForProtocol('bogus-protocol://')).to.equal('');
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform !== 'linux')('getApplicationInfoForProtocol()', () => {
|
|
it('returns promise rejection for a bogus protocol', async function () {
|
|
await expect(
|
|
app.getApplicationInfoForProtocol('bogus-protocol://')
|
|
).to.eventually.be.rejectedWith(
|
|
'Unable to retrieve installation path to app'
|
|
);
|
|
});
|
|
|
|
it('returns resolved promise with appPath, displayName and icon', async function () {
|
|
const appInfo = await app.getApplicationInfoForProtocol('https://');
|
|
expect(appInfo.path).not.to.be.undefined();
|
|
expect(appInfo.name).not.to.be.undefined();
|
|
expect(appInfo.icon).not.to.be.undefined();
|
|
});
|
|
});
|
|
|
|
describe('isDefaultProtocolClient()', () => {
|
|
it('returns false for a bogus protocol', () => {
|
|
expect(app.isDefaultProtocolClient('bogus-protocol://')).to.equal(false);
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform === 'win32')('app launch through uri', () => {
|
|
it('does not launch for argument following a URL', async () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'quit-app');
|
|
// App should exit with non 123 code.
|
|
const first = cp.spawn(process.execPath, [appPath, 'electron-test:?', 'abc']);
|
|
const [code] = await emittedOnce(first, 'exit');
|
|
expect(code).to.not.equal(123);
|
|
});
|
|
|
|
it('launches successfully for argument following a file path', async () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'quit-app');
|
|
// App should exit with code 123.
|
|
const first = cp.spawn(process.execPath, [appPath, 'e:\\abc', 'abc']);
|
|
const [code] = await emittedOnce(first, 'exit');
|
|
expect(code).to.equal(123);
|
|
});
|
|
|
|
it('launches successfully for multiple URIs following --', async () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'quit-app');
|
|
// App should exit with code 123.
|
|
const first = cp.spawn(process.execPath, [appPath, '--', 'http://electronjs.org', 'electron-test://testdata']);
|
|
const [code] = await emittedOnce(first, 'exit');
|
|
expect(code).to.equal(123);
|
|
});
|
|
});
|
|
|
|
// FIXME Get these specs running on Linux CI
|
|
ifdescribe(process.platform !== 'linux')('getFileIcon() API', () => {
|
|
const iconPath = path.join(__dirname, 'fixtures/assets/icon.ico');
|
|
const sizes = {
|
|
small: 16,
|
|
normal: 32,
|
|
large: process.platform === 'win32' ? 32 : 48
|
|
};
|
|
|
|
it('fetches a non-empty icon', async () => {
|
|
const icon = await app.getFileIcon(iconPath);
|
|
expect(icon.isEmpty()).to.equal(false);
|
|
});
|
|
|
|
it('fetches normal icon size by default', async () => {
|
|
const icon = await app.getFileIcon(iconPath);
|
|
const size = icon.getSize();
|
|
|
|
expect(size.height).to.equal(sizes.normal);
|
|
expect(size.width).to.equal(sizes.normal);
|
|
});
|
|
|
|
describe('size option', () => {
|
|
it('fetches a small icon', async () => {
|
|
const icon = await app.getFileIcon(iconPath, { size: 'small' });
|
|
const size = icon.getSize();
|
|
|
|
expect(size.height).to.equal(sizes.small);
|
|
expect(size.width).to.equal(sizes.small);
|
|
});
|
|
|
|
it('fetches a normal icon', async () => {
|
|
const icon = await app.getFileIcon(iconPath, { size: 'normal' });
|
|
const size = icon.getSize();
|
|
|
|
expect(size.height).to.equal(sizes.normal);
|
|
expect(size.width).to.equal(sizes.normal);
|
|
});
|
|
|
|
it('fetches a large icon', async () => {
|
|
// macOS does not support large icons
|
|
if (process.platform === 'darwin') return;
|
|
|
|
const icon = await app.getFileIcon(iconPath, { size: 'large' });
|
|
const size = icon.getSize();
|
|
|
|
expect(size.height).to.equal(sizes.large);
|
|
expect(size.width).to.equal(sizes.large);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getAppMetrics() API', () => {
|
|
it('returns memory and cpu stats of all running electron processes', () => {
|
|
const appMetrics = app.getAppMetrics();
|
|
expect(appMetrics).to.be.an('array').and.have.lengthOf.at.least(1, 'App memory info object is not > 0');
|
|
|
|
const types = [];
|
|
for (const entry of appMetrics) {
|
|
expect(entry.pid).to.be.above(0, 'pid is not > 0');
|
|
expect(entry.type).to.be.a('string').that.does.not.equal('');
|
|
expect(entry.creationTime).to.be.a('number').that.is.greaterThan(0);
|
|
|
|
types.push(entry.type);
|
|
expect(entry.cpu).to.have.ownProperty('percentCPUUsage').that.is.a('number');
|
|
expect(entry.cpu).to.have.ownProperty('idleWakeupsPerSecond').that.is.a('number');
|
|
|
|
expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0);
|
|
expect(entry.memory).to.have.property('peakWorkingSetSize').that.is.greaterThan(0);
|
|
|
|
if (entry.type === 'Utility' || entry.type === 'GPU') {
|
|
expect(entry.serviceName).to.be.a('string').that.does.not.equal('');
|
|
}
|
|
|
|
if (entry.type === 'Utility') {
|
|
expect(entry).to.have.property('name').that.is.a('string');
|
|
}
|
|
|
|
if (process.platform === 'win32') {
|
|
expect(entry.memory).to.have.property('privateBytes').that.is.greaterThan(0);
|
|
}
|
|
|
|
if (process.platform !== 'linux') {
|
|
expect(entry.sandboxed).to.be.a('boolean');
|
|
}
|
|
|
|
if (process.platform === 'win32') {
|
|
expect(entry.integrityLevel).to.be.a('string');
|
|
}
|
|
}
|
|
|
|
if (process.platform === 'darwin') {
|
|
expect(types).to.include('GPU');
|
|
}
|
|
|
|
expect(types).to.include('Browser');
|
|
});
|
|
});
|
|
|
|
describe('getGPUFeatureStatus() API', () => {
|
|
it('returns the graphic features statuses', () => {
|
|
const features = app.getGPUFeatureStatus();
|
|
expect(features).to.have.ownProperty('webgl').that.is.a('string');
|
|
expect(features).to.have.ownProperty('gpu_compositing').that.is.a('string');
|
|
});
|
|
});
|
|
|
|
// FIXME https://github.com/electron/electron/issues/24224
|
|
ifdescribe(process.platform !== 'linux')('getGPUInfo() API', () => {
|
|
const appPath = path.join(fixturesPath, 'api', 'gpu-info.js');
|
|
|
|
const getGPUInfo = async (type: string) => {
|
|
const appProcess = cp.spawn(process.execPath, [appPath, type]);
|
|
let gpuInfoData = '';
|
|
let errorData = '';
|
|
appProcess.stdout.on('data', (data) => {
|
|
gpuInfoData += data;
|
|
});
|
|
appProcess.stderr.on('data', (data) => {
|
|
errorData += data;
|
|
});
|
|
const [exitCode] = await emittedOnce(appProcess, 'exit');
|
|
if (exitCode === 0) {
|
|
// return info data on successful exit
|
|
return JSON.parse(gpuInfoData);
|
|
} else {
|
|
// return error if not clean exit
|
|
return Promise.reject(new Error(errorData));
|
|
}
|
|
};
|
|
const verifyBasicGPUInfo = async (gpuInfo: any) => {
|
|
// Devices information is always present in the available info.
|
|
expect(gpuInfo).to.have.ownProperty('gpuDevice')
|
|
.that.is.an('array')
|
|
.and.does.not.equal([]);
|
|
|
|
const device = gpuInfo.gpuDevice[0];
|
|
expect(device).to.be.an('object')
|
|
.and.to.have.property('deviceId')
|
|
.that.is.a('number')
|
|
.not.lessThan(0);
|
|
};
|
|
|
|
it('succeeds with basic GPUInfo', async () => {
|
|
const gpuInfo = await getGPUInfo('basic');
|
|
await verifyBasicGPUInfo(gpuInfo);
|
|
});
|
|
|
|
it('succeeds with complete GPUInfo', async () => {
|
|
const completeInfo = await getGPUInfo('complete');
|
|
if (process.platform === 'linux') {
|
|
// For linux and macOS complete info is same as basic info
|
|
await verifyBasicGPUInfo(completeInfo);
|
|
const basicInfo = await getGPUInfo('basic');
|
|
expect(completeInfo).to.deep.equal(basicInfo);
|
|
} else {
|
|
// Gl version is present in the complete info.
|
|
expect(completeInfo).to.have.ownProperty('auxAttributes')
|
|
.that.is.an('object');
|
|
if (completeInfo.gpuDevice.active) {
|
|
expect(completeInfo.auxAttributes).to.have.ownProperty('glVersion')
|
|
.that.is.a('string')
|
|
.and.does.not.equal([]);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('fails for invalid info_type', () => {
|
|
const invalidType = 'invalid';
|
|
const expectedErrorMessage = "Invalid info type. Use 'basic' or 'complete'";
|
|
return expect(app.getGPUInfo(invalidType as any)).to.eventually.be.rejectedWith(expectedErrorMessage);
|
|
});
|
|
});
|
|
|
|
describe('sandbox options', () => {
|
|
let appProcess: cp.ChildProcess = null as any;
|
|
let server: net.Server = null as any;
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox';
|
|
|
|
beforeEach(function (done) {
|
|
if (process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'arm')) {
|
|
// Our ARM tests are run on VSTS rather than CircleCI, and the Docker
|
|
// setup on VSTS disallows syscalls that Chrome requires for setting up
|
|
// sandboxing.
|
|
// See:
|
|
// - https://docs.docker.com/engine/security/seccomp/#significant-syscalls-blocked-by-the-default-profile
|
|
// - https://chromium.googlesource.com/chromium/src/+/70.0.3538.124/sandbox/linux/services/credentials.cc#292
|
|
// - https://github.com/docker/docker-ce/blob/ba7dfc59ccfe97c79ee0d1379894b35417b40bca/components/engine/profiles/seccomp/seccomp_default.go#L497
|
|
// - https://blog.jessfraz.com/post/how-to-use-new-docker-seccomp-profiles/
|
|
//
|
|
// Adding `--cap-add SYS_ADMIN` or `--security-opt seccomp=unconfined`
|
|
// to the Docker invocation allows the syscalls that Chrome needs, but
|
|
// are probably more permissive than we'd like.
|
|
this.skip();
|
|
}
|
|
fs.unlink(socketPath, () => {
|
|
server = net.createServer();
|
|
server.listen(socketPath);
|
|
done();
|
|
});
|
|
});
|
|
|
|
afterEach(done => {
|
|
if (appProcess != null) appProcess.kill();
|
|
|
|
server.close(() => {
|
|
if (process.platform === 'win32') {
|
|
done();
|
|
} else {
|
|
fs.unlink(socketPath, () => done());
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('when app.enableSandbox() is called', () => {
|
|
it('adds --enable-sandbox to all renderer processes', done => {
|
|
const appPath = path.join(fixturesPath, 'api', 'mixed-sandbox-app');
|
|
appProcess = cp.spawn(process.execPath, [appPath, '--app-enable-sandbox']);
|
|
|
|
server.once('error', error => { done(error); });
|
|
|
|
server.on('connection', client => {
|
|
client.once('data', (data) => {
|
|
const argv = JSON.parse(data.toString());
|
|
expect(argv.sandbox).to.include('--enable-sandbox');
|
|
expect(argv.sandbox).to.not.include('--no-sandbox');
|
|
|
|
expect(argv.noSandbox).to.include('--enable-sandbox');
|
|
expect(argv.noSandbox).to.not.include('--no-sandbox');
|
|
|
|
expect(argv.noSandboxDevtools).to.equal(true);
|
|
expect(argv.sandboxDevtools).to.equal(true);
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when the app is launched with --enable-sandbox', () => {
|
|
it('adds --enable-sandbox to all renderer processes', done => {
|
|
const appPath = path.join(fixturesPath, 'api', 'mixed-sandbox-app');
|
|
appProcess = cp.spawn(process.execPath, [appPath, '--enable-sandbox']);
|
|
|
|
server.once('error', error => { done(error); });
|
|
|
|
server.on('connection', client => {
|
|
client.once('data', data => {
|
|
const argv = JSON.parse(data.toString());
|
|
expect(argv.sandbox).to.include('--enable-sandbox');
|
|
expect(argv.sandbox).to.not.include('--no-sandbox');
|
|
|
|
expect(argv.noSandbox).to.include('--enable-sandbox');
|
|
expect(argv.noSandbox).to.not.include('--no-sandbox');
|
|
|
|
expect(argv.noSandboxDevtools).to.equal(true);
|
|
expect(argv.sandboxDevtools).to.equal(true);
|
|
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('disableDomainBlockingFor3DAPIs() API', () => {
|
|
it('throws when called after app is ready', () => {
|
|
expect(() => {
|
|
app.disableDomainBlockingFor3DAPIs();
|
|
}).to.throw(/before app is ready/);
|
|
});
|
|
});
|
|
|
|
const dockDescribe = process.platform === 'darwin' ? describe : describe.skip;
|
|
dockDescribe('dock APIs', () => {
|
|
after(async () => {
|
|
await app.dock.show();
|
|
});
|
|
|
|
describe('dock.setMenu', () => {
|
|
it('can be retrieved via dock.getMenu', () => {
|
|
expect(app.dock.getMenu()).to.equal(null);
|
|
const menu = new Menu();
|
|
app.dock.setMenu(menu);
|
|
expect(app.dock.getMenu()).to.equal(menu);
|
|
});
|
|
|
|
it('keeps references to the menu', () => {
|
|
app.dock.setMenu(new Menu());
|
|
const v8Util = process._linkedBinding('electron_common_v8_util');
|
|
v8Util.requestGarbageCollectionForTesting();
|
|
});
|
|
});
|
|
|
|
describe('dock.setIcon', () => {
|
|
it('throws a descriptive error for a bad icon path', () => {
|
|
const badPath = path.resolve('I', 'Do', 'Not', 'Exist');
|
|
expect(() => {
|
|
app.dock.setIcon(badPath);
|
|
}).to.throw(/Failed to load image from path (.+)/);
|
|
});
|
|
});
|
|
|
|
describe('dock.bounce', () => {
|
|
it('should return -1 for unknown bounce type', () => {
|
|
expect(app.dock.bounce('bad type' as any)).to.equal(-1);
|
|
});
|
|
|
|
it('should return a positive number for informational type', () => {
|
|
const appHasFocus = !!BrowserWindow.getFocusedWindow();
|
|
if (!appHasFocus) {
|
|
expect(app.dock.bounce('informational')).to.be.at.least(0);
|
|
}
|
|
});
|
|
|
|
it('should return a positive number for critical type', () => {
|
|
const appHasFocus = !!BrowserWindow.getFocusedWindow();
|
|
if (!appHasFocus) {
|
|
expect(app.dock.bounce('critical')).to.be.at.least(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('dock.cancelBounce', () => {
|
|
it('should not throw', () => {
|
|
app.dock.cancelBounce(app.dock.bounce('critical'));
|
|
});
|
|
});
|
|
|
|
describe('dock.setBadge', () => {
|
|
after(() => {
|
|
app.dock.setBadge('');
|
|
});
|
|
|
|
it('should not throw', () => {
|
|
app.dock.setBadge('1');
|
|
});
|
|
|
|
it('should be retrievable via getBadge', () => {
|
|
app.dock.setBadge('test');
|
|
expect(app.dock.getBadge()).to.equal('test');
|
|
});
|
|
});
|
|
|
|
describe('dock.hide', () => {
|
|
it('should not throw', () => {
|
|
app.dock.hide();
|
|
expect(app.dock.isVisible()).to.equal(false);
|
|
});
|
|
});
|
|
|
|
// Note that dock.show tests should run after dock.hide tests, to work
|
|
// around a bug of macOS.
|
|
// See https://github.com/electron/electron/pull/25269 for more.
|
|
describe('dock.show', () => {
|
|
it('should not throw', () => {
|
|
return app.dock.show().then(() => {
|
|
expect(app.dock.isVisible()).to.equal(true);
|
|
});
|
|
});
|
|
|
|
it('returns a Promise', () => {
|
|
expect(app.dock.show()).to.be.a('promise');
|
|
});
|
|
|
|
it('eventually fulfills', async () => {
|
|
await expect(app.dock.show()).to.eventually.be.fulfilled.equal(undefined);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('whenReady', () => {
|
|
it('returns a Promise', () => {
|
|
expect(app.whenReady()).to.be.a('promise');
|
|
});
|
|
|
|
it('becomes fulfilled if the app is already ready', async () => {
|
|
expect(app.isReady()).to.equal(true);
|
|
await expect(app.whenReady()).to.be.eventually.fulfilled.equal(undefined);
|
|
});
|
|
});
|
|
|
|
describe('app.applicationMenu', () => {
|
|
it('has the applicationMenu property', () => {
|
|
expect(app).to.have.property('applicationMenu');
|
|
});
|
|
});
|
|
|
|
describe('commandLine.hasSwitch', () => {
|
|
it('returns true when present', () => {
|
|
app.commandLine.appendSwitch('foobar1');
|
|
expect(app.commandLine.hasSwitch('foobar1')).to.equal(true);
|
|
});
|
|
|
|
it('returns false when not present', () => {
|
|
expect(app.commandLine.hasSwitch('foobar2')).to.equal(false);
|
|
});
|
|
});
|
|
|
|
describe('commandLine.hasSwitch (existing argv)', () => {
|
|
it('returns true when present', async () => {
|
|
const { hasSwitch } = await runTestApp('command-line', '--foobar');
|
|
expect(hasSwitch).to.equal(true);
|
|
});
|
|
|
|
it('returns false when not present', async () => {
|
|
const { hasSwitch } = await runTestApp('command-line');
|
|
expect(hasSwitch).to.equal(false);
|
|
});
|
|
});
|
|
|
|
describe('commandLine.getSwitchValue', () => {
|
|
it('returns the value when present', () => {
|
|
app.commandLine.appendSwitch('foobar', 'æøåü');
|
|
expect(app.commandLine.getSwitchValue('foobar')).to.equal('æøåü');
|
|
});
|
|
|
|
it('returns an empty string when present without value', () => {
|
|
app.commandLine.appendSwitch('foobar1');
|
|
expect(app.commandLine.getSwitchValue('foobar1')).to.equal('');
|
|
});
|
|
|
|
it('returns an empty string when not present', () => {
|
|
expect(app.commandLine.getSwitchValue('foobar2')).to.equal('');
|
|
});
|
|
});
|
|
|
|
describe('commandLine.getSwitchValue (existing argv)', () => {
|
|
it('returns the value when present', async () => {
|
|
const { getSwitchValue } = await runTestApp('command-line', '--foobar=test');
|
|
expect(getSwitchValue).to.equal('test');
|
|
});
|
|
|
|
it('returns an empty string when present without value', async () => {
|
|
const { getSwitchValue } = await runTestApp('command-line', '--foobar');
|
|
expect(getSwitchValue).to.equal('');
|
|
});
|
|
|
|
it('returns an empty string when not present', async () => {
|
|
const { getSwitchValue } = await runTestApp('command-line');
|
|
expect(getSwitchValue).to.equal('');
|
|
});
|
|
});
|
|
|
|
ifdescribe(process.platform === 'darwin')('app.setSecureKeyboardEntryEnabled', () => {
|
|
it('changes Secure Keyboard Entry is enabled', () => {
|
|
app.setSecureKeyboardEntryEnabled(true);
|
|
expect(app.isSecureKeyboardEntryEnabled()).to.equal(true);
|
|
app.setSecureKeyboardEntryEnabled(false);
|
|
expect(app.isSecureKeyboardEntryEnabled()).to.equal(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('default behavior', () => {
|
|
describe('application menu', () => {
|
|
it('creates the default menu if the app does not set it', async () => {
|
|
const result = await runTestApp('default-menu');
|
|
expect(result).to.equal(false);
|
|
});
|
|
|
|
it('does not create the default menu if the app sets a custom menu', async () => {
|
|
const result = await runTestApp('default-menu', '--custom-menu');
|
|
expect(result).to.equal(true);
|
|
});
|
|
|
|
it('does not create the default menu if the app sets a null menu', async () => {
|
|
const result = await runTestApp('default-menu', '--null-menu');
|
|
expect(result).to.equal(true);
|
|
});
|
|
});
|
|
|
|
describe('window-all-closed', () => {
|
|
afterEach(closeAllWindows);
|
|
|
|
it('quits when the app does not handle the event', async () => {
|
|
const result = await runTestApp('window-all-closed');
|
|
expect(result).to.equal(false);
|
|
});
|
|
|
|
it('does not quit when the app handles the event', async () => {
|
|
const result = await runTestApp('window-all-closed', '--handle-event');
|
|
expect(result).to.equal(true);
|
|
});
|
|
|
|
it('should omit closed windows from getAllWindows', async () => {
|
|
const w = new BrowserWindow({ show: false });
|
|
const len = new Promise(resolve => {
|
|
app.on('window-all-closed', () => {
|
|
resolve(BrowserWindow.getAllWindows().length);
|
|
});
|
|
});
|
|
w.close();
|
|
expect(await len).to.equal(0);
|
|
});
|
|
});
|
|
|
|
describe('user agent fallback', () => {
|
|
let initialValue: string;
|
|
|
|
before(() => {
|
|
initialValue = app.userAgentFallback!;
|
|
});
|
|
|
|
it('should have a reasonable default', () => {
|
|
expect(initialValue).to.include(`Electron/${process.versions.electron}`);
|
|
expect(initialValue).to.include(`Chrome/${process.versions.chrome}`);
|
|
});
|
|
|
|
it('should be overridable', () => {
|
|
app.userAgentFallback = 'test-agent/123';
|
|
expect(app.userAgentFallback).to.equal('test-agent/123');
|
|
});
|
|
|
|
it('should be restorable', () => {
|
|
app.userAgentFallback = 'test-agent/123';
|
|
app.userAgentFallback = '';
|
|
expect(app.userAgentFallback).to.equal(initialValue);
|
|
});
|
|
});
|
|
|
|
describe('app.allowRendererProcessReuse', () => {
|
|
it('should default to true', () => {
|
|
expect(app.allowRendererProcessReuse).to.equal(true);
|
|
});
|
|
|
|
it('should cause renderer processes to get new PIDs when false', async () => {
|
|
const output = await runTestApp('site-instance-overrides', 'false');
|
|
expect(output[0]).to.be.a('number').that.is.greaterThan(0);
|
|
expect(output[1]).to.be.a('number').that.is.greaterThan(0);
|
|
expect(output[0]).to.not.equal(output[1]);
|
|
});
|
|
|
|
it('should cause renderer processes to keep the same PID when true', async () => {
|
|
const output = await runTestApp('site-instance-overrides', 'true');
|
|
expect(output[0]).to.be.a('number').that.is.greaterThan(0);
|
|
expect(output[1]).to.be.a('number').that.is.greaterThan(0);
|
|
expect(output[0]).to.equal(output[1]);
|
|
});
|
|
});
|
|
|
|
describe('login event', () => {
|
|
afterEach(closeAllWindows);
|
|
let server: http.Server;
|
|
let serverUrl: string;
|
|
|
|
before((done) => {
|
|
server = http.createServer((request, response) => {
|
|
if (request.headers.authorization) {
|
|
return response.end('ok');
|
|
}
|
|
response
|
|
.writeHead(401, { 'WWW-Authenticate': 'Basic realm="Foo"' })
|
|
.end();
|
|
}).listen(0, '127.0.0.1', () => {
|
|
serverUrl = 'http://127.0.0.1:' + (server.address() as net.AddressInfo).port;
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should emit a login event on app when a WebContents hits a 401', async () => {
|
|
const w = new BrowserWindow({ show: false });
|
|
w.loadURL(serverUrl);
|
|
const [, webContents] = await emittedOnce(app, 'login');
|
|
expect(webContents).to.equal(w.webContents);
|
|
});
|
|
});
|
|
});
|
|
|
|
async function runTestApp (name: string, ...args: any[]) {
|
|
const appPath = path.join(fixturesPath, 'api', name);
|
|
const electronPath = process.execPath;
|
|
const appProcess = cp.spawn(electronPath, [appPath, ...args]);
|
|
|
|
let output = '';
|
|
appProcess.stdout.on('data', (data) => { output += data; });
|
|
|
|
await emittedOnce(appProcess.stdout, 'end');
|
|
|
|
return JSON.parse(output);
|
|
}
|