test: replace (webContents as any).destroy() with webContents.destroy() (#36653)

Co-authored-by: Milan Burda <miburda@microsoft.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Milan Burda 2022-12-14 22:07:38 +01:00 коммит произвёл GitHub
Родитель fb461effae
Коммит 5fd7a43970
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 21 добавлений и 21 удалений

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

@ -32,7 +32,7 @@ describe('BrowserView module', () => {
if (view && view.webContents) { if (view && view.webContents) {
const p = emittedOnce(view.webContents, 'destroyed'); const p = emittedOnce(view.webContents, 'destroyed');
(view.webContents as any).destroy(); view.webContents.destroy();
view = null as any; view = null as any;
await p; await p;
} }
@ -193,11 +193,11 @@ describe('BrowserView module', () => {
describe('BrowserWindow.addBrowserView()', () => { describe('BrowserWindow.addBrowserView()', () => {
it('does not throw for valid args', () => { it('does not throw for valid args', () => {
const view1 = new BrowserView(); const view1 = new BrowserView();
defer(() => (view1.webContents as any).destroy()); defer(() => view1.webContents.destroy());
w.addBrowserView(view1); w.addBrowserView(view1);
defer(() => w.removeBrowserView(view1)); defer(() => w.removeBrowserView(view1));
const view2 = new BrowserView(); const view2 = new BrowserView();
defer(() => (view2.webContents as any).destroy()); defer(() => view2.webContents.destroy());
w.addBrowserView(view2); w.addBrowserView(view2);
defer(() => w.removeBrowserView(view2)); defer(() => w.removeBrowserView(view2));
}); });
@ -212,7 +212,7 @@ describe('BrowserView module', () => {
it('does not crash if the BrowserView webContents are destroyed prior to window addition', () => { it('does not crash if the BrowserView webContents are destroyed prior to window addition', () => {
expect(() => { expect(() => {
const view1 = new BrowserView(); const view1 = new BrowserView();
(view1.webContents as any).destroy(); view1.webContents.destroy();
w.addBrowserView(view1); w.addBrowserView(view1);
}).to.not.throw(); }).to.not.throw();
}); });
@ -262,11 +262,11 @@ describe('BrowserView module', () => {
describe('BrowserWindow.getBrowserViews()', () => { describe('BrowserWindow.getBrowserViews()', () => {
it('returns same views as was added', () => { it('returns same views as was added', () => {
const view1 = new BrowserView(); const view1 = new BrowserView();
defer(() => (view1.webContents as any).destroy()); defer(() => view1.webContents.destroy());
w.addBrowserView(view1); w.addBrowserView(view1);
defer(() => w.removeBrowserView(view1)); defer(() => w.removeBrowserView(view1));
const view2 = new BrowserView(); const view2 = new BrowserView();
defer(() => (view2.webContents as any).destroy()); defer(() => view2.webContents.destroy());
w.addBrowserView(view2); w.addBrowserView(view2);
defer(() => w.removeBrowserView(view2)); defer(() => w.removeBrowserView(view2));

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

@ -2206,7 +2206,7 @@ describe('BrowserWindow module', () => {
w.setBrowserView(bv); w.setBrowserView(bv);
defer(() => { defer(() => {
w.removeBrowserView(bv); w.removeBrowserView(bv);
(bv.webContents as any).destroy(); bv.webContents.destroy();
}); });
await bv.webContents.loadURL('about:blank'); await bv.webContents.loadURL('about:blank');
expect(BrowserWindow.fromWebContents(bv.webContents)!.id).to.equal(w.id); expect(BrowserWindow.fromWebContents(bv.webContents)!.id).to.equal(w.id);
@ -2254,7 +2254,7 @@ describe('BrowserWindow module', () => {
w.setBrowserView(bv); w.setBrowserView(bv);
defer(() => { defer(() => {
w.removeBrowserView(bv); w.removeBrowserView(bv);
(bv.webContents as any).destroy(); bv.webContents.destroy();
}); });
expect(BrowserWindow.fromBrowserView(bv)!.id).to.equal(w.id); expect(BrowserWindow.fromBrowserView(bv)!.id).to.equal(w.id);
}); });
@ -2268,8 +2268,8 @@ describe('BrowserWindow module', () => {
defer(() => { defer(() => {
w.removeBrowserView(bv1); w.removeBrowserView(bv1);
w.removeBrowserView(bv2); w.removeBrowserView(bv2);
(bv1.webContents as any).destroy(); bv1.webContents.destroy();
(bv2.webContents as any).destroy(); bv2.webContents.destroy();
}); });
expect(BrowserWindow.fromBrowserView(bv1)!.id).to.equal(w.id); expect(BrowserWindow.fromBrowserView(bv1)!.id).to.equal(w.id);
expect(BrowserWindow.fromBrowserView(bv2)!.id).to.equal(w.id); expect(BrowserWindow.fromBrowserView(bv2)!.id).to.equal(w.id);
@ -2278,7 +2278,7 @@ describe('BrowserWindow module', () => {
it('returns undefined if not attached', () => { it('returns undefined if not attached', () => {
const bv = new BrowserView(); const bv = new BrowserView();
defer(() => { defer(() => {
(bv.webContents as any).destroy(); bv.webContents.destroy();
}); });
expect(BrowserWindow.fromBrowserView(bv)).to.be.null('BrowserWindow associated with bv'); expect(BrowserWindow.fromBrowserView(bv)).to.be.null('BrowserWindow associated with bv');
}); });

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

@ -144,7 +144,7 @@ describe('ipcRenderer module', () => {
}); });
after(() => { after(() => {
(contents as any).destroy(); contents.destroy();
contents = null as unknown as WebContents; contents = null as unknown as WebContents;
}); });

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

@ -74,7 +74,7 @@ describe('protocol module', () => {
let contents: WebContents = null as unknown as WebContents; let contents: WebContents = null as unknown as WebContents;
// NB. sandbox: true is used because it makes navigations much (~8x) faster. // NB. sandbox: true is used because it makes navigations much (~8x) faster.
before(() => { contents = (webContents as any).create({ sandbox: true }); }); before(() => { contents = (webContents as any).create({ sandbox: true }); });
after(() => (contents as any).destroy()); after(() => contents.destroy());
async function ajax (url: string, options = {}) { async function ajax (url: string, options = {}) {
// Note that we need to do navigation every time after a protocol is // Note that we need to do navigation every time after a protocol is
@ -964,7 +964,7 @@ describe('protocol module', () => {
// This is called in a timeout to avoid a crash that happens when // This is called in a timeout to avoid a crash that happens when
// calling destroy() in a microtask. // calling destroy() in a microtask.
setTimeout(() => { setTimeout(() => {
(newContents as any).destroy(); newContents.destroy();
}); });
} }
} }
@ -1062,7 +1062,7 @@ describe('protocol module', () => {
// This is called in a timeout to avoid a crash that happens when // This is called in a timeout to avoid a crash that happens when
// calling destroy() in a microtask. // calling destroy() in a microtask.
setTimeout(() => { setTimeout(() => {
(newContents as any).destroy(); newContents.destroy();
}); });
} }
} }

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

@ -43,7 +43,7 @@ describe('session.serviceWorkers', () => {
}); });
afterEach(async () => { afterEach(async () => {
(w as any).destroy(); w.destroy();
server.close(); server.close();
await ses.clearStorageData(); await ses.clearStorageData();
}); });

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

@ -1552,7 +1552,7 @@ describe('webContents module', () => {
const contents = (webContents as any).create() as WebContents; const contents = (webContents as any).create() as WebContents;
const originalEmit = contents.emit.bind(contents); const originalEmit = contents.emit.bind(contents);
contents.emit = (...args) => { return originalEmit(...args); }; contents.emit = (...args) => { return originalEmit(...args); };
contents.once(e.name as any, () => (contents as any).destroy()); contents.once(e.name as any, () => contents.destroy());
const destroyed = emittedOnce(contents, 'destroyed'); const destroyed = emittedOnce(contents, 'destroyed');
contents.loadURL(serverUrl + e.url); contents.loadURL(serverUrl + e.url);
await destroyed; await destroyed;

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

@ -55,7 +55,7 @@ describe('webRequest module', () => {
contents = (webContents as any).create({ sandbox: true }); contents = (webContents as any).create({ sandbox: true });
await contents.loadFile(path.join(fixturesPath, 'pages', 'fetch.html')); await contents.loadFile(path.join(fixturesPath, 'pages', 'fetch.html'));
}); });
after(() => (contents as any).destroy()); after(() => contents.destroy());
async function ajax (url: string, options = {}) { async function ajax (url: string, options = {}) {
return contents.executeJavaScript(`ajax("${url}", ${JSON.stringify(options)})`); return contents.executeJavaScript(`ajax("${url}", ${JSON.stringify(options)})`);

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

@ -1479,7 +1479,7 @@ describe('chromium features', () => {
}); });
afterEach(() => { afterEach(() => {
(contents as any).destroy(); contents.destroy();
contents = null as any; contents = null as any;
}); });
@ -1595,7 +1595,7 @@ describe('chromium features', () => {
afterEach(async () => { afterEach(async () => {
if (contents) { if (contents) {
(contents as any).destroy(); contents.destroy();
contents = null as any; contents = null as any;
} }
await closeAllWindows(); await closeAllWindows();

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

@ -790,7 +790,7 @@ describe('node feature', () => {
} }
})`)) })`))
.then(() => { .then(() => {
(w as any).destroy(); w.destroy();
child.send('plz-quit'); child.send('plz-quit');
done(); done();
}); });