Bug 869536 - Make Marionette use its own tab on Firefox, r=mdas
authorJonathan Griffin <jgriffin@mozilla.com>
Fri, 17 May 2013 11:43:52 -0700
changeset 143772 c3b24901a5184f9b26ae4fc5da1e037b9b17b143
parent 143771 8ed13280c8116ed1b09ff4919b0987bf9cb8e9f4
child 143773 e5e7221a2c8279fb383d9fc429fe4ee4789b7e41
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs869536
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 869536 - Make Marionette use its own tab on Firefox, r=mdas
testing/marionette/client/marionette/geckoinstance.py
testing/marionette/marionette-actors.js
--- a/testing/marionette/client/marionette/geckoinstance.py
+++ b/testing/marionette/client/marionette/geckoinstance.py
@@ -26,23 +26,27 @@ class GeckoInstance(object):
         profile_path = self.profile
         profile_args = {"preferences": self.required_prefs}
         if not profile_path:
             runner_class = Runner
             profile_args["restore"] = False
         else:
             runner_class = CloneRunner
             profile_args["path_from"] = profile_path
+
+        self.gecko_log = os.path.abspath('gecko.log')
+        if os.access(self.gecko_log, os.F_OK):
+            os.remove(self.gecko_log)
         self.runner = runner_class.create(
             binary=self.bin,
             profile_args=profile_args,
             cmdargs=['-no-remote'],
             kp_kwargs={
                 'processOutputLine': [NullOutput()],
-                'logfile': os.path.abspath('gecko.log')})
+                'logfile': self.gecko_log})
         self.runner.start()
 
     def close(self):
         self.runner.stop()
         self.runner.cleanup()
 
 
 class B2GDesktopInstance(GeckoInstance):
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1079,19 +1079,19 @@ MarionetteDriverActor.prototype = {
   },
 
   /**
    * Gets the page source of the content document
    */
   getPageSource: function MDA_getPageSource(){
     this.command_id = this.getCommandId();
     if (this.context == "chrome"){
-      var curWindow = this.getCurrentWindow();
-      var XMLSerializer = curWindow.XMLSerializer; 
-      var pageSource = new XMLSerializer().serializeToString(curWindow.document);
+      let curWindow = this.getCurrentWindow();
+      let XMLSerializer = curWindow.XMLSerializer; 
+      let pageSource = new XMLSerializer().serializeToString(curWindow.document);
       this.sendResponse(pageSource, this.command_id);
     }
     else {
       this.sendAsync("getPageSource", {}, this.command_id);
     }
   },
 
   /**
@@ -1187,30 +1187,30 @@ MarionetteDriverActor.prototype = {
    *        'value' if element is not set, then this
    *                holds either the id, name or index 
    *                of the frame to switch to
    */
   switchToFrame: function MDA_switchToFrame(aRequest) {
     let command_id = this.command_id = this.getCommandId();
     this.logRequest("switchToFrame", aRequest);
     let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    let curWindow = this.getCurrentWindow();
     let checkLoad = function() { 
       let errorRegex = /about:.+(error)|(blocked)\?/;
       if (curWindow.document.readyState == "complete") { 
         this.sendOk(command_id);
         return;
       } 
       else if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)) {
         this.sendError("Error loading page", 13, null, command_id);
         return;
       }
       
       checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
     }
-    let curWindow = this.getCurrentWindow();
     if (this.context == "chrome") {
       let foundFrame = null;
       if ((aRequest.value == null) && (aRequest.element == null)) {
         this.curFrame = null;
         if (aRequest.focus) {
           this.mainFrame.focus();
         }
         checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
@@ -2162,19 +2162,19 @@ MarionetteDriverActor.prototype = {
         try {
           browserType = message.target.getAttribute("type");
         } catch (ex) {
           // browserType remains undefined.
         }
         let reg = {};
         if (!browserType || browserType != "content") {
           reg.id = this.curBrowser.register(this.generateFrameId(message.json.value),
-                                         message.json.href); 
+                                            listenerWindow);
         }
-        this.curBrowser.elementManager.seenItems[reg.id] = Cu.getWeakReference(listenerWindow); //add to seenItems
+        this.curBrowser.elementManager.seenItems[reg.id] = Cu.getWeakReference(listenerWindow);
         reg.importedScripts = this.importedScripts.path;
         if (nullPrevious && (this.curBrowser.curFrameId != null)) {
           if (!this.sendAsync("newSession",
                               { B2G: (appName == "B2G") },
                               this.newSessionCommandId)) {
             return;
           }
           if (this.curBrowser.newSession) {
@@ -2294,17 +2294,17 @@ BrowserObj.prototype = {
    * @param boolean newTab
    *        If true, create new tab
    */
   startSession: function BO_startSession(newTab, win, callback) {
     if (appName != "Firefox") {
       callback(win, newTab);
     }
     else if (newTab) {
-      this.addTab(this.startPage);
+      this.tab = this.addTab(this.startPage);
       //if we have a new tab, make it the selected tab
       this.browser.selectedTab = this.tab;
       let newTabBrowser = this.browser.getBrowserForTab(this.tab);
       // wait for tab to be loaded
       newTabBrowser.addEventListener("load", function onLoad() {
         newTabBrowser.removeEventListener("load", onLoad, true);
         callback(win, newTab);
       }, true);
@@ -2330,17 +2330,17 @@ BrowserObj.prototype = {
 
   /**
    * Opens a tab with given uri
    *
    * @param string uri
    *      URI to open
    */
   addTab: function BO_addTab(uri) {
-    this.tab = this.browser.addTab(uri, true);
+    return this.browser.addTab(uri, true);
   },
 
   /**
    * Loads content listeners if we don't already have them
    *
    * @param string script
    *        path of script to load
    * @param nsIDOMWindow frame
@@ -2353,23 +2353,28 @@ BrowserObj.prototype = {
 
   /**
    * Registers a new frame, and sets its current frame id to this frame
    * if it is not already assigned, and if a) we already have a session 
    * or b) we're starting a new session and it is the right start frame.
    *
    * @param string uid
    *        frame uid
-   * @param string href
-   *        frame's href 
+   * @param object frameWindow
+   *        the DOMWindow object of the frame that's being registered
    */
-  register: function BO_register(uid, href) {
+  register: function BO_register(uid, frameWindow) {
     if (this.curFrameId == null) {
-      if ((!this.newSession) || (this.newSession && 
-          ((appName != "Firefox") || href.indexOf(this.startPage) > -1))) {
+      // If we're setting up a new session on Firefox, we only process the
+      // registration for this frame if it belongs to the tab we've just
+      // created.
+      if ((!this.newSession) ||
+          (this.newSession &&
+            ((appName != "Firefox") ||
+             frameWindow == this.browser.getBrowserForTab(this.tab).contentWindow))) {
         this.curFrameId = uid;
         this.mainContentId = uid;
       }
     }
     this.knownFrames.push(uid); //used to delete sessions
     return uid;
   },
 }