chore(firefox): remove FFPage._initialize to ensure early initialization (#1554)

This commit is contained in:
Dmitry Gozman 2020-03-26 16:13:11 -07:00 committed by GitHub
parent f420cbb528
commit b473d9dcf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 24 deletions

View file

@ -83,24 +83,13 @@ export class FFPage implements PageDelegate {
]; ];
this._pagePromise = new Promise(f => this._pageCallback = f); this._pagePromise = new Promise(f => this._pageCallback = f);
session.once(FFSessionEvents.Disconnected, () => this._page._didDisconnect()); session.once(FFSessionEvents.Disconnected, () => this._page._didDisconnect());
this._initialize(); this._session.once('Page.ready', () => {
}
async _initialize() {
try {
await Promise.all([
// TODO: we should get rid of this call to resolve before any early events arrive, e.g. dialogs.
this._session.send('Page.addScriptToEvaluateOnNewDocument', {
script: '',
worldName: UTILITY_WORLD_NAME,
}),
new Promise(f => this._session.once('Page.ready', f)),
]);
this._pageCallback(this._page); this._pageCallback(this._page);
} catch (e) { this._initialized = true;
this._pageCallback(e); });
} // Ideally, we somehow ensure that utility world is created before Page.ready arrives, but currently it is racy.
this._initialized = true; // Therefore, we can end up with an initialized page without utility world, although very unlikely.
this._session.send('Page.addScriptToEvaluateOnNewDocument', { script: '', worldName: UTILITY_WORLD_NAME }).catch(this._pageCallback);
} }
_initializedPage(): Page | null { _initializedPage(): Page | null {

View file

@ -399,9 +399,15 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
}); });
}); });
describe('focus', function() { describe.fail(!headless)('focus', function() {
it.fail(!headless)('should think that it is focused by default', async({page}) => { it('should think that it is focused by default', async({page}) => {
expect(await page.evaluate('document.hasFocus()')).toBe(true); expect(await page.evaluate('document.hasFocus()')).toBe(true);
}); });
it.fail(FFOX)('should think that all pages are focused', async({page}) => {
const page2 = await page.context().newPage();
expect(await page.evaluate('document.hasFocus()')).toBe(true);
expect(await page2.evaluate('document.hasFocus()')).toBe(true);
await page2.close();
});
}); });
}; };

View file

@ -220,14 +220,11 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WE
expect(popup).toBeTruthy(); expect(popup).toBeTruthy();
await context.close(); await context.close();
}); });
it.fail(FFOX)('should be able to capture alert', async({browser}) => { it('should be able to capture alert', async({browser}) => {
// Firefox:
// - immediately closes dialog by itself, without protocol call;
// - waits for Page.addScriptToEvaluateOnNewDocument before resolving page(), which is too late.
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage();
const evaluatePromise = page.evaluate(() => { const evaluatePromise = page.evaluate(() => {
const win = window.open('about:blank'); const win = window.open('');
win.alert('hello'); win.alert('hello');
}); });
const popup = await page.waitForEvent('popup'); const popup = await page.waitForEvent('popup');