Bug 1368439 - Retrieve content browser title via parent process. draft
authorHenrik Skupin <mail@hskupin.info>
Sun, 02 Jul 2017 04:31:18 -0700
changeset 603194 898a02f99675327e4b8b32c1caa4c76ce93f597a
parent 603193 5443e8f294906b6747eb4281b8d8a75b7c65e733
child 635830 9e7a2ab528c3e765036c9379aa535bfde2707b00
push id66679
push userbmo:hskupin@gmail.com
push dateSun, 02 Jul 2017 12:36:21 +0000
bugs1368439
milestone56.0a1
Bug 1368439 - Retrieve content browser title via parent process. To retrieve the title of the currently selected content browser it is not necessary to call into the frame script. Instead just take the value from the parent process directly. MozReview-Commit-ID: KEpYKLIydrJ
testing/marionette/browser.js
testing/marionette/driver.js
testing/marionette/listener.js
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -145,16 +145,35 @@ browser.Context = class {
     let rv = null;
     if (this.tab || this.driver.isReftestBrowser(this.contentBrowser)) {
       rv = this.getIdForBrowser(this.contentBrowser);
     }
     return rv;
   }
 
   /**
+   * Returns the current title of the content browser.
+   *
+   * @return {string}
+   *     Read-only property containing the current title.
+   *
+   * @throws {NoSuchWindowError}
+   *     If the current ChromeWindow does not have a content browser.
+   */
+  get currentTitle() {
+    // Bug 1363368 - contentBrowser could be null until we wait for its
+    // initialization been finished
+    if (this.contentBrowser) {
+      return this.contentBrowser.contentTitle;
+    }
+    throw new NoSuchWindowError(
+        "Current window does not have a content browser");
+  }
+
+  /**
    * Returns the current URI of the content browser.
    *
    * @return {nsIURI}
    *     Read-only property containing the currently loaded URL.
    *
    * @throws {NoSuchWindowError}
    *     If the current ChromeWindow does not have a content browser.
    */
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -190,16 +190,32 @@ Object.defineProperty(GeckoDriver.protot
         return new URL(this.curBrowser.currentURI.spec);
 
       default:
         throw TypeError(`Unknown context: ${this.context}`);
     }
   },
 });
 
+Object.defineProperty(GeckoDriver.prototype, "title", {
+  get() {
+    switch (this.context) {
+      case Context.CHROME:
+        let chromeWin = this.getCurrentWindow();
+        return chromeWin.document.documentElement.getAttribute("title");
+
+      case Context.CONTENT:
+        return this.curBrowser.currentTitle;
+
+      default:
+        throw TypeError(`Unknown context: ${this.context}`);
+    }
+  },
+});
+
 Object.defineProperty(GeckoDriver.prototype, "proxy", {
   get() {
     return this.capabilities.get("proxy");
   },
 });
 
 Object.defineProperty(GeckoDriver.prototype, "secureTLS", {
   get() {
@@ -1011,28 +1027,20 @@ GeckoDriver.prototype.getCurrentUrl = fu
  *     Document title of the top-level browsing context.
  *
  * @throws {NoSuchWindowError}
  *     Top-level browsing context has been discarded.
  * @throws {UnexpectedAlertOpenError}
  *     A modal dialog is open, blocking this operation.
  */
 GeckoDriver.prototype.getTitle = function* (cmd, resp) {
-  const win = assert.window(this.getCurrentWindow());
+  assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
-  switch (this.context) {
-    case Context.CHROME:
-      resp.body.value = win.document.documentElement.getAttribute("title");
-      break;
-
-    case Context.CONTENT:
-      resp.body.value = yield this.listener.getTitle();
-      break;
-  }
+  return this.title;
 };
 
 /** Gets the current type of the window. */
 GeckoDriver.prototype.getWindowType = function(cmd, resp) {
   let win = assert.window(this.getCurrentWindow());
 
   resp.body.value = win.document.documentElement.getAttribute("windowtype");
 };
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -488,17 +488,16 @@ function addMessageListenerId(messageNam
 
 /**
  * Remove a message listener that's tied to our listenerId.
  */
 function removeMessageListenerId(messageName, handler) {
   removeMessageListener(messageName + listenerId, handler);
 }
 
-var getTitleFn = dispatch(getTitle);
 var getPageSourceFn = dispatch(getPageSource);
 var getActiveElementFn = dispatch(getActiveElement);
 var getElementAttributeFn = dispatch(getElementAttribute);
 var getElementPropertyFn = dispatch(getElementProperty);
 var getElementTextFn = dispatch(getElementText);
 var getElementTagNameFn = dispatch(getElementTagName);
 var getElementRectFn = dispatch(getElementRect);
 var isElementEnabledFn = dispatch(isElementEnabled);
@@ -530,17 +529,16 @@ function startListeners() {
   addMessageListenerId("Marionette:singleTap", singleTapFn);
   addMessageListenerId("Marionette:performActions", performActionsFn);
   addMessageListenerId("Marionette:releaseActions", releaseActionsFn);
   addMessageListenerId("Marionette:actionChain", actionChainFn);
   addMessageListenerId("Marionette:multiAction", multiActionFn);
   addMessageListenerId("Marionette:get", get);
   addMessageListenerId("Marionette:waitForPageLoaded", waitForPageLoaded);
   addMessageListenerId("Marionette:cancelRequest", cancelRequest);
-  addMessageListenerId("Marionette:getTitle", getTitleFn);
   addMessageListenerId("Marionette:getPageSource", getPageSourceFn);
   addMessageListenerId("Marionette:goBack", goBack);
   addMessageListenerId("Marionette:goForward", goForward);
   addMessageListenerId("Marionette:refresh", refresh);
   addMessageListenerId("Marionette:findElementContent", findElementContentFn);
   addMessageListenerId(
       "Marionette:findElementsContent", findElementsContentFn);
   addMessageListenerId("Marionette:getActiveElement", getActiveElementFn);
@@ -604,17 +602,16 @@ function deleteSession(msg) {
   removeMessageListenerId("Marionette:singleTap", singleTapFn);
   removeMessageListenerId("Marionette:performActions", performActionsFn);
   removeMessageListenerId("Marionette:releaseActions", releaseActionsFn);
   removeMessageListenerId("Marionette:actionChain", actionChainFn);
   removeMessageListenerId("Marionette:multiAction", multiActionFn);
   removeMessageListenerId("Marionette:get", get);
   removeMessageListenerId("Marionette:waitForPageLoaded", waitForPageLoaded);
   removeMessageListenerId("Marionette:cancelRequest", cancelRequest);
-  removeMessageListenerId("Marionette:getTitle", getTitleFn);
   removeMessageListenerId("Marionette:getPageSource", getPageSourceFn);
   removeMessageListenerId("Marionette:goBack", goBack);
   removeMessageListenerId("Marionette:goForward", goForward);
   removeMessageListenerId("Marionette:refresh", refresh);
   removeMessageListenerId(
       "Marionette:findElementContent", findElementContentFn);
   removeMessageListenerId(
       "Marionette:findElementsContent", findElementsContentFn);
@@ -1237,23 +1234,16 @@ function refresh(msg) {
     }, command_id, pageTimeout);
 
   } catch (e) {
     sendError(e, command_id);
   }
 }
 
 /**
- * Get the title of the current browsing context.
- */
-function getTitle() {
-  return curContainer.frame.top.document.title;
-}
-
-/**
  * Get source of the current browsing context's DOM.
  */
 function getPageSource() {
   return curContainer.frame.document.documentElement.outerHTML;
 }
 
 /**
  * Find an element in the current browsing context's document using the