Skip to content

Commit

Permalink
feat(webkit): emulate timezone on webkit (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Feb 13, 2020
1 parent d26f47b commit 012bf67
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"playwright": {
"chromium_revision": "740847",
"firefox_revision": "1028",
"webkit_revision": "1146"
"webkit_revision": "1147"
},
"scripts": {
"ctest": "cross-env BROWSER=chromium node test/test.js",
Expand Down
2 changes: 1 addition & 1 deletion src/webkit/wkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class WKSession extends platform.EventEmitter {
export function createProtocolError(error: Error, method: string, object: { error: { message: string; data: any; }; }): Error {
let message = `Protocol error (${method}): ${object.error.message}`;
if ('data' in object.error)
message += ` ${object.error.data}`;
message += ` ${JSON.stringify(object.error.data)}`;
return rewriteError(error, message);
}

Expand Down
4 changes: 4 additions & 0 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export class WKPage implements PageDelegate {
promises.push(session.send('Network.setExtraHTTPHeaders', { headers: this._page._state.extraHTTPHeaders }));
if (this._page._state.hasTouch)
promises.push(session.send('Page.setTouchEmulationEnabled', { enabled: true }));
if (contextOptions.timezoneId) {
promises.push(session.send('Page.setTimeZone', { timeZone: contextOptions.timezoneId }).
catch(e => { throw new Error(`Invalid timezone ID: ${contextOptions.timezoneId}`); }));
}
await Promise.all(promises);
}

Expand Down
22 changes: 17 additions & 5 deletions test/emulation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,36 @@ module.exports.describe = function({testRunner, expect, playwright, headless, FF
});
});

describe.skip(FFOX || WEBKIT)('BrowserContext({timezoneId})', function() {
describe.skip(FFOX)('BrowserContext({timezoneId})', function() {
it('should work', async ({ newPage }) => {
const func = () => new Date(1479579154987).toString();
{
const page = await newPage({ timezoneId: 'America/Jamaica' });
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');
if (WEBKIT)
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (America/Jamaica)');
else
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');
}
{
const page = await newPage({ timezoneId: 'Pacific/Honolulu' });
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');
if (WEBKIT)
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Pacific/Honolulu)');
else
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');
}
{
const page = await newPage({ timezoneId: 'America/Buenos_Aires' });
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');
if (WEBKIT)
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (America/Buenos_Aires)');
else
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');
}
{
const page = await newPage({ timezoneId: 'Europe/Berlin' });
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');
if (WEBKIT)
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Europe/Berlin)');
else
expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');
}
});

Expand Down

0 comments on commit 012bf67

Please sign in to comment.