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",
"revision": "1116"
"revision": "1117"
},
{
"name": "webkit",

View File

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

View File

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

View File

@ -18,7 +18,7 @@
const utils = require('./utils');
const path = require('path');
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() {
it('should work', async({page, server}) => {
@ -896,6 +896,32 @@ describe('Page.goBack', function() {
await page.goForward();
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() {

View File

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