test: add test to validate user-agent sanity (#2887)
This commit is contained in:
parent
b93e0994bc
commit
c3ac0371e6
|
|
@ -1292,6 +1292,42 @@ describe('Page.frame', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('user-agent sanity', function() {
|
||||||
|
it('should be a sane user agent', async ({page}) => {
|
||||||
|
const userAgent = await page.evaluate(() => navigator.userAgent);
|
||||||
|
const [
|
||||||
|
part1,
|
||||||
|
part2,
|
||||||
|
part3,
|
||||||
|
part4,
|
||||||
|
part5,
|
||||||
|
] = userAgent.split(/[()]/).map(part => part.trim());
|
||||||
|
// First part is always "Mozilla/5.0"
|
||||||
|
expect(part1).toBe('Mozilla/5.0');
|
||||||
|
// Second part in parenthesis is platform - ignore it.
|
||||||
|
|
||||||
|
// Third part for Firefox is the last one and encodes engine and browser versions.
|
||||||
|
if (FFOX) {
|
||||||
|
const [engine, browser] = part3.split(' ');
|
||||||
|
expect(engine.startsWith('Gecko')).toBe(true);
|
||||||
|
expect(browser.startsWith('Firefox')).toBe(true);
|
||||||
|
expect(part4).toBe(undefined);
|
||||||
|
expect(part5).toBe(undefined);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// For both CHROMIUM and WEBKIT, third part is the AppleWebKit version.
|
||||||
|
expect(part3.startsWith('AppleWebKit/')).toBe(true);
|
||||||
|
expect(part4).toBe('KHTML, like Gecko');
|
||||||
|
// 5th part encodes real browser name and engine version.
|
||||||
|
const [engine, browser] = part5.split(' ');
|
||||||
|
expect(browser.startsWith('Safari/')).toBe(true);
|
||||||
|
if (CHROMIUM)
|
||||||
|
expect(engine.includes('Chrome/')).toBe(true);
|
||||||
|
else
|
||||||
|
expect(engine.startsWith('Version/')).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Page api coverage', function() {
|
describe('Page api coverage', function() {
|
||||||
it('Page.press should work', async({page, server}) => {
|
it('Page.press should work', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue