Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firefox): support Page.emulateMedia #4056

Merged
merged 1 commit into from Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion experimental/puppeteer-firefox/lib/Page.js
@@ -1,4 +1,4 @@
const {helper, debugError} = require('./helper');
const {helper, debugError, assert} = require('./helper');
const {Keyboard, Mouse} = require('./Input');
const {Dialog} = require('./Dialog');
const {TimeoutError} = require('./Errors');
Expand Down Expand Up @@ -84,6 +84,14 @@ class Page extends EventEmitter {
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 {Function} puppeteerFunction
Expand Down
2 changes: 1 addition & 1 deletion experimental/puppeteer-firefox/package.json
Expand Up @@ -9,7 +9,7 @@
"node": ">=8.9.4"
},
"puppeteer": {
"firefox_revision": "f8e2e3a2e86cd47766cd839624b3f08e093c1f27"
"firefox_revision": "86e93329fd528bd28ff1493f117f126b6f010eac"
},
"scripts": {
"install": "node install.js",
Expand Down
9 changes: 6 additions & 3 deletions test/elementhandle.spec.js
Expand Up @@ -16,7 +16,7 @@

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 {it, fit, xit, it_fails_ffox} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
Expand All @@ -29,13 +29,16 @@ module.exports.addTests = function({testRunner, expect}) {
const box = await elementHandle.boundingBox();
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.goto(server.PREFIX + '/frames/nested-frames.html');
const nestedFrame = page.frames()[1].childFrames()[1];
const elementHandle = await nestedFrame.$('div');
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}) => {
await page.setContent('<div style="display:none">hi</div>');
Expand Down
2 changes: 1 addition & 1 deletion test/emulation.spec.js
Expand Up @@ -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}) => {
expect(await page.evaluate(() => window.matchMedia('screen').matches)).toBe(true);
expect(await page.evaluate(() => window.matchMedia('print').matches)).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion test/evaluation.spec.js
Expand Up @@ -101,7 +101,7 @@ module.exports.addTests = function({testRunner, expect}) {
await page.goto(server.EMPTY_PAGE);
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
await page.exposeFunction('callController', async function(a, b) {
return await page.evaluate((a, b) => a * b, a, b);
Expand Down