2019-11-21 01:18:05 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-02-11 00:20:13 +03:00
|
|
|
/**
|
|
|
|
* @type {PageTestSuite}
|
|
|
|
*/
|
2020-01-09 02:34:35 +03:00
|
|
|
module.exports.describe = function ({ testRunner, expect, FFOX, WEBKIT }) {
|
2019-11-21 01:18:05 +03:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
2019-12-20 02:47:35 +03:00
|
|
|
const {it, fit, xit, dit} = testRunner;
|
2019-11-21 01:18:05 +03:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
|
|
|
|
2020-03-03 00:47:08 +03:00
|
|
|
describe.fail(FFOX)('Overrides.setGeolocation', function() {
|
2019-11-21 01:18:05 +03:00
|
|
|
it('should work', async({page, server, context}) => {
|
2019-12-21 00:07:14 +03:00
|
|
|
await context.setPermissions(server.PREFIX, ['geolocation']);
|
2019-11-21 01:18:05 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-01-03 21:14:50 +03:00
|
|
|
await context.setGeolocation({longitude: 10, latitude: 10});
|
2019-11-21 01:18:05 +03:00
|
|
|
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
|
|
|
|
});
|
|
|
|
});
|
2019-12-18 23:23:33 +03:00
|
|
|
it('should throw when invalid longitude', async({context}) => {
|
2019-11-21 01:18:05 +03:00
|
|
|
let error = null;
|
|
|
|
try {
|
2020-01-03 21:14:50 +03:00
|
|
|
await context.setGeolocation({longitude: 200, latitude: 10});
|
2019-11-21 01:18:05 +03:00
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Invalid longitude "200"');
|
|
|
|
});
|
2020-01-14 02:39:13 +03:00
|
|
|
it('should throw with missing latitude', async({context}) => {
|
|
|
|
let error = null;
|
|
|
|
try {
|
|
|
|
await context.setGeolocation({longitude: 10});
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Invalid latitude "undefined"');
|
|
|
|
});
|
2020-02-21 02:15:48 +03:00
|
|
|
it('should not modify passed default options object', async({browser}) => {
|
2020-01-04 01:42:18 +03:00
|
|
|
const geolocation = { longitude: 10, latitude: 10 };
|
|
|
|
const options = { geolocation };
|
2020-02-21 02:15:48 +03:00
|
|
|
const context = await browser.newContext(options);
|
2020-01-04 01:42:18 +03:00
|
|
|
await context.setGeolocation({ longitude: 20, latitude: 20 });
|
|
|
|
expect(options.geolocation).toBe(geolocation);
|
2020-02-21 02:15:48 +03:00
|
|
|
await context.close();
|
2020-01-04 01:42:18 +03:00
|
|
|
});
|
2020-02-21 02:15:48 +03:00
|
|
|
it('should throw with missing longitude in default options', async({browser}) => {
|
2020-01-14 02:39:13 +03:00
|
|
|
let error = null;
|
|
|
|
try {
|
2020-02-21 02:15:48 +03:00
|
|
|
const context = await browser.newContext({ geolocation: {latitude: 10} });
|
2020-01-14 02:39:13 +03:00
|
|
|
await context.close();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Invalid longitude "undefined"');
|
|
|
|
});
|
2020-02-21 02:15:48 +03:00
|
|
|
it('should use context options', async({browser, server}) => {
|
2020-01-14 00:32:44 +03:00
|
|
|
const options = { geolocation: { longitude: 10, latitude: 10 }, permissions: {} };
|
|
|
|
options.permissions[server.PREFIX] = ['geolocation'];
|
2020-02-21 02:15:48 +03:00
|
|
|
const context = await browser.newContext(options);
|
2020-01-14 00:32:44 +03:00
|
|
|
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
|
|
|
|
});
|
2020-02-21 02:15:48 +03:00
|
|
|
await context.close();
|
2020-01-14 00:32:44 +03:00
|
|
|
});
|
2019-11-21 01:18:05 +03:00
|
|
|
});
|
|
|
|
};
|