Skip to content

Commit

Permalink
feat(firefox): support Page.emualteMedia (#4056)
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Feb 22, 2019
1 parent 5c81836 commit 1315dc8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
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

0 comments on commit 1315dc8

Please sign in to comment.