diff --git a/html/browsers/browsing-the-web/remote-context-helper-tests/addWindow-from-window.window.js b/html/browsers/browsing-the-web/remote-context-helper-tests/addWindow-from-window.window.js new file mode 100644 index 00000000000000..85509a15b980bc --- /dev/null +++ b/html/browsers/browsing-the-web/remote-context-helper-tests/addWindow-from-window.window.js @@ -0,0 +1,16 @@ +// META: title=RemoteContextHelper with defaults +// META: script=/common/dispatcher/dispatcher.js +// META: script=/common/get-host-info.sub.js +// META: script=/common/utils.js +// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js +// META: script=./resources/test-helper.js + +'use strict'; + +promise_test(async t => { + const rcHelper = new RemoteContextHelper(); + const main = await rcHelper.addWindow(); + const childWindow = await main.addWindow(); + await assertSimplestScriptRuns(childWindow); + await assertOriginIsAsExpected(childWindow, location.origin); +}); diff --git a/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js b/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js index aca83720254308..6c88b49fd4a0fd 100644 --- a/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js +++ b/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js @@ -320,12 +320,9 @@ url.searchParams.append('pipe', formattedHeaders.join('|')); } - function windowExecutorCreator({target = '_blank', features} = {}) { - return (url, documentContent) => { - if (url && url.substring(0, 5) == 'data:') { - throw new TypeError('Windows cannot use data: URLs.'); - } - + function windowExecutorCreator( + { target = '_blank', features } = {}, remoteContextWrapper) { + let openWindow = (url, target, features, documentContent) => { const w = window.open(url, target, features); if (documentContent) { w.document.open(); @@ -333,6 +330,19 @@ w.document.close(); } }; + + return (url, documentContent) => { + if (url && url.substring(0, 5) == 'data:') { + throw new TypeError('Windows cannot use data: URLs.'); + } + + if (remoteContextWrapper) { + return remoteContextWrapper.executeScript( + openWindow, [url, target, features, documentContent]); + } else { + openWindow(url, target, features, documentContent); + } + }; } function elementExecutorCreator( @@ -527,6 +537,23 @@ }); } + /** + * Opens a window from the remote context. @see createContext for + * @param {RemoteContextConfig|object} [extraConfig] + * @param {Object} [options] + * @param {string} [options.target] Passed to `window.open` as the + * 2nd argument + * @param {string} [options.features] Passed to `window.open` as the + * 3rd argument + * @returns {Promise} The remote context. + */ + addWindow(extraConfig, options) { + return this.helper.createContext({ + executorCreator: windowExecutorCreator(options, this), + extraConfig, + }); + } + /** * Adds a dedicated worker to the current document. * @param {string|null} [globalVariable] The name of the global variable to