mirror of
https://github.com/electron/electron.git
synced 2026-02-18 19:05:06 -05:00
refactor: be more precise when creating api::WebContents (#23128)
This commit is contained in:
@@ -1382,6 +1382,7 @@ describe('chromium features', () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL(pdfSource);
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
await emittedOnce(contents, 'did-navigate');
|
||||
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
|
||||
});
|
||||
|
||||
@@ -1389,6 +1390,7 @@ describe('chromium features', () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'pdf-in-iframe.html'));
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
await emittedOnce(contents, 'did-navigate');
|
||||
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,8 +57,9 @@ describe('chrome extensions', () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, sandbox: true } });
|
||||
await w.loadURL('about:blank');
|
||||
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
|
||||
const args: any = await emittedOnce(app, 'web-contents-created');
|
||||
const args: any = await promise;
|
||||
const wc: Electron.WebContents = args[1];
|
||||
await expect(wc.executeJavaScript(`
|
||||
(() => {
|
||||
@@ -76,8 +77,9 @@ describe('chrome extensions', () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, sandbox: true } });
|
||||
await w.loadURL('about:blank');
|
||||
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
|
||||
const args: any = await emittedOnce(app, 'web-contents-created');
|
||||
const args: any = await promise;
|
||||
const wc: Electron.WebContents = args[1];
|
||||
await expect(wc.executeJavaScript('(()=>{try{openDatabase("t", "1.0", "test", 2e5);return true;}catch(e){throw e}})()')).to.not.be.rejected();
|
||||
});
|
||||
@@ -429,19 +431,21 @@ describe('chrome extensions', () => {
|
||||
|
||||
it('has session in background page', async () => {
|
||||
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession } });
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await w.loadURL('about:blank');
|
||||
const [, bgPageContents] = await promise;
|
||||
expect(bgPageContents.getType()).to.equal('backgroundPage');
|
||||
expect(bgPageContents.getURL()).to.match(/^chrome-extension:\/\/.+\/_generated_background_page.html$/);
|
||||
expect(bgPageContents.session).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
it('can open devtools of background page', async () => {
|
||||
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession } });
|
||||
const promise = emittedOnce(app, 'web-contents-created');
|
||||
await w.loadURL('about:blank');
|
||||
const [, bgPageContents] = await promise;
|
||||
expect(bgPageContents.getType()).to.equal('backgroundPage');
|
||||
|
||||
Reference in New Issue
Block a user