feat(lang): emulate language on firefox (#1453)

This commit is contained in:
Pavel Feldman 2020-03-20 19:32:27 -07:00 committed by GitHub
parent 21630d6de4
commit e210e5601c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 7 deletions

View file

@ -9,7 +9,7 @@
"main": "index.js",
"playwright": {
"chromium_revision": "751710",
"firefox_revision": "1044",
"firefox_revision": "1045",
"webkit_revision": "1180"
},
"scripts": {

View file

@ -170,8 +170,8 @@ export class FFBrowserContext extends BrowserContextBase {
async _initialize() {
if (this._options.permissions)
await this.grantPermissions(this._options.permissions);
if (this._options.extraHTTPHeaders)
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders);
if (this._options.extraHTTPHeaders || this._options.locale)
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {});
if (this._options.offline)
await this.setOffline(this._options.offline);
if (this._options.httpCredentials)
@ -257,7 +257,10 @@ export class FFBrowserContext extends BrowserContextBase {
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
this._options.extraHTTPHeaders = network.verifyHeaders(headers);
await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: headersArray(this._options.extraHTTPHeaders) });
const allHeaders = { ...this._options.extraHTTPHeaders };
if (this._options.locale)
allHeaders['Accept-Language'] = this._options.locale;
await this._browser._connection.send('Browser.setExtraHTTPHeaders', { browserContextId: this._browserContextId || undefined, headers: headersArray(allHeaders) });
}
async setOffline(offline: boolean): Promise<void> {

View file

@ -87,6 +87,7 @@ export class FFPage implements PageDelegate {
async _initialize() {
const geolocation = this._browserContext._options.geolocation;
const language = this._browserContext._options.locale;
try {
await Promise.all([
// TODO: we should get rid of this call to resolve before any early events arrive, e.g. dialogs.
@ -95,6 +96,7 @@ export class FFPage implements PageDelegate {
worldName: UTILITY_WORLD_NAME,
}),
geolocation ? this._setGeolocation(geolocation) : Promise.resolve(),
language ? this._session.send('Page.setLanguageOverride', { language }) : Promise.resolve(),
new Promise(f => this._session.once('Page.ready', f)),
]);
this._pageCallback(this._page);

View file

@ -0,0 +1,3 @@
<script>
window.result = (1000000.50).toLocaleString().replace(/\s/g, ' ');
</script>

View file

@ -291,7 +291,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
});
});
describe.fail(FFOX)('BrowserContext({locale})', function() {
describe('BrowserContext({locale})', function() {
it('should affect accept-language header', async({browser, server}) => {
const context = await browser.newContext({ locale: 'fr-CH' });
const page = await context.newPage();
@ -308,7 +308,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
expect(await page.evaluate(() => navigator.language)).toBe('fr-CH');
await context.close();
});
it('should format number', async({browser, server}) => {
it.fail(FFOX)('should format number', async({browser, server}) => {
{
const context = await browser.newContext({ locale: 'en-US' });
const page = await context.newPage();
@ -324,7 +324,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
await context.close();
}
});
it('should format date', async({browser, server}) => {
it.fail(FFOX)('should format date', async({browser, server}) => {
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Los_Angeles' });
const page = await context.newPage();
@ -342,6 +342,20 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
await context.close();
}
});
it.fail(CHROMIUM || FFOX)('should apply to popups', async({browser, server}) => {
const context = await browser.newContext({ locale: 'fr-CH' });
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.evaluate(url => window._popup = window.open(url), server.PREFIX + '/formatted-number.html'),
]);
await popup.waitForLoadState({ waitUntil: 'domcontentloaded' });
const result = await popup.evaluate(() => window.result);
expect(result).toBe('1 000 000,5');
await context.close();
});
});
describe('focus', function() {