mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(firefox): support Page.emualteMedia (#4056)
This commit is contained in:
parent
5c818368a5
commit
1315dc8234
@ -1,4 +1,4 @@
|
|||||||
const {helper, debugError} = require('./helper');
|
const {helper, debugError, assert} = require('./helper');
|
||||||
const {Keyboard, Mouse} = require('./Input');
|
const {Keyboard, Mouse} = require('./Input');
|
||||||
const {Dialog} = require('./Dialog');
|
const {Dialog} = require('./Dialog');
|
||||||
const {TimeoutError} = require('./Errors');
|
const {TimeoutError} = require('./Errors');
|
||||||
@ -84,6 +84,14 @@ class Page extends EventEmitter {
|
|||||||
await this._networkManager.setExtraHTTPHeaders(headers);
|
await this._networkManager.setExtraHTTPHeaders(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {?string} mediaType
|
||||||
|
*/
|
||||||
|
async emulateMedia(mediaType) {
|
||||||
|
assert(mediaType === 'screen' || mediaType === 'print' || mediaType === null, 'Unsupported media type: ' + mediaType);
|
||||||
|
await this._session.send('Page.setEmulatedMedia', {media: mediaType || ''});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @param {Function} puppeteerFunction
|
* @param {Function} puppeteerFunction
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"node": ">=8.9.4"
|
"node": ">=8.9.4"
|
||||||
},
|
},
|
||||||
"puppeteer": {
|
"puppeteer": {
|
||||||
"firefox_revision": "f8e2e3a2e86cd47766cd839624b3f08e093c1f27"
|
"firefox_revision": "86e93329fd528bd28ff1493f117f126b6f010eac"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install.js",
|
"install": "node install.js",
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
module.exports.addTests = function({testRunner, expect}) {
|
module.exports.addTests = function({testRunner, expect, CHROME}) {
|
||||||
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
|
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
|
||||||
const {it, fit, xit, it_fails_ffox} = testRunner;
|
const {it, fit, xit, it_fails_ffox} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
@ -29,13 +29,16 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
const box = await elementHandle.boundingBox();
|
const box = await elementHandle.boundingBox();
|
||||||
expect(box).toEqual({ x: 100, y: 50, width: 50, height: 50 });
|
expect(box).toEqual({ x: 100, y: 50, width: 50, height: 50 });
|
||||||
});
|
});
|
||||||
it_fails_ffox('should handle nested frames', async({page, server}) => {
|
it('should handle nested frames', async({page, server}) => {
|
||||||
await page.setViewport({width: 500, height: 500});
|
await page.setViewport({width: 500, height: 500});
|
||||||
await page.goto(server.PREFIX + '/frames/nested-frames.html');
|
await page.goto(server.PREFIX + '/frames/nested-frames.html');
|
||||||
const nestedFrame = page.frames()[1].childFrames()[1];
|
const nestedFrame = page.frames()[1].childFrames()[1];
|
||||||
const elementHandle = await nestedFrame.$('div');
|
const elementHandle = await nestedFrame.$('div');
|
||||||
const box = await elementHandle.boundingBox();
|
const box = await elementHandle.boundingBox();
|
||||||
expect(box).toEqual({ x: 28, y: 260, width: 264, height: 18 });
|
if (CHROME)
|
||||||
|
expect(box).toEqual({ x: 28, y: 260, width: 264, height: 18 });
|
||||||
|
else
|
||||||
|
expect(box).toEqual({ x: 28, y: 182, width: 254, height: 18 });
|
||||||
});
|
});
|
||||||
it('should return null for invisible elements', async({page, server}) => {
|
it('should return null for invisible elements', async({page, server}) => {
|
||||||
await page.setContent('<div style="display:none">hi</div>');
|
await page.setContent('<div style="display:none">hi</div>');
|
||||||
|
@ -99,7 +99,7 @@ module.exports.addTests = function({testRunner, expect, product}) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe_fails_ffox('Page.emulateMedia', function() {
|
describe('Page.emulateMedia', function() {
|
||||||
it('should work', async({page, server}) => {
|
it('should work', async({page, server}) => {
|
||||||
expect(await page.evaluate(() => window.matchMedia('screen').matches)).toBe(true);
|
expect(await page.evaluate(() => window.matchMedia('screen').matches)).toBe(true);
|
||||||
expect(await page.evaluate(() => window.matchMedia('print').matches)).toBe(false);
|
expect(await page.evaluate(() => window.matchMedia('print').matches)).toBe(false);
|
||||||
|
@ -101,7 +101,7 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
expect(await frameEvaluation).toBe(42);
|
expect(await frameEvaluation).toBe(42);
|
||||||
});
|
});
|
||||||
it_fails_ffox('should work from-inside an exposed function', async({page, server}) => {
|
it('should work from-inside an exposed function', async({page, server}) => {
|
||||||
// Setup inpage callback, which calls Page.evaluate
|
// Setup inpage callback, which calls Page.evaluate
|
||||||
await page.exposeFunction('callController', async function(a, b) {
|
await page.exposeFunction('callController', async function(a, b) {
|
||||||
return await page.evaluate((a, b) => a * b, a, b);
|
return await page.evaluate((a, b) => a * b, a, b);
|
||||||
|
Loading…
Reference in New Issue
Block a user