Bug 1423209 - Drop ability to put frame script to sleep. r=automatedtester
authorAndreas Tolfsen <ato@sny.no>
Tue, 05 Dec 2017 17:07:36 +0000
changeset 708683 b7b56045fab4fad2bf3be4515bb34bff5d66f74e
parent 708682 ea00ea69cb7e1b80a9cb31cf797efa891cbccc5f
child 708684 155c25df7f182c58baa2d493aa5c056f14c724c6
child 708946 78321e46393020c54dc8098f09f3a5412f79528d
push id92403
push userVYV03354@nifty.ne.jp
push dateWed, 06 Dec 2017 22:18:41 +0000
reviewersautomatedtester
bugs1423209
milestone59.0a1
Bug 1423209 - Drop ability to put frame script to sleep. r=automatedtester Marionette has a Marionette:sleepSession IPC command it uses to put a content frame script "to sleep". This removes certain message handlers and clears some state by calling deleteSession() in listener.js. The frame script can later be "restarted" by calling Marionette:restart. This is B2G-specific functionality we no longer need. In an effort to remove old cruft from Marionette before tackling the window tracking refactoring we want to remove support for this. This removes the Marionette:sleepSession and Marionette:restart IPC messages as well as GeckoDriver#switchToGlobalMessageManager. The latter function additionally resets GeckoDriver#mm to the global message manager which is fine, because for Firefox/Fennec we never use the targetted message manager. There will be a follow-up bug to remove OOP frame handling and the targetted message manager used in GeckoDriver#sendAsync. MozReview-Commit-ID: GRSBReBfQGX
testing/marionette/driver.js
testing/marionette/frame.js
testing/marionette/listener.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -289,34 +289,16 @@ GeckoDriver.prototype.globalModalDialogH
   if (topic === modal.COMMON_DIALOG_LOADED) {
     // Always keep a weak reference to the current dialog
     winr = Cu.getWeakReference(subject);
   }
   this.dialog = new modal.Dialog(() => this.curBrowser, winr);
 };
 
 /**
- * Switches to the global ChromeMessageBroadcaster, potentially replacing
- * a frame-specific ChromeMessageSender.  Has no effect if the global
- * ChromeMessageBroadcaster is already in use.  If this replaces a
- * frame-specific ChromeMessageSender, it removes the message listeners
- * from that sender, and then puts the corresponding frame script "to
- * sleep", which removes most of the message listeners from it as well.
- */
-GeckoDriver.prototype.switchToGlobalMessageManager = function() {
-  if (this.curBrowser &&
-      this.curBrowser.frameManager.currentRemoteFrame !== null) {
-    this.curBrowser.frameManager.removeMessageManagerListeners(this.mm);
-    this.sendAsync("sleepSession");
-    this.curBrowser.frameManager.currentRemoteFrame = null;
-  }
-  this.mm = globalMessageManager;
-};
-
-/**
  * Helper method to send async messages to the content listener.
  * Correct usage is to pass in the name of a function in listener.js,
  * a serialisable object, and optionally the current command's ID
  * when not using the modern dispatching technique.
  *
  * @param {string} name
  *     Suffix of the targetted message listener
  *     <tt>Marionette:SUFFIX</tt>.
@@ -423,17 +405,16 @@ GeckoDriver.prototype.isReftestBrowser =
     element.parentElement.id === "reftest";
 };
 
 GeckoDriver.prototype.addFrameCloseListener = function(action) {
   let win = this.getCurrentWindow();
   this.mozBrowserClose = e => {
     if (e.target.id == this.oopFrameId) {
       win.removeEventListener("mozbrowserclose", this.mozBrowserClose, true);
-      this.switchToGlobalMessageManager();
       throw new NoSuchWindowError("The window closed during action: " + action);
     }
   };
   win.addEventListener("mozbrowserclose", this.mozBrowserClose, true);
 };
 
 /**
  * Create a new browsing context for window and add to known browsers.
@@ -805,21 +786,19 @@ GeckoDriver.prototype.newSession = async
 
   if (!Preferences.get(CONTENT_LISTENER_PREF)) {
     waitForWindow.call(this);
   } else if (this.appId != APP_ID_FIREFOX && this.curBrowser === null) {
     // if there is a content listener, then we just wake it up
     let win = this.getCurrentWindow();
     this.addBrowser(win);
     this.whenBrowserStarted(win, false);
-    this.mm.broadcastAsyncMessage("Marionette:restart", {});
   } else {
     throw new WebDriverError("Session already running");
   }
-  this.switchToGlobalMessageManager();
 
   await registerBrowsers;
   await browserListening;
 
   if (this.curBrowser.tab) {
     this.curBrowser.contentBrowser.focus();
   }
 
@@ -1876,25 +1855,16 @@ GeckoDriver.prototype.switchToFrame = as
       }
       checkTimer.initWithCallback(
           checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
     } else {
       throw new NoSuchFrameError(`Unable to locate frame: ${id}`);
     }
 
   } else if (this.context == Context.Content) {
-    if (!id && !byFrame &&
-        this.curBrowser.frameManager.currentRemoteFrame !== null) {
-      // We're currently using a ChromeMessageSender for a remote frame,
-      // so this request indicates we need to switch back to the top-level
-      // (parent) frame.  We'll first switch to the parent's (global)
-      // ChromeMessageBroadcaster, so we send the message to the right
-      // listener.
-      this.switchToGlobalMessageManager();
-    }
     cmd.commandID = cmd.id;
 
     let res = await this.listener.switchToFrame(cmd.parameters);
     if (res) {
       let {win: winId, frame: frameId} = res;
       this.mm = this.curBrowser.frameManager.getFrameMM(winId, frameId);
 
       let registerBrowsers = this.registerPromise();
@@ -2819,20 +2789,16 @@ GeckoDriver.prototype.close = async func
 
   // If there is only one window left, do not close it. Instead return
   // a faked empty array of window handles.  This will instruct geckodriver
   // to terminate the application.
   if (nwins === 1) {
     return [];
   }
 
-  if (this.mm != globalMessageManager) {
-    this.mm.removeDelayedFrameScript(FRAME_SCRIPT);
-  }
-
   await this.curBrowser.closeTab();
   return this.windowHandles.map(String);
 };
 
 /**
  * Close the currently selected chrome window.
  *
  * If it is the last window currently open, the chrome window will not be
@@ -2858,20 +2824,16 @@ GeckoDriver.prototype.closeChromeWindow 
   // to terminate the application.
   if (nwins == 1) {
     return [];
   }
 
   // reset frame to the top-most frame
   this.curFrame = null;
 
-  if (this.mm != globalMessageManager) {
-    this.mm.removeDelayedFrameScript(FRAME_SCRIPT);
-  }
-
   await this.curBrowser.closeWindow();
   return this.chromeWindowHandles.map(String);
 };
 
 /** Delete Marionette session. */
 GeckoDriver.prototype.deleteSession = function() {
   if (this.curBrowser !== null) {
     // frame scripts can be safely reused
@@ -2894,18 +2856,16 @@ GeckoDriver.prototype.deleteSession = fu
             `Could not remove listener from page ${win.location.href}`);
       }
     }
 
     this.curBrowser.frameManager.removeMessageManagerListeners(
         globalMessageManager);
   }
 
-  this.switchToGlobalMessageManager();
-
   // reset frame to the top-most frame
   this.curFrame = null;
   if (this.mainFrame) {
     try {
       this.mainFrame.focus();
     } catch (e) {
       this.mainFrame = null;
     }
--- a/testing/marionette/frame.js
+++ b/testing/marionette/frame.js
@@ -159,17 +159,16 @@ frame.Manager = class {
           continue;
         }
       }
 
       if (fmm == mm) {
         this.currentRemoteFrame = f;
         this.addMessageManagerListeners(mm);
 
-        mm.sendAsyncMessage("Marionette:restart");
         return oopFrame.id;
       }
     }
 
     // if we get here, then we need to load the frame script in this frame,
     // and set the frame's ChromeMessageSender as the active message manager
     // the driver will listen to.
     this.addMessageManagerListeners(mm);
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -569,50 +569,32 @@ function startListeners() {
   addMessageListenerId("Marionette:isElementEnabled", isElementEnabledFn);
   addMessageListenerId("Marionette:isElementSelected", isElementSelectedFn);
   addMessageListenerId("Marionette:sendKeysToElement", sendKeysToElementFn);
   addMessageListenerId("Marionette:clearElement", clearElementFn);
   addMessageListenerId("Marionette:switchToFrame", switchToFrame);
   addMessageListenerId("Marionette:switchToParentFrame", switchToParentFrame);
   addMessageListenerId("Marionette:switchToShadowRoot", switchToShadowRootFn);
   addMessageListenerId("Marionette:deleteSession", deleteSession);
-  addMessageListenerId("Marionette:sleepSession", sleepSession);
   addMessageListenerId("Marionette:takeScreenshot", takeScreenshotFn);
   addMessageListenerId("Marionette:reftestWait", reftestWaitFn);
   addMessageListener("Marionette:DOM:AddEventListener", domAddEventListener);
   addMessageListener("Marionette:DOM:RemoveEventListener", domRemoveEventListener);
 }
 
 /**
  * Called when we start a new session. It registers the
  * current environment, and resets all values
  */
 function newSession(msg) {
   capabilities = session.Capabilities.fromJSON(msg.json);
   resetValues();
 }
 
 /**
- * Puts the current session to sleep, so all listeners are removed except
- * for the 'restart' listener.
- */
-function sleepSession() {
-  deleteSession();
-  addMessageListener("Marionette:restart", restart);
-}
-
-/**
- * Restarts all our listeners after this listener was put to sleep
- */
-function restart() {
-  removeMessageListener("Marionette:restart", restart);
-  registerSelf();
-}
-
-/**
  * Removes all listeners
  */
 function deleteSession() {
   removeMessageListenerId("Marionette:newSession", newSession);
   removeMessageListenerId("Marionette:execute", executeFn);
   removeMessageListenerId("Marionette:executeInSandbox", executeInSandboxFn);
   removeMessageListenerId("Marionette:singleTap", singleTapFn);
   removeMessageListenerId("Marionette:performActions", performActionsFn);
@@ -653,17 +635,16 @@ function deleteSession() {
       "Marionette:sendKeysToElement", sendKeysToElementFn);
   removeMessageListenerId("Marionette:clearElement", clearElementFn);
   removeMessageListenerId("Marionette:switchToFrame", switchToFrame);
   removeMessageListenerId(
       "Marionette:switchToParentFrame", switchToParentFrame);
   removeMessageListenerId(
       "Marionette:switchToShadowRoot", switchToShadowRootFn);
   removeMessageListenerId("Marionette:deleteSession", deleteSession);
-  removeMessageListenerId("Marionette:sleepSession", sleepSession);
   removeMessageListenerId("Marionette:takeScreenshot", takeScreenshotFn);
 
   seenEls.clear();
   // reset container frame to the top-most frame
   curContainer = {frame: content, shadowRoot: null};
   curContainer.frame.focus();
   legacyactions.touchIds = {};
   if (action.inputStateMap !== undefined) {