test: add tests for shell.moveItemToTrash (#25113)

This commit is contained in:
Jeremy Rose 2020-08-26 09:34:29 -07:00 коммит произвёл GitHub
Родитель fdb36eb5b5
Коммит 2c9e79c8d5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -13,6 +13,7 @@
#include "base/no_destructor.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/threading/thread_restrictions.h"
#include "components/dbus/thread_linux/dbus_thread_linux.h"
#include "content/public/browser/browser_thread.h"
#include "dbus/bus.h"
@ -125,6 +126,8 @@ bool XDGUtil(const std::vector<std::string>& argv,
return false;
if (wait_for_exit) {
base::ScopedAllowBaseSyncPrimitivesForTesting
allow_sync; // required by WaitForExit
int exit_code = -1;
bool success = process.WaitForExit(&exit_code);
if (!callback.is_null())

Просмотреть файл

@ -1,9 +1,12 @@
import { BrowserWindow } from 'electron/main';
import { BrowserWindow, app } from 'electron/main';
import { shell } from 'electron/common';
import { closeAllWindows } from './window-helpers';
import { emittedOnce } from './events-helpers';
import * as http from 'http';
import * as fs from 'fs-extra';
import * as path from 'path';
import { AddressInfo } from 'net';
import { expect } from 'chai';
describe('shell module', () => {
describe('shell.openExternal()', () => {
@ -57,4 +60,21 @@ describe('shell module', () => {
]);
});
});
describe('shell.moveItemToTrash()', () => {
it('moves an item to the trash', async () => {
const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-'));
const filename = path.join(dir, 'temp-to-be-deleted');
await fs.writeFile(filename, 'dummy-contents');
const result = shell.moveItemToTrash(filename);
expect(result).to.be.true();
expect(fs.existsSync(filename)).to.be.false();
});
it('returns false when called with a nonexistent path', () => {
const filename = path.join(app.getPath('temp'), 'does-not-exist');
const result = shell.moveItemToTrash(filename);
expect(result).to.be.false();
});
});
});