feat(lang): emulate language on firefox (#1453)
This commit is contained in:
parent
21630d6de4
commit
e210e5601c
|
|
@ -9,7 +9,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"playwright": {
|
"playwright": {
|
||||||
"chromium_revision": "751710",
|
"chromium_revision": "751710",
|
||||||
"firefox_revision": "1044",
|
"firefox_revision": "1045",
|
||||||
"webkit_revision": "1180"
|
"webkit_revision": "1180"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -170,8 +170,8 @@ export class FFBrowserContext extends BrowserContextBase {
|
||||||
async _initialize() {
|
async _initialize() {
|
||||||
if (this._options.permissions)
|
if (this._options.permissions)
|
||||||
await this.grantPermissions(this._options.permissions);
|
await this.grantPermissions(this._options.permissions);
|
||||||
if (this._options.extraHTTPHeaders)
|
if (this._options.extraHTTPHeaders || this._options.locale)
|
||||||
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders);
|
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {});
|
||||||
if (this._options.offline)
|
if (this._options.offline)
|
||||||
await this.setOffline(this._options.offline);
|
await this.setOffline(this._options.offline);
|
||||||
if (this._options.httpCredentials)
|
if (this._options.httpCredentials)
|
||||||
|
|
@ -257,7 +257,10 @@ export class FFBrowserContext extends BrowserContextBase {
|
||||||
|
|
||||||
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
|
async setExtraHTTPHeaders(headers: network.Headers): Promise<void> {
|
||||||
this._options.extraHTTPHeaders = network.verifyHeaders(headers);
|
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> {
|
async setOffline(offline: boolean): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ export class FFPage implements PageDelegate {
|
||||||
|
|
||||||
async _initialize() {
|
async _initialize() {
|
||||||
const geolocation = this._browserContext._options.geolocation;
|
const geolocation = this._browserContext._options.geolocation;
|
||||||
|
const language = this._browserContext._options.locale;
|
||||||
try {
|
try {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// TODO: we should get rid of this call to resolve before any early events arrive, e.g. dialogs.
|
// 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,
|
worldName: UTILITY_WORLD_NAME,
|
||||||
}),
|
}),
|
||||||
geolocation ? this._setGeolocation(geolocation) : Promise.resolve(),
|
geolocation ? this._setGeolocation(geolocation) : Promise.resolve(),
|
||||||
|
language ? this._session.send('Page.setLanguageOverride', { language }) : Promise.resolve(),
|
||||||
new Promise(f => this._session.once('Page.ready', f)),
|
new Promise(f => this._session.once('Page.ready', f)),
|
||||||
]);
|
]);
|
||||||
this._pageCallback(this._page);
|
this._pageCallback(this._page);
|
||||||
|
|
|
||||||
3
test/assets/formatted-number.html
Normal file
3
test/assets/formatted-number.html
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<script>
|
||||||
|
window.result = (1000000.50).toLocaleString().replace(/\s/g, ' ');
|
||||||
|
</script>
|
||||||
|
|
@ -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}) => {
|
it('should affect accept-language header', async({browser, server}) => {
|
||||||
const context = await browser.newContext({ locale: 'fr-CH' });
|
const context = await browser.newContext({ locale: 'fr-CH' });
|
||||||
const page = await context.newPage();
|
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');
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-CH');
|
||||||
await context.close();
|
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 context = await browser.newContext({ locale: 'en-US' });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
@ -324,7 +324,7 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
|
||||||
await context.close();
|
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 context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Los_Angeles' });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
@ -342,6 +342,20 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
|
||||||
await context.close();
|
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() {
|
describe('focus', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue