summaryrefslogtreecommitdiffstats
path: root/mobile/android/modules/geckoview/GeckoViewTestUtils.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /mobile/android/modules/geckoview/GeckoViewTestUtils.jsm
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--mobile/android/modules/geckoview/GeckoViewTestUtils.jsm65
1 files changed, 65 insertions, 0 deletions
diff --git a/mobile/android/modules/geckoview/GeckoViewTestUtils.jsm b/mobile/android/modules/geckoview/GeckoViewTestUtils.jsm
new file mode 100644
index 0000000000..966eae2d90
--- /dev/null
+++ b/mobile/android/modules/geckoview/GeckoViewTestUtils.jsm
@@ -0,0 +1,65 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["GeckoViewTabUtil"];
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
+});
+
+const GeckoViewTabUtil = {
+ /**
+ * Creates a new tab through service worker delegate.
+ * Needs to be ran in a parent process.
+ *
+ * @param {string} url
+ * @returns {Tab}
+ * @throws {Error} Throws an error if the tab cannot be created.
+ */
+ async createNewTab(url = "about:blank") {
+ let sessionId = "";
+ const windowPromise = new Promise(resolve => {
+ const openingObserver = (subject, topic, data) => {
+ if (subject.name === sessionId) {
+ Services.obs.removeObserver(
+ openingObserver,
+ "geckoview-window-created"
+ );
+ resolve(subject);
+ }
+ };
+ Services.obs.addObserver(openingObserver, "geckoview-window-created");
+ });
+
+ try {
+ sessionId = await lazy.EventDispatcher.instance.sendRequestForResult({
+ type: "GeckoView:Test:NewTab",
+ url,
+ });
+ } catch (errorMessage) {
+ throw new Error(
+ errorMessage + " GeckoView:Test:NewTab is not supported."
+ );
+ }
+
+ if (!sessionId) {
+ throw new Error("Could not open a session for the new tab.");
+ }
+
+ const window = await windowPromise;
+
+ // Immediately load the URI in the browser after creating the new tab to
+ // load into. This isn't done from the Java side to align with the
+ // ServiceWorkerOpenWindow infrastructure which this is built on top of.
+ window.browser.fixupAndLoadURIString(url, {
+ flags: Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
+ triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
+ });
+
+ return window.tab;
+ },
+};