diff --git a/testing/marionette/actors/MarionetteEventsParent.jsm b/testing/marionette/actors/MarionetteEventsParent.jsm index 944898274b4b..5df3f574baae 100644 --- a/testing/marionette/actors/MarionetteEventsParent.jsm +++ b/testing/marionette/actors/MarionetteEventsParent.jsm @@ -4,7 +4,12 @@ ("use strict"); -const EXPORTED_SYMBOLS = ["EventDispatcher", "MarionetteEventsParent"]; +const EXPORTED_SYMBOLS = [ + "EventDispatcher", + "MarionetteEventsParent", + "registerEventsActor", + "unregisterEventsActor", +]; const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" @@ -36,3 +41,36 @@ class MarionetteEventsParent extends JSWindowActorParent { return rv; } } + +/** + * Register Events actors to listen for page load events via EventDispatcher. + */ +function registerEventsActor() { + // Register the JSWindowActor pair for events as used by Marionette + ChromeUtils.registerWindowActor("MarionetteEvents", { + kind: "JSWindowActor", + parent: { + moduleURI: + "chrome://marionette/content/actors/MarionetteEventsParent.jsm", + }, + child: { + moduleURI: "chrome://marionette/content/actors/MarionetteEventsChild.jsm", + events: { + beforeunload: { capture: true }, + DOMContentLoaded: { mozSystemGroup: true }, + hashchange: { mozSystemGroup: true }, + pagehide: { mozSystemGroup: true }, + pageshow: { mozSystemGroup: true }, + // popstate doesn't bubble, as such use capturing phase + popstate: { capture: true, mozSystemGroup: true }, + }, + }, + + allFrames: true, + includeChrome: true, + }); +} + +function unregisterEventsActor() { + ChromeUtils.unregisterWindowActor("MarionetteEvents"); +} diff --git a/testing/marionette/navigate.js b/testing/marionette/navigate.js index d70b6834fab2..5daecae9193c 100644 --- a/testing/marionette/navigate.js +++ b/testing/marionette/navigate.js @@ -19,8 +19,12 @@ XPCOMUtils.defineLazyModuleGetters(this, { MarionettePrefs: "chrome://marionette/content/prefs.js", modal: "chrome://marionette/content/modal.js", PageLoadStrategy: "chrome://marionette/content/capabilities.js", + registerEventsActor: + "chrome://marionette/content/actors/MarionetteEventsParent.jsm", TimedPromise: "chrome://marionette/content/sync.js", truncate: "chrome://marionette/content/format.js", + unregisterEventsActor: + "chrome://marionette/content/actors/MarionetteEventsParent.jsm", }); XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get()); @@ -330,30 +334,7 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted( if (MarionettePrefs.useActors) { // Register the JSWindowActor pair for events as used by Marionette - ChromeUtils.registerWindowActor("MarionetteEvents", { - kind: "JSWindowActor", - parent: { - moduleURI: - "chrome://marionette/content/actors/MarionetteEventsParent.jsm", - }, - child: { - moduleURI: - "chrome://marionette/content/actors/MarionetteEventsChild.jsm", - events: { - beforeunload: { capture: true }, - DOMContentLoaded: { mozSystemGroup: true }, - hashchange: { mozSystemGroup: true }, - pagehide: { mozSystemGroup: true }, - pageshow: { mozSystemGroup: true }, - // popstate doesn't bubble, as such use capturing phase - popstate: { capture: true, mozSystemGroup: true }, - }, - }, - - allFrames: true, - includeChrome: true, - }); - + registerEventsActor(); EventDispatcher.on("page-load", onNavigation); } else { driver.mm.addMessageListener( @@ -406,7 +387,7 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted( if (MarionettePrefs.useActors) { EventDispatcher.off("page-load", onNavigation); - ChromeUtils.unregisterWindowActor("MarionetteEvents"); + unregisterEventsActor(); } else { driver.mm.removeMessageListener( "Marionette:NavigationEvent",