Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
browser(firefox): introduce browser level screencastFinished event (#3625)
Yury Semikhatsky17077fd9017f
diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBERindex 4133844557..48294aca41 100644--- a/browser_patches/firefox/BUILD_NUMBER+++ b/browser_patches/firefox/BUILD_NUMBER@@ -1,2 +1,2 @@-1166-Changed: [email protected] Thu Aug 20 13:55:50 PDT 2020+1167+Changed: [email protected] Tue Aug 25 14:46:17 PDT 2020diff --git a/browser_patches/firefox/juggler/TargetRegistry.js b/browser_patches/firefox/juggler/TargetRegistry.jsindex 8f9c2b79d9..620da981c6 100644--- a/browser_patches/firefox/juggler/TargetRegistry.js+++ b/browser_patches/firefox/juggler/TargetRegistry.js@@ -134,8 +134,7 @@ class TargetRegistry {if (!target)return;target.emit('crashed');- if (target)- target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));+ target.dispose();}}, 'oop-frameloader-crashed');@@ -204,7 +203,7 @@ class TargetRegistry {const linkedBrowser = tab.linkedBrowser;const target = this._browserToTarget.get(linkedBrowser);if (target)- target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));+ target.dispose();};Services.wm.addListener({@@ -460,17 +459,12 @@ class PageTarget {return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);}- async dispose() {+ dispose() {this._disposed = true;+ this._browserContext.pages.delete(this);this._registry._browserToTarget.delete(this._linkedBrowser);this._registry._browserBrowsingContextToTarget.delete(this._linkedBrowser.browsingContext);helper.removeListeners(this._eventListeners);-- const event = { pendingActivity: [], target: this };- this._registry.emit(TargetRegistry.Events.TargetWillBeDestroyed, event);- await Promise.all(event.pendingActivity);-- this._browserContext.pages.delete(this);this._registry.emit(TargetRegistry.Events.TargetDestroyed, this);}}@@ -740,7 +734,6 @@ function setViewportSizeForBrowser(viewportSize, browser, window) {TargetRegistry.Events = {TargetCreated: Symbol('TargetRegistry.Events.TargetCreated'),- TargetWillBeDestroyed: Symbol('TargetRegistry.Events.TargetWillBeDestroyed'),TargetDestroyed: Symbol('TargetRegistry.Events.TargetDestroyed'),DownloadCreated: Symbol('TargetRegistry.Events.DownloadCreated'),DownloadFinished: Symbol('TargetRegistry.Events.DownloadFinished'),diff --git a/browser_patches/firefox/juggler/protocol/BrowserHandler.js b/browser_patches/firefox/juggler/protocol/BrowserHandler.jsindex f5d0e087eb..9bed75397d 100644--- a/browser_patches/firefox/juggler/protocol/BrowserHandler.js+++ b/browser_patches/firefox/juggler/protocol/BrowserHandler.js@@ -44,10 +44,16 @@ class BrowserHandler {this._eventListeners = [helper.on(this._targetRegistry, TargetRegistry.Events.TargetCreated, this._onTargetCreated.bind(this)),- helper.on(this._targetRegistry, TargetRegistry.Events.TargetWillBeDestroyed, this._onTargetWillBeDestroyed.bind(this)),+ helper.on(this._targetRegistry, TargetRegistry.Events.TargetDestroyed, this._onTargetDestroyed.bind(this)),helper.on(this._targetRegistry, TargetRegistry.Events.DownloadCreated, this._onDownloadCreated.bind(this)),helper.on(this._targetRegistry, TargetRegistry.Events.DownloadFinished, this._onDownloadFinished.bind(this)),];++ const onScreencastStopped = (subject, topic, data) => {+ this._session.emitEvent('Browser.screencastFinished', {screencastId: '' + data});+ };+ Services.obs.addObserver(onScreencastStopped, 'juggler-screencast-stopped');+ this._eventListeners.push(() => Services.obs.removeObserver(onScreencastStopped, 'juggler-screencast-stopped'));}async createBrowserContext({removeOnDetach}) {@@ -65,11 +71,11 @@ class BrowserHandler {this._createdBrowserContextIds.delete(browserContextId);}- async dispose() {+ dispose() {helper.removeListeners(this._eventListeners);for (const [target, session] of this._attachedSessions) {target.disconnectSession(session);- await this._dispatcher.destroySession(session);+ this._dispatcher.destroySession(session);}this._attachedSessions.clear();for (const browserContextId of this._createdBrowserContextIds) {@@ -101,16 +107,12 @@ class BrowserHandler {sessions.push(session);}- _onTargetWillBeDestroyed({target, pendingActivity}) {- pendingActivity.push(this._detachFromTarget(target));- }-- async _detachFromTarget(target) {+ _onTargetDestroyed(target) {const session = this._attachedSessions.get(target);if (!session)return;this._attachedSessions.delete(target);- await this._dispatcher.destroySession(session);+ this._dispatcher.destroySession(session);this._session.emitEvent('Browser.detachedFromTarget', {sessionId: session.sessionId(),targetId: target.id(),diff --git a/browser_patches/firefox/juggler/protocol/Dispatcher.js b/browser_patches/firefox/juggler/protocol/Dispatcher.jsindex 242d7cb8a0..1c882dda33 100644--- a/browser_patches/firefox/juggler/protocol/Dispatcher.js+++ b/browser_patches/firefox/juggler/protocol/Dispatcher.js@@ -29,9 +29,9 @@ class Dispatcher {return session;}- async destroySession(session) {+ destroySession(session) {this._sessions.delete(session.sessionId());- await session._dispose();+ session._dispose();}_dispose() {@@ -108,15 +108,13 @@ class ProtocolSession {this._handlers.set(domainName, handler);}- async _dispose() {- const promises = [];+ _dispose() {for (const [domainName, handler] of this._handlers) {if (typeof handler.dispose !== 'function')throw new Error(`Handler for "${domainName}" domain does not define |dispose| method!`);- promises.push(handler.dispose());+ handler.dispose();}this._handlers.clear();- await Promise.all(promises);this._dispatcher = null;}diff --git a/browser_patches/firefox/juggler/protocol/PageHandler.js b/browser_patches/firefox/juggler/protocol/PageHandler.jsindex 523f12d41e..78d0a057b9 100644--- a/browser_patches/firefox/juggler/protocol/PageHandler.js+++ b/browser_patches/firefox/juggler/protocol/PageHandler.js@@ -311,7 +311,7 @@ class PageHandler {const rect = this._pageTarget.linkedBrowser().getBoundingClientRect();const devicePixelRatio = this._pageTarget._window.devicePixelRatio;this._videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, devicePixelRatio * rect.top);- this._session.emitEvent('Page.screencastStarted', {uid: '' + this._videoSessionId, file});+ this._session.emitEvent('Page.screencastStarted', {screencastId: '' + this._videoSessionId, file});}async stopVideoRecording() {@@ -320,7 +320,6 @@ class PageHandler {const videoSessionId = this._videoSessionId;this._videoSessionId = -1;const screencast = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);- const session = this._session;const result = new Promise(resolve =>Services.obs.addObserver(function onStopped(subject, topic, data) {if (videoSessionId != data)@@ -328,8 +327,6 @@ class PageHandler {Services.obs.removeObserver(onStopped, 'juggler-screencast-stopped');resolve();-- session.emitEvent('Page.screencastStopped', {uid: '' + videoSessionId});}, 'juggler-screencast-stopped'));screencast.stopVideoRecording(videoSessionId);diff --git a/browser_patches/firefox/juggler/protocol/Protocol.js b/browser_patches/firefox/juggler/protocol/Protocol.jsindex f47b73e449..c9794d3701 100644--- a/browser_patches/firefox/juggler/protocol/Protocol.js+++ b/browser_patches/firefox/juggler/protocol/Protocol.js@@ -216,6 +216,9 @@ const Browser = {canceled: t.Optional(t.Boolean),error: t.Optional(t.String),},+ 'screencastFinished': {+ screencastId: t.String,+ },},methods: {@@ -650,12 +653,9 @@ const Page = {message: t.String,},'screencastStarted': {- uid: t.String,+ screencastId: t.String,file: t.String,},- 'screencastStopped': {- uid: t.String,- },},methods: {