mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
[test] remove the client hints check in firefox & safari
This commit is contained in:
parent
e013038643
commit
b2fc76fe99
@ -3,6 +3,11 @@ import path from 'path';
|
|||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
|
||||||
const localHtml = `file://${path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../../')}/dist/ua-parser.html`;
|
const localHtml = `file://${path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../../')}/dist/ua-parser.html`;
|
||||||
|
const browserMap = {
|
||||||
|
chromium: 'Chrome Headless',
|
||||||
|
firefox: 'Firefox',
|
||||||
|
webkit: 'Safari'
|
||||||
|
}
|
||||||
|
|
||||||
test.describe('Custom navigator.userAgent tests', () => {
|
test.describe('Custom navigator.userAgent tests', () => {
|
||||||
|
|
||||||
@ -42,42 +47,48 @@ test.describe('User-defined user-agent tests', () => {
|
|||||||
|
|
||||||
test.describe('withClientHints() tests', () => {
|
test.describe('withClientHints() tests', () => {
|
||||||
|
|
||||||
test('Detect custom Client Hints data', async ({ page }) => {
|
test('Detect custom Client Hints data', async ({ page, browserName }) => {
|
||||||
await page.addInitScript(() => {
|
await page.addInitScript((browserName) => {
|
||||||
Object.defineProperty(navigator, 'userAgentData', {
|
if (browserName == 'chromium') {
|
||||||
value: {
|
Object.defineProperty(navigator, 'userAgentData', {
|
||||||
brands: [],
|
value: {
|
||||||
platform: '',
|
brands: [],
|
||||||
mobile: false,
|
platform: '',
|
||||||
getHighEntropyValues: () => {
|
mobile: false,
|
||||||
return Promise.resolve({
|
getHighEntropyValues: () => {
|
||||||
brands: [
|
return Promise.resolve({
|
||||||
{
|
brands: [
|
||||||
brand: 'Chromium',
|
{
|
||||||
version: '110'
|
brand: 'Chromium',
|
||||||
},
|
version: '110'
|
||||||
{
|
},
|
||||||
brand: 'Not(A:Brand',
|
{
|
||||||
version: '110'
|
brand: 'Not(A:Brand',
|
||||||
},
|
version: '110'
|
||||||
{
|
},
|
||||||
brand: 'New Browser',
|
{
|
||||||
version: '110'
|
brand: 'New Browser',
|
||||||
}
|
version: '110'
|
||||||
],
|
}
|
||||||
platform: 'New OS',
|
],
|
||||||
formFactors: 'New Form Factor'
|
platform: 'New OS',
|
||||||
});
|
formFactors: 'New Form Factor'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
});
|
}, browserName);
|
||||||
await page.goto(localHtml);
|
await page.goto(localHtml);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const uap = await page.evaluate(async () => await UAParser().withClientHints());
|
const uap = await page.evaluate(async () => await UAParser().withClientHints());
|
||||||
expect(uap).toHaveProperty('browser.name', 'New Browser');
|
if (browserName == 'chromium') {
|
||||||
expect(uap).toHaveProperty('os.name', 'New OS');
|
expect(uap).toHaveProperty('browser.name', 'New Browser');
|
||||||
expect(uap).toHaveProperty('device.type', undefined);
|
expect(uap).toHaveProperty('os.name', 'New OS');
|
||||||
|
expect(uap).toHaveProperty('device.type', undefined);
|
||||||
|
} else {
|
||||||
|
expect(uap).toHaveProperty('browser.name', browserMap[browserName]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,11 +105,6 @@ test.describe('withFeatureCheck() tests', () => {
|
|||||||
await page.goto(localHtml);
|
await page.goto(localHtml);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let uap = await page.evaluate(() => UAParser());
|
let uap = await page.evaluate(() => UAParser());
|
||||||
const browserMap = {
|
|
||||||
chromium: 'Chrome Headless',
|
|
||||||
firefox: 'Firefox',
|
|
||||||
webkit: 'Safari'
|
|
||||||
}
|
|
||||||
expect(uap).toHaveProperty('browser.name', browserMap[browserName]);
|
expect(uap).toHaveProperty('browser.name', browserMap[browserName]);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
uap = await page.evaluate(() => UAParser().withFeatureCheck());
|
uap = await page.evaluate(() => UAParser().withFeatureCheck());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user