fix(navigation): ensure that goBack/goForward work with file urls (#2792)

This commit is contained in:
Dmitry Gozman 2020-07-01 19:17:27 -07:00 committed by GitHub
parent c15dc94f8e
commit 9d6eaadba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 14 deletions

View File

@ -7,7 +7,7 @@
}, },
{ {
"name": "firefox", "name": "firefox",
"revision": "1116" "revision": "1117"
}, },
{ {
"name": "webkit", "name": "webkit",

View File

@ -315,13 +315,13 @@ export class FFPage implements PageDelegate {
} }
async goBack(): Promise<boolean> { async goBack(): Promise<boolean> {
const { navigationId } = await this._session.send('Page.goBack', { frameId: this._page.mainFrame()._id }); const { success } = await this._session.send('Page.goBack', { frameId: this._page.mainFrame()._id });
return navigationId !== null; return success;
} }
async goForward(): Promise<boolean> { async goForward(): Promise<boolean> {
const { navigationId } = await this._session.send('Page.goForward', { frameId: this._page.mainFrame()._id }); const { success } = await this._session.send('Page.goForward', { frameId: this._page.mainFrame()._id });
return navigationId !== null; return success;
} }
async evaluateOnNewDocument(source: string): Promise<void> { async evaluateOnNewDocument(source: string): Promise<void> {

View File

@ -461,23 +461,18 @@ export module Protocol {
frameId: string; frameId: string;
}; };
export type goBackReturnValue = { export type goBackReturnValue = {
navigationId: string|null; success: boolean;
navigationURL: string|null;
}; };
export type goForwardParameters = { export type goForwardParameters = {
frameId: string; frameId: string;
}; };
export type goForwardReturnValue = { export type goForwardReturnValue = {
navigationId: string|null; success: boolean;
navigationURL: string|null;
}; };
export type reloadParameters = { export type reloadParameters = {
frameId: string; frameId: string;
}; };
export type reloadReturnValue = { export type reloadReturnValue = void;
navigationId: string;
navigationURL: string;
};
export type getBoundingBoxParameters = { export type getBoundingBoxParameters = {
frameId: string; frameId: string;
objectId: string; objectId: string;

View File

@ -18,7 +18,7 @@
const utils = require('./utils'); const utils = require('./utils');
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');
const {FFOX, CHROMIUM, WEBKIT, MAC, WIN, CHANNEL} = utils.testOptions(browserType); const {FFOX, CHROMIUM, WEBKIT, ASSETS_DIR, MAC, WIN, CHANNEL} = utils.testOptions(browserType);
describe('Page.goto', function() { describe('Page.goto', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
@ -896,6 +896,32 @@ describe('Page.goBack', function() {
await page.goForward(); await page.goForward();
expect(page.url()).toBe(server.PREFIX + '/first.html'); expect(page.url()).toBe(server.PREFIX + '/first.html');
}); });
it.fail(WEBKIT && MAC)('should work for file urls', async ({page, server}) => {
// WebKit embedder fails to go back/forward to the file url.
const url1 = WIN
? 'file:///' + path.join(ASSETS_DIR, 'empty.html').replace(/\\/g, '/')
: 'file://' + path.join(ASSETS_DIR, 'empty.html');
const url2 = server.EMPTY_PAGE;
await page.goto(url1);
await page.setContent(`<a href='${url2}'>url2</a>`);
expect(page.url().toLowerCase()).toBe(url1.toLowerCase());
await page.click('a');
expect(page.url()).toBe(url2);
await page.goBack();
expect(page.url().toLowerCase()).toBe(url1.toLowerCase());
// Should be able to evaluate in the new context, and
// not reach for the old cross-process one.
expect(await page.evaluate(() => window.scrollX)).toBe(0);
// Should be able to screenshot.
await page.screenshot();
await page.goForward();
expect(page.url()).toBe(url2);
expect(await page.evaluate(() => window.scrollX)).toBe(0);
await page.screenshot();
});
}); });
describe('Frame.goto', function() { describe('Frame.goto', function() {

View File

@ -190,6 +190,7 @@ const utils = module.exports = {
testOptions(browserType) { testOptions(browserType) {
const GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name()); const GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name());
const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name()); const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());
const ASSETS_DIR = path.join(__dirname, 'assets');
return { return {
FFOX: browserType.name() === 'firefox', FFOX: browserType.name() === 'firefox',
WEBKIT: browserType.name() === 'webkit', WEBKIT: browserType.name() === 'webkit',
@ -200,6 +201,7 @@ const utils = module.exports = {
browserType, browserType,
GOLDEN_DIR, GOLDEN_DIR,
OUTPUT_DIR, OUTPUT_DIR,
ASSETS_DIR,
USES_HOOKS: !!process.env.PWCHANNEL, USES_HOOKS: !!process.env.PWCHANNEL,
CHANNEL: !!process.env.PWCHANNEL, CHANNEL: !!process.env.PWCHANNEL,
}; };