refactor: port parts of window-setup to use ctx bridge instead of being run in the main world (#23194)

* refactor: port parts of window-setup to use ctx bridge instead of being run in the main world

* chore: update ctx bridge specs for new base numbers
This commit is contained in:
Samuel Attard 2020-04-22 12:42:51 -07:00 committed by GitHub
parent 9d60cfa6fc
commit 96bf9ce77f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 167 additions and 25 deletions

View file

@ -346,16 +346,19 @@ describe('contextBridge', () => {
getFunction: () => () => 123
});
});
expect((await getGCInfo()).functionCount).to.equal(2);
await callWithBindings(async (root: any) => {
root.GCRunner.run();
});
const baseValue = (await getGCInfo()).functionCount;
await callWithBindings(async (root: any) => {
root.x = [root.example.getFunction()];
});
expect((await getGCInfo()).functionCount).to.equal(3);
expect((await getGCInfo()).functionCount).to.equal(baseValue + 1);
await callWithBindings(async (root: any) => {
root.x = [];
root.GCRunner.run();
});
expect((await getGCInfo()).functionCount).to.equal(2);
expect((await getGCInfo()).functionCount).to.equal(baseValue);
});
}
@ -369,14 +372,14 @@ describe('contextBridge', () => {
require('electron').ipcRenderer.send('window-ready-for-tasking');
});
const loadPromise = emittedOnce(ipcMain, 'window-ready-for-tasking');
expect((await getGCInfo()).functionCount).to.equal(1);
const baseValue = (await getGCInfo()).functionCount;
await callWithBindings((root: any) => {
root.location.reload();
});
await loadPromise;
// If this is ever "2" it means we leaked the exposed function and
// therefore the entire context after a reload
expect((await getGCInfo()).functionCount).to.equal(1);
expect((await getGCInfo()).functionCount).to.equal(baseValue);
});
}