From 49360eac10af81d914ad2aa79f5d7285ad614619 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Wed, 24 May 2023 11:56:24 +0200 Subject: [PATCH] chore: fixes expectation for test in Firefox (#10239) --- .../puppeteer-core/src/common/bidi/Browser.ts | 2 +- .../src/common/bidi/BrowsingContext.ts | 3 +- .../puppeteer-core/src/common/bidi/Page.ts | 25 ----- test/TestExpectations.json | 102 ++++++++++++++---- test/src/network.spec.ts | 9 +- 5 files changed, 93 insertions(+), 48 deletions(-) diff --git a/packages/puppeteer-core/src/common/bidi/Browser.ts b/packages/puppeteer-core/src/common/bidi/Browser.ts index b2b818c0..089deedf 100644 --- a/packages/puppeteer-core/src/common/bidi/Browser.ts +++ b/packages/puppeteer-core/src/common/bidi/Browser.ts @@ -33,7 +33,7 @@ import {Connection} from './Connection.js'; * @internal */ export class Browser extends BrowserBase { - static readonly subscribeModules = ['browsingContext', 'network']; + static readonly subscribeModules = ['browsingContext', 'network', 'log']; static async create(opts: Options): Promise { // TODO: await until the connection is established. diff --git a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts b/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts index 89b20323..597b281a 100644 --- a/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts +++ b/packages/puppeteer-core/src/common/bidi/BrowsingContext.ts @@ -54,7 +54,7 @@ export class BrowsingContext extends EventEmitter { connection: Connection; #timeoutSettings: TimeoutSettings; #id: string; - #url: string; + #url = 'about:blank'; constructor( connection: Connection, @@ -65,7 +65,6 @@ export class BrowsingContext extends EventEmitter { this.connection = connection; this.#timeoutSettings = timeoutSettings; this.#id = info.context; - this.#url = info.url; } get url(): string { diff --git a/packages/puppeteer-core/src/common/bidi/Page.ts b/packages/puppeteer-core/src/common/bidi/Page.ts index d8ae291b..768aaed5 100644 --- a/packages/puppeteer-core/src/common/bidi/Page.ts +++ b/packages/puppeteer-core/src/common/bidi/Page.ts @@ -25,8 +25,6 @@ import { WaitForOptions, } from '../../api/Page.js'; import {assert} from '../../util/assert.js'; -import {isErrorLike} from '../../util/ErrorLike.js'; -import {isTargetClosedError} from '../Connection.js'; import {ConsoleMessage, ConsoleMessageLocation} from '../ConsoleMessage.js'; import {Handler} from '../EventEmitter.js'; import {FrameManagerEmittedEvents} from '../FrameManager.js'; @@ -133,18 +131,6 @@ export class Page extends PageBase { connection.on(event, subscriber); } - await page.#connection - .send('session.subscribe', { - events: [...page.#subscribedEvents.keys()], - // TODO: We should subscribe globally - contexts: [info.context], - }) - .catch(error => { - if (isErrorLike(error) && isTargetClosedError(error)) { - throw error; - } - }); - return page; } @@ -295,17 +281,6 @@ export class Page extends PageBase { this.removeAllListeners(); this.#networkManager.dispose(); - await this.#connection - .send('session.unsubscribe', { - events: [...this.#subscribedEvents.keys()], - // TODO: Remove this once we subscrite gloablly - contexts: [this.mainFrame()._id], - }) - .catch(() => { - // Suppress the error as we remove the context - // after that anyway. - }); - await this.#connection.send('browsingContext.close', { context: this.mainFrame()._id, }); diff --git a/test/TestExpectations.json b/test/TestExpectations.json index e97d1e32..12abd918 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -95,6 +95,12 @@ "parameters": ["webDriverBiDi"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[network.spec] network Request.isNavigationRequest *", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Response.buffer *", "platforms": ["darwin", "linux", "win32"], @@ -461,12 +467,6 @@ "parameters": ["webDriverBiDi"], "expectations": ["FAIL"] }, - { - "testIdPattern": "[network.spec] network raw network headers Same-origin set-cookie subresource", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["webDriverBiDi"], - "expectations": ["FAIL"] - }, { "testIdPattern": "[network.spec] network Request.frame should work for subframe navigation request", "platforms": ["darwin", "linux", "win32"], @@ -491,18 +491,6 @@ "parameters": ["webDriverBiDi"], "expectations": ["FAIL"] }, - { - "testIdPattern": "[network.spec] network Request.isNavigationRequest should work", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["webDriverBiDi"], - "expectations": ["FAIL"] - }, - { - "testIdPattern": "[network.spec] network Request.isNavigationRequest should work with request interception", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["webDriverBiDi"], - "expectations": ["FAIL"] - }, { "testIdPattern": "[network.spec] network Request.postData should work", "platforms": ["darwin", "linux", "win32"], @@ -1295,6 +1283,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[navigation.spec] navigation Page.goto should navigate to dataURL and fire dataURL requests", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[navigation.spec] navigation Page.goto should navigate to empty page with domcontentloaded", "platforms": ["darwin", "linux", "win32"], @@ -1319,6 +1313,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[navigation.spec] navigation Page.goto should navigate to URL with hash and fire requests without hash", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[navigation.spec] navigation Page.goto should not leak listeners during navigation", "platforms": ["darwin", "linux", "win32"], @@ -1343,6 +1343,12 @@ "parameters": ["firefox", "webDriverBiDi"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[navigation.spec] navigation Page.goto should return last response in redirect chain", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[navigation.spec] navigation Page.goto should return response when page changes its URL after load", "platforms": ["darwin", "linux", "win32"], @@ -1409,6 +1415,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[navigation.spec] navigation Page.goto should work with self requesting page", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[navigation.spec] navigation Page.goto should work with subframes return 204", "platforms": ["darwin", "linux", "win32"], @@ -1541,12 +1553,24 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[network.spec] network Page.authenticate should work", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["SKIP"] + }, { "testIdPattern": "[network.spec] network Page.setExtraHTTPHeaders should work", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[network.spec] network raw network headers Same-origin set-cookie subresource", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network raw network headers Same-origin set-cookie subresource", "platforms": ["darwin", "linux", "win32"], @@ -1559,6 +1583,12 @@ "parameters": ["cdp", "chrome"], "expectations": ["FAIL", "PASS"] }, + { + "testIdPattern": "[network.spec] network Request.headers should define Firefox as user agent header", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Request.initiator should return the initiator", "platforms": ["darwin", "linux", "win32"], @@ -1571,12 +1601,24 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[network.spec] network Request.isNavigationRequest should work when navigating to image", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[network.spec] network Request.isNavigationRequest should work with request interception", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[network.spec] network Request.postData should be |undefined| when there is no post data", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Request.postData should work", "platforms": ["darwin", "linux", "win32"], @@ -1601,6 +1643,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[network.spec] network Response.fromCache should return |false| for non-cached content", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Response.fromCache should work", "platforms": ["darwin", "linux", "win32"], @@ -1613,12 +1661,30 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[network.spec] network Response.headers should work", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Response.json should work", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[network.spec] network Response.statusText handles missing status text", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, + { + "testIdPattern": "[network.spec] network Response.statusText should work", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox", "webDriverBiDi"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[network.spec] network Response.text should return uncompressed text", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/network.spec.ts b/test/src/network.spec.ts index a6d5c817..8b67d21b 100644 --- a/test/src/network.spec.ts +++ b/test/src/network.spec.ts @@ -556,7 +556,7 @@ describe('network', function () { const requests: HTTPRequest[] = []; page.on('requestfinished', request => { - return requests.push(request); + return !isFavicon(request) && requests.push(request); }); await page.goto(server.EMPTY_PAGE); expect(requests).toHaveLength(1); @@ -580,7 +580,12 @@ describe('network', function () { return events.push('requestfinished'); }); await page.goto(server.EMPTY_PAGE); - expect(events).toEqual(['request', 'response', 'requestfinished']); + // Events can sneak in after the page has navigate + expect(events.slice(0, 3)).toEqual([ + 'request', + 'response', + 'requestfinished', + ]); }); it('should support redirects', async () => { const {page, server} = getTestState();