fix(geolocation): use values from context options (#463)

This commit is contained in:
Pavel Feldman 2020-01-13 13:32:44 -08:00 коммит произвёл GitHub
Родитель 27f32a72e9
Коммит d19f10ef42
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 188 добавлений и 312 удалений

Просмотреть файл

@ -23,7 +23,7 @@
* [browserContext.clearPermissions()](#browsercontextclearpermissions) * [browserContext.clearPermissions()](#browsercontextclearpermissions)
* [browserContext.close()](#browsercontextclose) * [browserContext.close()](#browsercontextclose)
* [browserContext.cookies([...urls])](#browsercontextcookiesurls) * [browserContext.cookies([...urls])](#browsercontextcookiesurls)
* [browserContext.newPage()](#browsercontextnewpage) * [browserContext.newPage(url)](#browsercontextnewpageurl)
* [browserContext.pages()](#browsercontextpages) * [browserContext.pages()](#browsercontextpages)
* [browserContext.setCookies(cookies)](#browsercontextsetcookiescookies) * [browserContext.setCookies(cookies)](#browsercontextsetcookiescookies)
* [browserContext.setGeolocation(geolocation)](#browsercontextsetgeolocationgeolocation) * [browserContext.setGeolocation(geolocation)](#browsercontextsetgeolocationgeolocation)
@ -305,8 +305,7 @@ const playwright = require('playwright')('chromium'); // Or 'firefox' or 'webki
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage('http://example.com');
await page.goto('http://example.com');
// other actions... // other actions...
await browser.close(); await browser.close();
})(); })();
@ -335,10 +334,11 @@ const iPhone = playwright.devices['iPhone 6'];
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext({
const page = await context.newPage(); viewport: iPhone.viewport,
await page.emulate(iPhone); userAgent: iPhone.userAgent;
await page.goto('http://example.com'); });
const page = await context.newPage('http://example.com');
// other actions... // other actions...
await browser.close(); await browser.close();
})(); })();
@ -381,8 +381,7 @@ const playwright = require('playwright');
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage('https://example.com');
await page.goto('https://example.com');
await browser.close(); await browser.close();
})(); })();
``` ```
@ -441,8 +440,6 @@ Indicates that the browser is connected.
- `height` <[number]> page height in pixels. - `height` <[number]> page height in pixels.
- `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`.
- `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`.
- `hasTouch`<[boolean]> Specifies if viewport supports touch events. Defaults to `false`
- `isLandscape` <[boolean]> Specifies if viewport is in landscape mode. Defaults to `false`.
- `userAgent` <?[string]> Specific user agent to use in this page - `userAgent` <?[string]> Specific user agent to use in this page
- `javaScriptEnabled` <?[boolean]> Whether or not to enable or disable JavaScript in the page. Defaults to true. - `javaScriptEnabled` <?[boolean]> Whether or not to enable or disable JavaScript in the page. Defaults to true.
- `timezoneId` <?[string]> Changes the timezone of the page. See [ICUs `metaZones.txt`](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. - `timezoneId` <?[string]> Changes the timezone of the page. See [ICUs `metaZones.txt`](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs.
@ -450,6 +447,7 @@ Indicates that the browser is connected.
- `latitude` <[number]> Latitude between -90 and 90. - `latitude` <[number]> Latitude between -90 and 90.
- `longitude` <[number]> Longitude between -180 and 180. - `longitude` <[number]> Longitude between -180 and 180.
- `accuracy` <[number]> Optional non-negative accuracy value. - `accuracy` <[number]> Optional non-negative accuracy value.
- `permissions` <[Object]> A map from origin keys to permissions values. See [browserContext.setPermissions]((#browsercontextsetpermissionsorigin-permissions)) for more details.
- returns: <[Promise]<[BrowserContext]>> - returns: <[Promise]<[BrowserContext]>>
Creates a new browser context. It won't share cookies/cache with other browser contexts. Creates a new browser context. It won't share cookies/cache with other browser contexts.
@ -460,9 +458,7 @@ Creates a new browser context. It won't share cookies/cache with other browser c
// Create a new incognito browser context. // Create a new incognito browser context.
const context = await browser.newContext(); const context = await browser.newContext();
// Create a new page in a pristine context. // Create a new page in a pristine context.
const page = await context.newPage(); const page = await context.newPage('https://example.com');
// Do stuff
await page.goto('https://example.com');
})(); })();
``` ```
@ -482,9 +478,7 @@ Playwright allows creation of "incognito" browser contexts with `browser.newCont
// Create a new incognito browser context // Create a new incognito browser context
const context = await browser.newContext(); const context = await browser.newContext();
// Create a new page inside context. // Create a new page inside context.
const page = await context.newPage(); const page = await context.newPage('https://example.com');
// ... do stuff with page ...
await page.goto('https://example.com');
// Dispose context once it's no longer needed. // Dispose context once it's no longer needed.
await context.close(); await context.close();
``` ```
@ -533,10 +527,11 @@ If URLs are specified, only cookies that affect those URLs are returned.
> **NOTE** the default browser context cannot be closed. > **NOTE** the default browser context cannot be closed.
#### browserContext.newPage() #### browserContext.newPage(url)
- `url` <?[string]> Optional url to navigate the page to.
- returns: <[Promise]<[Page]>> - returns: <[Promise]<[Page]>>
Creates a new page in the browser context. Creates a new page in the browser context and optionally navigates it to the specified URL.
#### browserContext.pages() #### browserContext.pages()
- returns: <[Promise]<[Array]<[Page]>>> Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [target.page()](#targetpage). - returns: <[Promise]<[Array]<[Page]>>> Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [target.page()](#targetpage).
@ -725,8 +720,7 @@ const playwright = require('playwright');
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage('https://example.com');
await page.goto('https://example.com');
const hrefElement = await page.$('a'); const hrefElement = await page.$('a');
await hrefElement.click(); await hrefElement.click();
// ... // ...
@ -993,8 +987,7 @@ const playwright = require('playwright');
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage('https://www.google.com/chrome/browser/canary.html');
await page.goto('https://www.google.com/chrome/browser/canary.html');
dumpFrameTree(page.mainFrame(), ''); dumpFrameTree(page.mainFrame(), '');
await browser.close(); await browser.close();
@ -1782,8 +1775,7 @@ const playwright = require('playwright');
(async () => { (async () => {
const browser = await playwright.launch(); const browser = await playwright.launch();
const context = await browser.newContext(); const context = await browser.newContext();
const page = await context.newPage(); const page = await context.newPage('https://example.com');
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'}); await page.screenshot({path: 'screenshot.png'});
await browser.close(); await browser.close();
})(); })();
@ -2629,11 +2621,9 @@ await browser.close();
- `height` <[number]> page height in pixels. **required** - `height` <[number]> page height in pixels. **required**
- `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`.
- `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`.
- `hasTouch`<[boolean]> Specifies if viewport supports touch events. Defaults to `false`
- `isLandscape` <[boolean]> Specifies if viewport is in landscape mode. Defaults to `false`.
- returns: <[Promise]> - returns: <[Promise]>
> **NOTE** in certain cases, setting viewport will reload the page in order to set the `isMobile` or `hasTouch` properties. > **NOTE** in certain cases, setting viewport will reload the page in order to set the `isMobile` property.
In the case of multiple pages in a single browser, each page can have its own viewport size. In the case of multiple pages in a single browser, each page can have its own viewport size.
@ -2707,8 +2697,6 @@ This is a shortcut for [page.mainFrame().url()](#frameurl)
- `height` <[number]> page height in pixels. - `height` <[number]> page height in pixels.
- `deviceScaleFactor` <[number]> Specify device scale factor (can be though of as dpr). Defaults to `1`. - `deviceScaleFactor` <[number]> Specify device scale factor (can be though of as dpr). Defaults to `1`.
- `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`. - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account. Defaults to `false`.
- `hasTouch`<[boolean]> Specifies if viewport supports touch events. Defaults to `false`
- `isLandscape` <[boolean]> Specifies if viewport is in landscape mode. Defaults to `false`.
#### page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]) #### page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]])
- `selectorOrFunctionOrTimeout` <[string]|[number]|[function]> A [selector], predicate or timeout to wait for - `selectorOrFunctionOrTimeout` <[string]|[number]|[function]> A [selector], predicate or timeout to wait for

Просмотреть файл

@ -41,7 +41,8 @@ export type BrowserContextOptions = {
bypassCSP?: boolean, bypassCSP?: boolean,
userAgent?: string, userAgent?: string,
timezoneId?: string, timezoneId?: string,
geolocation?: types.Geolocation geolocation?: types.Geolocation,
permissions?: { [key: string]: string[] };
}; };
export class BrowserContext { export class BrowserContext {
@ -60,12 +61,22 @@ export class BrowserContext {
this._options.geolocation = { ...this._options.geolocation }; this._options.geolocation = { ...this._options.geolocation };
} }
async _initialize() {
const entries = Object.entries(this._options.permissions || {});
await Promise.all(entries.map(entry => this.setPermissions(entry[0], entry[1])));
if (this._options.geolocation)
await this.setGeolocation(this._options.geolocation);
}
async pages(): Promise<Page[]> { async pages(): Promise<Page[]> {
return this._delegate.pages(); return this._delegate.pages();
} }
async newPage(): Promise<Page> { async newPage(url?: string): Promise<Page> {
return this._delegate.newPage(); const page = await this._delegate.newPage();
if (url)
await page.goto(url);
return page;
} }
async cookies(...urls: string[]): Promise<network.NetworkCookie[]> { async cookies(...urls: string[]): Promise<network.NetworkCookie[]> {

Просмотреть файл

@ -156,6 +156,7 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> { async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {
const { browserContextId } = await this._client.send('Target.createBrowserContext'); const { browserContextId } = await this._client.send('Target.createBrowserContext');
const context = this._createBrowserContext(browserContextId, options); const context = this._createBrowserContext(browserContextId, options);
await context._initialize();
this._contexts.set(browserContextId, context); this._contexts.set(browserContextId, context);
return context; return context;
} }

Просмотреть файл

@ -299,15 +299,12 @@ export class CRPage implements PageDelegate {
height, height,
isMobile = false, isMobile = false,
deviceScaleFactor = 1, deviceScaleFactor = 1,
hasTouch = false,
isLandscape = false,
} = viewport; } = viewport;
const isLandscape = width > height;
const screenOrientation: Protocol.Emulation.ScreenOrientation = isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' }; const screenOrientation: Protocol.Emulation.ScreenOrientation = isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
await Promise.all([ await Promise.all([
this._client.send('Emulation.setDeviceMetricsOverride', { mobile: isMobile, width, height, deviceScaleFactor, screenOrientation }), this._client.send('Emulation.setDeviceMetricsOverride', { mobile: isMobile, width, height, deviceScaleFactor, screenOrientation }),
this._client.send('Emulation.setTouchEmulationEnabled', { this._client.send('Emulation.setTouchEmulationEnabled', { enabled: isMobile })
enabled: hasTouch
})
]); ]);
} }

Просмотреть файл

@ -25,9 +25,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 600, 'width': 600,
'height': 1024, 'height': 1024,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -37,9 +35,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 1024, 'width': 1024,
'height': 600, 'height': 600,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -49,9 +45,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -61,9 +55,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -73,9 +65,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -85,9 +75,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -97,9 +85,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -109,9 +95,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -121,9 +105,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -133,9 +115,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -145,9 +125,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -157,129 +135,87 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
'name': 'iPad', 'name': 'iPad (gen 6)',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 768, 'width': 768,
'height': 1024, 'height': 1024,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
'name': 'iPad landscape', 'name': 'iPad (gen 6) landscape',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 1024, 'width': 1024,
'height': 768, 'height': 768,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true, }
'isLandscape': true },
{
'name': 'iPad (gen 7)',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': {
'width': 810,
'height': 1080,
'deviceScaleFactor': 2,
'isMobile': true
}
},
{
'name': 'iPad (gen 7) landscape',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': {
'width': 1080,
'height': 810,
'deviceScaleFactor': 2,
'isMobile': true
} }
}, },
{ {
'name': 'iPad Mini', 'name': 'iPad Mini',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 768, 'width': 768,
'height': 1024, 'height': 1024,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
'name': 'iPad Mini landscape', 'name': 'iPad Mini landscape',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 1024, 'width': 1024,
'height': 768, 'height': 768,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
'name': 'iPad Pro', 'name': 'iPad Pro 11',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 1024, 'width': 834,
'height': 1366, 'height': 1194,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
'name': 'iPad Pro landscape', 'name': 'iPad Pro 11 landscape',
'userAgent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'userAgent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': { 'viewport': {
'width': 1366, 'width': 1194,
'height': 1024, 'height': 834,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
}
},
{
'name': 'iPhone 4',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
'viewport': {
'width': 320,
'height': 480,
'deviceScaleFactor': 2,
'isMobile': true,
'hasTouch': true,
'isLandscape': false
}
},
{
'name': 'iPhone 4 landscape',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
'viewport': {
'width': 480,
'height': 320,
'deviceScaleFactor': 2,
'isMobile': true,
'hasTouch': true,
'isLandscape': true
}
},
{
'name': 'iPhone 5',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
'viewport': {
'width': 320,
'height': 568,
'deviceScaleFactor': 2,
'isMobile': true,
'hasTouch': true,
'isLandscape': false
}
},
{
'name': 'iPhone 5 landscape',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
'viewport': {
'width': 568,
'height': 320,
'deviceScaleFactor': 2,
'isMobile': true,
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -289,9 +225,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 375, 'width': 375,
'height': 667, 'height': 667,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -301,9 +235,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 667, 'width': 667,
'height': 375, 'height': 375,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -313,9 +245,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 414, 'width': 414,
'height': 736, 'height': 736,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -325,9 +255,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 736, 'width': 736,
'height': 414, 'height': 414,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -337,9 +265,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 375, 'width': 375,
'height': 667, 'height': 667,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -349,9 +275,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 667, 'width': 667,
'height': 375, 'height': 375,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -361,9 +285,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 414, 'width': 414,
'height': 736, 'height': 736,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -373,9 +295,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 736, 'width': 736,
'height': 414, 'height': 414,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -385,9 +305,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 375, 'width': 375,
'height': 667, 'height': 667,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -397,9 +315,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 667, 'width': 667,
'height': 375, 'height': 375,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -409,9 +325,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 414, 'width': 414,
'height': 736, 'height': 736,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -421,9 +335,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 736, 'width': 736,
'height': 414, 'height': 414,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -433,9 +345,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 320, 'width': 320,
'height': 568, 'height': 568,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -445,9 +355,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 568, 'width': 568,
'height': 320, 'height': 320,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -457,9 +365,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 375, 'width': 375,
'height': 812, 'height': 812,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -469,9 +375,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 812, 'width': 812,
'height': 375, 'height': 375,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -481,9 +385,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 414, 'width': 414,
'height': 896, 'height': 896,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -493,9 +395,37 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 896, 'width': 896,
'height': 414, 'height': 414,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true, }
'isLandscape': true },
{
'name': 'iPhone 11',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': {
'width': 414,
'height': 896,
'deviceScaleFactor': 2,
'isMobile': true
}
},
{
'name': 'iPhone 11 Pro',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': {
'width': 375,
'height': 812,
'deviceScaleFactor': 3,
'isMobile': true
}
},
{
'name': 'iPhone 11 Pro Max',
'userAgent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1',
'viewport': {
'width': 414,
'height': 896,
'deviceScaleFactor': 3,
'isMobile': true
} }
}, },
{ {
@ -505,9 +435,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 240, 'width': 240,
'height': 320, 'height': 320,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -517,9 +445,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 320, 'width': 320,
'height': 240, 'height': 240,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -529,9 +455,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 800, 'width': 800,
'height': 1280, 'height': 1280,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -541,9 +465,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 1280, 'width': 1280,
'height': 800, 'height': 800,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -553,9 +475,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 384, 'width': 384,
'height': 640, 'height': 640,
'deviceScaleFactor': 1.25, 'deviceScaleFactor': 1.25,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -565,9 +485,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 384, 'height': 384,
'deviceScaleFactor': 1.25, 'deviceScaleFactor': 1.25,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -577,9 +495,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -589,9 +505,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 4, 'deviceScaleFactor': 4,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -601,9 +515,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 4, 'deviceScaleFactor': 4,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -613,9 +525,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 800, 'width': 800,
'height': 1280, 'height': 1280,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -625,9 +535,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 1280, 'width': 1280,
'height': 800, 'height': 800,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -637,9 +545,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 384, 'width': 384,
'height': 640, 'height': 640,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -649,9 +555,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 384, 'height': 384,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -661,9 +565,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 360, 'width': 360,
'height': 640, 'height': 640,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -673,9 +575,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 640, 'width': 640,
'height': 360, 'height': 360,
'deviceScaleFactor': 3, 'deviceScaleFactor': 3,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -685,9 +585,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 412, 'width': 412,
'height': 732, 'height': 732,
'deviceScaleFactor': 2.625, 'deviceScaleFactor': 2.625,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -697,9 +595,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 732, 'width': 732,
'height': 412, 'height': 412,
'deviceScaleFactor': 2.625, 'deviceScaleFactor': 2.625,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -709,9 +605,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 412, 'width': 412,
'height': 732, 'height': 732,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -721,9 +615,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 732, 'width': 732,
'height': 412, 'height': 412,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -733,9 +625,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 412, 'width': 412,
'height': 732, 'height': 732,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -745,9 +635,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 732, 'width': 732,
'height': 412, 'height': 412,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -757,9 +645,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 600, 'width': 600,
'height': 960, 'height': 960,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -769,9 +655,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 960, 'width': 960,
'height': 600, 'height': 600,
'deviceScaleFactor': 2, 'deviceScaleFactor': 2,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -781,9 +665,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 320, 'width': 320,
'height': 533, 'height': 533,
'deviceScaleFactor': 1.5, 'deviceScaleFactor': 1.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -793,9 +675,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 533, 'width': 533,
'height': 320, 'height': 320,
'deviceScaleFactor': 1.5, 'deviceScaleFactor': 1.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -805,9 +685,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 480, 'width': 480,
'height': 854, 'height': 854,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -817,9 +695,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 854, 'width': 854,
'height': 480, 'height': 480,
'deviceScaleFactor': 1, 'deviceScaleFactor': 1,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -829,9 +705,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 411, 'width': 411,
'height': 731, 'height': 731,
'deviceScaleFactor': 2.625, 'deviceScaleFactor': 2.625,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -841,9 +715,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 731, 'width': 731,
'height': 411, 'height': 411,
'deviceScaleFactor': 2.625, 'deviceScaleFactor': 2.625,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
}, },
{ {
@ -853,9 +725,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 411, 'width': 411,
'height': 823, 'height': 823,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': false
} }
}, },
{ {
@ -865,9 +735,7 @@ const descriptors: types.DeviceDescriptor[] = [
'width': 823, 'width': 823,
'height': 411, 'height': 411,
'deviceScaleFactor': 3.5, 'deviceScaleFactor': 3.5,
'isMobile': true, 'isMobile': true
'hasTouch': true,
'isLandscape': true
} }
} }
]; ];

Просмотреть файл

@ -83,6 +83,7 @@ export class FFBrowser extends platform.EventEmitter implements Browser {
if (options.ignoreHTTPSErrors) if (options.ignoreHTTPSErrors)
await this._connection.send('Browser.setIgnoreHTTPSErrors', { enabled: true }); await this._connection.send('Browser.setIgnoreHTTPSErrors', { enabled: true });
const context = this._createBrowserContext(browserContextId, options); const context = this._createBrowserContext(browserContextId, options);
await context._initialize();
this._contexts.set(browserContextId, context); this._contexts.set(browserContextId, context);
return context; return context;
} }

Просмотреть файл

@ -204,11 +204,9 @@ export class FFPage implements PageDelegate {
height, height,
isMobile = false, isMobile = false,
deviceScaleFactor = 1, deviceScaleFactor = 1,
hasTouch = false,
isLandscape = false,
} = viewport; } = viewport;
await this._session.send('Page.setViewport', { await this._session.send('Page.setViewport', {
viewport: { width, height, isMobile, deviceScaleFactor, hasTouch, isLandscape }, viewport: { width, height, isMobile, deviceScaleFactor, hasTouch: isMobile, isLandscape: width > height },
}); });
} }

Просмотреть файл

@ -393,12 +393,10 @@ export class Page extends platform.EventEmitter {
async setViewport(viewport: types.Viewport) { async setViewport(viewport: types.Viewport) {
const oldIsMobile = this._state.viewport ? !!this._state.viewport.isMobile : false; const oldIsMobile = this._state.viewport ? !!this._state.viewport.isMobile : false;
const oldHasTouch = this._state.viewport ? !!this._state.viewport.hasTouch : false;
const newIsMobile = !!viewport.isMobile; const newIsMobile = !!viewport.isMobile;
const newHasTouch = !!viewport.hasTouch;
this._state.viewport = { ...viewport }; this._state.viewport = { ...viewport };
await this._delegate.setViewport(viewport); await this._delegate.setViewport(viewport);
if (oldIsMobile !== newIsMobile || oldHasTouch !== newHasTouch) if (oldIsMobile !== newIsMobile)
await this.reload(); await this.reload();
} }

Просмотреть файл

@ -58,8 +58,6 @@ export type Viewport = {
height: number; height: number;
deviceScaleFactor?: number; deviceScaleFactor?: number;
isMobile?: boolean; isMobile?: boolean;
isLandscape?: boolean;
hasTouch?: boolean;
}; };
export type URLMatch = string | RegExp | ((url: URL) => boolean); export type URLMatch = string | RegExp | ((url: URL) => boolean);

Просмотреть файл

@ -80,6 +80,7 @@ export class WKBrowser extends platform.EventEmitter implements Browser {
const context = this._createBrowserContext(browserContextId, options); const context = this._createBrowserContext(browserContextId, options);
if (options.ignoreHTTPSErrors) if (options.ignoreHTTPSErrors)
await this._browserSession.send('Browser.setIgnoreCertificateErrors', { browserContextId, ignore: true }); await this._browserSession.send('Browser.setIgnoreCertificateErrors', { browserContextId, ignore: true });
await context._initialize();
this._contexts.set(browserContextId, context); this._contexts.set(browserContextId, context);
return context; return context;
} }

Просмотреть файл

@ -322,10 +322,10 @@ export class WKPage implements PageDelegate {
const height = viewport.height; const height = viewport.height;
const fixedLayout = !!viewport.isMobile; const fixedLayout = !!viewport.isMobile;
const deviceScaleFactor = viewport.deviceScaleFactor || 1; const deviceScaleFactor = viewport.deviceScaleFactor || 1;
this._page._state.hasTouch = !!viewport.hasTouch; this._page._state.hasTouch = !!viewport.isMobile;
await Promise.all([ await Promise.all([
this._pageProxySession.send('Emulation.setDeviceMetricsOverride', {width, height, fixedLayout, deviceScaleFactor }), this._pageProxySession.send('Emulation.setDeviceMetricsOverride', {width, height, fixedLayout, deviceScaleFactor }),
this._session.send('Page.setTouchEmulationEnabled', { enabled: !!viewport.hasTouch }), this._session.send('Page.setTouchEmulationEnabled', { enabled: !!viewport.isMobile }),
]); ]);
} }

Просмотреть файл

@ -66,7 +66,7 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
expect(await page.evaluate(() => document.body.textContent.trim())).toBe('YES'); expect(await page.evaluate(() => document.body.textContent.trim())).toBe('YES');
}); });
it('should detect touch when applying viewport with touches', async({page, server}) => { it('should detect touch when applying viewport with touches', async({page, server}) => {
await page.setViewport({ width: 800, height: 600, hasTouch: true }); await page.setViewport({ width: 800, height: 600, isMobile: true });
await page.addScriptTag({url: server.PREFIX + '/modernizr.js'}); await page.addScriptTag({url: server.PREFIX + '/modernizr.js'});
expect(await page.evaluate(() => Modernizr.touchevents)).toBe(true); expect(await page.evaluate(() => Modernizr.touchevents)).toBe(true);
}); });

Просмотреть файл

@ -49,5 +49,20 @@ module.exports.describe = function ({ testRunner, expect, FFOX, WEBKIT }) {
await context.setGeolocation({ longitude: 20, latitude: 20 }); await context.setGeolocation({ longitude: 20, latitude: 20 });
expect(options.geolocation).toBe(geolocation); expect(options.geolocation).toBe(geolocation);
}); });
it('should use context options', async({newContext, server}) => {
const options = { geolocation: { longitude: 10, latitude: 10 }, permissions: {} };
options.permissions[server.PREFIX] = ['geolocation'];
const context = await newContext(options);
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
const geolocation = await page.evaluate(() => new Promise(resolve => navigator.geolocation.getCurrentPosition(position => {
resolve({latitude: position.coords.latitude, longitude: position.coords.longitude});
})));
expect(geolocation).toEqual({
latitude: 10,
longitude: 10
});
});
}); });
}; };