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): add Download.cancel (#7390)
Max Schmitt18266722a158
diff --git a/browser_patches/firefox-beta/BUILD_NUMBER b/browser_patches/firefox-beta/BUILD_NUMBERindex 8a4fc24cd1..d30fa46dce 100644--- a/browser_patches/firefox-beta/BUILD_NUMBER+++ b/browser_patches/firefox-beta/BUILD_NUMBER@@ -1,2 +1,2 @@-1265-Changed: [email protected] Mon Jun 28 22:40:00 UTC 2021+1266+Changed: [email protected] Tue Jun 29 22:44:52 UTC 2021diff --git a/browser_patches/firefox-beta/juggler/TargetRegistry.js b/browser_patches/firefox-beta/juggler/TargetRegistry.jsindex 608a3f3d4f..29f34cc679 100644--- a/browser_patches/firefox-beta/juggler/TargetRegistry.js+++ b/browser_patches/firefox-beta/juggler/TargetRegistry.js@@ -12,6 +12,8 @@ const {NetUtil} = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");+const Cr = Components.results;+const helper = new Helper();const IDENTITY_NAME = 'JUGGLER ';@@ -26,6 +28,7 @@ class DownloadInterceptor {constructor(registry) {this._registry = registrythis._handlerToUuid = new Map();+ this._uuidToHandler = new Map();}//@@ -60,6 +63,7 @@ class DownloadInterceptor {}outFile.value = file;this._handlerToUuid.set(externalAppHandler, uuid);+ this._uuidToHandler.set(uuid, externalAppHandler);const downloadInfo = {uuid,browserContextId: browserContext.browserContextId,@@ -76,16 +80,24 @@ class DownloadInterceptor {if (!uuid)return;this._handlerToUuid.delete(externalAppHandler);+ this._uuidToHandler.delete(uuid);const downloadInfo = {uuid,+ error: errorName,};- if (errorName === 'NS_BINDING_ABORTED') {+ if (canceled === 'NS_BINDING_ABORTED') {downloadInfo.canceled = true;- } else {- downloadInfo.error = errorName;}this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo);}++ async cancelDownload(uuid) {+ const externalAppHandler = this._uuidToHandler.get(uuid);+ if (!externalAppHandler) {+ return;+ }+ await externalAppHandler.cancel(Cr.NS_BINDING_ABORTED);+ }}const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);@@ -227,13 +239,18 @@ class TargetRegistry {};const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService);- extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this));+ this._downloadInterceptor = new DownloadInterceptor(this);+ extHelperAppSvc.setDownloadInterceptor(this._downloadInterceptor);Services.wm.addListener({ onOpenWindow, onCloseWindow });for (const win of Services.wm.getEnumerator(null))onOpenWindow(win);}+ async cancelDownload(options) {+ this._downloadInterceptor.cancelDownload(options.uuid);+ }+setBrowserProxy(proxy) {this._browserProxy = proxy;}diff --git a/browser_patches/firefox-beta/juggler/protocol/BrowserHandler.js b/browser_patches/firefox-beta/juggler/protocol/BrowserHandler.jsindex 642281b688..a6c7449f46 100644--- a/browser_patches/firefox-beta/juggler/protocol/BrowserHandler.js+++ b/browser_patches/firefox-beta/juggler/protocol/BrowserHandler.js@@ -125,6 +125,10 @@ class BrowserHandler {this._session.emitEvent('Browser.downloadFinished', downloadInfo);}+ async ['Browser.cancelDownload']({uuid}) {+ await this._targetRegistry.cancelDownload({uuid});+ }+async ['Browser.newPage']({browserContextId}) {const targetId = await this._targetRegistry.newPage({browserContextId});return {targetId};diff --git a/browser_patches/firefox-beta/juggler/protocol/Protocol.js b/browser_patches/firefox-beta/juggler/protocol/Protocol.jsindex f658c5082f..d179f93cd4 100644--- a/browser_patches/firefox-beta/juggler/protocol/Protocol.js+++ b/browser_patches/firefox-beta/juggler/protocol/Protocol.js@@ -452,6 +452,11 @@ const Browser = {height: t.Number,},},+ 'cancelDownload': {+ params: {+ uuid: t.Optional(t.String),+ }+ }},};diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBERindex 0a84548b73..c909c0b8f3 100644--- a/browser_patches/firefox/BUILD_NUMBER+++ b/browser_patches/firefox/BUILD_NUMBER@@ -1,2 +1,2 @@-1272-Changed: [email protected] Mon Jun 28 10:29:55 UTC 2021+1273+Changed: [email protected] Tue Jun 29 22:39:37 UTC 2021diff --git a/browser_patches/firefox/juggler/TargetRegistry.js b/browser_patches/firefox/juggler/TargetRegistry.jsindex 608a3f3d4f..29f34cc679 100644--- a/browser_patches/firefox/juggler/TargetRegistry.js+++ b/browser_patches/firefox/juggler/TargetRegistry.js@@ -12,6 +12,8 @@ const {NetUtil} = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");+const Cr = Components.results;+const helper = new Helper();const IDENTITY_NAME = 'JUGGLER ';@@ -26,6 +28,7 @@ class DownloadInterceptor {constructor(registry) {this._registry = registrythis._handlerToUuid = new Map();+ this._uuidToHandler = new Map();}//@@ -60,6 +63,7 @@ class DownloadInterceptor {}outFile.value = file;this._handlerToUuid.set(externalAppHandler, uuid);+ this._uuidToHandler.set(uuid, externalAppHandler);const downloadInfo = {uuid,browserContextId: browserContext.browserContextId,@@ -76,16 +80,24 @@ class DownloadInterceptor {if (!uuid)return;this._handlerToUuid.delete(externalAppHandler);+ this._uuidToHandler.delete(uuid);const downloadInfo = {uuid,+ error: errorName,};- if (errorName === 'NS_BINDING_ABORTED') {+ if (canceled === 'NS_BINDING_ABORTED') {downloadInfo.canceled = true;- } else {- downloadInfo.error = errorName;}this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo);}++ async cancelDownload(uuid) {+ const externalAppHandler = this._uuidToHandler.get(uuid);+ if (!externalAppHandler) {+ return;+ }+ await externalAppHandler.cancel(Cr.NS_BINDING_ABORTED);+ }}const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);@@ -227,13 +239,18 @@ class TargetRegistry {};const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService);- extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this));+ this._downloadInterceptor = new DownloadInterceptor(this);+ extHelperAppSvc.setDownloadInterceptor(this._downloadInterceptor);Services.wm.addListener({ onOpenWindow, onCloseWindow });for (const win of Services.wm.getEnumerator(null))onOpenWindow(win);}+ async cancelDownload(options) {+ this._downloadInterceptor.cancelDownload(options.uuid);+ }+setBrowserProxy(proxy) {this._browserProxy = proxy;}diff --git a/browser_patches/firefox/juggler/protocol/BrowserHandler.js b/browser_patches/firefox/juggler/protocol/BrowserHandler.jsindex 642281b688..a6c7449f46 100644--- a/browser_patches/firefox/juggler/protocol/BrowserHandler.js+++ b/browser_patches/firefox/juggler/protocol/BrowserHandler.js@@ -125,6 +125,10 @@ class BrowserHandler {this._session.emitEvent('Browser.downloadFinished', downloadInfo);}+ async ['Browser.cancelDownload']({uuid}) {+ await this._targetRegistry.cancelDownload({uuid});+ }+async ['Browser.newPage']({browserContextId}) {const targetId = await this._targetRegistry.newPage({browserContextId});return {targetId};diff --git a/browser_patches/firefox/juggler/protocol/Protocol.js b/browser_patches/firefox/juggler/protocol/Protocol.jsindex f658c5082f..d179f93cd4 100644--- a/browser_patches/firefox/juggler/protocol/Protocol.js+++ b/browser_patches/firefox/juggler/protocol/Protocol.js@@ -452,6 +452,11 @@ const Browser = {height: t.Number,},},+ 'cancelDownload': {+ params: {+ uuid: t.Optional(t.String),+ }+ }},};